libUTL++
TArray.h
1 #pragma once
2 
4 
5 #include <libutl/Array.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
22 
24 template <class T>
25 class TArray : public Array
26 {
29 
30 public:
31  typedef T type;
32  typedef T* value_type; // for STL
33  typedef T* const* iterator;
34 
35 public:
45  TArray(size_t size,
46  size_t increment = uint_t_max,
47  bool owner = true,
48  bool multiSet = true,
49  bool keepSorted = false,
50  Ordering* ordering = nullptr)
51  : Array(size, increment, owner, multiSet, keepSorted, ordering)
52  {
53  }
54 
62  TArray(bool owner, bool multiSet = true, bool keepSorted = false, Ordering* ordering = nullptr)
63  : Array(owner, multiSet, keepSorted, ordering)
64  {
65  }
66 
68 
69  T*
70  get(size_t idx) const
71  {
72  return utl::cast<T>(Array::get(idx));
73  }
75 
77 
78  T*
79  findT(const Object& key) const
80  {
81  return utl::cast<T>(Array::find(key));
82  }
83 
84  iterator
85  findIt(const Object& key) const
86  {
87  return (iterator)Array::findIt(key);
88  }
89 
90  void
91  findIt(const Object& key, BidIt& it) const
92  {
93  super::findIt(key, it);
94  }
95 
96  void
97  findIt(const Object& key, BidIt& it)
98  {
99  super::findIt(key, it);
100  }
101 
102  iterator
103  findFirstIt(const Object& key, bool insert = false)
104  {
105  return (iterator)Array::findFirstIt(key, insert);
106  }
107 
108  void
109  findFirstIt(const Object& key, BidIt& it, bool insert = false) const
110  {
111  super::findFirstIt(key, it, insert);
112  }
113 
114  void
115  findFirstIt(const Object& key, BidIt& it, bool insert = false)
116  {
117  super::findFirstIt(key, it, insert);
118  }
119 
120  iterator
121  findLastIt(const Object& key)
122  {
123  return (iterator)Array::findLastIt(key);
124  }
125 
126  void
127  findLastIt(const Object& key, BidIt& it) const
128  {
129  super::findLastIt(key, it);
130  }
131 
132  void
133  findLastIt(const Object& key, BidIt& it)
134  {
135  super::findLastIt(key, it);
136  }
138 
140 
141  bool
142  add(const T& object)
143  {
144  return super::add(object);
145  }
146 
147  bool
148  add(const T* object)
149  {
150  return super::add(object);
151  }
152 
153  bool
154  add(const Object* object, bool keepSorted)
155  {
156  return super::add(object, keepSorted);
157  }
158 
159  void
160  add(const Collection& collection)
161  {
162  super::add(collection);
163  }
164 
165  void
166  add(size_t idx, size_t num = 1)
167  {
168  super::add(idx, num);
169  }
170 
171  void
172  add(size_t idx, const Object& object)
173  {
174  super::add(idx, object);
175  }
176 
177  void
178  add(size_t idx, const Object* object)
179  {
180  super::add(idx, object);
181  }
182 
183  void
184  insert(const Object& object, iterator it)
185  {
186  super::insert(object, (Array::iterator)it);
187  }
188 
189  void
190  insert(const Object* object, iterator it)
191  {
192  super::insert(object, (Array::iterator)it);
193  }
194 
195  void
196  insert(const Object& object, const BidIt& it)
197  {
198  super::insert(object, it);
199  }
200 
201  void
202  insert(const Object* object, const BidIt& it)
203  {
204  super::insert(object, it);
205  }
207 
209 
210  void
211  removeIt(iterator it)
212  {
213  super::removeIt((Array::iterator)it);
214  }
215 
216  void
217  removeIt(iterator begin, iterator end)
218  {
219  super::removeIt((Array::iterator)begin, (Array::iterator)end);
220  }
221 
222  void
224  {
225  super::removeIt(it);
226  }
227 
228  void
229  removeIt(BidIt& begin, BidIt& end)
230  {
231  super::removeIt(begin, end);
232  }
234 
236 
237  void
238  replace(iterator it, const Object* newObject)
239  {
240  super::replace((Array::iterator)it, newObject);
241  }
242 
243  void
244  replace(Array::base_iterator& it, const Object* newObject)
245  {
246  super::replace(it, newObject);
247  }
248 
249  void
250  replace(const Object* oldObject, const Object* newObject)
251  {
252  super::replace(oldObject, newObject);
253  }
254 
255  void
256  replace(size_t idx, const Object* newObject)
257  {
258  super::replace(idx, newObject);
259  }
261 
263 
264  void
265  relocate(iterator destIt, iterator srcIt)
266  {
267  super::relocate((Array::iterator)destIt, (Array::iterator)srcIt);
268  }
269 
270  void
271  relocate(size_t destIdx, size_t srcIdx)
272  {
273  super::relocate(destIdx, srcIdx);
274  }
276 
278 
279  iterator
280  begin() const
281  {
282  return (iterator)Array::begin();
283  }
284 
285  iterator
286  end() const
287  {
288  return (iterator)Array::end();
289  }
291 
293 
294  T* operator[](size_t idx) const
295  {
296  return utl::cast<T>(Array::operator[](idx));
297  }
298 
299  T* operator[](int idx) const
300  {
301  return operator[]((size_t)idx);
302  }
303 
304  T* operator[](size_t idx)
305  {
306  return utl::cast<T>(Array::operator[](idx));
307  }
308 
309  T* operator[](int idx)
310  {
311  return operator[]((size_t)idx);
312  }
313 
314 #if UTL_HOST_WORDSIZE == 64
315  T* operator[](uint_t idx) const
316  {
317  return operator[]((size_t)idx);
318  }
319  T* operator[](uint_t idx)
320  {
321  return operator[]((size_t)idx);
322  }
323 #endif
324 
325  T& operator()(size_t idx) const
326  {
327  auto ptr = utl::cast<T>(Array::operator[](idx));
328  ASSERTD(ptr != nullptr);
329  return *ptr;
330  }
331 
332  T* operator[](const Object* object)
333  {
334  return utl::cast<T>(addOrFind(object));
335  }
336 
337  T& operator()(int idx) const
338  {
339  return operator()((size_t)idx);
340  }
341 
342 #if UTL_HOST_WORDSIZE == 64
343  T& operator()(uint_t idx) const
344  {
345  return operator()((size_t)idx);
346  }
347 #endif
348 
349 };
350 
352 
353 UTL_NS_END;
354 
356 
#define UTL_CLASS_IMPL_TPL(className, T)
Implementation of standard UTL++ functionality for a template class.
Definition: macros.h:906
void insert(const Object *object, const BidIt &it)
Insert an object before the pointed-to location.
Definition: TArray.h:202
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
Definition: macros.h:532
Random-access Array iterator.
Definition: ArrayIt.h:22
Object comparison abstraction.
Definition: Ordering.h:30
TArray(size_t size, size_t increment=uint_t_max, bool owner=true, bool multiSet=true, bool keepSorted=false, Ordering *ordering=nullptr)
Constructor.
Definition: TArray.h:45
SortedCollection that stores objects in an array.
Definition: Array.h:116
Template version of Array.
Definition: TArray.h:25
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
void removeIt(BidIt &it)
Remove the object the given iterator points to.
Definition: TArray.h:223
const uint_t uint_t_max
Maximum uint_t value.
void findIt(const Object &key, BidIt &it)
Find an object matching a given key.
Definition: TArray.h:97
Bi-directional iterator abstraction.
Definition: BidIt.h:25
void findFirstIt(const Object &key, BidIt &it, bool insert=false)
Find the first object matching the given key.
Definition: TArray.h:115
#define UTL_CLASS_DECL_TPL(DC, T, BC)
Declaration of standard UTL++ functionality for a template class with one parameter.
Definition: macros.h:713
TArray(bool owner, bool multiSet=true, bool keepSorted=false, Ordering *ordering=nullptr)
Constructor.
Definition: TArray.h:62
Root of UTL++ class hierarchy.
Definition: Object.h:52
#define ASSERTD
Do an assertion in DEBUG mode only.
A collection of objects.
Definition: Collection.h:62
void findLastIt(const Object &key, BidIt &it)
Find the last object matching the given key.
Definition: TArray.h:133