This class is useful to pass and accept enum values of arbitrary C++ scoped enum types. Based on class Box , all interface is inherited, including type guessing and unboxing.
In the constructor, enum elements of arbitrary type are accepted. The element's underlying integral value is boxed and thus run-time type-information is added. Having the "original" element stored in protected base class Box, has the following advantages:
protected
instead of public, to hide bigger portions of the base class's interface. While some functions are explicitly made visible with keyword using
, for others, instances of this class have to be cased using overloaded methods CastToBox.Functors std::hash
, std::equal_to
and std::less
are specialized for this type with the inclusion of header file alib/compatibility/std_boxing_functional.hpp as documented with namespace alib::compatibility::std.
class Box
#include <enum.hpp>
Public Method Index: | |
Enum () | |
template<typename TEnum , typename TEnableIf > | |
constexpr | Enum (TEnum element) |
Box & | CastToBox () |
const Box & | CastToBox () const |
template<typename TEnum > | |
TEnum | Get () const |
template<typename TRecord > | |
const TRecord & | GetRecord () |
ALIB_API size_t | Hashcode () const |
integer | Integral () const |
template<typename TEnum > | |
bool | IsEnumType () const |
bool | operator!= (const Enum &rhs) const |
template<typename TEnum > | |
bool | operator!= (TEnum rhs) const |
bool | operator< (Enum const &rhs) const |
bool | operator== (const Enum &rhs) const |
template<typename TEnum > | |
bool | operator== (TEnum rhs) const |
template<typename TRecord > | |
const TRecord * | TryRecord () |
const std::type_info & | TypeID () const |
Implicit constructor which accepts arbitrary elements of scoped or non-scoped enum types.
TEnum | The external (user specific) enumeration type. |
TEnableIf | Selects this constructor only for enum types. Must not be specified (deduced by the compiler). |
element | The external (user specific) enumeration element. |
|
inline |
This is a shortcut to Box::Unbox() to retrieve the original enum element in a type-safe way.
Prior to invoking this, the boxed type can be checked with IsType. If the wrong type is tried to be received, an ALib assertion is raised.
TEnum | The external (user specific) enumeration type. |
Returns the ALib Enum Record associated with this enumeration element.
In debug-compilations an ALib assertion is raised, if no enum record was defined for the enumeration element represented by this instance.
TRecord | The enumeration record type associated with the enum type. This has to be explicitly provided. It is the caller's obligation to ensure that the requested type equals the one associated. Otherwise this method produces undefined behavior. |
Definition at line 305 of file enum.hpp.
size_t Hashcode | ( | ) | const |
Imports protected
base class's method Box::Hashcode .
Definition at line 1322 of file boxing.cpp.
|
inline |
Returns the underlying integral value of the original enum element casted to type integer .
Checks if this instance has an enum element of type TEnum stored.
This method is an inlined, simple alias for protected
base class's method Box::IsType .
TEnum | The external (user specific) enumeration type. |
true
if the encapsulated enum type of type TEnum , otherwise false
. Comparison operator with enum elements.
TEnum | The external (user specific) enumeration type. |
rhs | The right hand side argument of the comparison. |
true
if this object does not equal rhs , false
otherwise. Comparison operator with another Enum object. The sort order is primarily determined by the enum types that were boxed. If those are the same, then the underlying integral value of the enum elements is compared.
This leads to a nested sort order, with the type information being the outer order and the integral value of the enum being the inner one.
rhs | The right hand side argument of the comparison. |
true
if Integral() of this object is smaller than the one of rhs and otherwise false
. If the types are not the same, than the result is dependent on the tool chain (compiler) used for compiling ALib . Definition at line 276 of file enum.hpp.
Comparison operator with enum elements.
TEnum | The external (user specific) enumeration type. |
rhs | The right hand side argument of the comparison. |
true
if this object equals rhs , false
otherwise. Returns a pointer to the ALib Enum Record associated with this the enumeration element represented by this instance. If no enum record was is defined, nullptr
is returned.
TRecord | The enumeration record type associated with the enum type. This has to be explicitly provided. It is the caller's obligation to ensure that the requested type equals the one associated. Otherwise this method produces undefined behavior. |
nullptr
if no record was found. Definition at line 341 of file enum.hpp.
|
inline |
Imports protected
base class's method Box::TypeID .
std::type_info
of the mapped enum
type.