Bridges-C++  3.1.1
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 
102  SLelement<E>::setNext(next);
103  }
104 
105  public:
108  *last;
109 
110  public:
112 
113  class iterator {
115  public:
117  : current(c)
118  {}
119 
120  bool operator!= (const iterator& it) const {
121  return this->current != it.current;
122  }
123 
124  E const & operator* () const {
125  return current->getValue();
126  }
127 
128  E & operator* () {
129  return current->getValue();
130  }
131 
133  current = current->getNext();
134  return *this;
135  }
137  iterator clone(*this);
138  current = current->getNext();
139  return clone;
140  }
141  };
142 
144  return iterator(start);
145  }
146 
148  return iterator(last);
149  }
150  };
151 
155  typename bridges::datastructure::CircSLelement<E> const * start, *last;
156 
157  public:
159  : start(s), last(s)
160  {}
161 
162  class iterator {
163 
164  typename bridges::datastructure::CircSLelement< E > const * current;
165  public:
167  : current(c)
168  {}
169 
170  bool operator!=(const iterator& it) const {
171  return this->current != it.current;
172  }
173 
174  E const & operator*() const {
175  return current->getValue();
176  }
177 
179  current = current->getNext();
180  return *this;
181  }
182  };
183 
185  return iterator(start);
186  }
187 
189  return iterator(last);
190  }
191  };
192 
193  }; // end CircSLelement
194  template <class E>
196  template <class E>
198 
199  }
200 } // namespace bridges
201 #endif
virtual CircSLelement< E > * getNext() override
Definition: CircSLelement.h:92
typename CircSLelement< E >::CircSLelement_constlisthelper CircSLelement_ConstList
Definition: CircSLelement.h:197
CircSLelement(E val=E(), string label=string())
Definition: CircSLelement.h:54
typename CircSLelement< E >::CircSLelement_listhelper CircSLelement_List
Definition: CircSLelement.h:195
E const & getValue() const
Definition: Element.h:195
iterator(typename bridges::datastructure::CircSLelement< E > const *c)
Definition: CircSLelement.h:166
SLelement * next
Definition: SLelement.h:30
these are helper classes for CircSLelement for easy iteration in a range for loop. It is not meant to be created by the bridges user. But it may be returned by Bridges to provide an STL compliant list API.
Definition: CircSLelement.h:154
E const & operator*() const
Definition: CircSLelement.h:124
virtual const string getDStype() const override
Definition: CircSLelement.h:84
CircSLelement_listhelper(typename bridges::datastructure::CircSLelement< E > *s)
Definition: CircSLelement.h:111
bool operator!=(const iterator &it) const
Definition: CircSLelement.h:120
bool operator!=(const iterator &it) const
Definition: CircSLelement.h:170
This class can be used to instantiate Singly Linked Circular List Elements.
Definition: CircSLelement.h:35
The singly linked list element, derived from Element.
Definition: SLelement.h:27
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
CircSLelement(CircSLelement *next)
Definition: CircSLelement.h:76
CircSLelement_constlisthelper(typename bridges::datastructure::CircSLelement< E > const *s)
Definition: CircSLelement.h:158
virtual SLelement * getNext()
Definition: SLelement.h:70
iterator(typename bridges::datastructure::CircSLelement< E > *c)
Definition: CircSLelement.h:116
CircSLelement()
Definition: CircSLelement.h:43
CircSLelement(E e=E(), CircSLelement *next=nullptr)
Definition: CircSLelement.h:66
iterator begin()
Definition: CircSLelement.h:143
void setNext(CircSLelement< E > *next)
Definition: CircSLelement.h:101
void setNext(SLelement *n)
Definition: SLelement.h:88