UCommon
Public Member Functions | Protected Member Functions | Protected Attributes
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 (char *name)
 Find a child node of our object with the specified name.
NamedTreegetChild (char *name)
 Find a direct child of our node which matches the specified name.
NamedTreegetFirst (void)
 Get first child node in our ordered list of children.
OrderedIndexgetIndex (void)
 Get the ordered index of our child nodes.
NamedTreegetIndexed (unsigned index)
 Get child by index number.
NamedTreegetLeaf (char *name)
 Find a direct leaf node on our node.
NamedTreegetParent (void)
 Get parent node we are listed as a child on.
bool isLeaf (void)
 Test if node has children.
bool isRoot (void)
 Test if node is root node.
NamedTreeleaf (char *name)
 Find a child leaf node of our object with the specified name.
 operator bool ()
 Test if this node has a name.
bool operator! ()
 Test if this node is unnamed.
NamedTreepath (char *path)
 Find a subnode by a dot separated list of node names.
void relist (NamedTree *trunk=((void *) 0))
 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.
- Public Member Functions inherited from ucommon::NamedObject
void add (NamedObject **hash, char *name, unsigned size=1)
 Add object to hash indexed list.
virtual int compare (char *name)
 Compare the name of our object to see if equal.
bool equal (char *name)
 Equal function which calls compare.
char * getId (void)
 Get the named id string of this object.
NamedObjectgetNext (void)
 Get next effective object when iterating.
bool operator!= (char *name)
 Comparison operator between our name and a string.
bool operator== (char *name)
 Comparison operator between our name and a string.
- Public Member Functions inherited from ucommon::OrderedObject
void delist (OrderedIndex *index)
 Remove our ordered object from an existing index.
virtual void enlist (OrderedIndex *index)
 List our ordered object in default strategy mode.
void enlistHead (OrderedIndex *index)
 List our ordered object at start of a linked list on an index.
void enlistTail (OrderedIndex *index)
 List our ordered object at end of a linked list on an index.
- Public Member Functions inherited from ucommon::LinkedObject
void delist (LinkedObject **root)
 Locate and remove ourselves from a list of objects.
void enlist (LinkedObject **root)
 Add our object to an existing linked list through a pointer.
bool isMember (LinkedObject *list)
 Search to see if we are a member of a specific list.
virtual void release (void)
 Release list, mark as no longer linked.
virtual void retain (void)
 Retain by marking as self referenced list.
- Public Member Functions inherited from ucommon::ObjectProtocol
ObjectProtocolcopy (void)
 Retain (increase retention of) object when copying.
void operator++ (void)
 Increase retention operator.
void operator-- (void)
 Decrease retention operator.
virtual ~ObjectProtocol ()
 Required virtual destructor.

Protected Member Functions

 NamedTree (char *name=((void *) 0))
 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.
 NamedTree (NamedTree &source)
 Construct a copy of the tree.
void purge (void)
 Performs object destruction.
virtual ~NamedTree ()
 Delete node in a tree.
- Protected Member Functions inherited from ucommon::NamedObject
virtual void clearId (void)
 The behavior of clearing id's can be overridden if they are not assigned as strdup's from the heap...
 NamedObject ()
 Create an empty unnamed cell object.
 NamedObject (NamedObject **hash, char *name, unsigned size=1)
 Create a named object and add to hash indexed list.
 NamedObject (OrderedIndex *index, char *name)
 Created a named object on an ordered list.
 ~NamedObject ()
 Destroy named object.
- Protected Member Functions inherited from ucommon::OrderedObject
 OrderedObject (OrderedIndex *index)
 Construct an ordered object aot end of a an index.
 OrderedObject ()
 Construct an ordered object unattached.
- Protected Member Functions inherited from ucommon::LinkedObject
 LinkedObject (LinkedObject **root)
 Construct base class attached to a chain of objects.
 LinkedObject ()
 Construct base class unattached to anyone.

Protected Attributes

OrderedIndex child
NamedTreeparent
- Protected Attributes inherited from ucommon::NamedObject
char * id

Additional Inherited Members

- Static Public Member Functions inherited from ucommon::NamedObject
static unsigned count (NamedObject **hash, unsigned size)
 Count the total named objects in a hash table.
static NamedObjectfind (NamedObject *root, char *name)
 Find a named object from a simple list.
static NamedObject ** index (NamedObject **hash, unsigned size)
 Convert a hash index into a linear object pointer array.
static unsigned keyindex (char *name, unsigned size)
 Internal function to convert a name to a hash index number.
static NamedObjectmap (NamedObject **hash, char *name, unsigned size)
 Find a named object through a hash map table.
static void purge (NamedObject **hash, unsigned size)
 Purge a hash indexed table of named objects.
static NamedObjectremove (NamedObject **root, char *name)
 Remove a named object from a simple list.
static NamedObjectremove (NamedObject **hash, char *name, unsigned size)
 Remove an object from a hash map table.
static NamedObjectskip (NamedObject **hash, NamedObject *current, unsigned size)
 Iterate through a hash map table.
static NamedObject ** sort (NamedObject **list, size_t count=0)
 Sort an array of named objects in alphabetical order.

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.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 573 of file linked.h.


Constructor & Destructor Documentation

ucommon::NamedTree::NamedTree ( char *  name = ((void *) 0))
protected

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

Parameters:
namefor this node.
ucommon::NamedTree::NamedTree ( NamedTree parent,
char *  name 
)
protected

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

Parameters:
parentnode we are listed under.
nameof our node.
ucommon::NamedTree::NamedTree ( NamedTree source)
protected

Construct a copy of the tree.

Parameters:
sourceobject to copy from.
virtual ucommon::NamedTree::~NamedTree ( )
protectedvirtual

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 ( char *  name)

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:
nameto search for.
Returns:
tree object found or NULL.

Reimplemented in ucommon::treemap< T >.

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

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

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

Reimplemented in ucommon::treemap< T >.

NamedTree* ucommon::NamedTree::getFirst ( void  )
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 665 of file linked.h.

OrderedIndex* ucommon::NamedTree::getIndex ( void  )
inline

Get the ordered index of our child nodes.

Returns:
ordered index of our children.

Definition at line 687 of file linked.h.

NamedTree* ucommon::NamedTree::getIndexed ( unsigned  index)
inline

Get child by index number.

Parameters:
indexof child to fetch.
Returns:
indexed child node.

Reimplemented in ucommon::treemap< T >.

Definition at line 680 of file linked.h.

NamedTree* ucommon::NamedTree::getLeaf ( char *  name)

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:
nameof leaf child node to find.
Returns:
tree node object of leaf or NULL.

Reimplemented in ucommon::treemap< T >.

NamedTree* ucommon::NamedTree::getParent ( void  )
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 672 of file linked.h.

bool ucommon::NamedTree::isLeaf ( void  )
inline

Test if node has children.

Returns:
true if node contains child nodes.

Definition at line 721 of file linked.h.

bool ucommon::NamedTree::isRoot ( void  )
inline

Test if node is root node.

Returns:
true if node is root node.

Definition at line 728 of file linked.h.

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

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:
nameof leaf node to search for.
Returns:
tree node object found or NULL.

Reimplemented in ucommon::treemap< T >.

ucommon::NamedTree::operator bool ( )
inline

Test if this node has a name.

Returns:
true if name is set.

Definition at line 694 of file linked.h.

bool ucommon::NamedTree::operator! ( )
inline

Test if this node is unnamed.

Returns:
false if name is set.

Definition at line 701 of file linked.h.

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

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:
pathname 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 = ((void*)0))
inline

Default relist is by tail...

Parameters:
trunkwe add leaf node to, NULL to delist.

Definition at line 747 of file linked.h.

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

Add leaf to a trunk, by reverse order.

If NULL, just remove.

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

Add leaf to a trunk, by order.

If NULL, just remove.

Parameters:
trunkwe 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:
namefor this node to set.

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