Dynamic-typing system
Several places in Qiskit allow the runtime definition of additional types and behavior. These use a consistent set of dynamic-typing methods and helpers to declare and interact with such objects.
QkVtableEntry
struct QkVtableEntry
An entry in a vtable for defining objects with custom behavior.
This same structure is used in several places when defining “custom behavior” for objects dynamically at runtime of your C program. The valid values of slot, flag and the function-pointer type of ptr will vary based on the context you are passing it to.
Typically, you will defining program statics of tables of these, terminating in the sentinel value {-1, 0, NULL}. Various Qiskit C API functions will take arguments of this form, and return a “vtable” handle back, which can then be used to define “instances” of the object with this attached behavior.
uint32_t slot
The “slot” of the function, or the sentinel (uint32_t)-1 to mark the final array entry.
This is typically set to some enum value, where the particular enum varies depending on which vtable you are defining.
uint32_t flags
Any additional “flags” for the particular table entry. These will typically be or’d (|) together, and the valid set of flags will be documented by the table user.
void *ptr
A function pointer implementing the correct signature for the combination of the slot and flags.
This can be NULL only in the case of slots being the sentinel -1.