UCommon
|
A managed vector for generic object pointers. More...
#include <vector.h>
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... | |
ObjectProtocol * | begin (void) const |
Get the first object pointer contained in the vector. More... | |
void | clear (void) |
De-reference and remove all pointers from the vector. | |
ObjectProtocol * | end (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... | |
ObjectProtocol * | get (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... | |
ObjectProtocol * | operator() (vectorsize_t position) |
Retrieve a member of the vector directly. More... | |
void | operator() (ObjectProtocol *pointer) |
Append a member to the vector directly. More... | |
Vector & | operator+ (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... | |
ObjectProtocol * | operator[] (int index) |
Return a pointer from the vector by array reference. More... | |
Vector & | operator^ (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 ObjectProtocol * | invalid (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 |
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).
ucommon::Vector::Vector | ( | vectorsize_t | size | ) |
Create a vector of size object pointers.
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.
items | to place into the vector. |
size | of the vector to create, or use NULL item for end. |
void ucommon::Vector::add | ( | ObjectProtocol ** | list | ) |
Add (append) a NULL terminated list of objects to the vector.
list | of object pointers to add. |
void ucommon::Vector::add | ( | ObjectProtocol * | pointer | ) |
Add (append) a single object pointer to the vector.
pointer | to add to vector. |
|
inline |
ObjectProtocol* ucommon::Vector::begin | ( | void | ) | const |
Get the first object pointer contained in the vector.
Typically used in iterations.
ObjectProtocol* ucommon::Vector::end | ( | void | ) | const |
Get the last object pointer contained in the vector.
Typically used in iterations.
vectorsize_t ucommon::Vector::find | ( | ObjectProtocol * | pointer, |
vectorsize_t | offset = 0 |
||
) | const |
Find the first instance of a specific pointer in the vector.
pointer | to locate in the vector. |
offset | to start searching in vector. |
ObjectProtocol* ucommon::Vector::get | ( | int | index | ) | const |
Get an object pointer from a specified member of the vector.
index | of member pointer to return. Negative values from end. |
vectorsize_t ucommon::Vector::get | ( | void ** | mem, |
vectorsize_t | max | ||
) | const |
Copy the vector to an external pointer array.
mem | array of external pointers to hold vector. |
max | size of the external array. |
|
protectedvirtual |
Object handler for index outside vector range.
vectorsize_t ucommon::Vector::len | ( | void | ) | const |
Get the size of the vector (number of active members).
|
inline |
|
inline |
|
inline |
|
inline |
void ucommon::Vector::operator+= | ( | vectorsize_t | count | ) |
Drop first specified members from the vector.
count | of members to drop. |
void ucommon::Vector::operator-= | ( | vectorsize_t | count | ) |
Drop last specified members from the vector.
count | of members to drop. |
|
inline |
|
inline |
Release vector and concat vector from another vector.
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.
vector | to assign from. |
|
virtual |
Re-size & re-allocate the total (allocated) size of the vector.
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.
position | to 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.
position | in vector to place object pointer. |
pointer | to place in vector. |
void ucommon::Vector::set | ( | ObjectProtocol ** | list | ) |
Set the vector to a list of objects terminated by a NULL pointer.
list | of object pointers. |
|
inline |
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.
|
static |
Compute the effective vector size of a list of object pointers.
The size is found as the NULL pointer in the 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.
position | to split vector at. |