The named tree class is used to form a tree oriented list of associated objects. More...
#include <linked.h>
Public Member Functions | |
NamedTree * | find (const char *name) const |
Find a child node of our object with the specified name. | |
NamedTree * | path (const char *path) const |
Find a subnode by a dot seperated list of node names. | |
NamedTree * | leaf (const char *name) const |
Find a child leaf node of our object with the specified name. | |
NamedTree * | getChild (const char *name) const |
Find a direct child of our node which matches the specified name. | |
NamedTree * | getLeaf (const char *name) const |
Find a direct leaf node on our node. | |
NamedTree * | getFirst (void) const |
Get first child node in our ordered list of children. | |
NamedTree * | getParent (void) const |
Get parent node we are listed as a child on. | |
NamedTree * | getIndexed (unsigned index) const |
Get child by index number. | |
OrderedIndex * | getIndex (void) const |
Get the ordered index of our child nodes. | |
operator bool () const | |
Test if this node has a name. | |
bool | operator! () const |
Test if this node is unnamed. | |
void | setId (char *name) |
Set or replace the name id of this node. | |
void | remove (void) |
Remove our node from our parent list. | |
bool | isLeaf (void) const |
Test if node has children. | |
bool | isRoot (void) const |
Test if node is root node. | |
void | relistTail (NamedTree *trunk) |
Add leaf to a trunk, by order. | |
void | relistHead (NamedTree *trunk) |
Add leaf to a trunk, by reverse order. | |
void | relist (NamedTree *trunk=NULL) |
Default relist is by tail. | |
Protected Member Functions | |
NamedTree (char *name=NULL) | |
Create a stand-alone or root tree node, with an optional name. | |
NamedTree (NamedTree *parent, char *name) | |
Create a tree node as a child of an existing node. | |
virtual | ~NamedTree () |
Delete node in a tree. | |
void | purge (void) |
Performs object destruction. | |
Protected Attributes | |
NamedTree * | parent |
OrderedIndex | child |
The named tree class is used to form a tree oriented list of associated objects.
Typical uses for such data structures might be to form a parsed XML document, or for forming complex configuration management systems or for forming system resource management trees.
Definition at line 491 of file linked.h.
ucc::NamedTree::NamedTree | ( | char * | name = NULL |
) | [protected] |
Create a stand-alone or root tree node, with an optional name.
name | for this node. |
ucc::NamedTree::NamedTree | ( | NamedTree * | parent, | |
char * | name | |||
) | [protected] |
Create a tree node as a child of an existing node.
parent | node we are listed under. | |
name | of our node. |
virtual ucc::NamedTree::~NamedTree | ( | ) | [protected, virtual] |
Delete node in a tree.
If we delete a node, we must delist it from it's parent. We must also delink any child nodes. This is done by calling the purge() member.
NamedTree* ucc::NamedTree::find | ( | const char * | name | ) | const |
Find a child node of our object with the specified name.
This will also recursivily search all child nodes that have children until the named node can be found. This seeks a child node that has children.
name | to search for. |
Reimplemented in ucc::treemap< T >.
NamedTree* ucc::NamedTree::getChild | ( | const char * | name | ) | const |
Find a direct child of our node which matches the specified name.
name | of child node to find. |
Reimplemented in ucc::treemap< T >.
NamedTree* ucc::NamedTree::getFirst | ( | void | ) | const [inline] |
Get first child node in our ordered list of children.
This might be used to iterate child nodes. This may also be used to get unamed child nodes.
Reimplemented in ucc::treemap< T >.
OrderedIndex* ucc::NamedTree::getIndex | ( | void | ) | const [inline] |
NamedTree* ucc::NamedTree::getIndexed | ( | unsigned | index | ) | const [inline] |
Get child by index number.
index | of child to fetch. |
Reimplemented in ucc::treemap< T >.
NamedTree* ucc::NamedTree::getLeaf | ( | const char * | name | ) | const |
Find a direct leaf node on our node.
A leaf node is a node that has no children of it's own. This does not perform a recursive search.
name | of leaf child node to find. |
Reimplemented in ucc::treemap< T >.
NamedTree* ucc::NamedTree::getParent | ( | void | ) | const [inline] |
Get parent node we are listed as a child on.
Reimplemented in ucc::treemap< T >.
bool ucc::NamedTree::isLeaf | ( | void | ) | const [inline] |
bool ucc::NamedTree::isRoot | ( | void | ) | const [inline] |
NamedTree* ucc::NamedTree::leaf | ( | const char * | name | ) | const |
Find a child leaf node of our object with the specified name.
This will recursivily search all our child nodes until it can find a leaf node containing the specified id but that holds no further children.
name | of leaf node to search for. |
Reimplemented in ucc::treemap< T >.
ucc::NamedTree::operator bool | ( | ) | const [inline] |
bool ucc::NamedTree::operator! | ( | ) | const [inline] |
NamedTree* ucc::NamedTree::path | ( | const char * | path | ) | const |
Find a subnode by a dot seperated list of node names.
If one or more lead dots are used, then the search will go through parent node levels of our node. The dot seperated list could be thought of as a kind of pathname where dot is used like slash. This implies that individual nodes can never use names which contain dot's if the path function will be used.
path | name string being sought. |
Reimplemented in ucc::treemap< T >.
void ucc::NamedTree::purge | ( | void | ) | [protected] |
Performs object destruction.
Note, if we delete a named tree object the name of our member object is assumed to be a dynamically allocated string that will also be free'd.
void ucc::NamedTree::relist | ( | NamedTree * | trunk = NULL |
) | [inline] |
void ucc::NamedTree::relistHead | ( | NamedTree * | trunk | ) |
Add leaf to a trunk, by reverse order.
If NULL, just remove.
trunk | we add leaf node to. |
void ucc::NamedTree::relistTail | ( | NamedTree * | trunk | ) |
Add leaf to a trunk, by order.
If NULL, just remove.
trunk | we add leaf node to. |
void ucc::NamedTree::remove | ( | void | ) |
Remove our node from our parent list.
The name is set to NULL to keep delete from freeing the name string.
void ucc::NamedTree::setId | ( | char * | name | ) |
Set or replace the name id of this node.
This will free the string if a name had already been set.
name | for this node to set. |