Yate
ObjList Class Reference

An object list class. More...

#include <yateclass.h>

Inheritance diagram for ObjList:
GenObject

Public Member Functions

 ObjList ()
virtual ~ObjList ()
virtual void * getObject (const String &name) const
unsigned int length () const
unsigned int count () const
GenObjectget () const
GenObjectset (const GenObject *obj, bool delold=true)
ObjListnext () const
ObjListlast () const
ObjListskipNull () const
ObjListskipNext () const
GenObjectat (int index) const
ObjListoperator+ (int index) const
GenObjectoperator[] (signed int index) const
GenObjectoperator[] (unsigned int index) const
GenObjectoperator[] (const String &str) const
ObjListfind (const GenObject *obj) const
GenObjectfindObj (const GenObject *obj) const
ObjListfind (const String &str) const
int index (const GenObject *obj) const
int index (const String &str) const
ObjListinsert (const GenObject *obj, bool compact=true)
ObjListappend (const GenObject *obj, bool compact=true)
ObjListsetUnique (const GenObject *obj, bool compact=true)
GenObjectremove (bool delobj=true)
GenObjectremove (GenObject *obj, bool delobj=true)
GenObjectremove (const String &str, bool delobj=true)
void clear ()
void compact ()
bool autoDelete ()
void setDelete (bool autodelete)
GenObjectfind (Lockable &lock, const GenObject *obj, bool ref=false, long maxwait=-1) const
GenObjectfind (Lockable &lock, const String &str, bool ref=false, long maxwait=-1) const
ObjListinsert (Lockable &lock, const GenObject *obj, bool autoDelete=true, long maxwait=-1, bool compact=true)
ObjListappend (Lockable &lock, const GenObject *obj, bool autoDelete=true, long maxwait=-1, bool compact=true)
ObjListsetUnique (Lockable &lock, const GenObject *obj, bool autoDelete=true, long maxwait=-1, bool compact=true)
GenObjectremove (Lockable &lock, bool delobj=true, long maxwait=-1)
GenObjectremove (Lockable &lock, GenObject *obj, bool delobj=true, long maxwait=-1)
GenObjectremove (Lockable &lock, const String &str, bool delobj=true, long maxwait=-1)
void clear (Lockable &lock, long maxwait=-1)
void compact (Lockable &lock, long maxwait=-1)
ObjListmove (ObjList *dest, Lockable *lock=0, long maxwait=-1)
ObjListcopy (ObjList *dest, Lockable *lock=0, long maxwait=-1) const
void sort (int(*callbackCompare)(GenObject *obj1, GenObject *obj2, void *context), void *context=0)
Public Member Functions inherited from GenObject
 GenObject ()
virtual ~GenObject ()
virtual bool alive () const
virtual void destruct ()
virtual const StringtoString () const
virtual const StringtraceId () const
NamedCountergetObjCounter () const
NamedCountersetObjCounter (NamedCounter *counter)

Static Public Member Functions

static const ObjListempty ()
Static Public Member Functions inherited from GenObject
static void * getObject (const String &name, const GenObject *obj)
static bool getObjCounting ()
static void setObjCounting (bool enable)
static NamedCountergetObjCounter (const String &name, bool create=true)
static ObjListgetObjCounters ()

Detailed Description

An object list class.

A simple single-linked object list handling class

Constructor & Destructor Documentation

◆ ObjList()

◆ ~ObjList()

virtual ~ObjList ( )
virtual

Destroys the list and everything in it.

Member Function Documentation

◆ append() [1/2]

ObjList * append ( const GenObject * obj,
bool compact = true )

Append an object to the end of the list

Parameters
objPointer to the object to append
compactTrue to replace NULL values in list if possible
Returns
A pointer to the inserted list item

References compact(), GenObject::GenObject(), and ObjList().

◆ append() [2/2]

ObjList * append ( Lockable & lock,
const GenObject * obj,
bool autoDelete = true,
long maxwait = -1,
bool compact = true )

Append an object to the end of the list

Parameters
lockLockable to protect the operation. A RWLock will be write locked
objPointer to the object to set
autoDeleteObject autoDelete flag
maxwaitTime in microseconds to wait for locking, -1 wait forever
compactTrue to replace NULL values in list if possible
Returns
A pointer to the inserted list item

References autoDelete(), compact(), GenObject::GenObject(), and ObjList().

◆ at()

GenObject * at ( int index) const

Get the object at a specific index in list

Parameters
indexIndex of the object to retrieve
Returns
Pointer to the object or NULL

References GenObject::GenObject(), and index().

Referenced by operator[](), and operator[]().

◆ autoDelete()

bool autoDelete ( )
inline

Get the automatic delete flag

Returns
True if will delete on destruct, false otherwise

Referenced by append(), insert(), and setUnique().

◆ clear() [1/2]

void clear ( )

Clear the list and optionally delete all contained objects

◆ clear() [2/2]

void clear ( Lockable & lock,
long maxwait = -1 )

Safely clear the list and optionally delete all contained objects

Parameters
lockOptional Lockable to protect the operation. A RWLock will be write locked
maxwaitTime in microseconds to wait for locking, -1 wait forever

◆ compact() [1/2]

void compact ( )

Remove all empty objects in the list

Referenced by append(), append(), insert(), insert(), setUnique(), and setUnique().

◆ compact() [2/2]

void compact ( Lockable & lock,
long maxwait = -1 )

Safely remove all empty objects in the list

Parameters
lockOptional Lockable to protect the operation. A RWLock will be write locked
maxwaitTime in microseconds to wait for locking, -1 wait forever

◆ copy()

ObjList * copy ( ObjList * dest,
Lockable * lock = 0,
long maxwait = -1 ) const

Reference all items in this into another one

Parameters
destDestination list. Create a new one if not given
lockOptional Lockable to protect the operation. A RWLock will be read locked
maxwaitTime in microseconds to wait for locking, -1 wait forever
Returns
ObjList pointer ('dest' if given). The caller is owning the new list

References ObjList().

◆ count()

unsigned int count ( ) const

Get the number of non-null objects in the list

Returns
Count of items

Referenced by GenericVector< Obj >::append(), MatchingItemList::append(), and GenericVector< Obj >::assign().

◆ empty()

const ObjList & empty ( )
static

A static empty object list

Returns
Reference to a static empty list

References ObjList().

Referenced by XmlParent::getChildren().

◆ find() [1/4]

ObjList * find ( const GenObject * obj) const

Get the item in the list that holds an object

Parameters
objPointer to the object to search for
Returns
Pointer to the found item or NULL

References GenObject::GenObject(), and ObjList().

Referenced by ClientDir::findChildName(), XmlElement::findNextChild(), findObj(), NamedInt::lookup(), and operator[]().

◆ find() [2/4]

ObjList * find ( const String & str) const

Get the item in the list that holds an object by String value

Parameters
strString value (toString) of the object to search for
Returns
Pointer to the found item or NULL

References ObjList().

◆ find() [3/4]

GenObject * find ( Lockable & lock,
const GenObject * obj,
bool ref = false,
long maxwait = -1 ) const

Get the item in the list that holds an object

Parameters
lockLockable to protect the operation. A RWLock will be read locked
objPointer to the object to search for
refTrue to reference a found RefObject. the method will return NULL if a found object is not a RefObject one
maxwaitTime in microseconds to wait for locking, -1 wait forever
Returns
Pointer to the found item or NULL

References GenObject::GenObject().

◆ find() [4/4]

GenObject * find ( Lockable & lock,
const String & str,
bool ref = false,
long maxwait = -1 ) const

Get the item in the list that holds an object by String value

Parameters
lockLockable to protect the operation. A RWLock will be read locked
strString value (toString) of the object to search for
refTrue to reference a found RefObject. the method will return NULL if a found object is not a RefObject one
maxwaitTime in microseconds to wait for locking, -1 wait forever
Returns
Pointer to the found item or NULL

References GenObject::GenObject().

◆ findObj()

GenObject * findObj ( const GenObject * obj) const
inline

Find an object by pointer

Parameters
objPointer to the object to search for
Returns
Pointer to the object or NULL

References find(), GenObject::GenObject(), get(), and ObjList().

◆ get()

GenObject * get ( ) const
inline

Get the object associated to this list item

Returns
Pointer to the object or NULL

References GenObject::GenObject().

Referenced by ClientDir::findChildName(), findObj(), XmlFragment::getText(), NamedInt::lookup(), and operator[]().

◆ getObject()

virtual void * getObject ( const String & name) const
virtual

Get a pointer to a derived class given that class name

Parameters
nameName of the class we are asking for
Returns
Pointer to the requested class or NULL if this object doesn't implement it

Reimplemented from GenObject.

◆ index() [1/2]

int index ( const GenObject * obj) const

Get the position in list of a GenObject by a pointer to it

Parameters
objPointer to the object to search for
Returns
Index of object in list, -1 if not found

References GenObject::GenObject().

Referenced by at(), operator+(), operator[](), and operator[]().

◆ index() [2/2]

int index ( const String & str) const

Get the position in list of the first GenObject with a given value

Parameters
strString value (toString) of the object to search for
Returns
Index of object in list, -1 if not found

◆ insert() [1/2]

ObjList * insert ( const GenObject * obj,
bool compact = true )

Insert an object at this point

Parameters
objPointer to the object to insert
compactTrue to replace NULL values in list if possible
Returns
A pointer to the inserted list item

References compact(), GenObject::GenObject(), and ObjList().

◆ insert() [2/2]

ObjList * insert ( Lockable & lock,
const GenObject * obj,
bool autoDelete = true,
long maxwait = -1,
bool compact = true )

Insert an object at this point

Parameters
lockLockable to protect the operation. A RWLock will be write locked
objPointer to the object to set
autoDeleteObject autoDelete flag
maxwaitTime in microseconds to wait for locking, -1 wait forever
compactTrue to replace NULL values in list if possible
Returns
A pointer to the inserted list item

References autoDelete(), compact(), GenObject::GenObject(), and ObjList().

◆ last()

ObjList * last ( ) const

Get the last item in the list

Returns
Pointer to the last item in list

References ObjList().

◆ length()

unsigned int length ( ) const

Get the number of elements in the list

Returns
Count of items

◆ move()

ObjList * move ( ObjList * dest,
Lockable * lock = 0,
long maxwait = -1 )

Move or copy this list into another one autoDelete() is set in destination as found for each item in list

Parameters
destDestination list. Create a new one if not given
lockOptional Lockable to protect the operation. A RWLock will be write locked
maxwaitTime in microseconds to wait for locking, -1 wait forever
Returns
ObjList pointer ('dest' if given). The caller is owning the new list

References ObjList().

◆ next()

ObjList * next ( ) const
inline

Get the next item in the list

Returns
Pointer to the next item in list or NULL

References ObjList().

◆ operator+()

ObjList * operator+ ( int index) const

Pointer-like indexing operator

Parameters
indexIndex of the list item to retrieve
Returns
Pointer to the list item or NULL

References index(), and ObjList().

◆ operator[]() [1/3]

GenObject * operator[] ( const String & str) const
inline

Find an object by name

Parameters
strString value of the object to locate
Returns
Pointer to the object or NULL

References find(), GenObject::GenObject(), get(), and ObjList().

◆ operator[]() [2/3]

GenObject * operator[] ( signed int index) const
inline

Array-like indexing operator with signed parameter

Parameters
indexIndex of the object to retrieve
Returns
Pointer to the object or NULL

References at(), GenObject::GenObject(), and index().

◆ operator[]() [3/3]

GenObject * operator[] ( unsigned int index) const
inline

Array-like indexing operator with unsigned parameter

Parameters
indexIndex of the object to retrieve
Returns
Pointer to the object or NULL

References at(), GenObject::GenObject(), and index().

◆ remove() [1/6]

GenObject * remove ( bool delobj = true)

Delete this list item

Parameters
delobjTrue to delete the object (default)
Returns
Pointer to the object if not destroyed

References GenObject::GenObject().

Referenced by MatchingItemList::append(), HashList::remove(), and HashList::remove().

◆ remove() [2/6]

GenObject * remove ( const String & str,
bool delobj = true )

Delete the first list item that holds an object with a iven value

Parameters
strString value (toString) of the object to remove
delobjTrue to delete the object (default)
Returns
Pointer to the object if not destroyed

References GenObject::GenObject().

◆ remove() [3/6]

GenObject * remove ( GenObject * obj,
bool delobj = true )

Delete the list item that holds a given object

Parameters
objObject to search in the list
delobjTrue to delete the object (default)
Returns
Pointer to the object if not destroyed

References GenObject::GenObject().

◆ remove() [4/6]

GenObject * remove ( Lockable & lock,
bool delobj = true,
long maxwait = -1 )

Delete this list item

Parameters
lockOptional Lockable to protect the operation. A RWLock will be write locked
delobjTrue to delete the object (default)
maxwaitTime in microseconds to wait for locking, -1 wait forever
Returns
Pointer to the object if not destroyed

References GenObject::GenObject().

◆ remove() [5/6]

GenObject * remove ( Lockable & lock,
const String & str,
bool delobj = true,
long maxwait = -1 )

Delete the first list item that holds an object with a iven value

Parameters
lockOptional Lockable to protect the operation. A RWLock will be write locked
strString value (toString) of the object to remove
delobjTrue to delete the object (default)
maxwaitTime in microseconds to wait for locking, -1 wait forever
Returns
Pointer to the object if not destroyed

References GenObject::GenObject().

◆ remove() [6/6]

GenObject * remove ( Lockable & lock,
GenObject * obj,
bool delobj = true,
long maxwait = -1 )

Delete the list item that holds a given object

Parameters
lockOptional Lockable to protect the operation. A RWLock will be write locked
objObject to search in the list
delobjTrue to delete the object (default)
maxwaitTime in microseconds to wait for locking, -1 wait forever
Returns
Pointer to the object if not destroyed

References GenObject::GenObject().

◆ set()

GenObject * set ( const GenObject * obj,
bool delold = true )

Set the object associated to this list item

Parameters
objPointer to the new object to set
deloldTrue to delete the old object (default)
Returns
Pointer to the old object if not destroyed

References GenObject::GenObject().

◆ setDelete()

void setDelete ( bool autodelete)
inline

Set the automatic delete flag

Parameters
autodeleteTrue to delete on destruct, false otherwise

◆ setUnique() [1/2]

ObjList * setUnique ( const GenObject * obj,
bool compact = true )

Set unique entry in this list. If not found, append it to the list

Parameters
objPointer to the object to uniquely set in the list
compactTrue to replace NULL values in list if possible
Returns
A pointer to the set list item

References compact(), GenObject::GenObject(), and ObjList().

◆ setUnique() [2/2]

ObjList * setUnique ( Lockable & lock,
const GenObject * obj,
bool autoDelete = true,
long maxwait = -1,
bool compact = true )

Set unique entry in this list. If not found, append it to the list

Parameters
lockLockable to protect the operation. A RWLock will be write locked
objPointer to the object to set
autoDeleteObject autoDelete flag
maxwaitTime in microseconds to wait for locking, -1 wait forever
compactTrue to replace NULL values in list if possible
Returns
A pointer to the set list item

References autoDelete(), compact(), GenObject::GenObject(), and ObjList().

◆ skipNext()

ObjList * skipNext ( ) const

Advance in the list skipping over NULL holding items

Returns
Pointer to the next non NULL holding item in list or NULL

References ObjList().

Referenced by XmlElement::findNextChild(), XmlFragment::getText(), Module::itemComplete(), and NamedInt::lookupName().

◆ skipNull()

ObjList * skipNull ( ) const

Skip over NULL holding items in the list

Returns
Pointer to the first non NULL holding item in list or NULL

References ObjList().

Referenced by MatchingItemList::append(), DataTranslator::getConsumers(), XmlParent::hasChildren(), Module::itemComplete(), NamedInt::lookupName(), and NamedIterator::operator=().

◆ sort()

void sort ( int(* callbackCompare )(GenObject *obj1, GenObject *obj2, void *context),
void * context = 0 )

Sort this list

Parameters
callbackComparepointer to a callback function that should compare two objects.
    obj1 First object of the comparation
    obj2 Second object of the comparation
    context Data context
    return 0 if the objects are equal; positive value if obj2 > obj1; negative value if obj1 > obj2
    Note: the function should expect receiving null pointers
contextContext data.

References GenObject::GenObject(), and ObjList().


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