UCommon
|
A linked object base class with members found by name. More...
#include <linked.h>
Public Member Functions | |
void | add (NamedObject **hash, char *name, unsigned size=1) |
Add object to hash indexed list. 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... | |
char * | getId (void) const |
Get the named id string of this object. More... | |
NamedObject * | getNext (void) const |
Get next effective object when iterating. 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 | delist (OrderedIndex *index) |
Remove our ordered object from an existing index. More... | |
virtual void | enlist (OrderedIndex *index) |
List our ordered object in default strategy mode. More... | |
void | enlistHead (OrderedIndex *index) |
List our ordered object at start of a linked list on an index. More... | |
void | enlistTail (OrderedIndex *index) |
List our ordered object at end of a linked list on an index. More... | |
OrderedObject * | getNext (void) const |
Get next ordered member when iterating. More... | |
![]() | |
void | delist (LinkedObject **root) |
Locate and remove ourselves from a list of objects. More... | |
void | enlist (LinkedObject **root) |
Add our object to an existing linked list through a pointer. More... | |
LinkedObject * | getNext (void) const |
Get next effective object when iterating. More... | |
bool | is_member (LinkedObject *list) const |
Search to see if we are a member of a specific list. More... | |
virtual void | release (void) |
Release list, mark as no longer linked. More... | |
virtual void | retain (void) |
Retain by marking as self referenced list. More... | |
![]() | |
ObjectProtocol * | copy (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. | |
Static Public Member Functions | |
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 ** | index (NamedObject **hash, unsigned size) |
Convert a hash index into a linear object pointer array. More... | |
static unsigned | keyindex (const char *name, unsigned size) |
Internal function to convert a name to a hash index number. More... | |
static NamedObject * | map (NamedObject **hash, const char *name, unsigned size) |
Find a named object through a hash map table. More... | |
static void | purge (NamedObject **hash, unsigned size) |
Purge a hash indexed table of named objects. More... | |
static NamedObject * | remove (NamedObject **root, const char *name) |
Remove a named object from a simple list. 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 NamedObject ** | sort (NamedObject **list, size_t count=0) |
Sort an array of named objects in alphabetical order. 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... | |
static void | purge (LinkedObject *root) |
Release all objects from a list. More... | |
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. More... | |
NamedObject (OrderedIndex *index, char *name) | |
Created a named object on an ordered list. More... | |
~NamedObject () | |
Destroy named object. More... | |
![]() | |
OrderedObject (OrderedIndex *index) | |
Construct an ordered object aot end of a an index. More... | |
OrderedObject () | |
Construct an ordered object unattached. | |
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 | |
char * | Id |
![]() | |
LinkedObject * | Next |
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.
|
protected |
Create a named object and add to hash indexed list.
hash | map table to list node on. |
name | of the object we are listing. |
size | of hash map table used. |
|
protected |
Created a named object on an ordered list.
This is commonly used to form attribute lists.
index | to list object on. |
name | of the object we are listing. |
|
protected |
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.
void ucommon::NamedObject::add | ( | NamedObject ** | hash, |
char * | name, | ||
unsigned | size = 1 |
||
) |
Add object to hash indexed list.
hash | map table to list node on. |
name | of the object we are listing. |
size | of hash map table used. |
|
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.
name | to compare our name to. |
|
static |
Count the total named objects in a hash table.
hash | map table of objects to index. |
size | of hash map table used. |
|
inline |
|
static |
Find a named object from a simple list.
This may also use the begin() member of an ordered index of named objects.
root | node of named object list. |
name | of object to find. |
|
inline |
|
inline |
|
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.
hash | map table of objects to index. |
size | of hash map table used. |
|
static |
Internal function to convert a name to a hash index number.
name | to convert into index. |
size | of map table. |
|
static |
Find a named object through a hash map table.
hash | map table of objects to search. |
name | of object to find. |
size | of hash map table. |
|
inline |
|
inline |
|
static |
Purge a hash indexed table of named objects.
hash | map table to purge. |
size | of hash map table used. |
|
static |
Remove a named object from a simple list.
root | node of named object list. |
name | of object to find. |
|
static |
Remove an object from a hash map table.
hash | map table of object to remove from. |
name | of object to remove. |
size | of hash map table. |
|
static |
Iterate through a hash map table.
hash | map table to iterate. |
current | named object we iterated or NULL to find start of list. |
size | of map table. |
|
static |
Sort an array of named objects in alphabetical order.
This would typically be used to sort a list created and returned by index().
list | of named objects to sort. |
count | of objects in the list or 0 to find by NULL pointer. |