Class DContainer (unit SDL)

Inherits from

DIterHandler

DContainer is the base class of all containers. It provides a number of generic facilities for container usage and management. The basic iterator manipulation routines are made virtual and abstract, forcing subclasses to implement them.

Constructors


constructor create; virtual;

Creates this container using the default comparator (DObjectComparator).

constructor createWith(compare : DComparator); virtual;

Creates this container using the specified comparator for ordering elements.


Functions

procedure add(objs : array of const); virtual;

Add an array of objects to the container.

procedure addRef(const obj : DObject); virtual;

Add a DObject to this container.

function binaryCompare(const obj1, obj2 : DObject) : Integer;

Requests that this container compare two DObjects using its current comparator.

function binaryTest(const obj1, obj2 : DObject) : Boolean;

Determines if two objects are equal, using this container's current comparator.

function CaselessStringComparator(const obj1, obj2 : DObject) : Integer;

A comparator that compares strings without case sensitivity.

procedure clear; virtual;

Clear this container of all contents.

function clone : DContainer; virtual;

Return a complete copy of this container.

function contains(objs : array of const) : Boolean; virtual;

Determine if this container has an object matching any of objs.

function count(objs : array of const) : Integer; virtual;

Determine the total number of items matching objs.

function DObjectComparator(const obj1, obj2 : DObject) : Integer;

The standard comparator that can compare all atomic types.

procedure ensureCapacity(amount : Integer); virtual;

Inform the container that "amount" items are going to be inserted.

function finish : DIterator; virtual; abstract;

Return an iterator positioned after the last element in the container.

procedure getBinaryTest(var bt : DBinaryTest); virtual;

Retrives the current comparator of this container as a binary test, which enables testing for equality only.

procedure getComparator(var compare : DComparator); virtual;

Requests the comparator currently being used by this container.

function hashComparator(const obj1, obj2 : DObject) : Integer;

A comparator that uses hashes to differentiate objects.

function isEmpty : Boolean; virtual;

Determines if this container is empty.

function maxSize : Integer; virtual; abstract;

Return the absolute maximum number of objects that can be stored in this container.

procedure remove(objs : array of const); virtual;

Remove all instances of each in an array of objects, by value, from the container.

function size : Integer; virtual;

Determines the number of objects currently in this container.

function start : DIterator; virtual; abstract;

Return an iterator positioned on the first object in the container.

procedure trimToSize; virtual;

Request that the container use the minimum amount of memory possible for its current contents.

function usesPairs : Boolean; virtual;

Does this container use pairs?

procedure _add(const obj : DObject); virtual; abstract;

Add a DObject to this container.

function _contains(const obj : DObject) : Boolean; virtual;

Determine if this container has an object matching obj.

function _count(const obj : DObject) : Integer; virtual;

Determine the number of items matching obj.

procedure _remove(const obj : DObject); virtual; abstract;

Remove all instances of an object, by value, from the container.

Properties

Events

Variables


Constructors


constructor create; virtual;

Creates this container using the default comparator (DObjectComparator).


constructor createWith(compare : DComparator); virtual;

Creates this container using the specified comparator for ordering elements.


Functions


procedure add(objs : array of const); virtual;

Add an array of objects to the container. This call makes use of Delphi's open array system, and as such the array can contain any type of object. Each object will be copied into the container.


procedure addRef(const obj : DObject); virtual;

Add a DObject to this container. The object is NOT copied -- it is moved into the container. Do not clear the object afterwards.


function binaryCompare(const obj1, obj2 : DObject) : Integer;

Requests that this container compare two DObjects using its current comparator. If obj1 is less than obj2, the result is negative. If they are equal, the result is 0; otherwise it is positive.


function binaryTest(const obj1, obj2 : DObject) : Boolean;

Determines if two objects are equal, using this container's current comparator.


function CaselessStringComparator(const obj1, obj2 : DObject) : Integer;

A comparator that compares strings without case sensitivity.


procedure clear; virtual;

Clear this container of all contents. Note that this does not perform any type of free or destructor operation. If you want to free all the objects in a container before clearing if, use the ObjFree algorithm.


function clone : DContainer; virtual;

Return a complete copy of this container. This is a copy by value, as all objects are stored in DContainers by value.


function contains(objs : array of const) : Boolean; virtual;

Determine if this container has an object matching any of objs.


function count(objs : array of const) : Integer; virtual;

Determine the total number of items matching objs.


function DObjectComparator(const obj1, obj2 : DObject) : Integer;

The standard comparator that can compare all atomic types.


procedure ensureCapacity(amount : Integer); virtual;

Inform the container that "amount" items are going to be inserted. Most containers don't have any concept of setting the capacity, but for those that do, algorithms can call this to provide a hint to the container about how many items are going to be inserted.


function finish : DIterator; virtual; abstract;

Return an iterator positioned after the last element in the container. Note that the finish position is a valid insertion point for those containers that can have the add operation performed.


procedure getBinaryTest(var bt : DBinaryTest); virtual;

Retrives the current comparator of this container as a binary test, which enables testing for equality only.


procedure getComparator(var compare : DComparator); virtual;

Requests the comparator currently being used by this container.


function hashComparator(const obj1, obj2 : DObject) : Integer;

A comparator that uses hashes to differentiate objects.


function isEmpty : Boolean; virtual;

Determines if this container is empty.


function maxSize : Integer; virtual; abstract;

Return the absolute maximum number of objects that can be stored in this container. The container does not necessarily have this space allocated; it is just the maximum that could be allocated.


procedure remove(objs : array of const); virtual;

Remove all instances of each in an array of objects, by value, from the container.


function size : Integer; virtual;

Determines the number of objects currently in this container.


function start : DIterator; virtual; abstract;

Return an iterator positioned on the first object in the container.


procedure trimToSize; virtual;

Request that the container use the minimum amount of memory possible for its current contents. Note that this is only a hint to the container; it may or may not have any effect.


function usesPairs : Boolean; virtual;

Does this container use pairs?


procedure _add(const obj : DObject); virtual; abstract;

ParameterDescription
objThe object to add.

Add a DObject to this container. The object is copied and added to the container.


function _contains(const obj : DObject) : Boolean; virtual;

Determine if this container has an object matching obj.


function _count(const obj : DObject) : Integer; virtual;

Determine the number of items matching obj.


procedure _remove(const obj : DObject); virtual; abstract;

Remove all instances of an object, by value, from the container.


Properties


Events


Variables