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..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
ucommon::NamedObject Class Reference

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

#include <linked.h>

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

Public Member Functions

void add (NamedObject **hash, char *name, unsigned size=1)
 Add object to hash indexed list. More...
 
NamedObjectgetNext (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...
 
- Public Member Functions inherited from ucommon::OrderedObject
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...
 
OrderedObjectgetNext (void) const
 Get next ordered member when iterating. More...
 
- Public Member Functions inherited from ucommon::LinkedObject
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...
 
LinkedObjectgetNext (void) const
 Get next effective object when iterating. More...
 

Static Public Member Functions

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 NamedObjectfind (NamedObject *root, const char *name)
 Find a named object from a simple list. More...
 
static NamedObjectremove (NamedObject **root, const char *name)
 Remove a named object from a simple list. More...
 
static NamedObjectmap (NamedObject **hash, const char *name, unsigned size)
 Find a named object through a hash map table. More...
 
static NamedObjectremove (NamedObject **hash, const char *name, unsigned size)
 Remove an object from a hash map table. More...
 
static NamedObjectskip (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 Public Member Functions inherited from ucommon::LinkedObject
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 LinkedObjectgetIndexed (LinkedObject *root, unsigned index)
 Get member by index. More...
 

Protected Member Functions

 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...
 
- Protected Member Functions inherited from ucommon::OrderedObject
 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)
 
- Protected Member Functions inherited from ucommon::LinkedObject
 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
 
- Protected Attributes inherited from ucommon::LinkedObject
LinkedObjectNext
 

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 381 of file linked.h.

Constructor & Destructor Documentation

◆ NamedObject() [1/3]

ucommon::NamedObject::NamedObject ( )
protected

Create an empty unnamed cell object.

Definition at line 95 of file linked.cpp.

References Id.

◆ NamedObject() [2/3]

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.

Definition at line 135 of file linked.cpp.

References add(), Id, and ucommon::max().

Here is the call graph for this function:

◆ NamedObject() [3/3]

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.

Definition at line 101 of file linked.cpp.

References equal(), getNext(), ucommon::OrderedIndex::head, Id, ucommon::LinkedObject::Next, ucommon::LinkedObject::release(), and ucommon::OrderedIndex::tail.

Here is the call graph for this function:

◆ ~NamedObject()

ucommon::NamedObject::~NamedObject ( )
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.

Definition at line 192 of file linked.cpp.

References clearId().

Here is the call graph for this function:

Member Function Documentation

◆ add()

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.

Definition at line 146 of file linked.cpp.

References clearId(), equal(), getNext(), Id, keyindex(), ucommon::max(), ucommon::LinkedObject::Next, and ucommon::LinkedObject::release().

Referenced by NamedObject().

Here is the call graph for this function:

◆ clearId()

void ucommon::NamedObject::clearId ( void  )
protectedvirtual

The behavior of clearing id's can be overridden if they are not assigned as strdup's from the heap...

Definition at line 184 of file linked.cpp.

References Id.

Referenced by add(), ucommon::NamedTree::purge(), and ~NamedObject().

◆ compare()

int ucommon::NamedObject::compare ( const char *  name) const
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.

Definition at line 251 of file linked.cpp.

References Id.

◆ count()

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.

Definition at line 339 of file linked.cpp.

References count(), ucommon::max(), and ucommon::LinkedObject::Next.

Referenced by count(), and index().

Here is the call graph for this function:

◆ equal()

bool ucommon::NamedObject::equal ( const char *  name) const
inline

Equal function which calls compare.

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

Definition at line 545 of file linked.h.

Referenced by add(), find(), NamedObject(), and remove().

◆ find()

NamedObject * ucommon::NamedObject::find ( NamedObject root,
const 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.

Definition at line 384 of file linked.cpp.

References equal(), and getNext().

Referenced by map().

Here is the call graph for this function:

◆ getId()

char * ucommon::NamedObject::getId ( void  ) const
inline

Get the named id string of this object.

Returns
name id.

Definition at line 527 of file linked.h.

◆ getNext()

NamedObject * ucommon::NamedObject::getNext ( void  ) const
inline

Get next effective object when iterating.

Returns
next linked object in list.

Definition at line 519 of file linked.h.

Referenced by add(), find(), NamedObject(), ucommon::NamedTree::purge(), remove(), and skip().

◆ index()

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.

Definition at line 287 of file linked.cpp.

References count(), ucommon::max(), and skip().

Referenced by ucommon::treemap< T >::getIndexed().

Here is the call graph for this function:

◆ keyindex()

unsigned ucommon::NamedObject::keyindex ( const char *  name,
unsigned  size 
)
static

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

Parameters
nameto convert into index.
sizeof map table.

Definition at line 238 of file linked.cpp.

References ucommon::max().

Referenced by add(), map(), remove(), and skip().

Here is the call graph for this function:

◆ map()

NamedObject * ucommon::NamedObject::map ( NamedObject **  hash,
const 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.

Definition at line 372 of file linked.cpp.

References find(), keyindex(), and ucommon::max().

Here is the call graph for this function:

◆ operator!=()

bool ucommon::NamedObject::operator!= ( const char *  name) const
inline

Comparison operator between our name and a string.

Parameters
nameto compare with.
Returns
true if not equal.

Definition at line 563 of file linked.h.

◆ operator==()

bool ucommon::NamedObject::operator== ( const char *  name) const
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.

◆ purge()

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.

Definition at line 323 of file linked.cpp.

References ucommon::max(), and ucommon::LinkedObject::purge().

Here is the call graph for this function:

◆ remove() [1/2]

NamedObject * ucommon::NamedObject::remove ( NamedObject **  hash,
const 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.

Definition at line 360 of file linked.cpp.

References keyindex(), ucommon::max(), and remove().

Here is the call graph for this function:

◆ remove() [2/2]

NamedObject * ucommon::NamedObject::remove ( NamedObject **  root,
const 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.

Definition at line 396 of file linked.cpp.

References equal(), getNext(), and ucommon::LinkedObject::Next.

Referenced by remove().

Here is the call graph for this function:

◆ skip()

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.

Definition at line 303 of file linked.cpp.

References getNext(), Id, keyindex(), ucommon::max(), and ucommon::LinkedObject::Next.

Referenced by index().

Here is the call graph for this function:

◆ sort()

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.

Definition at line 274 of file linked.cpp.

References ucommon::ncompare().

Here is the call graph for this function:

Member Data Documentation

◆ Id


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