ucommon::Vector Class Reference

A managed vector for generic object pointers. More...

#include <vector.h>

Inheritance diagram for ucommon::Vector:
Inheritance graph
[legend]

Public Member Functions

void add (Vector &vector)
 Add (append) an existing vector to our vector.
void add (ObjectProtocol *pointer)
 Add (append) a single object pointer to the vector.
void add (ObjectProtocol **list)
 Add (append) a NULL terminated list of objects to the vector.
ObjectProtocolbegin (void) const
 Get the first object pointer contained in the vector.
void clear (void)
 De-reference and remove all pointers from the vector.
ObjectProtocolend (void) const
 Get the last object pointer contained in the vector.
vectorsize_t find (ObjectProtocol *pointer, vectorsize_t offset=0) const
 Find the first instance of a specific pointer in the vector.
vectorsize_t get (void **mem, vectorsize_t max) const
 Copy the vector to an external pointer array.
ObjectProtocolget (int index) const
 Get an object pointer from a specified member of the vector.
vectorsize_t len (void) const
 Get the size of the vector (number of active members).
void operator() (ObjectProtocol *pointer)
 Append a member to the vector directly.
ObjectProtocoloperator() (vectorsize_t position)
 Retrieve a member of the vector directly.
void operator() (vectorsize_t position, ObjectProtocol *pointer)
 Assign a member of the vector directly.
Vectoroperator+ (Vector &vector)
 Concatenate into our existing vector from assignment list.
void operator++ ()
 Drop first member of vector.
void operator+= (vectorsize_t count)
 Drop first specified members from the vector.
void operator+= (Vector &vector)
 Append into our existing vector from another vector.
void operator-- ()
 Drop last member of the vector.
void operator-= (vectorsize_t count)
 Drop last specified members from the vector.
void operator= (Vector &vector)
 Assign (copy) into our existing vector from another vector.
ObjectProtocoloperator[] (int index)
 Return a pointer from the vector by array reference.
Vectoroperator^ (Vector &vector)
 Release vector and concat vector from another vector.
void operator^= (Vector &vector)
 Release our existing vector and duplicate from another vector.
virtual bool resize (vectorsize_t size)
 Re-size & re-allocate the total (allocated) size of the vector.
void rsplit (vectorsize_t position)
 Split the vector after a specified offset.
void set (Vector &vector)
 Set (duplicate) an existing vector into our vector.
void set (ObjectProtocol **list)
 Set the vector to a list of objects terminated by a NULL pointer.
void set (vectorsize_t position, ObjectProtocol *pointer)
 Set a member of the vector to an object.
vectorsize_t size (void) const
 Get the effective allocation space used by the vector.
void split (vectorsize_t position)
 Split the vector at a specified offset.
 Vector (ObjectProtocol **items, vectorsize_t size=0)
 Create a vector of size objects from existing object pointers.
 Vector (vectorsize_t size)
 Create a vector of size object pointers.
 Vector ()
 Create an initially empty vector.
virtual ~Vector ()
 Destroy the current reference counted vector of object pointers.

Static Public Member Functions

static vectorsize_t size (void **list)
 Compute the effective vector size of a list of object pointers.

Static Public Attributes

static const vectorsize_t npos
 npos is a constant for an "invalid" position value.

Protected Member Functions

virtual void cow (vectorsize_t adj=0)
array * create (vectorsize_t size) const
ObjectProtocol ** list (void) const
virtual void release (void)

Protected Attributes

array * data

Friends

class Vector::array

Detailed Description

A managed vector for generic object pointers.

This vector is memory managed at runtime by basic cow (copy-on-write) operations of a reference counted object list. This allows the size of the vector to be changed at runtime and for the vector to be copied by managing reference counted copies of the list of objects as needed.

This class is somewhat analogous to the string class, but rather than holding a string "array of chars" that may be re-sized and reallocated, the Vector holds an array of Object pointers. Since the object pointers we store in the vector are objects inherited from Object, a vector can itself act as a vector of smart pointers to reference counted objects (derived from CountedObject).

Author:
David Sugar <dyfet@gnutelephony.org>.

Definition at line 107 of file vector.h.


Constructor & Destructor Documentation

ucommon::Vector::Vector ( vectorsize_t  size  ) 

Create a vector of size object pointers.

Parameters:
size of vector to create.
ucommon::Vector::Vector ( ObjectProtocol **  items,
vectorsize_t  size = 0 
)

Create a vector of size objects from existing object pointers.

This allocates the vector and initializes the object pointers from an existing array of object pointers. Either a specific vector size may be used, or the end of the vector will be found by a NULL object pointer.

Parameters:
items to place into the vector.
size of the vector to create, or use NULL item for end.

Member Function Documentation

void ucommon::Vector::add ( Vector vector  )  [inline]

Add (append) an existing vector to our vector.

Parameters:
vector to append.

Definition at line 285 of file vector.h.

Here is the call graph for this function:

void ucommon::Vector::add ( ObjectProtocol pointer  ) 

Add (append) a single object pointer to the vector.

Parameters:
pointer to add to vector.
void ucommon::Vector::add ( ObjectProtocol **  list  ) 

Add (append) a NULL terminated list of objects to the vector.

Parameters:
list of object pointers to add.
ObjectProtocol* ucommon::Vector::begin ( void   )  const

Get the first object pointer contained in the vector.

Typically used in iterations.

Returns:
first object pointer.
ObjectProtocol* ucommon::Vector::end ( void   )  const

Get the last object pointer contained in the vector.

Typically used in iterations.

Returns:
last object pointer.
vectorsize_t ucommon::Vector::find ( ObjectProtocol pointer,
vectorsize_t  offset = 0 
) const

Find the first instance of a specific pointer in the vector.

Parameters:
pointer to locate in the vector.
offset to start searching in vector.
Returns:
position of pointer in vector or npos if not found.
vectorsize_t ucommon::Vector::get ( void **  mem,
vectorsize_t  max 
) const

Copy the vector to an external pointer array.

Parameters:
mem array of external pointers to hold vector.
max size of the external array.
Returns:
number of elements copied into external array.
ObjectProtocol* ucommon::Vector::get ( int  index  )  const

Get an object pointer from a specified member of the vector.

Parameters:
index of member pointer to return. Negative values from end.
Returns:
object pointer of member.
vectorsize_t ucommon::Vector::len ( void   )  const

Get the size of the vector (number of active members).

Returns:
number of active pointers in vector.
void ucommon::Vector::operator() ( ObjectProtocol pointer  )  [inline]

Append a member to the vector directly.

Parameters:
pointer to object to add to vector.

Definition at line 315 of file vector.h.

Here is the call graph for this function:

ObjectProtocol* ucommon::Vector::operator() ( vectorsize_t  position  )  [inline]

Retrieve a member of the vector directly.

Parameters:
position to retrieve object from.
Returns:
object pointer retrieved from vector.

Reimplemented in ucommon::vectorof< T >, and ucommon::vectorbuf< T, S >.

Definition at line 308 of file vector.h.

void ucommon::Vector::operator() ( vectorsize_t  position,
ObjectProtocol pointer 
) [inline]

Assign a member of the vector directly.

Parameters:
position to assign.
pointer to object to assign to vector.

Definition at line 300 of file vector.h.

Vector& ucommon::Vector::operator+ ( Vector vector  )  [inline]

Concatenate into our existing vector from assignment list.

Parameters:
vector to append from.

Reimplemented in ucommon::vectorof< T >, and ucommon::vectorbuf< T, S >.

Definition at line 336 of file vector.h.

Here is the call graph for this function:

void ucommon::Vector::operator+= ( vectorsize_t  count  ) 

Drop first specified members from the vector.

Parameters:
count of members to drop.
void ucommon::Vector::operator+= ( Vector vector  )  [inline]

Append into our existing vector from another vector.

Parameters:
vector to append from.

Definition at line 329 of file vector.h.

Here is the call graph for this function:

void ucommon::Vector::operator-= ( vectorsize_t  count  ) 

Drop last specified members from the vector.

Parameters:
count of members to drop.
void ucommon::Vector::operator= ( Vector vector  )  [inline]

Assign (copy) into our existing vector from another vector.

Parameters:
vector to assign from.

Reimplemented in ucommon::MemVector.

Definition at line 322 of file vector.h.

ObjectProtocol* ucommon::Vector::operator[] ( int  index  )  [inline]

Return a pointer from the vector by array reference.

Parameters:
index of vector member pointer to return.

Reimplemented in ucommon::vectorof< T >, and ucommon::vectorbuf< T, S >.

Definition at line 292 of file vector.h.

Vector& ucommon::Vector::operator^ ( Vector vector  ) 

Release vector and concat vector from another vector.

Parameters:
vector to assign from.
void ucommon::Vector::operator^= ( Vector vector  ) 

Release our existing vector and duplicate from another vector.

This differs from assign in that the allocated size of the vector is reset to the new list.

Parameters:
vector to assign from.
virtual bool ucommon::Vector::resize ( vectorsize_t  size  )  [virtual]

Re-size & re-allocate the total (allocated) size of the vector.

Parameters:
size to allocate for vector.
void ucommon::Vector::rsplit ( vectorsize_t  position  ) 

Split the vector after a specified offset.

All members before the split are de-referenced and dropped. The member starting at the split point becomes the first member of the vector.

Parameters:
position to split vector at.
void ucommon::Vector::set ( Vector vector  )  [inline]

Set (duplicate) an existing vector into our vector.

Parameters:
vector to duplicate.

Definition at line 278 of file vector.h.

void ucommon::Vector::set ( ObjectProtocol **  list  ) 

Set the vector to a list of objects terminated by a NULL pointer.

Parameters:
list of object pointers.
void ucommon::Vector::set ( vectorsize_t  position,
ObjectProtocol pointer 
)

Set a member of the vector to an object.

If an existing member was present and is being replaced, it is de-referenced.

Parameters:
position in vector to place object pointer.
pointer to place in vector.
static vectorsize_t ucommon::Vector::size ( void **  list  )  [static]

Compute the effective vector size of a list of object pointers.

The size is found as the NULL pointer in the list.

Returns:
size of list.
vectorsize_t ucommon::Vector::size ( void   )  const

Get the effective allocation space used by the vector.

This is the number of pointers it can hold before it needs to be resized.

Returns:
storage size of vector.
void ucommon::Vector::split ( vectorsize_t  position  ) 

Split the vector at a specified offset.

All members after the split are de-referenced and dropped from the vector.

Parameters:
position to split vector at.

The documentation for this class was generated from the following file:
Generated on Thu Jul 14 16:40:12 2011 for ucommon by  doxygen 1.6.3