All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PCollection Class Referenceabstract

A collection is a container that collects together descendents of the `PObject` class. More...

`#include <contain.h>`

Inheritance diagram for PCollection:

## Public Member Functions

Construction
| PCollection (PINDEX initialSize=0)
| Create a new collection. More...
Overrides from class PObject
virtual void | PrintOn (ostream &strm) const
| Print the collection on the stream. More...
Common functions for collections
virtual PINDEX | Append (PObject *obj)=0
| Append a new object to the collection. More...
virtual PINDEX | Insert (const PObject &before, PObject *obj)=0
| Insert a new object immediately before the specified object. More...
virtual PINDEX | InsertAt (PINDEX index, PObject *obj)=0
| Insert a new object at the specified ordinal index. More...
virtual PBoolean | Remove (const PObject *obj)=0
| Remove the object from the collection. More...
virtual PObject * | RemoveAt (PINDEX index)=0
| Remove the object at the specified ordinal index from the collection. More...
virtual void | RemoveAll ()
| Remove all of the elements in the collection. More...
virtual PBoolean | SetAt (PINDEX index, PObject *val)=0
| Set the object at the specified ordinal position to the new value. More...
virtual PObject * | GetAt (PINDEX index) const =0
| Get the object at the specified ordinal position. More...
virtual PINDEX | GetObjectsIndex (const PObject *obj) const =0
| Search the collection for the specific instance of the object. More...
virtual PINDEX | GetValuesIndex (const PObject &obj) const =0
| Search the collection for the specified value of the object. More...
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...
PContainer & | operator= (const PContainer &cont)
| Assign one container reference to another. More...
virtual | ~PContainer ()
| Destroy the container class. More...
virtual PINDEX | GetSize () const
| Get the current size of the container. More...
virtual PBoolean | SetSize (PINDEX newSize)=0
| Set the new current size of the container. More...
PBoolean | SetMinSize (PINDEX minSize)
| Set the minimum size of container. More...
virtual PBoolean | IsEmpty () const
| Determine if the container is empty. More...
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
virtual | ~PObject ()
virtual PObject * | Clone () const
| Create a copy of the class on the heap. More...
virtual PINDEX | HashFunction () const
| This function yields a hash value required by the `PDictionary` class. More...
virtual Comparison | Compare (const PObject &obj) const
| Compare the two objects and return their relative rank. 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...
virtual void | ReadFrom (istream &strm)
| Input the contents of the object from the stream. More...

## Protected Member Functions

PINLINE | PCollection (int dummy, const PCollection *coll)
| Constructor used in support of the Clone() function. More...
Protected Member Functions inherited from PContainer
| PContainer (int dummy, const PContainer *cont)
| Constructor used in support of the Clone() function. More...
| PContainer (PContainerReference &reference)
| Construct using static PContainerReference. More...
virtual void | DestroyContents ()=0
| Destroy the container contents. More...
virtual void | AssignContents (const PContainer &c)
| Copy the container contents. More...
void | CopyContents (const PContainer &c)
| Copy the container contents. More...
void | CloneContents (const PContainer *src)
| Create a duplicate of the container contents. More...
void | Destruct ()
| Internal function called from container destructors. More...
virtual void | DestroyReference ()
| Destroy the PContainerReference instance. More...
Protected Member Functions inherited from PObject
| PObject ()
| Constructor for PObject, made protected so cannot ever create one on its own. More...

## 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...
Protected Attributes inherited from PContainer
PContainerReference * | reference

## Detailed Description

A collection is a container that collects together descendents of the `PObject` class.

The objects contained in the collection are always pointers to objects, not the objects themselves. The life of an object in the collection should be carefully considered. Typically, it is allocated by the user of the collection when it is added. The collection then automatically deletes it when it is removed or the collection is destroyed, ie when the container class has no more references to the collection. Other models may be accommodated but it is up to the programmer to determine the scope and life of the objects.

The exact form of the collection depends on the descendent of PCollection and determines the access modes for the objects in it. Thus a collection can be an array which allows fast random access at the expense of slow insertion and deletion. Or the collection may be a list which has fast insertion and deletion but very slow random access.

The basic paradigm of all collections is the "virtual array". Regardless of the internal implementation of the collection; array, list, sorted list etc, the user may access elements via an ordinal index. The implementation then optimises the access as best it can. For instance, in a list ordinal zero will go directly to the head of the list. Stepping along sequential indexes then will return the next element of the list, remembering the new position at each step, thus allowing sequential access with little overhead as is expected for lists. If a random location is specified, then the list implementation must sequentially search for that ordinal from either the last location or an end of the list, incurring an overhead.

All collection classes implement a base set of functions, though they may be meaningless or degenerative in some collection types eg `Insert()` for `PSortedList` will degenerate to be the same as `Append()`.

## Constructor & Destructor Documentation

PCollection::PCollection | ( | PINDEX | initialSize = `0` | ) |

Create a new collection.

Parameters

  initialSize | Initial number of things in the collection.

PINLINE PCollection::PCollection | ( | int | dummy,
|  | const PCollection * | coll
| ) |  |

protected

Constructor used in support of the Clone() function.

This creates a new unique reference of a copy of the contents. It does {not} create another reference.

The dummy parameter is there to prevent the contructor from being invoked automatically by the compiler when a pointer is used by accident when a normal instance or reference was expected. The container would be silently cloned and the copy used instead of the container expected leading to unpredictable results.

Parameters

  dummy | Dummy to prevent accidental use of the constructor.
  coll | Collection class to clone.

## Member Function Documentation

PINLINE void PCollection::AllowDeleteObjects | ( | PBoolean | yes = `true` | ) |

Allow or disallow the deletion of the objects contained in the collection.

If true then whenever an object is removed, overwritten or the colelction is deleted due to all references being destroyed, the object is deleted.

For example:

                  coll.SetAt(2, new PString("one"));
                  coll.SetAt(2, new PString("Two"));

would automatically delete the string containing "one" on the second call to SetAt().

Parameters

  yes | New value for flag for deleting objects

Referenced by PSet< T >::PSet().

virtual PINDEX PCollection::Append | ( | PObject * | obj | ) |

pure virtual

Append a new object to the collection.

The exact semantics depends on the specific type of the collection. So the function may not place the object at the "end" of the collection at all. For example, in a `PSortedList` the object is placed in the correct ordinal position in the list.

Returns
  index of the newly added object.

Parameters

  obj | New object to place into the collection.

Implemented in PArrayObjects, PAbstractSortedList, PAbstractSet, and PAbstractList.

Referenced by PSafeColl< PArray< Base >, Base >::Append().

void PCollection::DisallowDeleteObjects | ( |  | ) |

Disallow the deletion of the objects contained in the collection.

See the `AllowDeleteObjects()` function for more details.

Referenced by PQueue< PXML >::PQueue(), and PStack< T >::PStack().

virtual PObject* PCollection::GetAt | ( | PINDEX | index | ) | const

pure 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.

Implemented in PArrayObjects, PAbstractSortedList, PAbstractDictionary, PAbstractSet, and PAbstractList.

virtual PINDEX PCollection::GetObjectsIndex | ( | const PObject * | obj | ) | const

pure virtual

Search the collection for the specific instance of the object.

The object pointers are compared, not the values. The fastest search algorithm is employed depending on the collection type.

Returns
  ordinal index position of the object, or P_MAX_INDEX.

Parameters

  obj | Object to search for.

Implemented in PArrayObjects, PAbstractSortedList, PAbstractDictionary, PAbstractSet, and PAbstractList.

Referenced by PSafeColl< PArray< Base >, Base >::Append(), and PSafeDictionaryBase< PDictionary< Key, Base >, Key, Base >::SetAt().

virtual PINDEX PCollection::GetValuesIndex | ( | const PObject & | obj | ) | const

pure 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. The fastest search algorithm is employed depending on the collection type.

Returns
  ordinal index position of the object, or P_MAX_INDEX.

Parameters

  obj | Object to search for.

Implemented in PArrayObjects, PAbstractSortedList, PAbstractDictionary, PAbstractSet, and PAbstractList.

Referenced by PSafeColl< PArray< Base >, Base >::FindWithLock().

virtual PINDEX PCollection::Insert | ( | const PObject & | before,
|  | PObject * | obj
| ) |  |

pure 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.

The exact semantics depends on the specific type of the collection. So the function may not place the object before the specified object at all. For example, in a `PSortedList` the object is placed in the correct ordinal position in the list.

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.

Implemented in PArrayObjects, PAbstractSortedList, PAbstractDictionary, PAbstractSet, and PAbstractList.

virtual PINDEX PCollection::InsertAt | ( | PINDEX | index,
|  | PObject * | obj
| ) |  |

pure 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.

The exact semantics depends on the specific type of the collection. So the function may not place the object at the specified index at all. For example, in a `PSortedList` the object is placed in the correct ordinal position in the list.

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.

Implemented in PArrayObjects, PAbstractSortedList, PAbstractDictionary, PAbstractSet, and PAbstractList.

virtual void PCollection::PrintOn | ( | ostream & | strm | ) | const

virtual

Print the collection on the stream.

This simply executes the `PObject::PrintOn()` function on each element in the collection.

The default behaviour for collections is to print each element separated by the stream fill character. Note that if the fill character is the default ' ' then no separator is printed at all.

Also if the fill character is not ' ', the the streams width parameter is set before each individual element of the colllection.

Returns
  the stream printed to.

Parameters

  strm | Output stream to print the collection.

Reimplemented from PObject.

Reimplemented in PAbstractDictionary, PvCard::TextValues, PvCard::TypeValues, PvCard::ParamValues, and PMIMEInfo.

virtual PBoolean PCollection::Remove | ( | const PObject * | obj | ) |

pure virtual

Remove the object from the collection.

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

Note that the comparison for searching for the object in collection is made by pointer, not by value. Thus the parameter must point to the same instance of the object that is in the collection.

Returns
  true if the object was in the collection.

Parameters

  obj | Existing object to remove from the collection.

Implemented in PArrayObjects, PAbstractSortedList, PAbstractSet, and PAbstractList.

virtual void PCollection::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 in PArrayObjects, and PAbstractSortedList.

Referenced by PHTTPForm::RemoveAllFields(), and PHTTPConnectionInfo::ResetMultipartFormInfo().

virtual PObject* PCollection::RemoveAt | ( | PINDEX | index | ) |

pure virtual

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

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

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.

Implemented in PArrayObjects, PAbstractSortedList, PAbstractDictionary, PAbstractSet, and PAbstractList.

virtual PBoolean PCollection::SetAt | ( | PINDEX | index,
|  | PObject * | val
| ) |  |

pure 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.

The exact semantics depends on the specific type of the collection. For some, eg `PSortedList`, the object inserted will not stay at the ordinal position. Also the exact behaviour when the index is greater than the size of the collection depends on the collection type, eg in an array collection the array is expanded to accommodate the new index, whereas in a list it will return false.

Returns
  true if the object was successfully added.

Parameters

  index | Index position in collection to set.
  val | New value to place into the collection.

Implemented in PArrayObjects, PAbstractSortedList, PAbstractDictionary, PAbstractSet, and PAbstractList.

The documentation for this class was generated from the following file:

- contain.h