Bridges-C++  3.4.5-dev1-6-g935685a
Bridges(C++ API)
CircSLelement.h
Go to the documentation of this file.
1 #ifndef CIRC_SL_ELEMENT_H
2 
3 #define CIRC_SL_ELEMENT_H
4 #include "SLelement.h"
5 
6 namespace bridges {
7  namespace datastructure {
34  template <typename E>
35  class CircSLelement : public SLelement<E> {
36 
37  public:
43  CircSLelement() : SLelement<E> (this) {
44  }
54  CircSLelement (E val = E(), string label = string())
55  : SLelement<E> (this, val, label) {
56  }
57 
66  CircSLelement (E e = E(), CircSLelement *next = nullptr)
67  : SLelement<E> (next, e) {
68  }
69 
77  }
78 
84  virtual const string getDStype() const override {
85  return "CircularSinglyLinkedList";
86  }
87 
92  virtual CircSLelement<E> *getNext() override {
93  return static_cast<CircSLelement*> (SLelement<E>::getNext());
94  }
95 
103  }
104 
105  public:
112  *last;
113 
114  public:
116 
117  class iterator {
119  public:
121  : current(c)
122  {}
123 
124  bool operator!= (const iterator& it) const {
125  return this->current != it.current;
126  }
127 
128  E const & operator* () const {
129  return current->getValue();
130  }
131 
132  E & operator* () {
133  return current->getValue();
134  }
135 
137  current = current->getNext();
138  return *this;
139  }
141  iterator clone(*this);
142  current = current->getNext();
143  return clone;
144  }
145  };
146 
148  return iterator(start);
149  }
150 
152  return iterator(last);
153  }
154  };
155 
164  typename bridges::datastructure::CircSLelement<E> const * start, *last;
165 
166  public:
168  : start(s), last(s)
169  {}
170 
171  class iterator {
172 
173  typename bridges::datastructure::CircSLelement< E > const * current;
174  public:
176  : current(c)
177  {}
178 
179  bool operator!=(const iterator& it) const {
180  return this->current != it.current;
181  }
182 
183  E const & operator*() const {
184  return current->getValue();
185  }
186 
188  current = current->getNext();
189  return *this;
190  }
191  };
192 
194  return iterator(start);
195  }
196 
198  return iterator(last);
199  }
200  };
201 
202  }; // end CircSLelement
203  template <class E>
205  template <class E>
207 
208  }
209 } // namespace bridges
210 #endif
bool operator!=(const iterator &it) const
Definition: CircSLelement.h:179
iterator(typename bridges::datastructure::CircSLelement< E > const *c)
Definition: CircSLelement.h:175
these are helper classes for CircSLelement for easy iteration in a range for loop....
Definition: CircSLelement.h:163
CircSLelement_constlisthelper(typename bridges::datastructure::CircSLelement< E > const *s)
Definition: CircSLelement.h:167
E const & operator*() const
Definition: CircSLelement.h:128
iterator(typename bridges::datastructure::CircSLelement< E > *c)
Definition: CircSLelement.h:120
bool operator!=(const iterator &it) const
Definition: CircSLelement.h:124
This is a helper class to facilitate using iterators to traverse circular list.
Definition: CircSLelement.h:110
iterator begin()
Definition: CircSLelement.h:147
CircSLelement_listhelper(typename bridges::datastructure::CircSLelement< E > *s)
Definition: CircSLelement.h:115
This class can be used to instantiate Singly Linked Circular List Elements.
Definition: CircSLelement.h:35
CircSLelement()
Definition: CircSLelement.h:43
void setNext(CircSLelement< E > *next)
Definition: CircSLelement.h:101
virtual const string getDStype() const override
Definition: CircSLelement.h:84
CircSLelement(E val=E(), string label=string())
Definition: CircSLelement.h:54
CircSLelement(CircSLelement *next)
Definition: CircSLelement.h:76
CircSLelement(E e=E(), CircSLelement *next=nullptr)
Definition: CircSLelement.h:66
virtual CircSLelement< E > * getNext() override
Definition: CircSLelement.h:92
E const & getValue() const
Gets the object held in the generic object E.
Definition: Element.h:207
The singly linked list element, derived from Element.
Definition: SLelement.h:26
void setNext(SLelement *n)
Definition: SLelement.h:92
virtual SLelement * getNext()
Returns the next element in the list.
Definition: SLelement.h:74
SLelement * next
Definition: SLelement.h:29
typename CircSLelement< E >::CircSLelement_listhelper CircSLelement_List
Definition: CircSLelement.h:204
typename CircSLelement< E >::CircSLelement_constlisthelper CircSLelement_ConstList
Definition: CircSLelement.h:206
Support for drawing Bar charts.
Definition: alltypes.h:4