UCommon
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
ucommon::NamedObject Class Reference

A linked object base class with members found by name. More...

#include <linked.h>

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

Public Member Functions

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.

Static Public Member Functions

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.

Protected Member Functions

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 Attributes

char * id

Detailed Description

A linked object base class with members found by name.

This class is used to help form named option lists and other forms of name indexed associative data structures. The id is assumed to be passed from a dupped or dynamically allocated string. If a constant string is used then you must not call delete for this object.

Named objects are either listed on an ordered list or keyed through an associate hash map table. When using a hash table, the name id string is used to determine the slot number to use in a list of n sized linked object lists. Hence, a hash index refers to a specific sized array of object indexes.

Author:
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 384 of file linked.h.


Constructor & Destructor Documentation

ucommon::NamedObject::NamedObject ( NamedObject **  hash,
char *  name,
unsigned  size = 1 
) [protected]

Create a named object and add to hash indexed list.

Parameters:
hashmap table to list node on.
nameof the object we are listing.
sizeof hash map table used.
ucommon::NamedObject::NamedObject ( OrderedIndex index,
char *  name 
) [protected]

Created a named object on an ordered list.

This is commonly used to form attribute lists.

Parameters:
indexto list object on.
nameof the object we are listing.

Destroy named object.

We do not always destroy named objects, since we may use them in reusable pools or we may initialize a list that we keep permanently. If we do invoke delete for something based on NamedObject, then be aware the object id is assumed to be formed from a dup'd string which will also be freed unless clearId is overridden.


Member Function Documentation

void ucommon::NamedObject::add ( NamedObject **  hash,
char *  name,
unsigned  size = 1 
)

Add object to hash indexed list.

Parameters:
hashmap table to list node on.
nameof the object we are listing.
sizeof hash map table used.
virtual int ucommon::NamedObject::compare ( char *  name) [virtual]

Compare the name of our object to see if equal.

This is a virtual so that it can be overridden when using named lists or hash lookups that must be case insensitive.

Parameters:
nameto compare our name to.
Returns:
0 if effectivily equal, used for sorting keys.
static unsigned ucommon::NamedObject::count ( NamedObject **  hash,
unsigned  size 
) [static]

Count the total named objects in a hash table.

Parameters:
hashmap table of objects to index.
sizeof hash map table used.
bool ucommon::NamedObject::equal ( char *  name) [inline]

Equal function which calls compare.

Parameters:
nameto compare our name to.
Returns:
true if equal.

Definition at line 546 of file linked.h.

static NamedObject* ucommon::NamedObject::find ( NamedObject root,
char *  name 
) [static]

Find a named object from a simple list.

This may also use the begin() member of an ordered index of named objects.

Parameters:
rootnode of named object list.
nameof object to find.
Returns:
object pointer or NULL if not found.
char* ucommon::NamedObject::getId ( void  ) [inline]

Get the named id string of this object.

Returns:
name id.

Definition at line 529 of file linked.h.

Get next effective object when iterating.

Returns:
next linked object in list.

Reimplemented from ucommon::OrderedObject.

Definition at line 522 of file linked.h.

static NamedObject** ucommon::NamedObject::index ( NamedObject **  hash,
unsigned  size 
) [static]

Convert a hash index into a linear object pointer array.

The object pointer array is created from the heap and must be deleted when no longer used.

Parameters:
hashmap table of objects to index.
sizeof hash map table used.
Returns:
array of named object pointers.
static unsigned ucommon::NamedObject::keyindex ( char *  name,
unsigned  size 
) [static]

Internal function to convert a name to a hash index number.

Parameters:
nameto convert into index.
sizeof map table.
static NamedObject* ucommon::NamedObject::map ( NamedObject **  hash,
char *  name,
unsigned  size 
) [static]

Find a named object through a hash map table.

Parameters:
hashmap table of objects to search.
nameof object to find.
sizeof hash map table.
Returns:
object pointer or NULL if not found.
bool ucommon::NamedObject::operator!= ( char *  name) [inline]

Comparison operator between our name and a string.

Parameters:
nameto compare with.
Returns:
true if not equal.

Definition at line 562 of file linked.h.

bool ucommon::NamedObject::operator== ( char *  name) [inline]

Comparison operator between our name and a string.

Parameters:
nameto compare with.
Returns:
true if equal.

Definition at line 554 of file linked.h.

static void ucommon::NamedObject::purge ( NamedObject **  hash,
unsigned  size 
) [static]

Purge a hash indexed table of named objects.

Parameters:
hashmap table to purge.
sizeof hash map table used.
static NamedObject* ucommon::NamedObject::remove ( NamedObject **  root,
char *  name 
) [static]

Remove a named object from a simple list.

Parameters:
rootnode of named object list.
nameof object to find.
Returns:
object pointer or NULL if not found.
static NamedObject* ucommon::NamedObject::remove ( NamedObject **  hash,
char *  name,
unsigned  size 
) [static]

Remove an object from a hash map table.

Parameters:
hashmap table of object to remove from.
nameof object to remove.
sizeof hash map table.
Returns:
object that is removed or NULL if not found.
static NamedObject* ucommon::NamedObject::skip ( NamedObject **  hash,
NamedObject current,
unsigned  size 
) [static]

Iterate through a hash map table.

Parameters:
hashmap table to iterate.
currentnamed object we iterated or NULL to find start of list.
sizeof map table.
Returns:
next named object in hash map or NULL if no more objects.
static NamedObject** ucommon::NamedObject::sort ( NamedObject **  list,
size_t  count = 0 
) [static]

Sort an array of named objects in alphabetical order.

This would typically be used to sort a list created and returned by index().

Parameters:
listof named objects to sort.
countof objects in the list or 0 to find by NULL pointer.
Returns:
list in sorted order.

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