Yate
ObjVector Class Reference

A vector holding GenObjects. More...

#include <yateclass.h>

Inheritance diagram for ObjVector:
GenObject

Public Member Functions

 ObjVector (bool autodelete=true, unsigned int allocChunk=0)
 
 ObjVector (unsigned int maxLen, bool autodelete=true, unsigned int allocChunk=0)
 
 ObjVector (ObjList &list, bool move=true, unsigned int maxLen=0, bool autodelete=true, unsigned int allocChunk=0)
 
virtual ~ObjVector ()
 
virtual void * getObject (const String &name) const
 
unsigned int length () const
 
GenObject ** data ()
 
GenObject ** data (unsigned int offs, unsigned int len=1)
 
const GenObject ** data () const
 
const GenObject ** data (unsigned int offs, unsigned int len=1) const
 
unsigned int count () const
 
bool null () const
 
GenObjectat (unsigned int index) const
 
unsigned int assign (ObjList &list, bool move=true, unsigned int maxLen=0)
 
unsigned int insert (unsigned int pos, unsigned int items)
 
unsigned int cut (unsigned int pos, unsigned int items, bool reAlloc=true)
 
unsigned int cut (int items, bool reAlloc=true)
 
unsigned int resize (unsigned int len, bool keepData=false, bool reAlloc=true)
 
unsigned int compact (bool resizeToCount=false)
 
unsigned int compact (unsigned int pos, int len)
 
GenObjecttake (unsigned int index)
 
bool set (GenObject *obj, unsigned int index)
 
bool appendObj (GenObject *obj)
 
bool appendObj (GenObject *obj, bool fromStart, bool beforeNonNull=false)
 
bool insertObj (GenObject *obj, unsigned int pos)
 
int index (const GenObject *obj) const
 
int index (const String &str) const
 
int indexFree (bool fromStart, bool beforeNonNull=false) const
 
GenObjectoperator[] (unsigned int idx) const
 
GenObjectoperator[] (signed int idx) const
 
GenObjectoperator[] (const String &str) const
 
void clear ()
 
void reset (unsigned int pos=0, int len=-1)
 
bool autoDelete ()
 
void setDelete (bool autodelete)
 
unsigned int allocChunk () const
 
void allocChunk (unsigned int count)
 
unsigned int size () const
 
- 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)
 

Additional Inherited Members

- 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

A vector holding GenObjects.

Simple vector class that holds objects derived from GenObject

Constructor & Destructor Documentation

◆ ObjVector() [1/3]

ObjVector ( bool autodelete = true,
unsigned int allocChunk = 0 )
inlineexplicit

Constructor of a zero capacity vector

Parameters
autodeleteTrue to delete objects on destruct, false otherwise
allocChunkHow many items to allocate when needed to make space

◆ ObjVector() [2/3]

ObjVector ( unsigned int maxLen,
bool autodelete = true,
unsigned int allocChunk = 0 )

Constructor of an empty vector

Parameters
maxLenMaximum number of objects the vector can hold
autodeleteTrue to delete objects on destruct, false otherwise
allocChunkHow many items to allocate when needed to make space

◆ ObjVector() [3/3]

ObjVector ( ObjList & list,
bool move = true,
unsigned int maxLen = 0,
bool autodelete = true,
unsigned int allocChunk = 0 )

Constructor from an object list

Parameters
listList of objects to store in vector
moveTrue to move elements from list, false to just copy the pointer
maxLenMaximum number of objects to put in vector, zero to put all
autodeleteTrue to delete objects on destruct, false otherwise
allocChunkHow many items to allocate when needed to make space

◆ ~ObjVector()

virtual ~ObjVector ( )
virtual

Destroys the vector and the objects if automatic delete is set

Member Function Documentation

◆ allocChunk() [1/2]

unsigned int allocChunk ( ) const
inline

Retrieve the length of allocate chunk

Returns
Allocate chunk size

◆ allocChunk() [2/2]

void allocChunk ( unsigned int count)
inline

Set the length of the allocate chunk

Parameters
countLength of allocate chunk

◆ appendObj() [1/2]

bool appendObj ( GenObject * obj)
inline

Append an object to vector

Parameters
objObject to store in vector
Returns
True for success, false on failure (memory allocation error)

◆ appendObj() [2/2]

bool appendObj ( GenObject * obj,
bool fromStart,
bool beforeNonNull = false )
inline

Append an object to vector. Trye to use a free (NULL) entry

Parameters
objObject to store in vector
fromStartTrue to check from vector start, false to check from vector end in backward direction
beforeNonNullStop on first NULL object before first non NULL object
Returns
True for success, false on failure (memory allocation error)

◆ assign()

unsigned int assign ( ObjList & list,
bool move = true,
unsigned int maxLen = 0 )

Clear the vector and assign objects from a list

Parameters
listList of objects to store in vector
moveTrue to move elements from list, false to just copy the pointer
maxLenMaximum number of objects to put in vector, zero to put all
Returns
Capacity of the vector

◆ at()

GenObject * at ( unsigned int index) const
inline

Get the object at a specific index in vector

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

◆ autoDelete()

bool autoDelete ( )
inline

Get the automatic delete flag

Returns
True if will delete objects on destruct, false otherwise

◆ clear()

void clear ( )

Clear the vector and optionally delete all contained objects

◆ compact() [1/2]

unsigned int compact ( bool resizeToCount = false)
inline

Compact vector, move non NULL pointers in front

Parameters
resizeToCountResize to non null items count, clears the list if empty
Returns
The number of non NULL pointers

◆ compact() [2/2]

unsigned int compact ( unsigned int pos,
int len )

Compact vector, move non NULL pointers at given position

Parameters
posVector position
lenNumber of items to reset. Negative for all starting with given position
Returns
The number of non NULL pointers in given range

◆ count()

unsigned int count ( ) const

Get the number of non-null objects in the vector

Returns
Count of items

◆ cut() [1/2]

unsigned int cut ( int items,
bool reAlloc = true )
inline

Remove items from vector

Parameters
itemsNumber of items to remove. Negative to remove from start, positive to remove from end
reAllocRe-allocate buffer. Set it it to false to move/reset data only
Returns
Capacity of the vector

◆ cut() [2/2]

unsigned int cut ( unsigned int pos,
unsigned int items,
bool reAlloc = true )

Remove items from vector

Parameters
posVector position
itemsNumber of items to remove
reAllocRe-allocate buffer. Set it it to false to move/reset data only
Returns
Capacity of the vector

◆ data() [1/4]

GenObject ** data ( )
inline

Get a pointer to the stored data.

Returns
A pointer to the data or NULL

◆ data() [2/4]

const GenObject ** data ( ) const
inline

Get a pointer to the stored data.

Returns
A pointer to the data or NULL

◆ data() [3/4]

GenObject ** data ( unsigned int offs,
unsigned int len = 1 )
inline

Get a pointer to a byte range inside the stored data

Parameters
offsByte offset inside the stored data
lenNumber of bytes that must be valid starting at offset
Returns
A pointer to the data or NULL if the range is not available

◆ data() [4/4]

const GenObject ** data ( unsigned int offs,
unsigned int len = 1 ) const
inline

Get a pointer to a byte range inside the stored data

Parameters
offsByte offset inside the stored data
lenNumber of bytes that must be valid starting at offset
Returns
A pointer to the data or NULL if the range is not available

◆ 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 vector of a GenObject by a pointer to it

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

◆ index() [2/2]

int index ( const String & str) const

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

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

◆ indexFree()

int indexFree ( bool fromStart,
bool beforeNonNull = false ) const

Get the position in vector of the first or last NULL object

Parameters
fromStartTrue to check from vector start, false to check from vector end in backward direction
beforeNonNullStop on first NULL object before first non NULL object
Returns
Index of object in vector, -1 if not found

◆ insert()

unsigned int insert ( unsigned int pos,
unsigned int items )

Insert NULL items in vector

Parameters
posVector position. Append if past vector length
itemsNumber of items to insert
Returns
Capacity of the vector

◆ insertObj()

bool insertObj ( GenObject * obj,
unsigned int pos )
inline

Insert an object in vector

Parameters
objObject to store in vector
posVector position. Append if past vector length
Returns
True for success, false on failure (memory allocation error)

◆ length()

unsigned int length ( ) const
inline

Get the capacity of the vector

Returns
Number of items the vector can hold

◆ null()

bool null ( ) const

Check if the vector is empty

Returns
True if the vector contains no objects

◆ operator[]() [1/3]

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

Indexing operator with GenObject string value to search

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

◆ operator[]() [2/3]

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

Indexing operator with signed parameter

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

◆ operator[]() [3/3]

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

Indexing operator with unsigned parameter

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

◆ reset()

void reset ( unsigned int pos = 0,
int len = -1 )

Reset vector data. Delete reset item(s) if owned

Parameters
posVector position
lenNumber of items to reset. Negative to reset all items after given position

◆ resize()

unsigned int resize ( unsigned int len,
bool keepData = false,
bool reAlloc = true )
inline

Resize the vector. Reset data if not kept Reset (release) vector data if same length and data is not kept

Parameters
lenNew vector length
keepDataKeep old data
reAllocRe-allocate buffer. Set it it to false to move/reset data only
Returns
Capacity of the vector

◆ set()

bool set ( GenObject * obj,
unsigned int index )

Store an object in the vector

Parameters
objObject to store in vector
indexIndex of the object to store
Returns
True for success, false if index was out of bounds

◆ setDelete()

void setDelete ( bool autodelete)
inline

Set the automatic delete flag

Parameters
autodeleteTrue to delete objects on destruct, false otherwise

◆ size()

unsigned int size ( ) const
inline

Retrieve vector size (total allocated items, including over alloc)

Returns
Vector size

◆ take()

GenObject * take ( unsigned int index)
inline

Retrieve and remove an object from the vector

Parameters
indexIndex of the object to retrieve
Returns
Pointer to the stored object, NULL for out of bound index

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