Yate: GenericVector< Obj > Class Template Reference

Yate

Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
GenericVector< Obj > Class Template Reference

Template for generic object vector. More...

`#include <yateclass.h>`

Inheritance diagram for GenericVector< Obj >:

## 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 String & | name () 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)
GenericVector & | operator= (const GenericVector &other)
GenericVector & | operator= (const Obj &item)
GenericVector & | operator+= (const Obj &item)
GenericVector & | operator+= (const GenericVector &other)
virtual const String & | toString () const
Public Member Functions inherited from GenObject
| GenObject ()
virtual | ~GenObject ()
virtual bool | alive () const
virtual void | destruct ()
virtual const String & | traceId () const
virtual void * | getObject (const String &name) const
NamedCounter * | getObjCounter () const
NamedCounter * | setObjCounter (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 NamedCounter * | getObjCounter (const String &name, bool create=true)
static ObjList & | getObjCounters ()

## 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

  overAlloc | How many items to overallocate
  name | Optional 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

  items | Pointer to initial values
  count | Initial length
  overAlloc | How many items to overallocate
  name | Optional vector name

## ◆ GenericVector() [3/4]

template<class Obj >

GenericVector | ( | const ObjList & | items,
|  | unsigned int | overAlloc = 0,
|  | const char * | name = 0 )
| inline

Constructor

Parameters

  items | List to copy
  overAlloc | How items to overallocate
  name | Optional vector name

## ◆ GenericVector() [4/4]

template<class Obj >

GenericVector | ( | const GenericVector< Obj > & | other | ) |
| inline

Copy constructor

Parameters

  other | Vector 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

  item | Item 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

  items | Pointer to items to append
  count | The 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

  list | Items 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

  list | Items 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

  len | New vector length. No changes will be applied if 0
  items | Pointer to items to set. Pointer may be inside held buffer
  count | Number 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

  offs | Index to start
  count | Optional 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

  offs | Index to start
  count | Optional 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

  offs | Start offset
  count | Number of items to fill, negative to fill until vector end
  value | Optional 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

  value | Value to fill
  offs | Start offset
  count | Number 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

  items | Items to fill
  count | Number of items to fill
  offs | Optional 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

  name | Object name
  offs | Optional 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

  val | Object value
  offs | Optional 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

  name | Object name
  offs | Optional index to start
  found | Optional 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

  val | Object value
  offs | Optional index to start
  found | Optional 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

Retrieve vector length

Returns
  Vector length

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

## ◆ 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

  other | Vector 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

  item | Item to append

## ◆ operator=() [1/2]

template<class Obj >

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

Assignment (from other vector) operator

Parameters

  other | Vector 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

  item | Item 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

  count | Value of over alloc length

## ◆ removeLast()

template<class Obj >

bool removeLast | ( | unsigned int | count = 1 | ) |
| inline

Remove last item(s)

Parameters

  count | Number 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

  len | New 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

  item | Item 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:

- yateclass.h