Previous topic

SObject Structure

Next topic

SObject Functions

SObjectClass StructureΒΆ

speect class SObjectClass

The base class structure.

The class defines a constructor and destructor for the class objects, as well as class members, i.e. members that belong to all object instances of a specific class type. All classes that want to work with the Speect Generic Object System must have this class in their inheritance hierarchy.

Protected Attributes
const char *name

Object hierarchy name.

The object hierarchy name must be a colon (”:”) separated list of object names, with the last object being the object implementation. The base class’s object (SObject) must not be included, as it is assumed to be the base object of all other objects.

size_t size

The size of the objects of this class, in bytes (sizeof).

s_version ver

The class version.

void(*const init)(void *obj, s_erc *error)

Constructor function pointer.

Initialize the members of the objects of this class type. This function receives a chunk of allocated memory for the object (will always be valid memory), and initializes/allocated the members of the object of this class type.

Parameters:
  • obj

    Memory for the newly created object.

  • error

    Error code.

void(*const destroy)(void *obj, s_erc *error)

Destructor function pointer.

Free up any resources allocated to the object by the SObjectClass function pointer init. The object’s memory itself must not be freed.

Parameters:
  • obj

    The object to be destroyed.

  • error

    Error code.

Note:

See S_DELETE and S_FORCE_DELETE.

void(*const dispose)(void *obj, s_erc *error)

Dispose function pointer.

Decrement the object’s reference counter if the object can be deleted by a call to S_DELETE.

Parameters:
  • obj

    The object to be disposed.

  • error

    Error code.

Note:

See S_DELETE and S_FORCE_DELETE.

s_bool (*const compare)(const SObject *first, const SObject *second, s_erc *error)

Comparison function pointer.

Compare the two given objects with each other and return, either TRUE or FALSE, if the objects are equal or not. The given objects will always be the same type and valid. The two given objects reference must not be factored into the comparison.

Parameters:
  • first

    Object to be compared with second.

  • second

    Object to be compared with first.

  • error

    Error code.

Return:

TRUE if the objects are the same, else FALSE.

char *(*const print)(const SObject *self, s_erc *error)

Print function pointer.

Print the given object to a character string buffer.

Parameters:
  • self

    The object to print.

  • error

    Error code.

Return:

Pointer to a character buffer containing a textual representation of the given object. Utf8 encoding is assumed.

SObject *(*const copy)(const SObject *self, s_erc *error)

Copy function pointer.

Copy (deep) the given object. Create a new object and deep copy all the given object’s members to the new object. If the given object has other objects as data members they must in turn be copied with a call to SObjectCopy. The new object’s reference count must be 0.

Parameters:
  • self

    The object to copy.

  • error

    Error code.

Return:

Pointer to new copy of the given object.