PTLib
Version 2.14.3
|
An array of objects. More...
#include <array.h>
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 PObject * | RemoveAt (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 PObject * | GetAt (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... | |
![]() | |
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... | |
![]() | |
PContainer (PINDEX initialSize=0) | |
Create a new unique container. More... | |
PContainer (const PContainer &cont) | |
Create a new refernce to container. More... | |
PContainer & | operator= (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... | |
![]() | |
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 PObject * | Clone () 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 PObject * | PTraceObjectInstance () const |
virtual void | ReadFrom (istream &strm) |
Input the contents of the object from the stream. More... | |
Protected Attributes | |
PBaseArray< PObject * > * | theArray |
Additional Inherited Members | |
![]() | |
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 } |
Result of the comparison operation performed by the Compare() function. More... | |
![]() | |
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 PObject * | PTraceObjectInstance (const char *) |
static __inline const PObject * | PTraceObjectInstance (const PObject *obj) |
![]() | |
PINLINE | PCollection (int dummy, const PCollection *coll) |
Constructor used in support of the Clone() function. More... | |
![]() |
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[]).
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.
initialSize | Initial number of objects in the array. |
|
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.
obj | New object to place into the collection. |
Implements PCollection.
|
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.EqualTo
for same, LessThan
for obj
logically less than the object and GreaterThan
for obj
logically greater than the object. obj | Other PAbstractArray to compare against. |
Reimplemented from PObject.
|
virtual |
Get the object at the specified ordinal position.
If the index was greater than the size of the collection then NULL is returned.
index | Index position in the collection of the object. |
Implements PCollection.
Referenced by PArray< PODBC::Field >::operator[]().
|
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.
P_MAX_INDEX
. obj | Object to find. |
Implements PCollection.
|
virtual |
Get size of array.
Reimplemented from PContainer.
Referenced by PXMLRPCStructBase::GetNumVariables(), PXMLElement::GetSize(), and PSafeDictionary< K, D >::iterator_base::SetPosition().
|
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.
P_MAX_INDEX
. Implements PCollection.
Referenced by PSafeDictionary< K, D >::iterator_base::iterator_base().
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.
before | Object value to insert before. |
obj | New object to place into the collection. |
Implements PCollection.
|
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.
index | Index position in collection to place the object. |
obj | New object to place into the collection. |
Implements PCollection.
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.
true
if the object was in the collection. obj | Existing object to remove from the collection. |
Implements PCollection.
|
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 |
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.
index | Index position in collection of object to remove. |
Implements PCollection.
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.
true
if the object was successfully added. index | Index position in collection to set. |
val | New value to place into the collection. |
Implements PCollection.
|
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.
newSize | New size of the array in objects. |
Implements PContainer.
|
protected |