carb::variant::VTable
Defined in carb/variant/VariantTypes.h
- 
struct VTable
- A v-table definition for a variant type. Each registered type has a unique v-table pointer that is retrievable via IVariant::getVTable(). Each entry in the v-table is a function with a default behavior if - nullptr.- Note - This class is applicable only to users of carb.variant.plugin that author a custom Translator class. - Warning - Functions in the v-table should not be called directly; the Variant wrapper class calls them through various traits functions. - Warning - All functions require that - self->vtable->[function]is equal to the function called.- Public Members - 
uint32_t sizeOf
- A member used as version control. - This member should be set to - sizeof(VTable)for the version of the v-table that a module is built against.
 - 
RString typeName
- Indicates the type name of the v-table. - Once registered with IVariant::registerType(), this name can be used to look up the type with IVariant::getVTable(). - Warning - This must be a unique name within the running process and may not match any of the built-in type names. 
 - 
void (*Destructor)(VariantData *self) noexcept
- Used to destroy the VariantData::data member. - A - nullptrdestructor function indicates that no destruction needs to take place.- Param self
- The VariantData to destroy. Can assume that - self->vtable->Destructoris the same as the function called.
 
 - 
VariantData (*Copy)(const VariantData *self) noexcept
- Called to create a functional copy of the given VariantData. - A - nullptrfunction indicates that VariantData can be trivially copied.- Note - The resulting VariantData need not have the same v-table as - self.- Param self
- The VariantData to copy. Can assume that - self->vtable->Copyis the same as the function called.
- Return
- A VariantData that is a functional copy of - self. traits::equals() should be- truefor- *selfand the returned VariantData.
 
 - 
bool (*Equals)(const VariantData *self, const VariantData *other) noexcept
- Called to test equality of - *selfwith (possibly different type)- *other.- A - nullptrfunction indicates that a trivial comparison of the VariantData is performed (i.e.- memcmp).- Warning - Generally speaking, order should not matter: assuming that - lhsand- rhsare both- const VariantData*with non-null- Equals, it should hold that- lhs->vtable->Equals(lhs, rhs)should always equal- rhs->vtable->Equals(rhs, lhs)regardless of their respective v-tables.- Param self
- The VariantData performing the compare. Can assume that - self->vtable->Equalsis the same as the function called.
- Param other
- The same or a different VariantData to compare with - self. May have a different- vtablethan- self.
- Return
- trueif the types are equal;- falseotherwise.
 
 - 
omni::string (*ToString)(const VariantData *self) noexcept
- Called to render the VariantData as a string. - A - nullptrfunction indicates that a string is produced that contains “<vtable pointer>:<data pointer>”.- Param self
- The VariantData to render. Can assume that - self->vtable->ToStringis the same as the function called.
- Return
- A type-dependent printable string representing the type, useful for debugging. 
 
 - 
bool (*ConvertTo)(const VariantData *self, const VTable *newtype, VariantData *out) noexcept
- Called to attempt to convert - selfto a different type.- A - nullptrfunction is the same as returning false.- Note - Generally speaking, Equals() and ConvertTo() should understand the same types. - Warning - If - falseis returned,- outis in an undefined state. If and only if- trueis returned, traits::destruct() must be called at some later point on- *out.- Param self
- The VariantData performing the conversion. Can assume that - self->vtable->ConvertTois this same as the function called.
- Param newtype
- A v-table representing the type to attempt to convert to. If the function recognizes the given v-table (which should not be the same as - self->vtable) and can convert to that type then the function should write to- outand return- true. If the v-table is not recognized, the function must return- false.
- Param out
- If - trueis returned from the function, this must be a valid VariantData and must be later destroyed with traits::destruct(). If- falseis returned then the state of- outis undefined. There is no requirement that- out->vtablematches- newtypeif- trueis returned; it must merely be valid.
- Return
- trueif and only if- outcontains a valid converted representation of- self;- falseotherwise.
 
 - 
size_t (*Hash)(const VariantData *self) noexcept
- Computes a hash of - self.- A - nullptrfunction casts- self->datato a- size_tfor use as a hash.- Param self
- The VariantData to hash. Can assume that - self->vtable->Hashis the same as the function called.
- Return
- A value to use as a hash identifying - *self.
 
 
- 
uint32_t sizeOf