ucommon::NamedTree Class Reference

The named tree class is used to form a tree oriented list of associated objects. More...

#include <linked.h>

Inheritance diagram for ucommon::NamedTree:
Inheritance graph
[legend]
Collaboration diagram for ucommon::NamedTree:
Collaboration graph
[legend]

Public Member Functions

NamedTreefind (const char *name) const
 Find a child node of our object with the specified name.
NamedTreegetChild (const char *name) const
 Find a direct child of our node which matches the specified name.
NamedTreegetFirst (void) const
 Get first child node in our ordered list of children.
OrderedIndexgetIndex (void) const
 Get the ordered index of our child nodes.
NamedTreegetIndexed (unsigned index) const
 Get child by index number.
NamedTreegetLeaf (const char *name) const
 Find a direct leaf node on our node.
NamedTreegetParent (void) const
 Get parent node we are listed as a child on.
bool is_leaf (void) const
 Test if node has children.
bool is_root (void) const
 Test if node is root node.
NamedTreeleaf (const char *name) const
 Find a child leaf node of our object with the specified name.
 operator bool () const
 Test if this node has a name.
bool operator! () const
 Test if this node is unnamed.
NamedTreepath (const char *path) const
 Find a subnode by a dot separated list of node names.
void relist (NamedTree *trunk=NULL)
 Default relist is by tail.
void relistHead (NamedTree *trunk)
 Add leaf to a trunk, by reverse order.
void relistTail (NamedTree *trunk)
 Add leaf to a trunk, by order.
void remove (void)
 Remove our node from our parent list.
void setId (char *name)
 Set or replace the name id of this node.

Protected Member Functions

 NamedTree (const NamedTree &source)
 Construct a copy of the tree.
 NamedTree (NamedTree *parent, char *name)
 Create a tree node as a child of an existing node.
 NamedTree (char *name=NULL)
 Create a stand-alone or root tree node, with an optional name.
void purge (void)
 Performs object destruction.
virtual ~NamedTree ()
 Delete node in a tree.

Protected Attributes

OrderedIndex Child
NamedTreeParent

Detailed Description

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.

Author:
David Sugar <dyfet@gnutelephony.org>

Definition at line 585 of file linked.h.


Constructor & Destructor Documentation

ucommon::NamedTree::NamedTree ( char *  name = NULL  )  [protected]

Create a stand-alone or root tree node, with an optional name.

Parameters:
name for this node.
ucommon::NamedTree::NamedTree ( NamedTree parent,
char *  name 
) [protected]

Create a tree node as a child of an existing node.

Parameters:
parent node we are listed under.
name of our node.
ucommon::NamedTree::NamedTree ( const NamedTree source  )  [protected]

Construct a copy of the tree.

Parameters:
source object to copy from.
virtual ucommon::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.


Member Function Documentation

NamedTree* ucommon::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.

Parameters:
name to search for.
Returns:
tree object found or NULL.

Reimplemented in ucommon::treemap< T >.

NamedTree* ucommon::NamedTree::getChild ( const char *  name  )  const

Find a direct child of our node which matches the specified name.

Parameters:
name of child node to find.
Returns:
tree node object of child or NULL.

Reimplemented in ucommon::treemap< T >.

NamedTree* ucommon::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.

Returns:
first child node or NULL if no children.

Reimplemented in ucommon::treemap< T >.

Definition at line 677 of file linked.h.

OrderedIndex* ucommon::NamedTree::getIndex ( void   )  const [inline]

Get the ordered index of our child nodes.

Returns:
ordered index of our children.

Definition at line 699 of file linked.h.

NamedTree* ucommon::NamedTree::getIndexed ( unsigned  index  )  const [inline]

Get child by index number.

Parameters:
index of child to fetch.
Returns:
indexed child node.

Reimplemented in ucommon::treemap< T >.

Definition at line 692 of file linked.h.

NamedTree* ucommon::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.

Parameters:
name of leaf child node to find.
Returns:
tree node object of leaf or NULL.

Reimplemented in ucommon::treemap< T >.

NamedTree* ucommon::NamedTree::getParent ( void   )  const [inline]

Get parent node we are listed as a child on.

Returns:
parent node or NULL if none.

Reimplemented in ucommon::treemap< T >.

Definition at line 684 of file linked.h.

bool ucommon::NamedTree::is_leaf ( void   )  const [inline]

Test if node has children.

Returns:
true if node contains child nodes.

Definition at line 733 of file linked.h.

bool ucommon::NamedTree::is_root ( void   )  const [inline]

Test if node is root node.

Returns:
true if node is root node.

Definition at line 740 of file linked.h.

NamedTree* ucommon::NamedTree::leaf ( const char *  name  )  const

Find a child leaf node of our object with the specified name.

This will recursively search all our child nodes until it can find a leaf node containing the specified id but that holds no further children.

Parameters:
name of leaf node to search for.
Returns:
tree node object found or NULL.

Reimplemented in ucommon::treemap< T >.

ucommon::NamedTree::operator bool (  )  const [inline]

Test if this node has a name.

Returns:
true if name is set.

Definition at line 706 of file linked.h.

bool ucommon::NamedTree::operator! (  )  const [inline]

Test if this node is unnamed.

Returns:
false if name is set.

Definition at line 713 of file linked.h.

NamedTree* ucommon::NamedTree::path ( const char *  path  )  const

Find a subnode by a dot separated 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 separated 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.

Parameters:
path name string being sought.
Returns:
tree node object found at the path or NULL.

Reimplemented in ucommon::treemap< T >.

void ucommon::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 ucommon::NamedTree::relist ( NamedTree trunk = NULL  )  [inline]

Default relist is by tail.

..

Parameters:
trunk we add leaf node to, NULL to delist.

Definition at line 759 of file linked.h.

void ucommon::NamedTree::relistHead ( NamedTree trunk  ) 

Add leaf to a trunk, by reverse order.

If NULL, just remove.

Parameters:
trunk we add leaf node to.
void ucommon::NamedTree::relistTail ( NamedTree trunk  ) 

Add leaf to a trunk, by order.

If NULL, just remove.

Parameters:
trunk we add leaf node to.
void ucommon::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 ucommon::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.

Parameters:
name for this node to set.

The documentation for this class was generated from the following file:

Generated on 30 Jul 2013 for UCommon by  doxygen 1.6.1