libUTL++
FwdIt.h
1 #pragma once
2 
4 
5 #include <libutl/FlagsMI.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
24 
26 class FwdIt : public Object, protected FlagsMI
27 {
29 
30 public:
35  virtual int compare(const Object& rhs) const;
36 
40  virtual void copy(const Object& rhs);
41 
47  virtual void forward(size_t dist = 1) = 0;
48 
53  virtual Object* get() const = 0;
54 
60  bool
61  isConst() const
62  {
63  return getFlag(flg_const);
64  }
65 
67  void
68  setConst(bool p_const)
69  {
70  setFlag(flg_const, p_const);
71  }
72 
77  virtual bool
78  isEnd() const
79  {
80  return (get() == nullptr);
81  }
82 
90  virtual void set(const Object* object) = 0;
91 
97  Object* operator*() const
98  {
99  return get();
100  }
101 
107  {
108  forward();
109  return *this;
110  }
111 
116  void operator++(int)
117  {
118  forward();
119  }
120 
126  FwdIt& operator+=(size_t dist)
127  {
128  forward(dist);
129  return *this;
130  }
131 
132 #ifdef DEBUG
133 
134  bool isValid(const utl::Object* owner = nullptr) const;
135 
137  void
138  invalidate() const
139  {
140  _owner = nullptr;
141  }
142 
144  bool
145  hasSameOwner(const FwdIt* it) const
146  {
147  return (_owner == it->_owner);
148  }
149 
151  const Object*
152  owner() const
153  {
154  return _owner;
155  }
156 
158  void setOwner(const Object* owner, bool notifyOwner = true) const;
159 #endif
160 public:
161  // for STL
162  typedef Object* value_type;
163  typedef Object*& reference;
164  typedef Object** pointer;
165  typedef std::forward_iterator_tag iterator_category;
166  typedef std::ptrdiff_t difference_type;
167 
168 private:
169  enum flg_t
170  {
171  flg_const
172  };
173 
174 private:
175 #ifdef DEBUG
176  void init();
177  void deInit();
178 #else
179  void
180  init()
181  {
182  }
183  void
184  deInit()
185  {
186  }
187 #endif
188 #ifdef DEBUG
189  mutable const Object* _owner;
190  mutable bool _notifyOwner;
191 #endif
192 };
193 
195 
196 UTL_NS_END;
197 
199 
200 #include <libutl/TFwdIt.h>
void deInit()
De-initialize UTL++.
void invalidate() const
Invalidate the iterator.
Definition: FwdIt.h:138
virtual bool isEnd() const
Determine whether the iterator points to the end of the sequence.
Definition: FwdIt.h:78
bool isConst() const
Get the const flag.
Definition: FwdIt.h:61
FwdIt & operator++()
Pre-increment operator.
Definition: FwdIt.h:106
Mix-in to provide 64-bits for space-efficient storage of up to 64 boolean flags.
Definition: FlagsMI.h:25
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Definition: util_inl.h:690
Object * operator*() const
Pointer dereference operator.
Definition: FwdIt.h:97
void operator++(int)
Post-increment operator.
Definition: FwdIt.h:116
Forward iterator abstraction.
Definition: FwdIt.h:26
void setConst(bool p_const)
Set the const flag.
Definition: FwdIt.h:68
#define UTL_CLASS_DECL_ABC(DC, BC)
Declaration of standard UTL++ functionality for an abstract base class (ABC).
Definition: macros.h:650
bool hasSameOwner(const FwdIt *it) const
Query if self has the same owner as the given iterator.
Definition: FwdIt.h:145
FwdIt & operator+=(size_t dist)
Increment operator.
Definition: FwdIt.h:126
Root of UTL++ class hierarchy.
Definition: Object.h:52
int compare(bool lhs, bool rhs)
Compare two boolean values.
void init()
Initialize UTL++.
const Object * owner() const
Get the owner.
Definition: FwdIt.h:152