34 #ifndef GRAPH_TREE_BASE_H
35 #define GRAPH_TREE_BASE_H
56 typedef std::list<BaseTree *>::iterator
iterator;
66 BaseTree(
bool allowsChildren =
true );
69 const std::list<BaseTree *> &
children()
const;
71 bool getAllowsChildren()
const;
73 BaseTree* getChildAt(
unsigned childIndex )
const;
92 void removeFromParent();
94 void setParent(
BaseTree* newParent );
104 virtual size_t size() const
105 __attribute__((__deprecated__("use childrenSize() for the number of children")));
107 virtual
size_t childrenSize() const;
117 bool _allowsChildren;
126 : _allowsChildren( allowsChildren ), _parent( 0 )
133 return _allowsChildren;
142 for( i=0, it=_children.begin(); i<childIndex && it!=_children.end();
144 if( it != _children.end() )
return *it;
151 return _children.size();
157 return _children.size();
169 return _children.size() == 0;
175 return _children.begin();
181 return _children.end();
187 return _children.rbegin();
193 return _children.rend();
199 if( getParent() ) getParent()->remove(
this );
const std::list< BaseTree * > & children() const
void insert(BaseTree *child, int index=-1)
Adds child to the receiver at index (default: end)
bool getAllowsChildren() const
Returns true if the receiver allows children.
void setParent(BaseTree *newParent)
Sets the parent of the receiver to newParent.
BaseTree * getChildAt(unsigned childIndex) const
Returns the child BaseTree pointer at index childIndex.
void remove(unsigned index)
Removes the child at index index from the receiver.
void remove(BaseTree *node)
Removes node from the receiver.
void removeFromParent()
Removes the receiver from its parent.
BaseTree * getTopParent()
Returns the top-level parent BaseTree of the receiver.
std::list< BaseTree * >::iterator iterator
int getIndex(BaseTree *node) const
Returns the index of node in the receivers children.
const BaseTree * getTopParent() const
Returns the top-level parent of the receiver (const version)
bool isLeaf() const
Returns true if the receiver is a leaf (terminal node)
virtual size_t size() const __attribute__((__deprecated__("use childrenSize() for the number of children")))
deprecated - use childrenSize() for the number of children.
virtual size_t childrenSize() const
Returns the number of children BaseTree the receiver contains.
const_reverse_iterator rbegin() const
void clear()
Deletes all children from the tree.
std::list< BaseTree * >::const_reverse_iterator const_reverse_iterator
BaseTree * getParent() const
Returns the parent BaseTree of the receiver.
const_iterator end() const
std::list< BaseTree * >::reverse_iterator reverse_iterator
const_reverse_iterator rend() const
std::list< BaseTree * >::const_iterator const_iterator
const_iterator begin() const