ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::boxing::Enum Struct Reference

Description:

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 the header-file ALib.Boxing.StdFunctors.H as documented with namespace alib::boxing::compatibility::std.

Friends

class Box

See also
With the inclusion of the module ALib EnumRecords in the ALib Build, the namespace functions GetRecord and TryRecord become available, which receive an enum record for a value of this class.

Definition at line 46 of file enum.inl.

Inheritance diagram for alib::boxing::Enum:
[legend]
Collaboration diagram for alib::boxing::Enum:
[legend]

Public Method Index:

 Enum ()
 Default constructor.
 
template<typename TEnum>
requires std::is_enum<TEnum>::value
constexpr Enum (TEnum element)
 
BoxCastToBox ()
 
const BoxCastToBox () const
 
template<typename TEnum>
requires std::is_enum<TEnum>::value
TEnum Get () const
 
ALIB_DLL size_t Hashcode () const
 
integer Integral () const
 
template<typename TEnum>
requires std::is_enum<TEnum>::value
bool IsEnumType () const
 
bool operator!= (const Enum &rhs) const
 
template<typename TEnum>
requires std::is_enum<TEnum>::value
bool operator!= (TEnum rhs) const
 
bool operator< (Enum const &rhs) const
 
bool operator== (const Enum &rhs) const
 
template<typename TEnum>
requires std::is_enum<TEnum>::value
bool operator== (TEnum rhs) const
 
const std::type_info & TypeID () const
 

Additional Inherited Members

- Protected Type Index: inherited from alib::boxing::Box
using TypeCode = uinteger
 The type of type codes received with ExportType.
 
- Protected Static Method Index: inherited from alib::boxing::Box
template<typename TBoxable>
static constexpr detail::VTablegetVTable ()
 
- Protected Field Index: inherited from alib::boxing::Box
Placeholder data
 The data that we encapsulate.
 
detail::VTablevtable
 
- Protected Method Index: inherited from alib::boxing::Box
template<typename T>
constexpr void initPH (const T &src) noexcept
 
 Box () noexcept
 
template<typename TBoxable>
constexpr Box (const TBoxable &src) noexcept
 
 Box (TypeCode typeCode, const Placeholder &placeholder) noexcept
 
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_DLL void Clone (MonoAllocator &memory)
 
PlaceholderData ()
 
const PlaceholderData () const
 
const detail::VTableDbgGetVTable () 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_DLL 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_DLL 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_DLL operator bool () const
 
bool operator!= (const Box &rhs) const
 
ALIB_DLL bool operator< (Box const &rhs) const
 
ALIB_DLL bool operator<= (Box const &rhs) const
 
ALIB_DLL bool operator== (Box const &rhs) const
 
ALIB_DLL bool operator> (Box const &rhs) const
 
bool operator>= (Box const &rhs) const
 
const std::type_info & TypeID () const
 
template<typename TValue>
requires IsUnboxableStringType<TValue>
TValue Unbox () const
 
template<typename TValue>
requires ( !std::is_pointer_v<TValue> && !IsUnboxableStringType<TValue> )
TValue Unbox () const
 
template<typename TPointer>
requires ( std::is_pointer_v<TPointer> && !IsUnboxableStringType<TPointer> )
const std::remove_pointer_t< TPointer > * Unbox () const
 
template<typename TElementType>
TElementType * UnboxArray () const
 
wchar UnboxCharacter () const
 
template<typename TElementType>
TElementType & UnboxElement (integer idx) const
 
ALIB_DLL double UnboxFloatingPoint () const
 
integer UnboxLength () const
 
template<typename TPointer>
requires std::is_pointer_v<TPointer>
TPointer UnboxMutable () const
 
integer UnboxSignedIntegral () const
 
uinteger UnboxUnsignedIntegral () const
 

Constructor(s) / Destructor Details:

◆ Enum() [1/2]

alib::boxing::Enum::Enum ( )
inline

Default constructor.

Definition at line 53 of file enum.inl.

Here is the call graph for this function:

◆ Enum() [2/2]

template<typename TEnum>
requires std::is_enum<TEnum>::value
alib::boxing::Enum::Enum ( TEnum element)
inlineconstexpr

Implicit constructor, which accepts arbitrary elements of scoped or non-scoped enum types.

Template Parameters
TEnumThe external (user specific) enumeration type.
Parameters
elementThe external (user specific) enumeration element.

Definition at line 63 of file enum.inl.

Here is the call graph for this function:

Method Details:

◆ CastToBox() [1/2]

Box & alib::boxing::Enum::CastToBox ( )
inline

This method casts an instance of this class to a reference of base class Box. To hide the bases class's interface, this class inherits class Box only as a protected base. With this method, this "artificial limitation " (its a design decision) is lifted.

Returns
A mutable reference to this object.

Definition at line 129 of file enum.inl.

Here is the call graph for this function:

◆ CastToBox() [2/2]

const Box & alib::boxing::Enum::CastToBox ( ) const
inline

Same as overloaded version, but returns a const reference and consequently this method is declaredconst itself.

Returns
A constant reference to this object.

Definition at line 138 of file enum.inl.

Here is the call graph for this function:

◆ Get()

template<typename TEnum>
requires std::is_enum<TEnum>::value
TEnum alib::boxing::Enum::Get ( ) const
inline

This is a shortcut to Box::Unbox<TEnum>() to retrieve the original enum element in a type-safe way.

Before invoking this, the boxed type can be checked with IsType. If the wrong type is tried to be received, an ALib assertion is raised.

Template Parameters
TEnumThe external (user specific) enumeration type.
Returns
The underlying integral value of the encapsulated enum element.

Definition at line 76 of file enum.inl.

Here is the call graph for this function:

◆ Hashcode()

ALIB_DLL size_t alib::boxing::Box::Hashcode ( ) const

Imports protected base class's method Box::Hashcode.

Returns
A hashcode for the boxed enum type and value.

◆ Integral()

integer alib::boxing::Enum::Integral ( ) const
inline

Returns the underlying integral value of the original enum element cast to type integer.

Note
Boxed enum element values are always stored as type integer, regardless of the underlying type of the enumeration.
Returns
The underlying integral value.

Definition at line 87 of file enum.inl.

◆ IsEnumType()

template<typename TEnum>
requires std::is_enum<TEnum>::value
bool alib::boxing::Enum::IsEnumType ( ) const
inline

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.

Template Parameters
TEnumThe external (user specific) enumeration type.
Returns
true if the encapsulated enum type of type TEnum, otherwise false.

Definition at line 153 of file enum.inl.

Here is the call graph for this function:

◆ operator!=() [1/2]

bool alib::boxing::Enum::operator!= ( const Enum & rhs) const
inline

Comparison operator.

Parameters
rhsThe right hand side argument of the comparison.
Returns
true if this object does not equal rhs, false otherwise.

Definition at line 105 of file enum.inl.

Here is the call graph for this function:

◆ operator!=() [2/2]

template<typename TEnum>
requires std::is_enum<TEnum>::value
bool alib::boxing::Enum::operator!= ( TEnum rhs) const
inline

Comparison operator with enum elements.

Template Parameters
TEnumThe external (user specific) enumeration type.
Parameters
rhsThe right hand side argument of the comparison.
Returns
true if this object does not equal rhs, false otherwise.

Definition at line 175 of file enum.inl.

Here is the call graph for this function:

◆ operator<()

bool alib::boxing::Enum::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
rhsThe 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 198 of file enum.inl.

Here is the call graph for this function:

◆ operator==() [1/2]

bool alib::boxing::Enum::operator== ( const Enum & rhs) const
inline

Comparison operator.

Parameters
rhsThe right hand side argument of the comparison.
Returns
true if this object equals rhs, false otherwise.

Definition at line 96 of file enum.inl.

Here is the call graph for this function:

◆ operator==() [2/2]

template<typename TEnum>
requires std::is_enum<TEnum>::value
bool alib::boxing::Enum::operator== ( TEnum rhs) const
inline

Comparison operator with enum elements.

Template Parameters
TEnumThe external (user specific) enumeration type.
Parameters
rhsThe right hand side argument of the comparison.
Returns
true if this object equals rhs, false otherwise.

Definition at line 162 of file enum.inl.

Here is the call graph for this function:

◆ TypeID()

const std::type_info & alib::boxing::Box::TypeID ( ) const
inline

Imports protected base class's method Box::TypeID.

Returns
The std::type_info of the mapped enum type.

Definition at line 827 of file box.inl.


The documentation for this struct was generated from the following file: