Collections
UCX defines common attributes for collections. If you want to implement an own collection data type that uses the same features, you can use the CX_COLLECTION_BASE macro at the beginning of your struct to roll out all members a usual UCX collection has.
This macro will embed a structure in your collection that can be accessed with the member name collection.
Base Attributes of a Collection
The following attributes are declared by the CX_COLLECTION_BASE macro:
Attribute | Description |
|---|---|
| The allocator that shall be used for the collection data. |
| A function to compare two elements. |
| The size of one element in bytes. |
| The size, meaning the number of elements, currently stored. |
| An optional simple destructor function. |
| An optional advanced destructor function. |
| A pointer to the custom data that shall be passed to the advanced destructor. |
| A |
| A |
The attributes can be accessed directly via the collection member of your struct, or with the following convenience macros.
In each case the argument c is a pointer to your collection. The macro will then access the base data with c->collection.
Destructor Functions
For working with destructors, the following macros are defined:
With cxDefineDestructor() you can assign a simple destructor function to an instance of your collection. Similarly, you can assign an advanced destructor with custom data by using cxDefineAdvancedDestructor.
Your collection should be supporting destructors by invoking cx_invoke_destructor() whenever an element is removed from your collection without being returned to the caller. This macro will invoke a simple destructor, if one is assigned, first, and then the advanced destructor (again, if assigned).