Yate: ObjVector Class Reference

Yate

Public Member Functions | List of all members
ObjVector Class Reference

A vector holding GenObjects. More...

`#include <yateclass.h>`

Inheritance diagram for ObjVector:

## 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
GenObject * | at (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)
GenObject * | take (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
GenObject * | operator[] (unsigned int idx) const
GenObject * | operator[] (signed int idx) const
GenObject * | operator[] (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 String & | toString () const
virtual const String & | traceId () const
NamedCounter * | getObjCounter () const
NamedCounter * | setObjCounter (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 NamedCounter * | getObjCounter (const String &name, bool create=true)
static ObjList & | getObjCounters ()

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

  autodelete | True to delete objects on destruct, false otherwise
  allocChunk | How 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

  maxLen | Maximum number of objects the vector can hold
  autodelete | True to delete objects on destruct, false otherwise
  allocChunk | How 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

  list | List of objects to store in vector
  move | True to move elements from list, false to just copy the pointer
  maxLen | Maximum number of objects to put in vector, zero to put all
  autodelete | True to delete objects on destruct, false otherwise
  allocChunk | How 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

  count | Length of allocate chunk

## ◆ appendObj() [1/2]

bool appendObj | ( | GenObject * | obj | ) |
| inline

Append an object to vector

Parameters

  obj | Object 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

  obj | Object to store in vector
  fromStart | True to check from vector start, false to check from vector end in backward direction
  beforeNonNull | Stop 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

  list | List of objects to store in vector
  move | True to move elements from list, false to just copy the pointer
  maxLen | Maximum 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

  index | Index 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

  resizeToCount | Resize 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

  pos | Vector position
  len | Number 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

  items | Number of items to remove. Negative to remove from start, positive to remove from end
  reAlloc | Re-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

  pos | Vector position
  items | Number of items to remove
  reAlloc | Re-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

  offs | Byte offset inside the stored data
  len | Number 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

  offs | Byte offset inside the stored data
  len | Number 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

  name | Name 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

  obj | Pointer 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

  str | String 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

  fromStart | True to check from vector start, false to check from vector end in backward direction
  beforeNonNull | Stop 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

  pos | Vector position. Append if past vector length
  items | Number of items to insert

Returns
  Capacity of the vector

## ◆ insertObj()

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

Insert an object in vector

Parameters

  obj | Object to store in vector
  pos | Vector 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

  str | String 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

  idx | Index 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

  idx | Index 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

  pos | Vector position
  len | Number 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

  len | New vector length
  keepData | Keep old data
  reAlloc | Re-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

  obj | Object to store in vector
  index | Index 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

  autodelete | True 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

  index | Index 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:

- yateclass.h