Public Types | Public Member Functions | Public Attributes | List of all members
IndexRange Class Reference

#include <IndexRange.h>

Public Types

using Index = unsigned int
 
using Name = std::string
 
using NameVector = std::vector< Name >
 

Public Member Functions

 IndexRange ()
 
 IndexRange (Index len)
 
 IndexRange (Index a_begin, Index a_end)
 
 IndexRange (Name a_name, Index a_begin, Index a_end, Name lab0="", Name lab1="", Name lab2="", Name lab3="")
 
 IndexRange (Name sran)
 
Index size () const
 
bool operator< (const IndexRange &rhs) const
 
bool isValid () const
 
Index first () const
 
Index last () const
 
std::string rangeString () const
 
void setLabel (Name lab)
 
void setLabel (Index ilab, Name lab)
 
Name label (Index ilab=0) const
 
bool contains (Index ival) const
 

Public Attributes

Name name
 
NameVector labels
 
Index begin =0
 
Index end =0
 

Detailed Description

Definition at line 23 of file IndexRange.h.

Member Typedef Documentation

using IndexRange::Index = unsigned int

Definition at line 27 of file IndexRange.h.

Definition at line 28 of file IndexRange.h.

Definition at line 29 of file IndexRange.h.

Constructor & Destructor Documentation

IndexRange::IndexRange ( )
inline

Definition at line 38 of file IndexRange.h.

38 { };
IndexRange::IndexRange ( Index  len)
inline

Definition at line 39 of file IndexRange.h.

39 : end(len) { }
Index end
Definition: IndexRange.h:35
IndexRange::IndexRange ( Index  a_begin,
Index  a_end 
)
inline

Definition at line 40 of file IndexRange.h.

40 : begin(a_begin), end(a_end) { }
Index begin
Definition: IndexRange.h:34
Index end
Definition: IndexRange.h:35
IndexRange::IndexRange ( Name  a_name,
Index  a_begin,
Index  a_end,
Name  lab0 = "",
Name  lab1 = "",
Name  lab2 = "",
Name  lab3 = "" 
)
inline

Definition at line 41 of file IndexRange.h.

43  : name(a_name), begin(a_begin), end(a_end) {
44  if ( lab0.size() ) setLabel(0, lab0);
45  if ( lab1.size() ) setLabel(1, lab1);
46  if ( lab2.size() ) setLabel(2, lab2);
47  if ( lab3.size() ) setLabel(3, lab3);
48  }
Index begin
Definition: IndexRange.h:34
Index end
Definition: IndexRange.h:35
Name name
Definition: IndexRange.h:32
void setLabel(Name lab)
Definition: IndexRange.h:101
IndexRange::IndexRange ( Name  sran)
inlineexplicit

Definition at line 50 of file IndexRange.h.

50  {
51  // name
52  std::string srem = sran;
53  std::string::size_type ipos = srem.find(":");
54  if ( ipos ==0 || ipos == std::string::npos ) return;
55  std::string nameTmp = srem.substr(0, ipos);
56  // begin
57  srem = srem.substr(ipos+1);
58  if ( srem.size() == 0 ) return;
59  ipos = srem.find(":");
60  if ( ipos ==0 || ipos == std::string::npos ) return;
61  std::string swrd = srem.substr(0, ipos);
62  if ( swrd.find_first_not_of("0123456789") != std::string::npos ) return;
63  Index beginTmp = std::stoi(swrd);
64  // end
65  srem = srem.substr(ipos+1);
66  if ( srem.size() == 0 ) return;
67  ipos = srem.find(":");
68  if ( ipos ==0 ) return;
69  swrd = srem.substr(0, ipos);
70  if ( swrd.find_first_not_of( "0123456789" ) != std::string::npos ) return;
71  Index endTmp = std::stoi(swrd);
72  if ( endTmp <= beginTmp ) return;
73  // We now have a valid range.
74  name = nameTmp;
75  begin = beginTmp;
76  end = endTmp;
77  // Add any labels.
78  Index ilab = 0;
79  while ( ipos != std::string::npos ) {
80  srem = srem.substr(ipos+1);
81  swrd = srem.substr(0, ipos);
82  ipos = srem.find(":");
83  setLabel(ilab++, swrd);
84  }
85  }
std::string string
Definition: nybbler.cc:12
Index begin
Definition: IndexRange.h:34
unsigned int Index
Index end
Definition: IndexRange.h:35
Name name
Definition: IndexRange.h:32
void setLabel(Name lab)
Definition: IndexRange.h:101

Member Function Documentation

bool IndexRange::contains ( Index  ival) const
inline

Definition at line 110 of file IndexRange.h.

110 { return ival >= begin && ival < end; }
Index begin
Definition: IndexRange.h:34
Index end
Definition: IndexRange.h:35
Index IndexRange::first ( ) const
inline

Definition at line 95 of file IndexRange.h.

95 { return begin; }
Index begin
Definition: IndexRange.h:34
bool IndexRange::isValid ( ) const
inline

Definition at line 94 of file IndexRange.h.

94 { return end > begin; }
Index begin
Definition: IndexRange.h:34
Index end
Definition: IndexRange.h:35
Name IndexRange::label ( Index  ilab = 0) const
inline

Definition at line 106 of file IndexRange.h.

106  {
107  if ( ilab >= labels.size() ) return "";
108  return labels[ilab];
109  }
NameVector labels
Definition: IndexRange.h:33
Index IndexRange::last ( ) const
inline

Definition at line 96 of file IndexRange.h.

96 { return end > 0 ? end - 1 : 0; }
Index end
Definition: IndexRange.h:35
bool IndexRange::operator< ( const IndexRange rhs) const
inline

Definition at line 91 of file IndexRange.h.

91 { return name < rhs.name; }
Name name
Definition: IndexRange.h:32
std::string IndexRange::rangeString ( ) const
inline

Definition at line 97 of file IndexRange.h.

97  {
98  if ( ! isValid() ) return "[]";
99  return "[" + std::to_string(begin) + ", " + std::to_string(end) + ")";
100  }
Index begin
Definition: IndexRange.h:34
bool isValid() const
Definition: IndexRange.h:94
Index end
Definition: IndexRange.h:35
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
void IndexRange::setLabel ( Name  lab)
inline

Definition at line 101 of file IndexRange.h.

101 { setLabel(0, lab); }
void setLabel(Name lab)
Definition: IndexRange.h:101
void IndexRange::setLabel ( Index  ilab,
Name  lab 
)
inline

Definition at line 102 of file IndexRange.h.

102  {
103  labels.resize(ilab+1, "");
104  labels[ilab] = lab;
105  }
NameVector labels
Definition: IndexRange.h:33
Index IndexRange::size ( ) const
inline

Definition at line 88 of file IndexRange.h.

88 { return end>begin ? end - begin : 0; }
Index begin
Definition: IndexRange.h:34
Index end
Definition: IndexRange.h:35

Member Data Documentation

Index IndexRange::begin =0

Definition at line 34 of file IndexRange.h.

Index IndexRange::end =0

Definition at line 35 of file IndexRange.h.

NameVector IndexRange::labels

Definition at line 33 of file IndexRange.h.

Name IndexRange::name

Definition at line 32 of file IndexRange.h.


The documentation for this class was generated from the following file: