PArrayObjects Class Reference

An array of objects. More...

#include <array.h>

Inheritance diagram for PArrayObjects:

PCollection PContainer PObject PArray< T > PStringArray List of all members.

Public Member Functions

Construction
PINLINE PArrayObjects (PINDEX initialSize=0)
 Create a new array of objects.
Overrides from class PObject
virtual Comparison Compare (const PObject &obj) const
 Get the relative rank of the two arrays.
Overrides from class PContainer
virtual PINDEX GetSize () const
 Get size of array.
virtual PBoolean SetSize (PINDEX newSize)
 Set the size of the array in objects.
Overrides from class PCollection
virtual PINDEX Append (PObject *obj)
 Append a new object to the collection.
virtual PINDEX Insert (const PObject &before, PObject *obj)
 Insert a new object immediately before the specified object.
virtual PINDEX InsertAt (PINDEX index, PObject *obj)
 Insert a new object at the specified ordinal index.
virtual PBoolean Remove (const PObject *obj)
 Remove the object from the collection.
virtual PObjectRemoveAt (PINDEX index)
 Remove the object at the specified ordinal index from the collection.
virtual PBoolean SetAt (PINDEX index, PObject *val)
 Set the object at the specified ordinal position to the new value.
virtual PObjectGetAt (PINDEX index) const
 Get the object at the specified ordinal position.
virtual PINDEX GetObjectsIndex (const PObject *obj) const
 Search the collection for the specific instance of the object.
virtual PINDEX GetValuesIndex (const PObject &obj) const
 Search the collection for the specified value of the object.
virtual void RemoveAll ()
 Remove all of the elements in the collection.

Protected Attributes

PBaseArray< PObject * > * theArray

Detailed Description

An array of objects.

This class is a collection of objects which are descendents of the PObject class. It is implemeted as a dynamic, linear array of pointers to the objects.

The implementation of an array allows very fast random access to items in the collection, but has severe penalties for inserting and deleting objects as all other objects must be moved to accommodate the change.

An array of objects may have "gaps" in it. These are array entries that contain NULL as the object pointer.

The PArrayObjects class would very rarely be descended from directly by the user. The PARRAY macro would normally be used to create a class. That will instantiate the template based on PArray or directly declare and define the class (using inline functions) if templates are not being used.

The PArray class or PARRAY macro will define the correctly typed operators for pointer access (operator const T *) and subscript access (operator[]).


Constructor & Destructor Documentation

PINLINE PArrayObjects::PArrayObjects ( PINDEX  initialSize = 0  ) 

Create a new array of objects.

The array is initially set to the specified size with each entry having NULL as is pointer value.

Note that by default, objects placed into the list will be deleted when removed or when all references to the list are destroyed.

Parameters:
initialSize  Initial number of objects in the array.


Member Function Documentation

virtual PINDEX PArrayObjects::Append ( PObject obj  )  [virtual]

Append a new object to the collection.

This will increase the size of the array by one and place the new object at that position.

Returns:
Index of the newly added object.
Parameters:
obj  New object to place into the collection.

Implements PCollection.

virtual Comparison PArrayObjects::Compare ( const PObject obj  )  const [virtual]

Get the relative rank of the two arrays.

The following algorithm is employed for the comparison:

Returns:
Comparison of the two objects, EqualTo for same, LessThan for obj logically less than the object and GreaterThan for obj logically greater than the object.
Parameters:
obj  Other PAbstractArray to compare against.

Reimplemented from PObject.

virtual PObject* PArrayObjects::GetAt ( PINDEX  index  )  const [virtual]

Get the object at the specified ordinal position.

If the index was greater than the size of the collection then NULL is returned.

Returns:
Pointer to object at the specified index.
Parameters:
index  Index position in the collection of the object.

Implements PCollection.

virtual PINDEX PArrayObjects::GetObjectsIndex ( const PObject obj  )  const [virtual]

Search the collection for the specific instance of the object.

The object pointers are compared, not the values. A simple linear search from ordinal position zero is performed.

Returns:
Ordinal index position of the object, or P_MAX_INDEX.
Parameters:
obj  Object to find.

Implements PCollection.

virtual PINDEX PArrayObjects::GetSize (  )  const [virtual]

Get size of array.

Reimplemented from PContainer.

virtual PINDEX PArrayObjects::GetValuesIndex ( const PObject obj  )  const [virtual]

Search the collection for the specified value of the object.

The object values are compared, not the pointers. So the objects in the collection must correctly implement the PObject::Compare() function. A simple linear search from ordinal position zero is performed.

Returns:
Ordinal index position of the object, or P_MAX_INDEX.

Implements PCollection.

virtual PINDEX PArrayObjects::Insert ( const PObject before,
PObject obj 
) [virtual]

Insert a new object immediately before the specified object.

If the object to insert before is not in the collection then the equivalent of the Append() function is performed.

All objects, including the before object are shifted up one in the array.

Note that the object values are compared for the search of the before parameter, not the pointers. So the objects in the collection must correctly implement the PObject::Compare() function.

Returns:
index of the newly inserted object.
Parameters:
before  Object value to insert before.
obj  New object to place into the collection.

Implements PCollection.

virtual PINDEX PArrayObjects::InsertAt ( PINDEX  index,
PObject obj 
) [virtual]

Insert a new object at the specified ordinal index.

If the index is greater than the number of objects in the collection then the equivalent of the Append() function is performed.

All objects, including the index position object are shifted up one in the array.

Returns:
Index of the newly inserted object.
Parameters:
index  Index position in collection to place the object.
obj  New object to place into the collection.

Implements PCollection.

virtual PBoolean PArrayObjects::Remove ( const PObject obj  )  [virtual]

Remove the object from the collection.

If the AllowDeleteObjects option is set then the object is also deleted.

All objects are shifted down to fill the vacated position.

Returns:
true if the object was in the collection.
Parameters:
obj  Existing object to remove from the collection.

Implements PCollection.

virtual void PArrayObjects::RemoveAll (  )  [virtual]

Remove all of the elements in the collection.

This operates by continually calling RemoveAt() until there are no objects left.

The objects are removed from the last, at index (GetSize()-1) toward the first at index zero.

Reimplemented from PCollection.

virtual PObject* PArrayObjects::RemoveAt ( PINDEX  index  )  [virtual]

Remove the object at the specified ordinal index from the collection.

If the AllowDeleteObjects option is set then the object is also deleted.

All objects are shifted down to fill the vacated position.

Note if the index is beyond the size of the collection then the function will assert.

Returns:
Pointer to the object being removed, or NULL if it was deleted.
Parameters:
index  Index position in collection to place the object.

Implements PCollection.

virtual PBoolean PArrayObjects::SetAt ( PINDEX  index,
PObject val 
) [virtual]

Set the object at the specified ordinal position to the new value.

This will overwrite the existing entry. If the AllowDeleteObjects option is set then the old object is also deleted.

Returns:
true if the object was successfully added.
Parameters:
index  Index position in collection to set.
val  New value to place into the collection.

Implements PCollection.

virtual PBoolean PArrayObjects::SetSize ( PINDEX  newSize  )  [virtual]

Set the size of the array in objects.

A new array may be allocated to accomodate the new number of objects. If the array increases in size then the new object pointers are initialised to NULL. If the array is made smaller then the data beyond the new size is lost.

Returns:
true if the memory for the array was allocated successfully.
Parameters:
newSize  New size of the array in objects.

Implements PContainer.


Member Data Documentation

PBaseArray<PObject *>* PArrayObjects::theArray [protected]


The documentation for this class was generated from the following file:
Generated on Fri Oct 14 01:44:10 2011 for PTLib by  doxygen 1.4.7