PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PArrayObjects Class Reference

An array of objects. More...

#include <array.h>

Inheritance diagram for PArrayObjects:
Collaboration diagram for PArrayObjects:

Public Member Functions

Construction
PINLINE PArrayObjects (PINDEX initialSize=0)
 Create a new array of objects. More...
 
Overrides from class PObject
virtual Comparison Compare (const PObject &obj) const
 Get the relative rank of the two arrays. More...
 
Overrides from class PContainer
virtual PINDEX GetSize () const
 Get size of array. More...
 
virtual PBoolean SetSize (PINDEX newSize)
 Set the size of the array in objects. More...
 
Overrides from class PCollection
virtual PINDEX Append (PObject *obj)
 Append a new object to the collection. More...
 
virtual PINDEX Insert (const PObject &before, PObject *obj)
 Insert a new object immediately before the specified object. More...
 
virtual PINDEX InsertAt (PINDEX index, PObject *obj)
 Insert a new object at the specified ordinal index. More...
 
virtual PBoolean Remove (const PObject *obj)
 Remove the object from the collection. More...
 
virtual PObjectRemoveAt (PINDEX index)
 Remove the object at the specified ordinal index from the collection. More...
 
virtual PBoolean SetAt (PINDEX index, PObject *val)
 Set the object at the specified ordinal position to the new value. More...
 
virtual PObjectGetAt (PINDEX index) const
 Get the object at the specified ordinal position. More...
 
virtual PINDEX GetObjectsIndex (const PObject *obj) const
 Search the collection for the specific instance of the object. More...
 
virtual PINDEX GetValuesIndex (const PObject &obj) const
 Search the collection for the specified value of the object. More...
 
virtual void RemoveAll ()
 Remove all of the elements in the collection. More...
 
- Public Member Functions inherited from PCollection
 PCollection (PINDEX initialSize=0)
 Create a new collection. More...
 
virtual void PrintOn (ostream &strm) const
 Print the collection on the stream. More...
 
__inline void remove (const PObject *obj)
 
__inline void clear ()
 
PINLINE void AllowDeleteObjects (PBoolean yes=true)
 Allow or disallow the deletion of the objects contained in the collection. More...
 
void DisallowDeleteObjects ()
 Disallow the deletion of the objects contained in the collection. More...
 
- Public Member Functions inherited from PContainer
 PContainer (PINDEX initialSize=0)
 Create a new unique container. More...
 
 PContainer (const PContainer &cont)
 Create a new refernce to container. More...
 
PContaineroperator= (const PContainer &cont)
 Assign one container reference to another. More...
 
virtual ~PContainer ()
 Destroy the container class. More...
 
__inline size_t size () const
 
PBoolean SetMinSize (PINDEX minSize)
 Set the minimum size of container. More...
 
virtual PBoolean IsEmpty () const
 Determine if the container is empty. More...
 
__inline bool empty () const
 
PBoolean IsUnique () const
 Determine if container is unique reference. More...
 
virtual PBoolean MakeUnique ()
 Make this instance to be the one and only reference to the container contents. More...
 
- Public Member Functions inherited from PObject
unsigned GetTraceContextIdentifier () const
 Get PTRACE context identifier. More...
 
void SetTraceContextIdentifier (unsigned id)
 
void GetTraceContextIdentifier (PObject &obj)
 
void GetTraceContextIdentifier (PObject *obj)
 
void SetTraceContextIdentifier (const PObject &obj)
 
void SetTraceContextIdentifier (const PObject *obj)
 
virtual ~PObject ()
 
virtual PObjectClone () const
 Create a copy of the class on the heap. More...
 
template<class CLS >
CLS * CloneAs () const
 As for Clone() but converts to specified type. More...
 
virtual PINDEX HashFunction () const
 This function yields a hash value required by the PDictionary class. More...
 
virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
 Determine the byte wise comparison of two objects. More...
 
bool operator== (const PObject &obj) const
 Compare the two objects. More...
 
bool operator!= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator< (const PObject &obj) const
 Compare the two objects. More...
 
bool operator> (const PObject &obj) const
 Compare the two objects. More...
 
bool operator<= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator>= (const PObject &obj) const
 Compare the two objects. More...
 
virtual const char * GetClass (unsigned ancestor=0) const
 Get the current dynamic type of the object instance. More...
 
PBoolean IsClass (const char *cls) const
 
virtual PBoolean InternalIsDescendant (const char *clsName) const
 Determine if the dynamic type of the current instance is a descendent of the specified class. More...
 
__inline const PObjectPTraceObjectInstance () const
 
virtual void ReadFrom (istream &strm)
 Input the contents of the object from the stream. More...
 

Protected Attributes

PBaseArray< PObject * > * theArray
 

Additional Inherited Members

- Public Types inherited from PObject
enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
 Result of the comparison operation performed by the Compare() function. More...
 
- Static Public Member Functions inherited from PObject
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 
static const char * Class ()
 Get the name of the class as a C string. More...
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
- Protected Member Functions inherited from PCollection
PINLINE PCollection (int dummy, const PCollection *coll)
 Constructor used in support of the Clone() function. More...
 
- Friends inherited from PObject

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
initialSizeInitial 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
objNew 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:

  • EqualTo if the two array memory blocks are identical in length and each objects values, not pointer, are equal.
  • LessThan if the instances object value at an ordinal position is less than the corresponding objects value in the obj parameters array. This is also returned if all objects are equal and the instances array length is less than the obj parameters array length.
  • GreaterThan if the instances object value at an ordinal position is greater than the corresponding objects value in the obj parameters array. This is also returned if all objects are equal and the instances array length is greater than the obj parameters array length.
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
objOther 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
indexIndex position in the collection of the object.

Implements PCollection.

Referenced by PArray< PODBC::Field >::operator[]().

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
objObject to find.

Implements PCollection.

virtual PINDEX PArrayObjects::GetSize ( ) const
virtual
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.

Referenced by PSafeDictionary< K, D >::iterator_base::iterator_base().

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
beforeObject value to insert before.
objNew 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
indexIndex position in collection to place the object.
objNew 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
objExisting 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
indexIndex position in collection of object to remove.

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
indexIndex position in collection to set.
valNew 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
newSizeNew 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: