43template <
class n_value>
class tnode
80 bool DoReparentTo(
self & p,
self * s,
bool behind )
83 if ( &p ==
this || p.IsDescendantOf(
this ) )
92 if ( !s || s->parent != parent )
93 s = behind ? parent->lchild : parent->fchild;
98 parent->fchild = parent->lchild =
this;
105 nsibling = s->nsibling;
109 nsibling->psibling =
this;
111 parent->lchild =
this;
115 psibling = s->psibling;
120 psibling->nsibling =
this;
122 parent->fchild =
this;
133 virtual void PreDisconnect() {}
135 virtual void PostDisconnect() {}
137 virtual void PreReparent() {}
139 virtual void PostReparent() {}
154 DoReparentTo( *p, 0, behind );
167 DoReparentTo( p, 0, behind );
181 DoReparentTo( p, &s, behind );
202 psibling->nsibling = nsibling;
204 parent->fchild = nsibling;
207 nsibling->psibling = psibling;
209 parent->lchild = psibling;
211 parent = psibling = nsibling = 0;
224 return DoReparentTo( p, 0, behind );
241 return DoReparentTo( p, &s, behind );
245 n_value & Value()
const {
return val; }
250 self * Parent() {
return parent; }
252 const self * Parent()
const {
return parent; }
278 bool HasParent()
const {
return parent; }
280 bool HasSiblings()
const {
return psibling || nsibling; }
282 bool HasChildren()
const {
return fchild; }
284 bool IsParentOf(
const self & c )
const {
return c.parent ==
this; }
286 bool IsSiblingOf(
const self & s )
const {
return parent && s.parent == parent; }
288 bool IsChildOf(
const self & p )
const {
return parent == &p; }
293 self * l =
const_cast<self *
>( this );
307 bool IsDescendantOf(
const self & n )
const
309 for (
const self * l = parent; l; l = l->parent )
318 bool IsDescendantOf(
const self * n )
const
320 return( n && IsDescendantOf( *n ) );
344 while ( !l->nsibling )
349 return restart ? l : 0;
355 self * Prev(
bool restart =
false )
357 if ( !psibling && parent )
360 if ( !psibling && !restart )
364 self * l = psibling ? psibling :
this;
375 return c =
Next( restart );
381 return c = Prev( restart );
386 const self &
Top()
const
388 return const_cast<self *
>( this )->
Top();
391 const self *
Next(
bool restart =
false )
const
393 return const_cast<self *
>( this )->
Next( restart );
396 const self * Prev(
bool restart =
false )
const
398 return const_cast<self *
>( this )->Prev( restart );
401 const self *
Next(
const self *& c,
bool restart =
false )
const
403 return c =
const_cast<self *
>( this )->
Next( restart );
406 const self * Prev(
const self *& c,
bool restart =
false )
const
408 return c =
const_cast<self *
>( this )->Prev( restart );
n_value & operator()() const
Alias for Value.
Definition tnode.h:248
self * Lchild()
Last child.
Definition tnode.h:273
self * Nsibling()
Next sibling.
Definition tnode.h:261
self * Prev(self *&c, bool restart=false)
Return Prev and assign it to c.
Definition tnode.h:379
void Disconnect()
Disconnect from the parent and siblings, but keep children.
Definition tnode.h:194
const self * Psibling() const
Previous sibling.
Definition tnode.h:258
tnode(n_value v, self &p, bool behind=true)
Definition tnode.h:159
bool ReparentTo(self &p, self &s, bool behind=true)
Definition tnode.h:239
const self * Nsibling() const
Next sibling.
Definition tnode.h:264
self * Psibling()
Previous sibling.
Definition tnode.h:255
tnode(n_value v, self *p=0, bool behind=true)
Definition tnode.h:145
self * Next(self *&c, bool restart=false)
Return Next and assign it to c.
Definition tnode.h:373
self * Next(bool restart=false)
Definition tnode.h:337
unsigned Depth() const
Depth: zero if no parent, otherwise 1 + parent's depth.
Definition tnode.h:291
const self * Fchild() const
First child.
Definition tnode.h:270
const self * Lchild() const
Last child.
Definition tnode.h:276
bool ReparentTo(self &p, bool behind=true)
Definition tnode.h:222
self * Fchild()
First child.
Definition tnode.h:267
tnode(n_value v, self &p, self &s, bool behind=true)
Definition tnode.h:173
self & Top()
Root of the tree.
Definition tnode.h:324