ucc::Vector Class Reference

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

#include <vector.h>

Inheritance diagram for ucc::Vector:

Inheritance graph
[legend]

Public Member Functions

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

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

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

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 anagalous 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 110 of file vector.h.


Constructor & Destructor Documentation

ucc::Vector::Vector ( vectorsize_t  size  ) 

Create a vector of size object pointers.

Parameters:
size of vector to create.

ucc::Vector::Vector ( Object **  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 ucc::Vector::add ( Vector vector  )  [inline]

Add (append) an existing vector to our vector.

Parameters:
vector to append.

Definition at line 288 of file vector.h.

void ucc::Vector::add ( Object pointer  ) 

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

Parameters:
pointer to add to vector.

void ucc::Vector::add ( Object **  list  ) 

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

Parameters:
list of object pointers to add.

Object* ucc::Vector::begin ( void   )  const

Get the first object pointer contained in the vector.

Typically used in iterations.

Returns:
first object pointer.

Object* ucc::Vector::end ( void   )  const

Get the last object pointer contained in the vector.

Typically used in iterations.

Returns:
last object pointer.

vectorsize_t ucc::Vector::find ( Object 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 ucc::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.

Object* ucc::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 ucc::Vector::len ( void   )  const

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

Returns:
number of active pointers in vector.

void ucc::Vector::operator() ( Object pointer  )  [inline]

Append a member to the vector directly.

Parameters:
pointer to object to add to vector.

Definition at line 318 of file vector.h.

Object* ucc::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 ucc::vectorof< T >, and ucc::vectorbuf< T, S >.

Definition at line 311 of file vector.h.

void ucc::Vector::operator() ( vectorsize_t  position,
Object pointer 
) [inline]

Assign a member of the vector directly.

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

Definition at line 303 of file vector.h.

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

Concatenate into our existing vector from assignment list.

Parameters:
vector to append from.

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

Definition at line 339 of file vector.h.

Here is the call graph for this function:

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

Drop first specified members from the vector.

Parameters:
count of members to drop.

void ucc::Vector::operator+= ( Vector vector  )  [inline]

Append into our existing vector from another vector.

Parameters:
vector to append from.

Definition at line 332 of file vector.h.

Here is the call graph for this function:

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

Drop last specified members from the vector.

Parameters:
count of members to drop.

void ucc::Vector::operator= ( Vector vector  )  [inline]

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

Parameters:
vector to assign from.

Reimplemented in ucc::MemVector.

Definition at line 325 of file vector.h.

Here is the call graph for this function:

Object* ucc::Vector::operator[] ( int  index  )  [inline]

Return a pointer from the vector by array reference.

Parameters:
index of vector member pointer to return.

Definition at line 295 of file vector.h.

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

Release vector and concat vector from another vector.

Parameters:
vector to assign from.

void ucc::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 ucc::Vector::resize ( vectorsize_t  size  )  [virtual]

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

Parameters:
size to allocate for vector.

void ucc::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 ucc::Vector::set ( Vector vector  )  [inline]

Set (duplicate) an existing vector into our vector.

Parameters:
vector to duplicate.

Definition at line 281 of file vector.h.

void ucc::Vector::set ( Object **  list  ) 

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

Parameters:
list of object pointers.

void ucc::Vector::set ( vectorsize_t  position,
Object 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 ucc::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 ucc::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 ucc::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 Wed May 13 08:43:32 2009 for UCommon by  doxygen 1.5.7.1