ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
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 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:

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 57 of file enum.hpp.

#include <enum.hpp>

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

Public Method Index:

 Enum ()
 
template<typename TEnum , typename TEnableIf >
constexpr Enum (TEnum element)
 
BoxCastToBox ()
 
const BoxCastToBox () 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
 

Constructor(s) / Destructor Details::

◆ Enum() [1/2]

Enum ( )
inline

Default constructor.

Definition at line 66 of file enum.hpp.

◆ Enum() [2/2]

constexpr 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.
TEnableIfSelects this constructor only for enum types. Must not be specified (deduced by the compiler).
Parameters
elementThe external (user specific) enumeration element.

Method Details:

◆ CastToBox() [1/2]

Box & 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 175 of file enum.hpp.

◆ CastToBox() [2/2]

const Box & 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 186 of file enum.hpp.

◆ Get()

template<typename TEnum >
TEnum Get ( ) const
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.

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

◆ GetRecord()

template<typename TRecord >
const TRecord & GetRecord ( )
inline

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.

See also
Template Parameters
TRecordThe 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.
Returns
The record that is associated with this enumeration element.

Definition at line 305 of file enum.hpp.

Here is the call graph for this function:

◆ Hashcode()

size_t Hashcode ( ) const

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

Returns
A hashcode for the boxed enum type and value.

Definition at line 1322 of file boxing.cpp.

◆ Integral()

integer Integral ( ) const
inline

Returns the underlying integral value of the original enum element casted 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 123 of file enum.hpp.

◆ IsEnumType()

template<typename TEnum >
bool 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.

◆ operator!=() [1/2]

bool 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 145 of file enum.hpp.

Here is the call graph for this function:

◆ operator!=() [2/2]

template<typename TEnum >
bool 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.

◆ operator<()

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 can not 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 276 of file enum.hpp.

Here is the call graph for this function:

◆ operator==() [1/2]

bool 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 134 of file enum.hpp.

Here is the call graph for this function:

◆ operator==() [2/2]

template<typename TEnum >
bool 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.

◆ TryRecord()

template<typename TRecord >
const TRecord * TryRecord ( )
inline

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.

See also
Template Parameters
TRecordThe 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.
Returns
A pointer to the record that is associated with this enumeration element, respectively nullptr if no record was found.

Definition at line 341 of file enum.hpp.

Here is the call graph for this function:

◆ TypeID()

const std::type_info & TypeID ( ) const
inline

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

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

Definition at line 902 of file box.inl.


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