Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

rdPtrArray Class Reference

A class for storing an array of void pointers. More...

#include <rdPtrArray.h>

Inheritance diagram for rdPtrArray:

rdObject rdActuatorSet rdCallbackSet rdContactForceSet rdControlSet rdEdges rdGBodies rdStorage rdTriangles rdVertices List of all members.

Public Member Functions

 rdPtrArray (int aCapacity=128, const char *aName="UNKNOWN")
 Default constructor.

 rdPtrArray (const char *aFileName)
 Construct from a file.

 rdPtrArray (IDOM_Element *aElement)
 Construct based on an XML element.

virtual ~rdPtrArray ()
 Destructor.

virtual void setDescription (const char *aDescrip=NULL)
 Set the description of this storage.

virtual const char * getDescription () const
 Get a description of this storage.

virtual bool ensureCapacity (int aCapacity)
 Ensure that the capacity of this expandable array is at least the specified amount.

virtual int getCapacity () const
 Get the capacity of this storage instance.

virtual void setCapacityIncrement (int aIncrement=-1)
 Set the amount by which the capacity is increased.

virtual int getCapacityIncrement () const
 Get the amount by which the capacity is increased.

virtual void reset ()
 Reset the storage to start storing at index 0.

virtual void reset (int aIndex)
 Reset the storage to start storing after the specified index.

virtual int getFirstEmpty () const
 Get the index of the first empty array element.

virtual int getIndex (void *aObject) const
 Get the index of an object by pointer value.

virtual void * set (int aIndex, void *aObject)
 Set the pointer at a specified array index.

virtual void * get (int aIndex) const
 Get the pointer at a specified array index.

virtual void * getLast () const
 Get the last pointer in the array.

virtual int append (void *aObject)
 Append an object.

virtual int append (rdPtrArray *aArray)
 Append all the objects in an rdPtrArray object.

virtual void * remove (int aIndex)
 Remove an object by index.

virtual void * remove (void *aObject)
 Remove an object based on the object's pointer.

virtual void updateObject (bool aDeep=true)
 Update this object based on its XML node.

virtual void updateNode (bool aDeep=true)
 Update the XML node representing this object.


Protected Attributes

int _firstEmpty
 Index of the first empty rdStateVector pointer- also the size.

char * _descrip
 Description.

int _capacity
 Current capacity.

int _capacityIncrement
 Increment by which the current capacity is increased when the capacity of this storage instance is reached.

void ** _array
 Array of void pointers.


Static Protected Attributes

const int CAPMIN = rdPtrArray_CAPMIN
 Minimum capacity.


Private Member Functions

void allocateCapacity ()
void setNull ()
 Set all member variables to their null or default values.


Detailed Description

A class for storing an array of void pointers.

Because the pointers are void pointers, this class is suitable for storing an array of pointers to objects of any type. The capacity of the class grows as needed.

When an rdPtrArray object is deleted, the delete operators for the stored elements are NOT called. The user or derived class is responsible for explicitly deleting all stored objects.

Version:
1.0
Author:
Frank C. Anderson


Constructor & Destructor Documentation

rdPtrArray::rdPtrArray const char *  aFileName  ) 
 

Construct from a file.

Parameters:
aElement 

rdPtrArray::rdPtrArray IDOM_Element *  aElement  ) 
 

Construct based on an XML element.

Parameters:
aElement 

rdPtrArray::~rdPtrArray  )  [virtual]
 

Destructor.

The destructor does NOT call the destructor for the pointer elements held in the array. It simply deletes the array itself. The user or derived class is responsible for deleting the array elements.


Member Function Documentation

int rdPtrArray::append void *  aObject  )  [virtual]
 

Append an object.

Parameters:
aObject Object to be appended.
Returns:
Index to the first empty element in the array (i.e., the end of the array).

Reimplemented in rdStorage.

bool rdPtrArray::ensureCapacity int  aCapacity  )  [virtual]
 

Ensure that the capacity of this expandable array is at least the specified amount.

Parameters:
aCapacity Desired capacity.
Returns:
true if the capacity was successfully obtained, false otherwise.

void * rdPtrArray::get int  aIndex  )  const [virtual]
 

Get the pointer at a specified array index.

If the index is greater than or equal to the capacity of the array, NULL is returned.

Parameters:
aIndex Index of the desired array element.
Returns:
Pointer at aIndex or NULL.

const char * rdPtrArray::getDescription  )  const [virtual]
 

Get a description of this storage.

Returns:
Description.

int rdPtrArray::getFirstEmpty  )  const [virtual]
 

Get the index of the first empty array element.

Returns:
Index of the first empty array element.

int rdPtrArray::getIndex void *  aObject  )  const [virtual]
 

Get the index of an object by pointer value.

Parameters:
aObject Pointer value of the object whose index is desired.
Returns:
Index of the object; -1 if no such object is in the array.

void * rdPtrArray::getLast  )  const [virtual]
 

Get the last pointer in the array.

Returns:
Last pointer in the array.

void * rdPtrArray::remove void *  aObject  )  [virtual]
 

Remove an object based on the object's pointer.

When an object is removed, the array locations of all objects following the removed object are shifted down by 1.

This method is fairly expensive to call at this time because the entire array is searched sequentially. The caller is responsible for deleting the removed object.

To remove an object without shifting the array locations of all objects following the removed object, use the method set().

Parameters:
aObject Pointer to the object to be removed.
Returns:
Pointer to the object that was removed. If no object was found, NULL is returned.
See also:
set()

void * rdPtrArray::remove int  aIndex  )  [virtual]
 

Remove an object by index.

When an object is removed, the array locations of all objects following the removed object are shifted down by 1.

The caller is responsible for deleting the removed object.

To remove an object without shifting the array locations of all objects following the removed object, use the method set().

Parameters:
aIndex Index of the object to remove.
Returns:
Pointer to the removed object; NULL if there was no object at aIndex.
See also:
set()

void * rdPtrArray::set int  aIndex,
void *  aObject
[virtual]
 

Set the pointer at a specified array index.

If the index is greater than or equal to the capacity, sufficient capacity is added. It is permissible to set the value of an array element to NULL.

Parameters:
aIndex Index of the array element being set.
aObject Pointer to an object or NULL.
Returns:
Pointer to the object formerly at aIndex. The caller is responsible for deleting any non-null returned object.

void rdPtrArray::setCapacityIncrement int  aIncrement = -1  )  [virtual]
 

Set the amount by which the capacity is increased.

If an increment is sent in that is less than 0 or this method is called with no argument, the capacity is set to double whenever the capacity is exceeded.

Parameters:
aIncrement Desired capacity increment. By default, the capacity increment is set to double.

void rdPtrArray::setDescription const char *  aDescrip = NULL  )  [virtual]
 

Set the description of this storage.

If the last character of a description is a carriage return, it is stripped.

Parameters:
aDescrip Description.

void rdPtrArray::updateNode bool  aDeep = true  )  [virtual]
 

Update the XML node representing this object.

Parameters:
aDeep If true, update the XML node of this object AND the XML nodes of all class members that are rdObjects (child nodes); if false, update only the XML node of this object without updating the XML nodes of its children.

Reimplemented from rdObject.

Reimplemented in rdControlSet, rdActuatorSet, rdContactForceSet, rdEdges, rdGBodies, rdTriangles, and rdVertices.

void rdPtrArray::updateObject bool  aDeep = true  )  [virtual]
 

Update this object based on its XML node.

Parameters:
aDeep If true, update this object and all its child objects (that is, member variables that are rdObject's); if false, update only the member variables that are not rdObject's.

Reimplemented from rdObject.

Reimplemented in rdControlSet, rdActuatorSet, rdContactForceSet, rdEdges, rdGBodies, and rdVertices.


The documentation for this class was generated from the following files:
Generated on Wed Aug 20 02:17:12 2003 for Simulation Software by doxygen1.3