libUTL++
DequeIt.h
1 #pragma once
2 
4 
5 #include <libutl/BidIt.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
20 
22 class DequeIt : public BidIt
23 {
25 
26 public:
33  DequeIt(const Deque* deque, Object*** blockPtr, uint32_t blockPos)
34  : _deque(const_cast<Deque*>(deque))
35  , _blockPtr(blockPtr)
36  , _blockPos(blockPos)
37  {
38  IFDEBUG(FwdIt::setOwner(deque));
39  }
40 
42  virtual int compare(const Object& rhs) const;
43 
45  virtual void copy(const Object& rhs);
46 
47  virtual void forward(size_t dist = 1);
48 
49  virtual void reverse(size_t dist = 1);
50 
51  virtual Object* get() const;
52 
54  Deque*
55  deque() const
56  {
57  return _deque;
58  }
59 
60  virtual void set(const Object* object);
61 
68  void
69  set(const Deque* deque, Object*** blockPtr, uint32_t blockPos)
70  {
71  _deque = const_cast<Deque*>(deque);
72  _blockPtr = blockPtr;
73  _blockPos = blockPos;
74  IFDEBUG(FwdIt::setOwner(deque));
75  }
76 
77  DequeIt& operator++()
78  {
79  forward();
80  return *this;
81  }
82 
83  DequeIt operator++(int)
84  {
85  DequeIt res = *this;
86  forward();
87  return res;
88  }
89 
90  DequeIt& operator--()
91  {
92  reverse();
93  return *this;
94  }
95 
96  DequeIt operator--(int)
97  {
98  DequeIt res = *this;
99  reverse();
100  return res;
101  }
102 
103 #ifdef DEBUG
104  bool isValid(const utl::Object* owner = nullptr) const;
105 #endif
106 
107 private:
108  void
109  init()
110  {
111  _deque = nullptr;
112  _blockPtr = nullptr;
113  _blockPos = uint32_t_max;
114  }
115  void
116  deInit()
117  {
118  }
119 
120 private:
121  Deque* _deque;
122  Object*** _blockPtr;
123  uint32_t _blockPos;
124 };
125 
127 
129 Deque::begin() const
130 {
131  DequeIt it(this, _beginBlock, _beginPos);
132  IFDEBUG(it.setConst(true));
133  return it;
134 }
135 
137 
139 Deque::begin()
140 {
141  return DequeIt(this, _beginBlock, _beginPos);
142 }
143 
145 
146 BidIt*
147 Deque::beginNew() const
148 {
149  BidIt* it = new DequeIt(this, _beginBlock, _beginPos);
150  IFDEBUG(it->setConst(true));
151  return it;
152 }
153 
155 
156 BidIt*
157 Deque::beginNew()
158 {
159  return new DequeIt(this, _beginBlock, _beginPos);
160 }
161 
163 
165 Deque::end() const
166 {
167  DequeIt it(this, _endBlock, _endPos);
168  IFDEBUG(it.setConst(true));
169  return it;
170 }
171 
173 
175 Deque::end()
176 {
177  return DequeIt(this, _endBlock, _endPos);
178 }
179 
181 
182 BidIt*
183 Deque::endNew() const
184 {
185  BidIt* it = new DequeIt(this, _endBlock, _endPos);
186  IFDEBUG(it->setConst(true));
187  return it;
188 }
189 
191 
192 BidIt*
193 Deque::endNew()
194 {
195  return new DequeIt(this, _endBlock, _endPos);
196 }
197 
199 
200 UTL_NS_END;
void deInit()
De-initialize UTL++.
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
const uint32_t uint32_t_max
Maximum uint32_t value.
void reverse(const BidIt &begin, const BidIt &end)
Reverse a sequence.
#define IFDEBUG(x)
Do x in DEBUG mode only.
Deque iterator.
Definition: DequeIt.h:22
unsigned int uint32_t
Unsigned 32-bit integer.
Definition: types.h:115
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Definition: util_inl.h:690
Deque * deque() const
Get the associated Deque.
Definition: DequeIt.h:55
DequeIt(const Deque *deque, Object ***blockPtr, uint32_t blockPos)
Constructor.
Definition: DequeIt.h:33
void setConst(bool p_const)
Set the const flag.
Definition: FwdIt.h:68
Bi-directional iterator abstraction.
Definition: BidIt.h:25
A sequence of objects permitting efficient insertion and removal at either end.
Definition: Deque.h:28
Root of UTL++ class hierarchy.
Definition: Object.h:52
int compare(bool lhs, bool rhs)
Compare two boolean values.
void init()
Initialize UTL++.