Intrusive Containers
TreeIn.h
Go to the documentation of this file.
1 #ifndef TreeIn_H
2 #define TreeIn_H
3 
103 template <class R, class N, class K, int n = 0> class TreeInNode;
104 template <class R, class N, class K, int n = 0> class TreeInRoot;
105 
119 template <class R, class N, class K, int n> class TreeInRoot {
120  friend class TreeInNode<R, N, K, n>;
121  typedef class TreeInRoot<R, N, K, n> Root;
122  typedef class TreeInNode<R, N, K, n> Node;
123 protected:
124  TreeInRoot();
125  ~TreeInRoot();
126 
127  // These two member functions to be provided by the user.
128  int compare(N const& node1, N const& node2) const;
129  int compareKey(N const& node, K key) const;
130 
131  virtual void add(N& node);
132  void add(N* node);
133  void remove(N& node);
134  void remove(N* node);
135  N* find(K key) const;
136 
137  N* base() const { return base_; }
138  N* first() const;
139  N* last() const;
140 
141  void check() const;
142 private:
143 #if __cplusplus < 201101L
144  TreeInRoot(TreeInRoot const&);
145  void operator =(TreeInRoot const&);
146 #else
147  TreeInRoot(TreeInRoot const&) = delete;
148  void operator =(TreeInRoot const&) = delete;
149 #endif
150  N* base_;
151 };
152 
166 template <class R, class N, class K, int n> class TreeInNode {
167  friend class TreeInRoot<R, N, K, n>;
168  typedef class TreeInRoot<R, N, K, n> Root;
169  typedef class TreeInNode<R, N, K, n> Node;
170 protected:
171  TreeInNode(); // No default add as that needs our Parent already constructed
172  ~TreeInNode();
173 
174  void addTo(R& root);
175  void addTo(R* root);
176  virtual void remove(); // Virtual so "fancier" trees can rebalence
177 
178  R* root() const { return root_; }
179  N* parent() const { return parent_; }
180  N* left() const { return left_; }
181  N* right() const { return right_; }
182  N* next() const;
183  N* prev() const;
184 
185  void check() const;
186 
187 private:
188 #if __cplusplus < 201101L
189  TreeInNode(TreeInNode const&);
190  void operator =(TreeInNode const&);
191 #else
192  TreeInNode(TreeInNode const&) = delete;
193  void operator =(TreeInNode const&) = delete;
194 #endif
195  R* root_;
196  N* parent_;
197  N* left_;
198  N* right_;
199 };
200 
201 #endif
TreeInRoot()
Definition: TreeIn.hpp:390
int compareKey(N const &node, K key) const
N * last() const
Definition: TreeIn.hpp:176
void check() const
Definition: TreeIn.hpp:93
N * right() const
Definition: TreeIn.h:181
Definition: TreeIn.h:103
void check() const
Definition: TreeIn.hpp:61
N * parent() const
Definition: TreeIn.h:179
~TreeInNode()
Definition: TreeIn.hpp:444
N * first() const
Definition: TreeIn.hpp:164
virtual void add(N &node)
Definition: TreeIn.hpp:289
Definition: TreeIn.h:104
N * next() const
Definition: TreeIn.hpp:107
void addTo(R &root)
Definition: TreeIn.hpp:348
int compare(N const &node1, N const &node2) const
N * prev() const
Definition: TreeIn.hpp:137
~TreeInRoot()
Definition: TreeIn.hpp:402
N * base() const
Definition: TreeIn.h:137
N * left() const
Definition: TreeIn.h:180
N * find(K key) const
Definition: TreeIn.hpp:371
TreeInNode()
Definition: TreeIn.hpp:432
R * root() const
Return pointer to list we are on.
Definition: TreeIn.h:178