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

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
 
virtual ObjectProtocolinvalid (void) const
 Object handler for index outside vector range. More...
 
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.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org.

Definition at line 108 of file vector.h.

Constructor & Destructor Documentation

ucommon::Vector::Vector ( vectorsize_t  size)

Create a vector of size object pointers.

Parameters
sizeof 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
itemsto place into the vector.
sizeof the vector to create, or use NULL item for end.

Member Function Documentation

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

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

Parameters
listof object pointers to add.
void ucommon::Vector::add ( ObjectProtocol pointer)

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

Parameters
pointerto add to vector.
void ucommon::Vector::add ( Vector vector)
inline

Add (append) an existing vector to our vector.

Parameters
vectorto append.

Definition at line 293 of file vector.h.

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
pointerto locate in the vector.
offsetto start searching in vector.
Returns
position of pointer in vector or npos if not found.
ObjectProtocol* ucommon::Vector::get ( int  index) const

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

Parameters
indexof member pointer to return. Negative values from end.
Returns
object pointer of member.
vectorsize_t ucommon::Vector::get ( void **  mem,
vectorsize_t  max 
) const

Copy the vector to an external pointer array.

Parameters
memarray of external pointers to hold vector.
maxsize of the external array.
Returns
number of elements copied into external array.
virtual ObjectProtocol* ucommon::Vector::invalid ( void  ) const
protectedvirtual

Object handler for index outside vector range.

Returns
default object, often NULL.
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() ( vectorsize_t  position,
ObjectProtocol pointer 
)
inline

Assign a member of the vector directly.

Parameters
positionto assign.
pointerto object to assign to vector.

Definition at line 308 of file vector.h.

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

Retrieve a member of the vector directly.

Parameters
positionto retrieve object from.
Returns
object pointer retrieved from vector.

Definition at line 316 of file vector.h.

void ucommon::Vector::operator() ( ObjectProtocol pointer)
inline

Append a member to the vector directly.

Parameters
pointerto object to add to vector.

Definition at line 323 of file vector.h.

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

Concatenate into our existing vector from assignment list.

Parameters
vectorto append from.

Definition at line 344 of file vector.h.

void ucommon::Vector::operator+= ( Vector vector)
inline

Append into our existing vector from another vector.

Parameters
vectorto append from.

Definition at line 337 of file vector.h.

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

Drop first specified members from the vector.

Parameters
countof members to drop.
void ucommon::Vector::operator-= ( vectorsize_t  count)

Drop last specified members from the vector.

Parameters
countof members to drop.
void ucommon::Vector::operator= ( Vector vector)
inline

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

Parameters
vectorto assign from.

Definition at line 330 of file vector.h.

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

Return a pointer from the vector by array reference.

Parameters
indexof vector member pointer to return.

Definition at line 300 of file vector.h.

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

Release vector and concat vector from another vector.

Parameters
vectorto 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
vectorto assign from.
virtual bool ucommon::Vector::resize ( vectorsize_t  size)
virtual

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

Parameters
sizeto 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
positionto split vector at.
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
positionin vector to place object pointer.
pointerto place in vector.
void ucommon::Vector::set ( ObjectProtocol **  list)

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

Parameters
listof object pointers.
void ucommon::Vector::set ( Vector vector)
inline

Set (duplicate) an existing vector into our vector.

Parameters
vectorto duplicate.

Definition at line 286 of file vector.h.

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.
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.
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
positionto split vector at.

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