TNSCollection Class Reference

[tvision Index] [tvision Hierarchy] [Headers]


A non-streamable collection of objects More...

#include <tvobjs.h>

Inherits: TObject

Public Members

Protected Members


Detailed Description

A non-streamable collection of objects.

This class stores an array of pointers to generic objects. This array may grow or shrink at run-time. Note: type `ccIndex' is defined in file `ttypes.h' as `int'.


TNSCollection( ccIndex aLimit, ccIndex aDelta ) [public]

Constructor.

`aLimit' is the initial size of the array of pointers. `aDelta' is used every time the array must be enlarged. In this case a number of `aDelta' pointers will be added to the array.

~TNSCollection() [public]

Destructor.

Deletes the array of pointers. Does not delete the objects.

void shutDown() [public virtual]

Releases all the resources allocated by this class.

If class flag `shouldDelete' is True the function freeAll() is called. This will delete each object of the array.

See Also:
TNSCollection::freeAll, TNSCollection::shouldDelete

void* at( ccIndex index ) [public]

Returns the address of the object at position `index'.

ccIndex indexOf( void *item ) [public virtual]

Returns the position of an object in the array.

The address is passed in the `item' parameter. If the object does not exist the function error() will be called.

See Also:
TNSCollection::error

void atFree( ccIndex index ) [public]

Removes the object at position `index' from the array.

Then calls delete on the object.

void atRemove( ccIndex index ) [public]

Removes the object at position `index' from the array.

Does not call delete on the object.

void remove( void *item ) [public]

Removes the object at address `item' from the array.

It just does `atRemove(indexOf(item))'. Does not call delete on the object.

void removeAll() [public]

It just sets class variable `count' to 0.

See Also:
TNSCollection::count

void free( void *item ) [public]

Removes the object at address `index' from the array.

It just does `atRemove(indexOf(item))'. Then calls delete on the object.

void freeAll() [public]

Deletes all the objects in the array.

The array is cleared out but not deleted.

void atInsert( ccIndex index, void *item ) [public]

Inserts a new object at position `index'.

Objects starting from position `index' to the end of the array are moved one position forward.

void atPut( ccIndex index, void *item ) [public]

Replaces the object at position `index'.

Old object is lost.

ccIndex insert( void *item ) [public virtual]

Inserts an object at the end of the array.

void error( ccIndex code, ccIndex info ) [public virtual]

This function is called on error conditions.

By default calls function exit() to terminate the program.

void* firstThat( ccTestFunc Test, void *arg ) [public]

Applies a test function to each object in the array.

`Test' is a pointer to a function whose type `ccTestFunc' is defined as:

typedef Boolean (*ccTestFunc)(void *, void *)

This method returns when one object of the array passes the test or when each object is tested without success. In the first case it returns the address of the object. In the latter case it returns 0. `arg' stores the argument of the function (if you need it).

This method scans the array forward. This is an example:

#define Uses_TNSCollection

#include "tv.h"

class XObject {

int value;

public:

XObject(int aValue): value(aValue) {}

int getValue() { return value; }

};

Boolean matchTest(void *obj, void *value) {

if (((XObject *) obj)->getValue() == *((int *) value)) return True;

return False;

}

void main() {

TNSCollection array(10, 5);

array.insert(new XObject(14));

array.insert(new XObject(32));

array.insert(new XObject(23));

array.insert(new XObject(41));

int find = 23;

XObject *p = (XObject *) array.firstThat(&matchTest, &find);

if (p != 0) array.free(p);

}

See Also:
TNSCollection::lastThat, TNSCollection::forEach

void* lastThat( ccTestFunc Test, void *arg ) [public]

Applies a test function to each object in the array.

This method scans the array backward.

See Also:
TNSCollection::firstThat, TNSCollection::forEach

void forEach( ccAppFunc action, void *arg ) [public]

Applies a function to each object in the array.

`action' is a pointer to a function whose type `ccAppFunc' is defined as:

typedef void (*ccAppFunc)(void *, void *);

This method scans the array forward.

See Also:
TNSCollection::firstThat, TNSCollection::lastThat

void pack() [public]

Packs the array by removing null pointers from it.

void setLimit( ccIndex aLimit ) [public virtual]

Resizes the array.

`aLimit' is the new size. If it is lesser than `count' the new size will be forced to be `count'. It it is grater than `maxCollectionSize' the new size will be forced to be `maxCollectionSize'. Integer constant `maxCollectionSize' is defined in `tvconfig.h' as `INT_MAX / sizeof(void *)'.

See Also:
TNSCollection::count

ccIndex getCount() [public]

Returns the number of pointers stored in the array.

TNSCollection() [protected]

Constructor.

void **items[protected]

This variable stores the array starting address.

ccIndex count[protected]

This variable stores the number of objects in the array.

See Also:
TNSCollection::limit

ccIndex limit[protected]

Current size of the array. Greater or equal to `count'.

See Also:
TNSCollection::count

ccIndex delta[protected]

This value is used every time the array must be enlarged. In this case a number of `delta' pointers will be added to the array.

Boolean shouldDelete[protected]

If this flag is True, all objects will be deleted when method shutDown() is called. Its initial value is True.

See Also:
TNSCollection::shutDown

Documentation generated by sergio@athena.milk.it on Wed Feb 10 22:11:47 CET 1999
Kdoc