32 #ifndef _UCOMMON_LINKED_H_
33 #define _UCOMMON_LINKED_H_
35 #ifndef _UCOMMON_CONFIG_H_
39 #ifndef _UCOMMON_OBJECT_H_
58 friend class LinkedRing;
60 friend class ObjectStack;
211 unsigned count(
void)
const;
227 virtual void lock_index(
void);
233 virtual void unlock_index(
void);
262 {
return LinkedObject::getIndexed((
LinkedObject*)head, index);};
290 {
copy(
object);
return *
this;}
435 virtual void clearId(
void);
444 void add(
NamedObject **hash,
char *name,
unsigned size = 1);
519 static unsigned keyindex(
const char *name,
unsigned size);
551 virtual int compare(
const char *name)
const;
558 inline bool equal(
const char *name)
const
559 {
return (compare(name) == 0);};
567 {
return compare(name) == 0;};
575 {
return compare(name) != 0;};
661 NamedTree *getChild(
const char *name)
const;
669 NamedTree *getLeaf(
const char *name)
const;
678 {
return static_cast<NamedTree *
>(Child.begin());};
693 {
return static_cast<NamedTree *
>(Child.getIndexed(index));};
706 inline operator bool()
const
707 {
return (Id != NULL);};
714 {
return (Id == NULL);};
721 void setId(
char *name);
734 {
return (Child.begin() == NULL);};
741 {
return (Parent == NULL);};
760 {relistTail(trunk);};
872 {insertTail(
object);};
879 {insertHead(
object);};
927 class __EXPORT ObjectStack
961 {
return ObjectStack::pull();};
1002 virtual bool equal(
unsigned path, caddr_t key,
size_t size)
const;
1020 void enlist(
unsigned path,
MultiMap **index, caddr_t key,
unsigned size,
size_t keysize = 0);
1026 void delist(
unsigned path);
1032 MultiMap *next(
unsigned path)
const;
1041 static unsigned keyindex(caddr_t key,
unsigned max,
size_t size = 0);
1052 static MultiMap *find(
unsigned path,
MultiMap **index, caddr_t key,
unsigned max,
size_t size = 0);
1062 template <
typename T,
class O=NamedObject>
1072 {LinkedObject::enlist(root); O::id = name;};
1079 {this->set(typed_value);};
1088 {
return static_cast<named_value *
>(NamedObject::find(first, name));};
1099 template <
typename T,
class O=OrderedObject>
1113 {LinkedObject::enlist(root);};
1120 {O::enlist(index);};
1128 {LinkedObject::enlist(root); this->set(typed_value);};
1136 {O::enlist(index); this->set(typed_value);};
1143 {this->set(typed_value);};
1170 {ObjectStack::push(
object);}
1177 {ObjectStack::push(
object);}
1184 {
return (T *)ObjectStack::pull();}
1191 {
return (T *)ObjectStack::pull();}
1228 {
return (T *)OrderedIndex::get();}
1235 {
return (T *)OrderedIndex::get();}
1271 {
return (T *)ObjectQueue::pull();}
1278 {
return (T *)ObjectQueue::pop();}
1306 {ptr = pointer.ptr;};
1313 {ptr =
static_cast<T*
>(pointer);};
1316 {ptr =
static_cast<T*
>(pointer);};
1323 {ptr =
static_cast<T*
>(index->
begin());};
1343 {ptr = pointer.ptr;};
1350 {ptr =
static_cast<T*
>(index->
begin());};
1357 {ptr =
static_cast<T*
>(pointer);};
1377 inline operator T*()
const
1384 {ptr =
static_cast<T*
>(ptr->getPrev());};
1390 {ptr =
static_cast<T*
>(ptr->getNext());};
1397 {
return static_cast<T*
>(ptr->getNext());};
1405 {
return static_cast<T*
>(ptr->getPrev());};
1411 {ptr =
static_cast<T*
>(ptr->getNext());};
1417 {ptr =
static_cast<T*
>(ptr->getPrev());};
1424 {
return (ptr->getNext() != NULL);};
1431 {
return (ptr->getPrev() != NULL);};
1437 inline operator bool()
const
1438 {
return (ptr != NULL);};
1445 {
return (ptr == NULL);};
1462 template <
typename T,
unsigned P>
1483 inline T &
get(void)
const
1492 {
return static_cast<multimap*
>(MultiMap::next(path));};
1512 inline void set(
const T &reference)
1513 {value = reference;};
1532 {
return static_cast<multimap*
>(MultiMap::find(path, index, key, size, keysize));};
1552 template <
typename T>
1571 {value = source.value;};
1587 NamedTree(parent, name) {value = reference;};
1593 inline const T&
get(void)
const
1609 {
return (node == NULL) ? NULL : node->value;};
1616 {
return (!Child.begin() && value != NULL);};
1643 inline void set(
const T& reference)
1644 {value = reference;};
1659 {
return static_cast<treemap*
>(Child.getIndexed(index));};
1666 {
return static_cast<treemap*
>(Parent);};
1675 {
return static_cast<treemap*
>(NamedTree::getChild(name));};
1684 {
return static_cast<treemap*
>(NamedTree::getLeaf(name));};
1694 {
return getPointer(getLeaf(name));};
1703 {
return static_cast<treemap*
>(NamedTree::find(name));};
1712 {
return static_cast<treemap*
>(NamedTree::path(path));};
1721 {
return static_cast<treemap*
>(NamedTree::leaf(name));};
1728 {
return static_cast<treemap*
>(NamedTree::getFirst());};
1738 template <
class T,
unsigned M = 177>
1749 {NamedObject::purge(idx, M);};
1770 inline T *
get(
const char *name)
const
1771 {
return static_cast<T*
>(NamedObject::map(idx, name, M));};
1779 {
return static_cast<T*
>(NamedObject::map(idx, name, M));};
1786 inline void add(
const char *name, T&
object)
1787 {
object.NamedObject::add(idx, name, M);};
1794 inline void add(
const char *name, T *
object)
1795 {
object->NamedObject::add(idx, name, M);};
1802 inline T *
remove(
const char *name)
1803 {
return static_cast<T*
>(NamedObject::remove(idx, name, M));};
1810 {
return static_cast<T*
>(NamedObject::skip(idx, NULL, M));};
1818 {
return static_cast<T*
>(NamedObject::skip(idx, current, M));};
1825 {
return NamedObject::count(idx, M);};
1834 {
return NamedObject::index(idx, M);};
1843 {
return NamedObject::sort(NamedObject::index(idx, M));};
1874 {
return static_cast<T*
>(head);};
1882 {
return static_cast<T*
>(tail);};
1891 {
return new T(
this, name);};
1899 {
return static_cast<T*
>(current->
getNext());};
1907 {
return static_cast<T*
>(NamedObject::find(begin(), name));};
1909 inline T *offset(
unsigned offset)
1910 {
return static_cast<T*
>(OrderedIndex::find(offset));};
1918 {
return static_cast<T&
>(OrderedIndex::find(offset));};
1920 inline T& operator[](
const char *name)
1921 {
return static_cast<T&
>(NamedObject::find(begin(), name));};
1930 {
return static_cast<T**
>(OrderedIndex::index());};
1939 {
return static_cast<T**
>(NamedObject::sort(index()));};
void operator=(const T &typed_value)
Assign embedded value from related type.
void add(const char *name, T *object)
Add a typed object derived from NamedObject to the hash map by name.
void set(const T &reference)
Set the value of a data based value tree.
unsigned count(void) const
Count the number of typed objects in our hash map.
virtual void enlist(OrderedIndex *index)
List our ordered object in default strategy mode.
void operator+=(LinkedList *object)
Insert object behind our object.
T &() max(T &o1, T &o2)
Convenience function to return max of two objects.
T * operator->() const
Return member from typed object our pointer references.
OrderedIndex objfifo_t
Convenience type for a fifo of linked objects.
bool equal(const char *name) const
Equal function which calls compare.
Class for resource bound memory pools between threads.
Template for typesafe basic object stack container.
T * pull(void)
Pull an object from the object stack.
treemap * find(const char *name) const
Find a subnode from our node by name.
~keymap()
Destroy the hash map by puring the index chains.
ObjectStack objstack_t
Convenience type for a stack of linked objects.
LinkedObject * end(void) const
Return last object in list for iterators.
multimap * next(unsigned path)
Return next multimap typed object.
linked_value(LinkedObject **root)
Construct embedded object on a linked list.
void enlistTail(OrderedIndex *index)
List our ordered object at end of a linked list on an index.
OrderedIndex * getIndex(void) const
Get the ordered index of our child nodes.
Template for typesafe basic object fifo container.
A smart pointer template for iterating linked lists.
static const LinkedObject * inv
Marker for invalid list pointer.
void enlistHead(OrderedIndex *index)
List our ordered object at start of a linked list on an index.
T & operator[](const char *name) const
Find a typed object derived from NamedObject in the hash map by name.
void operator=(OrderedIndex *index)
Assign our pointer from the start of an ordered index.
ObjectQueue objqueue_t
Convenience type for a queue of linked objects.
objfifo()
Create a new object stack.
void add(T *object)
Add an object onto the object stack.
treemap(treemap *parent, char *name)
Construct a child node on an existing tree.
Various miscellaneous platform specific headers and defines.
treemap * leaf(const char *name) const
Search for a leaf node of our node.
treemap(const treemap &source)
Construct a copy of the treemap object.
Template for embedding a data structure into a reference counted object.
T ** index(void)
Convert our linked list into a linear object pointer array.
LinkedList * getNext(void) const
Get next node in the list when iterating.
NamedObject * getNext(void) const
Get next effective object when iterating.
char * getId(void) const
Get the named id string of this object.
void setPointer(const T pointer)
Set the pointer of a pointer based value tree.
T * next(LinkedObject *current)
Iterate next object in list.
T * operator*() const
Return object we currently point to.
const T & getData(void) const
Get the data value of a data based value tree.
linked_pointer(LinkedObject *pointer)
Create a linked pointer assigned from a raw linked object pointer.
T * begin(void) const
Find first typed object in hash map to iterate.
NamedTree * getFirst(void) const
Get first child node in our ordered list of children.
OrderedIndex & operator=(const OrderedIndex &object)
Assign ordered index.
A template for ordered index of typed name key mapped objects.
bool is_next(void) const
Test for next member in linked list.
A multipath linked list where membership is managed in multiple lists.
treemap * getChild(const char *name) const
Get direct typed child node of our node of specified name.
OrderedObject * getNext(void) const
Get next ordered member when iterating.
void setPointer(const T pointer)
Set the pointer of a pointer based value tree.
A linked object base class with members found by name.
void add(T *object)
Add an object to the end of the object queue.
objstack(T *list)
Create an object stack from a list of objects.
void enlist(LinkedObject **root)
Add our object to an existing linked list through a pointer.
NamedTree * getParent(void) const
Get parent node we are listed as a child on.
void delist(LinkedObject **root)
Locate and remove ourselves from a list of objects.
T ** index(void) const
Convert our hash map into a linear object pointer array.
void relist(NamedTree *trunk=((void *) 0))
Default relist is by tail...
const T getPointer(void) const
Get the pointer of a pointer based value tree.
named_value(LinkedObject **root, char *name)
Construct embedded named object on a linked list.
ReusableObject * getNext(void)
Get next effective reusable object when iterating.
void prev(void)
Move (iterate) pointer to previous member in double linked list.
static const LinkedObject * nil
Marker for end of linked list.
void operator=(LinkedObject *pointer)
Assign our pointer from a generic linked object pointer.
void push(T *object)
Push an object onto the object fifo.
bool operator!() const
Test if linked list is empty/we are at end of list.
T * pull(void)
Pull an object from the start of the object queue.
treemap(treemap *parent, char *name, T &reference)
Construct a child node on an existing tree and assign it's value.
treemap * getParent(void) const
Get the typed parent node for our node.
treemap(char *name=((void *) 0))
Construct a typed root node for the tree.
static T getPointer(treemap *node)
Return value from tree element when value is a pointer.
static named_value find(named_value *first, const char *name)
Find embedded object in chain by name.
A queue of double linked object.
NamedObject ** root(void)
Return a root node pointer to use in NamedObject constructors.
Common base class for all objects that can be formed into a linked list.
bool is_tail(void) const
Test if we are at the end of a list.
linked_pointer(const linked_pointer &pointer)
Create a copy of an existing linked pointer.
void push(T *object)
Push an object onto the object stack.
T * pop(void)
Pop an object from the end of the object queue.
treemap * getFirst(void) const
Get first child of our node.
bool operator!=(const char *name) const
Comparison operator between our name and a string.
T * begin(void)
Return first item in ordered list.
T * find(const char *name)
Find a specific object by name.
void delist(OrderedIndex *index)
Remove our ordered object from an existing index.
A linked object base class for ordered objects.
void operator=(T *pointer)
Assign our typed iterative pointer from a matching typed object.
treemap * path(const char *path) const
Find a subnode by pathname.
Template value class to embed data structure into a named list.
Template value class to embed data structure into a linked list.
LinkedObject * operator*() const
Return head object pointer.
void add(T *object)
Add an object onto the object fifo.
void operator=(const T &data)
Assign the value of our node.
static void purge(LinkedObject *root)
Release all objects from a list.
bool is_prev(void) const
Test for previous member in double linked list.
linked_value(OrderedIndex *index, const T &typed_value)
Assign embedded value from related type and add to list.
ObjectProtocol * copy(ObjectProtocol *object)
Convenience function to access object copy.
T * pop(void)
Pull (pop) an object from the object stack.
T * pull(void)
Pull an object from the object stack.
bool is_head(void) const
Test if we are at the head of a list.
T * create(const char *name)
Create a new typed named object with default constructor.
void add(const char *name, T &object)
Add a typed object derived from NamedObject to the hash map by name.
void set(const T &reference)
Set the value of a data based value tree.
Embed data objects into a multipap structured memory database.
const T & operator*() const
Return typed value of this node by pointer reference.
static multimap * find(unsigned path, MultiMap **index, caddr_t key, unsigned size, unsigned keysize=0)
Find multimap key entry.
static void purge(NamedObject **hash, unsigned size)
Purge a hash indexed table of named objects.
multimap()
Construct a multimap node.
void next(void)
Move (iterate) pointer to next member in linked list.
LinkedObject * begin(void) const
Return first object in list for iterators.
bool operator!() const
Test if this node is unnamed.
T & operator*() const
Return typed value of this node by pointer reference.
objstack()
Create a new object stack.
LinkedObject * LinkedIndex
Convenience typedef for root pointers of single linked lists.
T getValue(const char *name) const
Get the value pointer of a leaf node of a pointer tree.
void operator*=(LinkedList *object)
Insert object in list with our object.
linked_pointer(OrderedIndex *index)
Create a linked pointer to examine an ordered index.
T * next(T *current) const
Find next typed object in hash map for iteration.
Embed data objects into a tree structured memory database.
bool is_attribute(void) const
Test if this node is a leaf node for a tree pointer table.
treemap * getLeaf(const char *name) const
Find a direct typed leaf node on our node.
Reusable objects for forming private heaps.
T * end(void)
Return last item in ordered list.
virtual void release(void)=0
Method to release (or decrease retention) of an object.
A common object base class with auto-pointer support.
LinkedList * getPrev(void) const
Get previous node in the list for reverse iteration.
T & operator[](unsigned offset)
Retrieve a specific object by position in list.
T ** sort(void) const
Convert our hash map into an alphabetically sorted linear object pointer array.
void operator++()
Move (iterate) pointer to next member in linked list.
objqueue()
Create a new object stack.
~multimap()
Destroy a multimap object.
void operator=(const T &data)
Assign the value of our node.
LinkedObject * getIndexed(unsigned index) const
Get an indexed member from the ordered index.
linked_value()
Create embedded value object unlinked.
unsigned limit(void) const
Retrieve key size to use in NamedObject constructors.
A double linked list object.
NamedTree * getIndexed(unsigned index) const
Get child by index number.
A common base class for all managed objects.
linked_pointer()
Create a linked pointer not attached to a list.
void operator--()
Move (iterate) pointer to previous member in double linked list.
void operator-=(LinkedList *object)
Insert object in front of our object.
T ** sort(void)
Convert our linked list into an alphabetically sorted linear object pointer array.
NamedObject ** root(void) const
Retrieve root of index to use in NamedObject constructors.
linked_pointer(T *pointer)
Create a linked pointer and assign to start of a list.
static NamedObject * find(NamedObject *root, const char *name)
Find a named object from a simple list.
An index container for maintaining an ordered list of objects.
Template for typesafe basic object queue container.
linked_value(LinkedObject **root, const T &typed_value)
Assign embedded value from related type and link to list.
LinkedObject ** root(void) const
Return pointer to our linked pointer to use as root node of a chain.
A template class for a hash map.
void push(T *object)
Push an object to start of queue.
Generic smart pointer class.
T * getNext(void) const
Get the next member in linked list.
void operator=(const T &typed_value)
Assign embedded value from related type.
bool is_leaf(void) const
Test if node has children.
T * getPrev(void) const
Get the previous member in double linked list.
void operator=(linked_pointer &pointer)
Assign our pointer from another pointer.
treemap * getIndexed(unsigned index) const
Get child member node by index.
virtual void release(void)
Release list, mark as no longer linked.
The named tree class is used to form a tree oriented list of associated objects.
virtual void retain(void)=0
Method to retain (or increase retention) of an object.
void add(OrderedObject *ordered)
Add an object into the ordered index.
T * pop(void)
Pull (pop) an object from the object stack.
bool is_root(void) const
Test if node is root node.
linked_value(OrderedIndex *index)
Construct embedded object on an ordered list.
static unsigned count(const LinkedObject *root)
Count the number of linked objects in a list.
bool operator==(const char *name) const
Comparison operator between our name and a string.
A double-linked Object, used for certain kinds of lists.
LinkedObject * getNext(void) const
Get next effective object when iterating.