This class is useful to pass and accept enum values of arbitrary C++ scoped enum types. Based on class Box, all interfaces are inherited, including type guessing and unboxing.
In the constructor, enum elements of an 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:
- Note
- The implementation of this class, by deriving from class Box, introduces a small memory overhead (usually 8 bytes per instance on 64-bit system), in respect to a possible alternative "direct" implementation. This is due to the fact that boxing allows one dimensional array types to be boxed as well as scalar types - which is never the case with this class.
But the advantages of doing so certainly surpass this small drawback.
-
Class Box is inherited
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 In Namespace std
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.
Friends
class Box
Definition at line 53 of file enum.hpp.
|
using | TypeCode = uinteger |
| The type of type codes received with ExportType.
|
|
template<typename TBoxable , bool NoStaticAsserts = false> |
static detail::VTable * | getVTable () |
|
Placeholder | data |
| The data that we encapsulate.
|
|
detail::VTable * | vtable |
|
| Box () noexcept |
|
| Box (Box &&) noexcept=default |
| Trivial default move constructor.
|
|
| Box (const Box &) noexcept=default |
| Trivial default copy constructor.
|
|
template<typename TBoxable > |
constexpr | Box (const TBoxable &src) noexcept |
|
| Box (TypeCode typeCode, const Placeholder &placeholder) noexcept |
|
| ~Box () noexcept=default |
| Trivial default destructor.
|
|
size_t | ArrayElementSize () const |
|
template<typename TFDecl , typename... TArgs> |
decltype(std::declval< typename TFDecl::Signature >()(std::declval< Box & >(), std::declval< TArgs >()...)) | Call (TArgs &&... args) |
|
template<typename TFDecl , typename... TArgs> |
decltype(std::declval< typename TFDecl::Signature >()(std::declval< Box & >(), std::declval< TArgs >()...)) | Call (TArgs &&... args) const |
|
template<typename TFDecl , typename... TArgs> |
decltype(std::declval< typename TFDecl::Signature >()(std::declval< Box & >(), std::declval< TArgs >()...)) | CallDirect (typename TFDecl::Signature function, TArgs &&... args) |
|
template<typename TFDecl , typename... TArgs> |
decltype(std::declval< typename TFDecl::Signature >()(std::declval< Box & >(), std::declval< TArgs >()...)) | CallDirect (typename TFDecl::Signature function, TArgs &&... args) const |
|
ALIB_API void | Clone (MonoAllocator &memory) |
|
Placeholder & | Data () |
|
const Placeholder & | Data () const |
|
const detail::VTable * | DbgGetVTable () const |
|
const std::type_info & | ElementTypeID () const |
|
TypeCode | ExportType () const |
|
Placeholder | ExportValue () const |
|
template<typename TFDecl > |
TFDecl::Signature | GetFunction (Reach searchScope, bool isInvocation=false) const |
|
unsigned int | GetPlaceholderUsageLength () const |
|
ALIB_API size_t | Hashcode () const |
|
void | Import (TypeCode typeCode) |
|
void | Import (TypeCode typeCode, const Placeholder &placeholder) |
|
bool | IsArray () const |
|
template<typename TElementType > |
bool | IsArrayOf () const |
|
bool | IsCharacter () const |
|
bool | IsEnum () const |
|
bool | IsFloatingPoint () const |
|
ALIB_API bool | IsNotNull () const |
|
bool | IsNull () const |
|
bool | IsPointer () const |
|
bool | IsSameType (const Box &other) const |
|
bool | IsSignedIntegral () const |
|
template<typename TBoxable > |
bool | IsType () const |
|
bool | IsUnsignedIntegral () const |
|
ALIB_API | operator bool () const |
|
bool | operator!= (const Box &rhs) const |
|
ALIB_API bool | operator< (Box const &rhs) const |
|
ALIB_API bool | operator<= (Box const &rhs) const |
|
Box & | operator= (Box &&) noexcept=default |
|
Box & | operator= (const Box &) noexcept=default |
|
ALIB_API bool | operator== (Box const &rhs) const |
|
ALIB_API bool | operator> (Box const &rhs) const |
|
bool | operator>= (Box const &rhs) const |
|
const std::type_info & | TypeID () const |
|
template<typename TUnboxable > |
const TUnboxable | Unbox () const |
|
template<typename TElementType > |
TElementType * | UnboxArray () const |
|
wchar | UnboxCharacter () const |
|
template<typename TElementType > |
TElementType & | UnboxElement (integer idx) const |
|
ALIB_API double | UnboxFloatingPoint () const |
|
integer | UnboxLength () const |
|
template<typename TUnboxable > |
TUnboxable | UnboxMutable () const |
|
integer | UnboxSignedIntegral () const |
|
uinteger | UnboxUnsignedIntegral () const |
|
bool operator< |
( |
Enum const & | rhs | ) |
const |
|
inline |
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.
- Note
- It is a matter of the compiler how the outer sort of types is performed and thus this cannot be determined by the user code.
- Parameters
-
rhs | The right hand side argument of the comparison. |
- Returns
- If the encapsulated type of this instance is the same as that of rhs, this methods returns
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 272 of file enum.hpp.