TF++, Miscellaneous classes and modules in C++:
rangelist.h
Go to the documentation of this file.
1 
36 // include guard
37 #ifndef TF_RANGELIST_H_VERSION
38 
39 #define TF_RANGELIST_H_VERSION \
40  "TF_RANGELIST_H V1.1"
41 
42 #include<tfxx/range.h>
43 #include<list>
44 
45 namespace tfxx {
46 
47  template<class T>
48  class RangeList {
49  public:
50  typedef T Tvalue;
52  typedef std::list<Trange> Tlist;
53  RangeList() { }
54  RangeList& append(const Trange& r)
55  { Mlist.push_back(r); return *this; }
56  void clear()
57  { Mlist.erase(Mlist.begin(), Mlist.end()); }
58  typename Tlist::size_type size() const { return Mlist.size(); }
59  bool contains(const Tvalue& v) const
60  {
61  bool retval=false;
62  typename Tlist::const_iterator i=Mlist.begin();
63  while ((i!=Mlist.end()) && (!retval))
64  { retval = i->contains(v); ++i; }
65  return retval;
66  }
67  Tlist list() const { return Mlist; }
68  private:
70  }; // template class RangeList
71 
72  /*----------------------------------------------------------------------*/
73 
74  template<class T>
76  public:
78  typedef typename Trangelist::Tvalue Tvalue;
79  typedef typename Trangelist::Tlist Tlist;
82  const Tvalue& stepsize=1):
83  Mlist(rangelist.list()), Mstepsize(stepsize),
84  Miterator(Mlist.begin()),
86  { }
88  Tvalue current() const { return(Mrangestepper.current()); }
90  operator Tvalue() const { return(this->current()); }
94  bool valid() const
95  {
96  return(Mrangestepper.valid() && (Miterator!=Mlist.end()));
97  }
99  bool more() const
100  {
101  bool retval=this->valid();
102  if (retval && (!Mrangestepper.more()))
103  {
104  typename Tlist::const_iterator I=Miterator;
105  ++I;
106  if (!(I!=Mlist.end())) { retval=false; }
107  }
108  return(retval);
109  }
112  {
113  if (this->valid())
114  {
115  if (Mrangestepper.more()) { Mrangestepper.next(); }
116  else {
117  ++Miterator;
118  if (Miterator != Mlist.end())
119  {
121  }
122  }
123  }
124  return(this->current());
125  }
127  Tvalue operator++() { return(this->next()); }
128  private:
129  Tlist Mlist;
131  typename Tlist::const_iterator Miterator;
133  }; // template class RangeListStepper
134 
135 
136 }
137 
138 #endif // TF_RANGELIST_H_VERSION (includeguard)
139 
140 /* ----- END OF rangelist.h ----- */
Trangelist::Tlist Tlist
Definition: rangelist.h:79
Tlist::size_type size() const
Definition: rangelist.h:58
Tvalue current() const
return current value in range list
Definition: rangelist.h:88
bool more() const
true if stepper is still in range after next step forward
Definition: rangelist.h:99
Tvalue next()
step forward and return current value
Definition: rangelist.h:111
bool valid() const
true if stepper is still in range and can return a current value
Definition: rangelist.h:94
Tvalue next()
advance to next value and return current value
Definition: range.h:132
RangeList & append(const Trange &r)
Definition: rangelist.h:54
RangeStepper< Tvalue > Trangestepper
Definition: rangelist.h:80
Trangestepper Mrangestepper
Definition: rangelist.h:132
Tvalue operator++()
step forward and return current value
Definition: rangelist.h:127
Tlist::const_iterator Miterator
Definition: rangelist.h:131
Tvalue current() const
return current value
Definition: range.h:124
bool contains(const Tvalue &v) const
Definition: rangelist.h:59
bool more() const
true if stepper will still be in range after next advance
Definition: range.h:130
Tlist list() const
Definition: rangelist.h:67
RangeList< T > Trangelist
Definition: rangelist.h:77
tfxx::Range< Tvalue > Trange
Definition: rangelist.h:51
tfxx::RangeList< T > rangelist(const std::string &s)
Definition: rangestring.h:98
Trangelist::Tvalue Tvalue
Definition: rangelist.h:78
void clear()
Definition: rangelist.h:56
bool valid() const
true if stepper is still in range and can return a current value
Definition: range.h:128
std::list< Trange > Tlist
Definition: rangelist.h:52
RangeListStepper(const Trangelist &rangelist, const Tvalue &stepsize=1)
Definition: rangelist.h:81
Namespace containing all code of library libtfxx.