libUTL++
TList.h
1 #pragma once
2 
4 
5 #include <libutl/TListIt.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
22 
24 template <class T>
25 class TList : public List
26 {
29 
30 public:
38  TList(bool owner, bool multiSet = true, bool keepSorted = false, Ordering* ordering = nullptr);
39 
40  T*
41  front() const
42  {
43  return utl::cast<T>(List::front());
44  }
45 
46  T*
47  back() const
48  {
49  return utl::cast<T>(List::back());
50  }
51 
52  bool
53  add(const T& object)
54  {
55  return super::add(const_cast<T&>(object));
56  }
57 
58  bool
59  add(const T* object)
60  {
61  return super::add(const_cast<T*>(object));
62  }
63 
64  void
65  add(const Collection& collection)
66  {
67  super::add(collection);
68  }
69 
71  T*
72  findT(const Object& key) const
73  {
74  return utl::cast<T>(List::find(key));
75  }
76 
78  findIt(const Object& key) const
79  {
80  TListIt<T> res;
81  res.copy(List::findIt(key));
82  return res;
83  }
84 
86  findIt(const Object& key)
87  {
88  TListIt<T> res;
89  res.copy(List::findIt(key));
90  return res;
91  }
92 
93  void
94  findFirstIt(const Object& key, BidIt& it, bool insert = false) const
95  {
96  super::findFirstIt(key, it, insert);
97  }
98 
99  virtual void
100  findFirstIt(const Object& key, BidIt& it, bool insert = false)
101  {
102  super::findFirstIt(key, it, insert);
103  }
104 
105  TListIt<T>
106  findFirstIt(const Object& key, bool insert = false) const
107  {
108  TListIt<T> res;
109  res.copy(List::findFirstIt(key, insert));
110  return res;
111  }
112 
113  TListIt<T>
114  findFirstIt(const Object& key, bool insert = false)
115  {
116  TListIt<T> res;
117  res.copy(List::findFirstIt(key, insert));
118  return res;
119  }
120 
121  void
122  findLastIt(const Object& key, BidIt& it) const
123  {
124  super::findLastIt(key, it);
125  }
126 
127  virtual void
128  findLastIt(const Object& key, BidIt& it)
129  {
130  super::findLastIt(key, it);
131  }
132 
133  TListIt<T>
134  findLastIt(const Object& key) const
135  {
136  TListIt<T> res;
137  res.copy(List::findLastIt(key));
138  return res;
139  }
140 
141  TListIt<T>
142  findLastIt(const Object& key)
143  {
144  TListIt<T> res;
145  res.copy(List::findLastIt(key));
146  return res;
147  }
148 
149  T*
150  popFront()
151  {
152  return utl::cast<T>(List::popFront());
153  }
154 
155  T*
156  popBack()
157  {
158  return utl::cast<T>(List::popBack());
159  }
160 
161  TListIt<T>
162  begin() const
163  {
164  TListIt<T> res;
165  res.copy(List::begin());
166  return res;
167  }
168 
169  TListIt<T>
170  begin()
171  {
172  TListIt<T> res;
173  res.copy(List::begin());
174  return res;
175  }
176 
177  TListIt<T>
178  end() const
179  {
180  TListIt<T> res;
181  res.copy(List::end());
182  return res;
183  }
184 
185  TListIt<T>
186  end()
187  {
188  TListIt<T> res;
189  res.copy(List::end());
190  return res;
191  }
192 
193 public:
194  typedef T type;
195  typedef TListIt<T> iterator;
196  typedef T* value_type; // for STL
197 };
198 
200 
201 template <class T>
202 TList<T>::TList(bool owner, bool multiSet, bool keepSorted, Ordering* ordering)
203  : List(owner, multiSet, keepSorted, ordering)
204 {
205 }
206 
208 
209 UTL_NS_END;
210 
212 
T * findT(const Object &key) const
See find().
Definition: TList.h:72
#define UTL_CLASS_IMPL_TPL(className, T)
Implementation of standard UTL++ functionality for a template class.
Definition: macros.h:906
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
Definition: macros.h:532
Doubly-linked list.
Definition: List.h:80
Object comparison abstraction.
Definition: Ordering.h:30
Template version of ListIt.
Definition: TListIt.h:23
Templated proxy for BidIt.
Definition: TBidIt.h:19
Bi-directional iterator abstraction.
Definition: BidIt.h:25
virtual void copy(const Object &rhs)
Copy another ListIt.
#define UTL_CLASS_DECL_TPL(DC, T, BC)
Declaration of standard UTL++ functionality for a template class with one parameter.
Definition: macros.h:713
Template version of List.
Definition: TList.h:25
virtual void findFirstIt(const Object &key, BidIt &it, bool insert=false)
Find the first object matching the given key.
Definition: TList.h:100
Root of UTL++ class hierarchy.
Definition: Object.h:52
virtual void findLastIt(const Object &key, BidIt &it)
Find the last object matching the given key.
Definition: TList.h:128
A collection of objects.
Definition: Collection.h:62