33 #ifndef _UCOMMON_LINKED_H_
34 #define _UCOMMON_LINKED_H_
36 #ifndef _UCOMMON_CONFIG_H_
40 #ifndef _UCOMMON_OBJECT_H_
55 class __EXPORT LinkedObject :
public __PROTOCOL ObjectProtocol
58 friend class OrderedIndex;
59 friend class NamedObject;
68 LinkedObject(LinkedObject **root);
77 LinkedObject(
const LinkedObject& from);
80 virtual ~LinkedObject();
85 virtual void release(
void) __OVERRIDE;
90 virtual void retain(
void) __OVERRIDE;
98 void enlist(LinkedObject **root);
106 void delist(LinkedObject **root);
112 bool is_member(LinkedObject *list)
const;
118 static void purge(LinkedObject *root);
124 static unsigned count(
const LinkedObject *root);
132 static LinkedObject *getIndexed(LinkedObject *root,
unsigned index);
138 inline LinkedObject *getNext(
void)
const {
152 class __EXPORT ReusableObject :
public LinkedObject
154 friend class ReusableAllocator;
157 virtual void release(
void) __OVERRIDE;
164 inline ReusableObject *getNext(
void) {
165 return polypointer_cast<ReusableObject*>(LinkedObject::getNext());
176 class __EXPORT OrderedIndex
179 friend class OrderedObject;
180 friend class DLinkedObject;
181 friend class NamedObject;
183 OrderedObject *head, *tail;
186 void copy(
const OrderedIndex& source);
193 inline OrderedIndex(
const OrderedIndex& source) {
200 virtual ~OrderedIndex();
206 LinkedObject *find(
unsigned offset)
const;
212 unsigned count(
void)
const;
228 virtual void lock_index(
void);
234 virtual void unlock_index(
void);
242 LinkedObject **index(
void)
const;
249 LinkedObject *get(
void);
255 void add(OrderedObject *ordered);
262 inline LinkedObject *getIndexed(
unsigned index)
const {
263 return LinkedObject::getIndexed(polystatic_cast<LinkedObject*>(head), index);
270 inline LinkedObject *begin(
void)
const {
271 return polystatic_cast<LinkedObject*>(head);
278 inline LinkedObject *end(
void)
const {
279 return polystatic_cast<LinkedObject*>(tail);
286 inline LinkedObject *operator*()
const {
287 return polystatic_cast<LinkedObject*>(head);
294 OrderedIndex& operator=(
const OrderedIndex&
object) {
303 void operator*=(OrderedObject *
object);
312 class __EXPORT OrderedObject :
public LinkedObject
315 friend class DLinkedObject;
316 friend class OrderedIndex;
323 OrderedObject(OrderedIndex *index);
330 OrderedObject(
const OrderedObject& from);
337 void enlistTail(OrderedIndex *index);
343 void enlistHead(OrderedIndex *index);
350 virtual void enlist(OrderedIndex *index);
356 void delist(OrderedIndex *index);
362 inline OrderedObject *getNext(
void)
const {
363 return static_cast<OrderedObject *
>(LinkedObject::getNext());
381 class __EXPORT NamedObject :
public OrderedObject
397 NamedObject(NamedObject **hash,
char *name,
unsigned size = 1);
405 NamedObject(OrderedIndex *index,
char *name);
420 virtual void clearId(
void);
429 void add(NamedObject **hash,
char *name,
unsigned size = 1);
436 static void purge(NamedObject **hash,
unsigned size);
446 static NamedObject **index(NamedObject **hash,
unsigned size);
453 static unsigned count(NamedObject **hash,
unsigned size);
462 static NamedObject *find(NamedObject *root,
const char *name);
470 static NamedObject *remove(NamedObject **root,
const char *name);
479 static NamedObject *map(NamedObject **hash,
const char *name,
unsigned size);
488 static NamedObject *remove(NamedObject **hash,
const char *name,
unsigned size);
497 static NamedObject *skip(NamedObject **hash, NamedObject *current,
unsigned size);
504 static unsigned keyindex(
const char *name,
unsigned size);
513 static NamedObject **sort(NamedObject **list,
size_t count = 0);
519 inline NamedObject *getNext(
void)
const {
520 return static_cast<NamedObject*
>(LinkedObject::getNext());
527 inline char *getId(
void)
const {
538 virtual int compare(
const char *name)
const;
545 inline bool equal(
const char *name)
const {
546 return (compare(name) == 0);
554 inline bool operator==(
const char *name)
const {
555 return compare(name) == 0;
563 inline bool operator!=(
const char *name)
const {
564 return compare(name) != 0;
575 class __EXPORT NamedTree :
public NamedObject
585 NamedTree(
char *name = NULL);
592 NamedTree(NamedTree *parent,
char *name);
598 NamedTree(
const NamedTree& source);
605 virtual ~NamedTree();
623 NamedTree *find(
const char *name)
const;
635 NamedTree *path(
const char *path)
const;
644 NamedTree *leaf(
const char *name)
const;
651 NamedTree *getChild(
const char *name)
const;
659 NamedTree *getLeaf(
const char *name)
const;
667 inline NamedTree *getFirst(
void)
const {
668 return static_cast<NamedTree *
>(Child.begin());
675 inline NamedTree *getParent(
void)
const {
676 return static_cast<NamedTree *
>(Parent);
684 inline NamedTree *getIndexed(
unsigned index)
const {
685 return static_cast<NamedTree *
>(Child.getIndexed(index));
692 inline OrderedIndex *getIndex(
void)
const {
693 return const_cast<OrderedIndex*
>(&Child);
700 inline operator bool()
const {
708 inline bool operator!()
const {
717 void setId(
char *name);
729 inline bool is_leaf(
void)
const {
730 return (Child.begin() == NULL);
737 inline bool is_root(
void)
const {
738 return (Parent == NULL);
745 void relistTail(NamedTree *trunk);
751 void relistHead(NamedTree *trunk);
757 inline void relist(NamedTree *trunk = NULL) {
768 class __EXPORT DLinkedObject :
public OrderedObject
771 friend class ObjectQueue;
780 DLinkedObject(OrderedIndex *index);
787 DLinkedObject(
const DLinkedObject& from);
793 virtual ~DLinkedObject();
806 void enlistHead(OrderedIndex *index);
813 void enlistTail(OrderedIndex *index);
820 void enlist(OrderedIndex *index);
826 inline bool is_head(
void)
const {
827 return polypointer_cast<DLinkedObject *>(Root->head) ==
this;
834 inline bool is_tail(
void)
const {
835 return polypointer_cast<DLinkedObject *>(Root->tail) ==
this;
842 inline DLinkedObject *getPrev(
void)
const {
843 return static_cast<DLinkedObject*
>(Prev);
850 inline DLinkedObject *getNext(
void)
const {
851 return static_cast<DLinkedObject*
>(LinkedObject::getNext());
858 void insertTail(DLinkedObject *
object);
864 void insertHead(DLinkedObject *
object);
870 virtual void insert(DLinkedObject *
object);
876 inline DLinkedObject& operator+=(DLinkedObject *
object) {
885 inline DLinkedObject& operator-=(DLinkedObject *
object) {
894 inline DLinkedObject& operator*=(DLinkedObject *
object) {
908 template <
typename T,
class O = LinkedObject>
927 LinkedObject::enlist(root);
944 LinkedObject::enlist(root);
958 inline void set(
const T& typed_value) {
971 inline T& operator*() {
975 inline operator T&() {
979 inline void operator()(
const T data) {
1018 ptr =
static_cast<T*
>(
pointer);
1022 ptr =
static_cast<T*
>(
pointer);
1030 ptr =
static_cast<T*
>(index->begin());
1061 ptr =
static_cast<T*
>(index->begin());
1069 ptr =
static_cast<T*
>(
pointer);
1092 inline operator T*()
const {
1100 ptr =
static_cast<T*
>(ptr->getPrev());
1107 ptr =
static_cast<T*
>(ptr->getNext());
1115 return static_cast<T*
>(ptr->getNext());
1124 return static_cast<T*
>(ptr->getPrev());
1131 ptr =
static_cast<T*
>(ptr->getNext());
1138 ptr =
static_cast<T*
>(ptr->getPrev());
1146 return (ptr->getNext() != NULL);
1154 return (ptr->getPrev() != NULL);
1161 inline operator bool()
const {
1162 return (ptr != NULL);
1170 return (ptr == NULL);
1173 inline bool is()
const {
1174 return (ptr != NULL);
1181 inline LinkedObject **
root(
void)
const {
1183 return static_cast<LinkedObject**
>(r);
1204 template <
typename T>
1216 inline treemap(
char *name = NULL) : NamedTree(name) {}
1223 value = source.value;
1239 inline treemap(
treemap *parent,
char *name, T& reference) : NamedTree(parent, name) {
1247 inline const T&
get(
void)
const {
1265 return (node == NULL) ? NULL : node->value;
1273 return (!Child.begin() && value != NULL);
1304 inline void set(
const T& reference) {
1322 return static_cast<treemap*
>(Child.getIndexed(index));
1330 return static_cast<treemap*
>(Parent);
1340 return static_cast<treemap*
>(NamedTree::getChild(name));
1350 return static_cast<treemap*
>(NamedTree::getLeaf(name));
1371 return static_cast<treemap*
>(NamedTree::find(name));
1381 return static_cast<treemap*
>(NamedTree::path(
path));
1391 return static_cast<treemap*
>(NamedTree::leaf(name));
1399 return static_cast<treemap*
>(NamedTree::getFirst());
1408 typedef DLinkedObject LinkedList;
Various miscellaneous platform specific headers and defines.
Common namespace for all ucommon objects.
LinkedObject * LinkedIndex
Convenience typedef for root pointers of single linked lists.
T copy(const T &src)
Convenience function to copy objects.
Generic smart pointer class.
A linked object base class for ordered objects.
linked_value(OrderedIndex *index)
Construct embedded object on an ordered list.
linked_value & operator=(const T &typed_value)
Assign embedded value from related type.
linked_value(LinkedObject **root, const T &typed_value)
Assign embedded value from related type and link to list.
linked_value(LinkedObject **root)
Construct embedded object on a linked list.
linked_value(OrderedIndex *index, const T &typed_value)
Assign embedded value from related type and add to list.
linked_value()
Create embedded value object unlinked.
A smart pointer template for iterating linked lists.
T * operator*() const
Return object we currently point to.
T * operator->() const
Return member from typed object our pointer references.
T * getPrev(void) const
Get the previous member in double linked list.
LinkedObject ** root(void) const
Return pointer to our linked pointer to use as root node of a chain.
linked_pointer(T *pointer)
Create a linked pointer and assign to start of a list.
void operator=(T *pointer)
Assign our typed iterative pointer from a matching typed object.
T * getNext(void) const
Get the next member in linked list.
linked_pointer(OrderedIndex *index)
Create a linked pointer to examine an ordered index.
void prev(void)
Move (iterate) pointer to previous member in double linked list.
void operator++()
Move (iterate) pointer to next member in linked list.
void operator=(linked_pointer &pointer)
Assign our pointer from another pointer.
void operator--()
Move (iterate) pointer to previous member in double linked list.
void operator=(LinkedObject *pointer)
Assign our pointer from a generic linked object pointer.
linked_pointer()
Create a linked pointer not attached to a list.
void next(void)
Move (iterate) pointer to next member in linked list.
linked_pointer(LinkedObject *pointer)
Create a linked pointer assigned from a raw linked object pointer.
bool is_next(void) const
Test for next member in linked list.
linked_pointer(const linked_pointer &pointer)
Create a copy of an existing linked pointer.
void operator=(OrderedIndex *index)
Assign our pointer from the start of an ordered index.
bool operator!() const
Test if linked list is empty/we are at end of list.
bool is_prev(void) const
Test for previous member in double linked list.
Embed data objects into a tree structured memory database.
treemap * getParent(void) const
Get the typed parent node for our node.
treemap(char *name=NULL)
Construct a typed root node for the tree.
const T & get(void) const
Return the typed value of this node.
const T & operator*() const
Return typed value of this node by pointer reference.
treemap * find(const char *name) const
Find a subnode from our node by name.
treemap * path(const char *path) const
Find a subnode by pathname.
void operator=(const T &data)
Assign the value of our node.
const T & getData(void) const
Get the data value of a data based value tree.
T getValue(const char *name) const
Get the value pointer of a leaf node of a pointer tree.
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.
static T getPointer(treemap *node)
Return value from tree element when value is a pointer.
const T getPointer(void) const
Get the pointer of a pointer based value tree.
bool is_attribute(void) const
Test if this node is a leaf node for a tree pointer table.
void set(const T &reference)
Set the value of a data based value tree.
treemap * getFirst(void) const
Get first child of our node.
treemap(treemap *parent, char *name)
Construct a child node on an existing tree.
void setPointer(const T pointer)
Set the pointer of a pointer based value tree.
treemap * getChild(const char *name) const
Get direct typed child node of our node of specified name.
treemap(treemap *parent, char *name, T &reference)
Construct a child node on an existing tree and assign it's value.
treemap * getIndexed(unsigned index) const
Get child member node by index.
treemap * getLeaf(const char *name) const
Find a direct typed leaf node on our node.
A common object base class with auto-pointer support.