traits#
Fully qualified name: carb::variant::traits
Defined in carb/variant/VariantUtils.h
-
struct traits#
A structure containing functions for performing the prescribed actions on a VariantData. The functions handle the default behavior if the v-table or v-table function are
nullptr.Public Static Functions
-
static void swap(VariantData &lhs, VariantData &rhs) noexcept#
Swaps two VariantData members.
Note
VariantData is treated as a trivial type and no v-table functions are required to perform this.
- Parameters:
lhs – The left-hand VariantData.
rhs – The right-hand VariantData.
-
static void destruct(VariantData &self) noexcept#
Destructs a VariantData.
See also
Note
The default behavior (if
!self.vtable->Destructor) treatsselfas trivially destructible.- Parameters:
self – The VariantData to destruct.
-
static VariantData copy(const VariantData &self) noexcept#
Copies a VariantData.
See also
Note
The default behavior (if
!self.vtable->Copy) treatsselfas trivially copyable.- Parameters:
self – The VariantData to copy.
- Returns:
A VariantData that represents a copy of
self. The v-table of the return value must be the same asself.vtable. When finished with the return value, it must be destroyed via destruct().
- static bool equals(
- const VariantData &self,
- const VariantData &other,
Tests two VariantData instances for equality.
See also
Note
The default behavior (if
!self.vtable->Equals) treatsselfandotheras trivially comparable (i.e. bitwise compare viastd::memcmp).- Parameters:
self – The VariantData to compare. This parameter provides the v-table for the comparison.
other – The other VariantData to compare.
- Returns:
trueifselfandotherare equal;falseotherwise.
-
static omni::string toString(const VariantData &self) noexcept#
Renders a VariantData as a string for debugging purposes.
See also
Note
The default behavior (if
!self.vtable->ToString) produces"<vtable>:<data>".- Parameters:
self – The VariantData to render as a string.
- Returns:
A string representing
selffor debugging purposes.
- static bool convertTo(
- const VariantData &self,
- const VTable *newType,
- VariantData &out,
Attempts to convert a VariantData to a different type.
If
newTypeis the same asself.vtable, then traits::copy() is invoked instead.See also
Note
The default behavior (if
!self.vtable->ConvertTo) merely returnsfalse.- Parameters:
self – The VariantData to convert. This parameter provides the v-table for the comparison.
newType – The v-table representing the type to convert to.
out – The VariantData to write the result to. Only valid if
trueis returned.
- Returns:
trueif and only ifoutcontains a valid converted representation ofself;falseotherwise.
-
static size_t hash(const VariantData &self) noexcept#
Computes a hash of a VariantData.
See also
Note
The default behavior (if
!self.vtable->Hash) producessize_t(self.data).- Parameters:
self – The VariantData to hash.
- Returns:
A hash value representing
self.
- static bool convertFrom(
- const VTable *desired,
- VariantData &out,
- const VariantData &from,
Attempts to convert a VariantData to a different type.
If
desiredis the same asfrom.vtable, then traits::copy() is invoked instead.See also
Note
The default behavior (if
!from.vtable->ConvertFrom) merely returnsfalse.- Parameters:
desired – The v-table representing the type to convert to.
out – The VariantData to write the result to. Only valid if
trueis returned.from – The VariantData to convert from.
- Returns:
trueif and only ifoutcontains a valid converted representation offrom;falseotherwise.
-
static void swap(VariantData &lhs, VariantData &rhs) noexcept#