Table Of Contents

Previous topic

s_logger Structure

Next topic

SContainer Structure

Containers

Container data types to store a collection of other objects.

Container Definitions

SContainer is an abstract container object from which all other container objects must inherit.

speect object SContainer

Inheritance diagram of SObject.SContainer

An abstract data type which is a collections of other objects.

All containers inherit from this object.

SContainer Structure

speect class SContainerClass

Inheritance diagram of SObjectClass.SContainerClass

The container class structure.

All containers classes inherit from this class.

SContainerClass Structure

Iterator Definitions

SIterator provides an interface for iteration over the objects stored in a container. Specific container implementations must implement the SIteratorClass functions.

Also see SList Iteration Example.

speect object SIterator

Inheritance diagram of SObject.SIterator

An abstract iterator for container data types.

All container iterators inherit from this object.

SIterator Structure

speect class SIteratorClass

Inheritance diagram of SObjectClass.SIteratorClass

The iterator class structure.

All container iterators classes inherit from this class.

SIteratorClass Structure

Macros

macro S_CONTAINER(SELF)

Return the given SContainer child class object as a container object.

Parameters:
  • SELF

    The given object.

Return:

Given object as SContainer* type.

Note:

This casting is not safety checked.

macro S_CONTAINER_CALL(SELF, FUNC)

Call the given function method of the given SContainer.

Parameters:
  • SELF

    The given SContainer*.

  • FUNC

    The function method of the given object to call.

Note:

This casting is not safety checked.

Example usage:

 S_CONTAINER_CALL(self, func)(param1, param2, ..., paramN);
where param1, param2, ..., paramN are the parameters passed to the object function func.

macro S_ITERATOR(SELF)

Return the given SIterator child class object as an iterator object.

Parameters:
  • SELF

    The given object.

Return:

Given object as SIterator* type.

Note:

This casting is not safety checked.

macro S_ITERATOR_GET(SELF, ERROR)

Get an iterator to the given SContainer object.

If SPCT_DO_SAFE_CAST is defined then the given object, will be safely cast to SContainer and, if successful, SContainerGetIterator called. Otherwise this is just a wrapper with an unsafe cast to SContainerGetIterator.

Parameters:
  • SELF

    The given SContainer* or child object.

  • ERROR

    Pointer to error code.

Return:

SIterator to SELF.

Note:

Of course SELF must be a child type of SObject, or else the behaviour will be undefined.

See also SPCT_DO_SAFE_CAST

Functions

SIterator *SContainerGetIterator(const SContainer *self, s_erc *error)

Get an iterator that points to the first object of the container.

If the container is empty then NULL is returned.

Parameters:
  • self

    The container for which an iterator is requested.

  • error

    Error code.

Return:

Iterator that points to first object in container or NULL if the container is empty.

See also:

S_ITERATOR_GET

SIterator *SIteratorNext(SIterator *self)

Return an iterator to the next object of the container associated with the given iterator.

Parameters:
  • self

    The given iterator.

Return:

Iterator to the next object of the container. If there are no more objects in the container, the iterator will be deleted and NULL will be returned.

Note:

If an error occurred, then the iterator self will be deleted, the error will be logged and NULL will be returned.

const char *SIteratorKey(SIterator *self, s_erc *error)

Return the key that is pointed to by the iterator.

This is only useful for mapping type containers (e.g. Map) and will return NULL for any other type of container.

Parameters:
  • self

    The given iterator.

  • error

    Error code.

Return:

The key pointed to by the iterator.

const SObject *SIteratorObject(SIterator *self, s_erc *error)

Return the object that is pointed to by the iterator.

Parameters:
  • self

    The given iterator.

  • error

    Error code.

Return:

The object pointed to by the iterator. This object can be anything and depends on the specific container iterator implementation.

Note:

The returned object should not be deleted.

Unlink the object from the container, and return it.

Parameters:
  • self

    The given iterator.

  • error

    Error code.

Return:

The unlinked object pointed to by the iterator. This object can be anything and depends on the specific container iterator implementation.

Note:

The iterator is still valid, but does not point to any objects in the container.

The caller is responsible for the memory of the returned object.