libUTL++
Deque.h
1 #pragma once
2 
4 
5 #include <libutl/SortedCollection.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
13 class DequeIt;
14 
16 
26 
28 class Deque : public SortedCollection
29 {
30  friend class DequeIt;
32 
33 public:
34  typedef DequeIt iterator;
35 
36 public:
42  Deque(bool owner, Ordering* ordering = nullptr);
43 
44  virtual void steal(Object& rhs);
45 
46  virtual size_t innerAllocatedSize() const;
47 
49 
50 
51  Object*
52  front() const
53  {
54  return first();
55  }
56 
58  Object*
59  back() const
60  {
61  return last();
62  }
63 
64  Object* get(size_t idx) const;
66 
68 
69  iterator findIt(const Object& key) const;
70 
71  iterator findIt(const Object& key);
72 
73  void
74  findIt(const Object& key, BidIt& it) const
75  {
76  const_cast_this->findIt(key, it);
77  IFDEBUG(it.setConst(true));
78  }
79 
80  virtual void findIt(const Object& key, BidIt& it);
82 
84 
85  bool
86  add(const Object& object)
87  {
88  return super::add(object);
89  }
90 
91  virtual bool add(const Object* object);
92 
93  void
94  add(const Collection& collection)
95  {
96  super::add(collection);
97  }
98 
100  bool
101  pushFront(const Object& object)
102  {
103  return isOwner() ? pushFront(object.clone()) : pushFront(&object);
104  }
105 
107  bool
108  pushBack(const Object& object)
109  {
110  return isOwner() ? pushBack(object.clone()) : pushBack(&object);
111  }
112 
114  bool pushFront(const Object* object);
115 
117  bool pushBack(const Object* object);
119 
121 
122 
123  virtual void clear();
124 
126  bool removeFront();
127 
129  bool removeBack();
130 
132  Object* popFront();
133 
135  Object* popBack();
137 
139 
140  inline iterator begin() const;
141 
142  inline iterator begin();
143 
144  inline virtual BidIt* beginNew() const;
145 
146  inline virtual BidIt* beginNew();
147 
148  inline iterator end() const;
149 
150  inline iterator end();
151 
152  inline virtual BidIt* endNew() const;
153 
154  inline virtual BidIt* endNew();
156 
157 private:
158  void init(bool owner = true, Ordering* ordering = nullptr);
159  void deInit();
160 
161  void grow();
162 
163  void next(Object***& blockPtr, uint32_t& blockPos);
164  void prev(Object***& blockPtr, uint32_t& blockPos);
165 
166 private:
167  Object*** _blocks;
168  Object*** _blocksLim;
169  Object*** _beginBlock;
170  Object*** _endBlock;
171  uint32_t _beginPos;
172  uint32_t _endPos;
173 };
174 
176 
177 UTL_NS_END;
178 
180 
181 #include <libutl/TDeque.h>
bool pushFront(const Object &object)
Add the given object at the front end.
Definition: Deque.h:101
T * clone(const T *object)
Create a clone of the given object.
Definition: util_inl.h:404
#define const_cast_this
Pointer to the object the method was invoked on (casting away const).
Definition: macros.h:41
void deInit()
De-initialize UTL++.
Object * back() const
Return the object at the back end (nullptr if none).
Definition: Deque.h:59
Object comparison abstraction.
Definition: Ordering.h:30
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
Templated proxy for BidIt.
Definition: TBidIt.h:19
#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
bool pushBack(const Object &object)
Add the given object at the back end.
Definition: Deque.h:108
Abstraction for a Collection whose objects may be sorted.
void setConst(bool p_const)
Set the const flag.
Definition: FwdIt.h:68
Bi-directional iterator abstraction.
Definition: BidIt.h:25
Object * front() const
Return the object at the front end (nullptr if none).
Definition: Deque.h:52
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
void init()
Initialize UTL++.
A collection of objects.
Definition: Collection.h:62