vt_construction 7 2016-02-28 genvector manual

NAME

vt_construction - optional constructor, destructor and copy callbacks

SYNPOSIS

#define GVT_ELEM_CONSTRUCTOR

int (*elem_constructor)(GVTTYPE *vect, GVT_ELEM_TYPE *elem);

#define GVT_ELEM_DESTRUCTOR

void (*elem_destructor)(GVTTYPE *vect, GVT_ELEM_TYPE *elem);

#define GVT_ELEM_COPY

int (*elem_copy)(GVTTYPE *dst_vect, GVT_ELEM_TYPE *dst, GVT_ELEM_TYPE *src);

DESCRIPTION

Vector elements are often structures with fields that need allocation. Genvector provides an optional constructor/destructor/copy mechanism to handle this use case. Each feature consist of a GVT_ELEM_ macro that should be defined during the vt_instantiation(7) to enable the feature and a function pointer in vt_t(7). When any of these are enabled, the user needs to fill in the function pointers before or after vector initialization. The code makes sure no NULL pointer function is called.

When constructor and destructor are enabled, genvector makes sure that elements that enter the list are always constructed and elements leaving the vector are always destructed. Elements may enter or leave the vector implicitly, when the vector is growing or shrinking multiple elements.

Altough it is possible to enable constructor, destructor and copy selectively, it is strongly recommended to either enable all three or disable all three.

constructor

Whenever a new element is created, the constructor is called, except if the new element is created by copying an existing element (see section copy below).

destructor

Whenever a new element falls out of the vector, the destructor is called. This may happen only when the vector is shrinking or when the element is overwritten by another element (see vt_set, vt_set_ptr).

copy

If defined, this function is called whenever element content needs to be copied into an element of the vector. If the copy is to overwrite an existing element, the old element is destructed first. Thus the dst element on which elem_copy is called is never constructed; elem_copy needs to run the constructor if it is needed for the copy.

SEE ALSO

vt_construction 7 2016-02-28 genvector manual