ucommon
7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
![]() ![]() |
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. More... | |
NamedTree * | path (const char *path) const |
Find a subnode by a dot separated list of node names. More... | |
NamedTree * | leaf (const char *name) const |
Find a child leaf node of our object with the specified name. More... | |
NamedTree * | getChild (const char *name) const |
Find a direct child of our node which matches the specified name. More... | |
NamedTree * | getLeaf (const char *name) const |
Find a direct leaf node on our node. More... | |
NamedTree * | getFirst (void) const |
Get first child node in our ordered list of children. More... | |
NamedTree * | getParent (void) const |
Get parent node we are listed as a child on. More... | |
NamedTree * | getIndexed (unsigned index) const |
Get child by index number. More... | |
OrderedIndex * | getIndex (void) const |
Get the ordered index of our child nodes. More... | |
operator bool () const | |
Test if this node has a name. More... | |
bool | operator! () const |
Test if this node is unnamed. More... | |
void | setId (char *name) |
Set or replace the name id of this node. More... | |
void | remove (void) |
Remove our node from our parent list. More... | |
bool | is_leaf (void) const |
Test if node has children. More... | |
bool | is_root (void) const |
Test if node is root node. More... | |
void | relistTail (NamedTree *trunk) |
Add leaf to a trunk, by order. More... | |
void | relistHead (NamedTree *trunk) |
Add leaf to a trunk, by reverse order. More... | |
void | relist (NamedTree *trunk=NULL) |
Default relist is by tail... More... | |
![]() | |
void | add (NamedObject **hash, char *name, unsigned size=1) |
Add object to hash indexed list. More... | |
NamedObject * | getNext (void) const |
Get next effective object when iterating. More... | |
char * | getId (void) const |
Get the named id string of this object. More... | |
virtual int | compare (const char *name) const |
Compare the name of our object to see if equal. More... | |
bool | equal (const char *name) const |
Equal function which calls compare. More... | |
bool | operator== (const char *name) const |
Comparison operator between our name and a string. More... | |
bool | operator!= (const char *name) const |
Comparison operator between our name and a string. More... | |
![]() | |
void | enlistTail (OrderedIndex *index) |
List our ordered object at end of a linked list on an index. More... | |
void | enlistHead (OrderedIndex *index) |
List our ordered object at start of a linked list on an index. More... | |
virtual void | enlist (OrderedIndex *index) |
List our ordered object in default strategy mode. More... | |
void | delist (OrderedIndex *index) |
Remove our ordered object from an existing index. More... | |
OrderedObject * | getNext (void) const |
Get next ordered member when iterating. More... | |
![]() | |
virtual | ~LinkedObject () |
virtual void | release (void) __OVERRIDE |
Release list, mark as no longer linked. More... | |
virtual void | retain (void) __OVERRIDE |
Retain by marking as self referenced list. More... | |
void | enlist (LinkedObject **root) |
Add our object to an existing linked list through a pointer. More... | |
void | delist (LinkedObject **root) |
Locate and remove ourselves from a list of objects. More... | |
bool | is_member (LinkedObject *list) const |
Search to see if we are a member of a specific list. More... | |
LinkedObject * | getNext (void) const |
Get next effective object when iterating. More... | |
Protected Member Functions | |
NamedTree (char *name=NULL) | |
Create a stand-alone or root tree node, with an optional name. More... | |
NamedTree (NamedTree *parent, char *name) | |
Create a tree node as a child of an existing node. More... | |
NamedTree (const NamedTree &source) | |
Construct a copy of the tree. More... | |
virtual | ~NamedTree () |
Delete node in a tree. More... | |
void | purge (void) |
Performs object destruction. More... | |
![]() | |
NamedObject () | |
Create an empty unnamed cell object. More... | |
NamedObject (NamedObject **hash, char *name, unsigned size=1) | |
Create a named object and add to hash indexed list. More... | |
NamedObject (OrderedIndex *index, char *name) | |
Created a named object on an ordered list. More... | |
~NamedObject () | |
Destroy named object. More... | |
virtual void | clearId (void) |
The behavior of clearing id's can be overridden if they are not assigned as strdup's from the heap... More... | |
![]() | |
OrderedObject (OrderedIndex *index) | |
Construct an ordered object aot end of a an index. More... | |
OrderedObject () | |
Construct an ordered object unattached. More... | |
OrderedObject (const OrderedObject &from) | |
![]() | |
LinkedObject (LinkedObject **root) | |
Construct base class attached to a chain of objects. More... | |
LinkedObject () | |
Construct base class unattached to anyone. More... | |
LinkedObject (const LinkedObject &from) | |
Protected Attributes | |
NamedTree * | Parent |
OrderedIndex | Child |
![]() | |
char * | Id |
![]() | |
LinkedObject * | Next |
Additional Inherited Members | |
![]() | |
static void | purge (NamedObject **hash, unsigned size) |
Purge a hash indexed table of named objects. More... | |
static NamedObject ** | index (NamedObject **hash, unsigned size) |
Convert a hash index into a linear object pointer array. More... | |
static unsigned | count (NamedObject **hash, unsigned size) |
Count the total named objects in a hash table. More... | |
static NamedObject * | find (NamedObject *root, const char *name) |
Find a named object from a simple list. More... | |
static NamedObject * | remove (NamedObject **root, const char *name) |
Remove a named object from a simple list. More... | |
static NamedObject * | map (NamedObject **hash, const char *name, unsigned size) |
Find a named object through a hash map table. More... | |
static NamedObject * | remove (NamedObject **hash, const char *name, unsigned size) |
Remove an object from a hash map table. More... | |
static NamedObject * | skip (NamedObject **hash, NamedObject *current, unsigned size) |
Iterate through a hash map table. More... | |
static unsigned | keyindex (const char *name, unsigned size) |
Internal function to convert a name to a hash index number. More... | |
static NamedObject ** | sort (NamedObject **list, size_t count=0) |
Sort an array of named objects in alphabetical order. More... | |
![]() | |
static void | purge (LinkedObject *root) |
Release all objects from a list. More... | |
static unsigned | count (const LinkedObject *root) |
Count the number of linked objects in a list. More... | |
static LinkedObject * | getIndexed (LinkedObject *root, unsigned index) |
Get member by index. More... | |
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.
|
protected |
Create a stand-alone or root tree node, with an optional name.
name | for this node. |
Definition at line 426 of file linked.cpp.
References ucommon::NamedObject::Id, and Parent.
|
protected |
Create a tree node as a child of an existing node.
parent | node we are listed under. |
name | of our node. |
Definition at line 440 of file linked.cpp.
References Child, ucommon::OrderedObject::enlistTail(), ucommon::NamedObject::Id, and Parent.
|
protected |
Construct a copy of the tree.
source | object to copy from. |
Definition at line 433 of file linked.cpp.
References Child, ucommon::NamedObject::Id, and Parent.
|
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.
Definition at line 451 of file linked.cpp.
References ucommon::NamedObject::Id, and purge().
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.
name | to search for. |
Definition at line 565 of file linked.cpp.
References ucommon::OrderedIndex::begin(), Child, ucommon::eq(), and ucommon::linked_pointer< T >::next().
Referenced by ucommon::treemap< T >::find().
NamedTree * ucommon::NamedTree::getChild | ( | const char * | name | ) | const |
Find a direct child of our node which matches the specified name.
name | of child node to find. |
Definition at line 457 of file linked.cpp.
References ucommon::OrderedIndex::begin(), Child, ucommon::eq(), and ucommon::linked_pointer< T >::next().
Referenced by ucommon::treemap< T >::getChild(), and path().
|
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.
Definition at line 667 of file linked.h.
References ucommon::OrderedIndex::begin().
Referenced by ucommon::treemap< T >::getFirst().
|
inline |
|
inline |
Get child by index number.
index | of child to fetch. |
Definition at line 684 of file linked.h.
References ucommon::OrderedIndex::getIndexed().
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.
name | of leaf child node to find. |
Definition at line 531 of file linked.cpp.
References ucommon::OrderedIndex::begin(), Child, ucommon::eq(), and ucommon::linked_pointer< T >::next().
Referenced by ucommon::treemap< T >::getLeaf().
|
inline |
|
inline |
Test if node has children.
Definition at line 729 of file linked.h.
References ucommon::OrderedIndex::begin().
|
inline |
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.
name | of leaf node to search for. |
Definition at line 545 of file linked.cpp.
References ucommon::OrderedIndex::begin(), Child, ucommon::eq(), and ucommon::linked_pointer< T >::next().
Referenced by ucommon::treemap< T >::leaf().
|
inline |
|
inline |
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.
path | name string being sought. |
Definition at line 496 of file linked.cpp.
References getChild(), Parent, and ucommon::String::set().
Referenced by ucommon::treemap< T >::path().
|
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.
Definition at line 603 of file linked.cpp.
References ucommon::OrderedIndex::begin(), Child, ucommon::NamedObject::clearId(), ucommon::OrderedObject::delist(), ucommon::NamedObject::getNext(), and Parent.
Referenced by ~NamedTree().
|
inline |
void ucommon::NamedTree::relistHead | ( | NamedTree * | trunk | ) |
Add leaf to a trunk, by reverse order.
If NULL, just remove.
trunk | we add leaf node to. |
Definition at line 484 of file linked.cpp.
References Child, ucommon::OrderedObject::delist(), ucommon::OrderedObject::enlistHead(), and Parent.
void ucommon::NamedTree::relistTail | ( | NamedTree * | trunk | ) |
Add leaf to a trunk, by order.
If NULL, just remove.
trunk | we add leaf node to. |
Definition at line 471 of file linked.cpp.
References Child, ucommon::OrderedObject::delist(), ucommon::OrderedObject::enlistTail(), and Parent.
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.
Definition at line 595 of file linked.cpp.
References Child, ucommon::OrderedObject::delist(), ucommon::NamedObject::Id, and Parent.
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.
name | for this node to set. |
Definition at line 585 of file linked.cpp.
References ucommon::NamedObject::Id.
|
protected |
Definition at line 579 of file linked.h.
Referenced by find(), getChild(), ucommon::treemap< T >::getIndexed(), getLeaf(), ucommon::treemap< T >::is_attribute(), leaf(), NamedTree(), purge(), relistHead(), relistTail(), and remove().
|
protected |
Definition at line 578 of file linked.h.
Referenced by ucommon::treemap< T >::getParent(), NamedTree(), path(), purge(), relistHead(), relistTail(), and remove().