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.
Note
The default behavior (if
!self.vtable->Destructor
) treatsself
as trivially destructible.- Parameters
self – The VariantData to destruct.
-
static VariantData copy(const VariantData &self) noexcept
Copies a VariantData.
Note
The default behavior (if
!self.vtable->Copy
) treatsself
as 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) noexcept
Tests two VariantData instances for equality.
Note
The default behavior (if
!self.vtable->Equals
) treatsself
andother
as 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
true
ifself
andother
are equal;false
otherwise.
-
static omni::string toString(const VariantData &self) noexcept
Renders a VariantData as a string for debugging purposes.
Note
The default behavior (if
!self.vtable->ToString
) produces"<vtable>:<data>"
.- Parameters
self – The VariantData to render as a string.
- Returns
A string representing
self
for debugging purposes.
-
static bool convertTo(const VariantData &self, const VTable *newType, VariantData &out) noexcept
Attempts to convert a VariantData to a different type.
If
newType
is the same asself.vtable
, then traits::copy() is invoked instead.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.
-
static size_t hash(const VariantData &self) noexcept
Computes a hash of a VariantData.
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 void swap(VariantData &lhs, VariantData &rhs) noexcept