libUTL++
HeapIt.h
1 #pragma once
2 
4 
5 #include <libutl/BidIt.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
20 
22 class HeapIt : public BidIt
23 {
25 
26 public:
32  HeapIt(const Heap* heap, size_t idx)
33  : _heap(const_cast<Heap*>(heap))
34  , _idx(idx)
35  {
36  IFDEBUG(FwdIt::setOwner(_heap));
37  }
38 
40  virtual int compare(const Object& rhs) const;
41 
43  virtual void copy(const Object& rhs);
44 
45  virtual void forward(size_t dist = 1);
46 
47  virtual Object* get() const;
48 
50  Heap*
51  getHeap() const
52  {
53  return _heap;
54  }
55 
57  size_t
58  getIdx() const
59  {
60  return _idx;
61  }
62 
63  virtual void reverse(size_t dist = 1);
64 
65  virtual void set(const Object* object);
66 
67  HeapIt& operator++()
68  {
69  forward();
70  return *this;
71  }
72 
73  HeapIt operator++(int)
74  {
75  HeapIt res = *this;
76  forward();
77  return res;
78  }
79 
80  HeapIt& operator--()
81  {
82  reverse();
83  return *this;
84  }
85 
86  HeapIt operator--(int)
87  {
88  HeapIt res = *this;
89  reverse();
90  return res;
91  }
92 
93 private:
94  void
95  init()
96  {
97  _heap = nullptr;
98  _idx = size_t_max;
99  }
100  void
101  deInit()
102  {
103  }
104 
105 private:
106  Heap* _heap;
107  size_t _idx;
108 };
109 
111 
113 Heap::begin() const
114 {
115  iterator it(this, 0);
116  IFDEBUG(it.setConst(true));
117  return it;
118 }
119 
121 
123 Heap::begin()
124 {
125  return iterator(this, 0);
126 }
127 
129 
130 BidIt*
131 Heap::beginNew() const
132 {
133  BidIt* it = new iterator(this, 0);
134  IFDEBUG(it->setConst(true));
135  return it;
136 }
137 
139 
140 BidIt*
141 Heap::beginNew()
142 {
143  return new iterator(this, 0);
144 }
145 
147 
149 Heap::end() const
150 {
151  iterator it(this, _items);
152  IFDEBUG(it.setConst(true));
153  return it;
154 }
155 
157 
159 Heap::end()
160 {
161  return iterator(this, _items);
162 }
163 
165 
166 BidIt*
167 Heap::endNew() const
168 {
169  BidIt* it = new iterator(this, _items);
170  IFDEBUG(it->setConst(true));
171  return it;
172 }
173 
175 
176 BidIt*
177 Heap::endNew()
178 {
179  return new iterator(this, _items);
180 }
181 
183 
184 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
HeapIt(const Heap *heap, size_t idx)
Constructor.
Definition: HeapIt.h:32
size_t getIdx() const
Get the heap index.
Definition: HeapIt.h:58
void reverse(const BidIt &begin, const BidIt &end)
Reverse a sequence.
Templated proxy for BidIt.
Definition: TBidIt.h:19
const size_t size_t_max
Maximum size_t value.
#define IFDEBUG(x)
Do x in DEBUG mode only.
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Definition: util_inl.h:690
Heap data structure.
Definition: Heap.h:55
Heap * getHeap() const
Get the associated Heap.
Definition: HeapIt.h:51
void setConst(bool p_const)
Set the const flag.
Definition: FwdIt.h:68
Bi-directional Heap iterator.
Definition: HeapIt.h:22
Bi-directional iterator abstraction.
Definition: BidIt.h:25
Root of UTL++ class hierarchy.
Definition: Object.h:52
int compare(bool lhs, bool rhs)
Compare two boolean values.
void init()
Initialize UTL++.