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

References name(), and overAlloc().

Referenced by GenericVector(), operator+=(), operator+=(), operator=(), and operator=().

◆ 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

References assign(), name(), and overAlloc().

◆ 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

References assign(), name(), and overAlloc().

◆ GenericVector() [4/4]

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

Copy constructor

Parameters
otherVector to copy

References assign(), data(), GenericVector(), length(), name(), and overAlloc().

◆ ~GenericVector()

template<class Obj>
virtual ~GenericVector ( )
inlinevirtual

Destructor

References clear().

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

References length(), and resize().

Referenced by operator+=(), operator+=(), and set().

◆ 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

References length(), and resize().

◆ 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(), length(), and resize().

◆ 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(), and resize().

◆ 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

Referenced by GenericVector(), GenericVector(), GenericVector(), operator=(), operator=(), and resize().

◆ clear()

template<class Obj>
void clear ( )
inline

Clear data

Referenced by removeLast(), and ~GenericVector().

◆ 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(), indexOf(), indexOfValue(), operator+=(), and 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

References length().

Referenced by fillObj(), and resize().

◆ 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

References fill().

Referenced by operator+=().

◆ 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

References indexOf(), and name().

◆ 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

References indexOfValue().

◆ 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 data(), length(), and name().

Referenced by find(), and set().

◆ 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

References data(), and length().

Referenced by findValue().

◆ last() [1/2]

template<class Obj>
Obj * last ( )
inline

Retrieve a pointer to last item in vector

Returns
Obj pointer, NULL if not found

References length().

◆ 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

References length().

◆ length()

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

Retrieve vector length

Returns
Vector length

Referenced by append(), append(), append(), fill(), GenericVector(), indexOf(), indexOfValue(), last(), last(), operator+=(), operator=(), removeLast(), and resize().

◆ name()

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

Retrieve vector name

Returns
Vector name

Referenced by find(), GenericVector(), GenericVector(), GenericVector(), GenericVector(), indexOf(), and toString().

◆ operator+=() [1/2]

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

Addition (append) operator

Parameters
otherVector to append

References append(), data(), fillObj(), GenericVector(), length(), and resize().

◆ operator+=() [2/2]

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

Addition (append) operator

Parameters
itemItem to append

References append(), and GenericVector().

◆ operator=() [1/2]

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

Assignment (from other vector) operator

Parameters
otherVector to assign

References assign(), data(), GenericVector(), and length().

◆ operator=() [2/2]

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

Assignment (from Obj vector) operator

Parameters
itemItem to assign

References assign(), and GenericVector().

◆ overAlloc() [1/2]

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

Retrieve the over alloc value

Returns
Over alloc value

Referenced by GenericVector(), GenericVector(), GenericVector(), and GenericVector().

◆ 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

References clear(), length(), and resize().

◆ 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

References assign(), fill(), length(), and size().

Referenced by append(), append(), append(), assign(), operator+=(), and removeLast().

◆ 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

References append(), and indexOf().

◆ size()

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

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

Returns
Vector size

Referenced by resize().

◆ toString()

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

Retrieve vector name

Returns
Vector name

Reimplemented from GenObject.

References name().


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