libUTL++
TRBtree.h
1 #pragma once
2 
4 
5 #include <libutl/TRBtreeIt.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
22 
24 template <class T>
25 class TRBtree : public RBtree
26 {
29 
30 public:
37  TRBtree(bool owner, bool multiSet = false, Ordering* ordering = nullptr);
38 
39  bool
40  add(const T& object)
41  {
42  return super::add(const_cast<T&>(object));
43  }
44 
45  bool
46  add(const T* object)
47  {
48  return super::add(const_cast<T*>(object));
49  }
50 
51  void
52  add(const Collection& collection)
53  {
54  super::add(collection);
55  }
56 
58  begin() const
59  {
60  TRBtreeIt<T> res;
61  res.copy(RBtree::begin());
62  return res;
63  }
64 
66  begin()
67  {
68  TRBtreeIt<T> res;
69  res.copy(RBtree::begin());
70  return res;
71  }
72 
74  end() const
75  {
76  TRBtreeIt<T> res;
77  res.copy(RBtree::end());
78  return res;
79  }
80 
82  end()
83  {
84  TRBtreeIt<T> res;
85  res.copy(RBtree::end());
86  return res;
87  }
88 
89  T*
90  findT(const Object& key) const
91  {
92  return utl::cast<T>(RBtree::find(key));
93  }
94 
96  findIt(const Object& key) const
97  {
98  TRBtreeIt<T> res;
99  res.copy(RBtree::findIt(key));
100  return res;
101  }
102 
104  findIt(const Object& key)
105  {
106  TRBtreeIt<T> res;
107  res.copy(RBtree::findIt(key));
108  return res;
109  }
110 
111  void
112  findFirstIt(const Object& key, BidIt& it, bool insert = false) const
113  {
114  super::findFirstIt(key, it, insert);
115  }
116 
117  virtual void
118  findFirstIt(const Object& key, BidIt& it, bool insert = false)
119  {
120  super::findFirstIt(key, it, insert);
121  }
122 
124  findFirstIt(const Object& key, bool insert = false) const
125  {
126  TRBtreeIt<T> res;
127  res.copy(RBtree::findFirstIt(key, insert));
128  return res;
129  }
130 
132  findFirstIt(const Object& key, bool insert = false)
133  {
134  TRBtreeIt<T> res;
135  res.copy(RBtree::findFirstIt(key, insert));
136  return res;
137  }
138 
139  void
140  findLastIt(const Object& key, BidIt& it) const
141  {
142  super::findLastIt(key, it);
143  }
144 
145  virtual void
146  findLastIt(const Object& key, BidIt& it)
147  {
148  super::findLastIt(key, it);
149  }
150 
152  findLastIt(const Object& key) const
153  {
154  TRBtreeIt<T> res;
155  res.copy(RBtree::findLastIt(key));
156  return res;
157  }
158 
160  findLastIt(const Object& key)
161  {
162  TRBtreeIt<T> res;
163  res.copy(RBtree::findLastIt(key));
164  return res;
165  }
166 
167  bool
168  remove(const Object& key)
169  {
170  return super::remove(key);
171  }
172 
173 public:
174  typedef T type;
175  typedef TRBtreeIt<T> iterator;
176  typedef T* value_type; // for STL
177 };
178 
180 
181 template <class T>
182 TRBtree<T>::TRBtree(bool owner, bool multiSet, Ordering* ordering)
183  : RBtree(owner, multiSet, ordering)
184 {
185 }
186 
188 
189 UTL_NS_END;
190 
192 
virtual void copy(const Object &rhs)
Copy another iterator.
#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
Object comparison abstraction.
Definition: Ordering.h:30
void remove(FwdIt &begin, const FwdIt &end, bool cmp=false, const Predicate *pred=nullptr, bool predVal=false)
Remove objects from a sequence.
Template version of RBtree.
Definition: TRBtree.h:25
Red/black tree.
Definition: RBtree.h:37
virtual void findLastIt(const Object &key, BidIt &it)
Find the last object matching the given key.
Definition: TRBtree.h:146
virtual void findFirstIt(const Object &key, BidIt &it, bool insert=false)
Find the first object matching the given key.
Definition: TRBtree.h:118
In-order bi-directional BinTree iterator.
Definition: BinTreeIt.h:22
Bi-directional iterator abstraction.
Definition: BidIt.h:25
#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 RBtreeIt.
Definition: TRBtreeIt.h:23
Root of UTL++ class hierarchy.
Definition: Object.h:52
A collection of objects.
Definition: Collection.h:62