Yate
GenericVector< Obj > Class Template Reference

Template for generic object vector. More...

#include <yateclass.h>

Inheritance diagram for GenericVector< Obj >:
GenObject

Public Member Functions

 GenericVector (unsigned int overAlloc=0, const char *name=0)
 
 GenericVector (const Obj *items, unsigned int count, unsigned int overAlloc=0, const char *name=0)
 
 GenericVector (const ObjList &items, unsigned int overAlloc=0, const char *name=0)
 
 GenericVector (const GenericVector &other)
 
virtual ~GenericVector ()
 
unsigned int length () const
 
unsigned int size () const
 
unsigned int overAlloc () const
 
void overAlloc (unsigned int count)
 
const Stringname () const
 
Obj * data (unsigned int offs=0, unsigned int count=0)
 
const Obj * data (unsigned int offs=0, unsigned int count=0) const
 
Obj * first ()
 
const Obj * first () const
 
Obj * last ()
 
const Obj * last () const
 
int indexOf (const String &name, unsigned int offs=0, Obj **found=0) const
 
Obj * find (const String &name, unsigned int offs=0) const
 
int indexOfValue (const Obj &val, unsigned int offs=0, Obj **found=0) const
 
Obj * findValue (const Obj &val, unsigned int offs=0) const
 
void clear ()
 
bool assign (unsigned int len, const Obj *items=0, unsigned int count=0)
 
bool resize (unsigned int len)
 
bool removeLast (unsigned int count=1)
 
unsigned int fill (unsigned int offs=0, int count=-1, const Obj *value=0)
 
unsigned int fillObj (const Obj &value, unsigned int offs=0, int count=-1)
 
unsigned int fillObj (const Obj *items, unsigned int count, unsigned int offs=0)
 
Obj * append (const Obj &item)
 
unsigned int append (const Obj *items, unsigned int count)
 
unsigned int append (const ObjList &list)
 
unsigned int assign (const ObjList &list)
 
Obj * set (const Obj &item)
 
GenericVectoroperator= (const GenericVector &other)
 
GenericVectoroperator= (const Obj &item)
 
GenericVectoroperator+= (const Obj &item)
 
GenericVectoroperator+= (const GenericVector &other)
 
virtual const StringtoString () const
 
- Public Member Functions inherited from GenObject
 GenObject ()
 
virtual ~GenObject ()
 
virtual bool alive () const
 
virtual void destruct ()
 
virtual const StringtraceId () const
 
virtual void * getObject (const String &name) const
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (NamedCounter *counter)
 

Protected Member Functions

Obj * dataAvail (unsigned int offs, unsigned int count) const
 
unsigned int numItems (unsigned int offs, unsigned int count) const
 

Static Protected Member Functions

static void fillArray (const Obj &value, Obj *dest, unsigned int n)
 
static void copy (Obj *dest, const ObjList &src)
 
static void copy (Obj *dest, const Obj *src, unsigned int n)
 

Protected Attributes

Obj * m_data
 
unsigned int m_length
 
unsigned int m_size
 
unsigned int m_overAlloc
 

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

template<class Obj>
class GenericVector< Obj >

Template for generic object vector.

Template for generic object vector The vector can be resized (up/down) Objects MUST implement a default contructor and an assignment operator When name based find or set are used objects should implement toString() This template should be used for simple objects

Constructor & Destructor Documentation

◆ GenericVector() [1/4]

template<class Obj >
GenericVector ( unsigned int overAlloc = 0,
const char * name = 0 )
inline

Constructor

Parameters
overAllocHow many items to overallocate
nameOptional vector name

◆ GenericVector() [2/4]

template<class Obj >
GenericVector ( const Obj * items,
unsigned int count,
unsigned int overAlloc = 0,
const char * name = 0 )
inline

Constructor

Parameters
itemsPointer to initial values
countInitial length
overAllocHow many items to overallocate
nameOptional vector name

◆ GenericVector() [3/4]

template<class Obj >
GenericVector ( const ObjList & items,
unsigned int overAlloc = 0,
const char * name = 0 )
inline

Constructor

Parameters
itemsList to copy
overAllocHow items to overallocate
nameOptional vector name

◆ GenericVector() [4/4]

template<class Obj >
GenericVector ( const GenericVector< Obj > & other)
inline

Copy constructor

Parameters
otherVector to copy

References GenericVector< Obj >::data(), and GenericVector< Obj >::length().

◆ ~GenericVector()

template<class Obj >
virtual ~GenericVector ( )
inlinevirtual

Destructor

Member Function Documentation

◆ append() [1/3]

template<class Obj >
Obj * append ( const Obj & item)
inline

Append an item to vector

Parameters
itemItem to append
Returns
Given item pointer, NULL on failure

◆ append() [2/3]

template<class Obj >
unsigned int append ( const Obj * items,
unsigned int count )
inline

Append an array of items to vector

Parameters
itemsPointer to items to append
countThe number of items to append
Returns
Number of added items

◆ append() [3/3]

template<class Obj >
unsigned int append ( const ObjList & list)
inline

Append a list of items

Parameters
listItems to append
Returns
Number of added items

References ObjList::count().

◆ assign() [1/2]

template<class Obj >
unsigned int assign ( const ObjList & list)
inline

Append a list of items

Parameters
listItems to append
Returns
Number of added items, 0 on empty list or failure

References ObjList::count().

◆ assign() [2/2]

template<class Obj >
bool assign ( unsigned int len,
const Obj * items = 0,
unsigned int count = 0 )
inline

Assign new data or just allocate new space

Parameters
lenNew vector length. No changes will be applied if 0
itemsPointer to items to set. Pointer may be inside held buffer
countNumber of items to copy, 0 to use 'len', At most 'len' items will be copied
Returns
True on success, false on memory allocation failure

◆ clear()

template<class Obj >
void clear ( )
inline

Clear data

◆ data() [1/2]

template<class Obj >
Obj * data ( unsigned int offs = 0,
unsigned int count = 0 )
inline

Retrieve a pointer to data

Parameters
offsIndex to start
countOptional number of elements to retrieve
Returns
Obj pointer, NULL if data not set or given index and count are past vector length

Referenced by GenericVector< Obj >::GenericVector(), GenericVector< Obj >::operator+=(), and GenericVector< Obj >::operator=().

◆ data() [2/2]

template<class Obj >
const Obj * data ( unsigned int offs = 0,
unsigned int count = 0 ) const
inline

Retrieve a pointer to data

Parameters
offsIndex to start
countOptional number of elements to retrieve
Returns
Obj pointer, NULL if data not set or given index and count are past vector length

◆ fill()

template<class Obj >
unsigned int fill ( unsigned int offs = 0,
int count = -1,
const Obj * value = 0 )
inline

Fill vector with data

Parameters
offsStart offset
countNumber of items to fill, negative to fill until vector end
valueOptional value to fill. Fill with default Obj if not given
Returns
Number of filled items. 0 on empty count or failure

◆ fillObj() [1/2]

template<class Obj >
unsigned int fillObj ( const Obj & value,
unsigned int offs = 0,
int count = -1 )
inline

Fill vector with data

Parameters
valueValue to fill
offsStart offset
countNumber of items to fill, negative to fill until vector end
Returns
Number of filled items. 0 on empty count or failure

◆ fillObj() [2/2]

template<class Obj >
unsigned int fillObj ( const Obj * items,
unsigned int count,
unsigned int offs = 0 )
inline

Fill vector with data

Parameters
itemsItems to fill
countNumber of items to fill
offsOptional start offset
Returns
Number of filled items, 0 on empty items or failure

◆ find()

template<class Obj >
Obj * find ( const String & name,
unsigned int offs = 0 ) const
inline

Find an object by name Obj MUST implement toString()

Parameters
nameObject name
offsOptional index to start
Returns
Obj pointer, NULL if not found

◆ findValue()

template<class Obj >
Obj * findValue ( const Obj & val,
unsigned int offs = 0 ) const
inline

Find an object by name Obj MUST implement the == operator

Parameters
valObject value
offsOptional index to start
Returns
Obj pointer, NULL if not found

◆ first() [1/2]

template<class Obj >
Obj * first ( )
inline

Retrieve a pointer to first item in vector

Returns
Obj pointer, NULL if not found

◆ first() [2/2]

template<class Obj >
const Obj * first ( ) const
inline

Retrieve a pointer to first item in vector

Returns
Obj pointer, NULL if not found

◆ indexOf()

template<class Obj >
int indexOf ( const String & name,
unsigned int offs = 0,
Obj ** found = 0 ) const
inline

Retrieve index of object by name Obj MUST implement toString()

Parameters
nameObject name
offsOptional index to start
foundOptional pointer to be filled with found object pointer
Returns
Index of object, -1 if not found

References String::toString().

◆ indexOfValue()

template<class Obj >
int indexOfValue ( const Obj & val,
unsigned int offs = 0,
Obj ** found = 0 ) const
inline

Retrieve index of object by value Obj MUST implement the == operator

Parameters
valObject value
offsOptional index to start
foundOptional pointer to be filled with found object pointer
Returns
Index of object, -1 if not found

◆ last() [1/2]

template<class Obj >
Obj * last ( )
inline

Retrieve a pointer to last item in vector

Returns
Obj pointer, NULL if not found

◆ last() [2/2]

template<class Obj >
const Obj * last ( ) const
inline

Retrieve a pointer to last item in vector

Returns
Obj pointer, NULL if not found

◆ length()

template<class Obj >
unsigned int length ( ) const
inline

◆ name()

template<class Obj >
const String & name ( ) const
inline

Retrieve vector name

Returns
Vector name

◆ operator+=() [1/2]

template<class Obj >
GenericVector & operator+= ( const GenericVector< Obj > & other)
inline

Addition (append) operator

Parameters
otherVector to append

References GenericVector< Obj >::data(), and GenericVector< Obj >::length().

◆ operator+=() [2/2]

template<class Obj >
GenericVector & operator+= ( const Obj & item)
inline

Addition (append) operator

Parameters
itemItem to append

◆ operator=() [1/2]

template<class Obj >
GenericVector & operator= ( const GenericVector< Obj > & other)
inline

Assignment (from other vector) operator

Parameters
otherVector to assign

References GenericVector< Obj >::data(), and GenericVector< Obj >::length().

◆ operator=() [2/2]

template<class Obj >
GenericVector & operator= ( const Obj & item)
inline

Assignment (from Obj vector) operator

Parameters
itemItem to assign

◆ overAlloc() [1/2]

template<class Obj >
unsigned int overAlloc ( ) const
inline

Retrieve the over alloc value

Returns
Over alloc value

◆ overAlloc() [2/2]

template<class Obj >
void overAlloc ( unsigned int count)
inline

Set over alloc length

Parameters
countValue of over alloc length

◆ removeLast()

template<class Obj >
bool removeLast ( unsigned int count = 1)
inline

Remove last item(s)

Parameters
countNumber of items to remove
Returns
True on success, false on memory allocation failure

◆ resize()

template<class Obj >
bool resize ( unsigned int len)
inline

Resize the vector 'len' between length() and size(): just increase length 'len' between (size() - overAlloc()) and size(): just decrease length, assign empty Obj to remaining items

Parameters
lenNew vector length. No changes will be applied if len is 0 or equal to current vector length
Returns
True on success, false on memory allocation failure

◆ set()

template<class Obj >
Obj * set ( const Obj & item)
inline

Append or set an item to vector

Parameters
itemItem to append or set
Returns
Given item pointer, NULL on failure

◆ size()

template<class Obj >
unsigned int size ( ) const
inline

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

Returns
Vector size

◆ toString()

template<class Obj >
virtual const String & toString ( ) const
inlinevirtual

Retrieve vector name

Returns
Vector name

Reimplemented from GenObject.


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