ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::enums Namespace Reference

Description:

This is the reference documentation of sub-namespace enums of the ALib C++ Library, which holds types of library module ALib Enums.

Extensive documentation for this module is provided with ALib Module Enums - Programmer's Manual.

Attention
All operators are declared in the global namespace, other than this namespace documentation indicates!

Nested Namespaces:

namespace  arithmetical
 
namespace  bitwise
 
namespace  detail
 Details of namespace alib::enums.
 
namespace  iterable
 

Type Index:

struct  EnumIterator
 
struct  EnumRecordParser
 
struct  EnumRecordPrototype
 
struct  EnumRecords
 
struct  ERSerializable
 
struct  T_EnumIsArithmetical
 
struct  T_EnumIsBitwise
 
struct  T_EnumIsIterable
 
struct  T_EnumRecords
 

Type Definition Index:

template<typename TEnum >
using EnumBitSet
 

Function Index:

void Bootstrap ()
 
template<typename TEnum >
const T_EnumRecords< TEnum >::Type & GetRecord (TEnum element)
 
template<typename TEnum , typename TChar , Case TSensitivity = Case::Ignore, Whitespaces TTrimBeforeConsume = Whitespaces::Trim>
bool Parse (strings::TSubstring< TChar > &input, TEnum &result)
 
template<typename TEnum , typename TChar , Case TSensitivity = Case::Ignore, Whitespaces TTrimBeforeConsume = Whitespaces::Trim, TChar delimiter = ',', bool keepLastDelim = true>
bool ParseBitwise (strings::TSubstring< TChar > &input, TEnum &result)
 
template<typename TEnum , typename TChar , Case TSensitivity = Case::Ignore, Whitespaces TTrimBeforeConsume = Whitespaces::Trim>
bool ParseEnumOrTypeBool (strings::TSubstring< TChar > &input, TEnum &result, TEnum falseValue, TEnum trueValue)
 
void Shutdown ()
 
template<typename TEnum >
const T_EnumRecords< TEnum >::Type * TryRecord (TEnum element)
 
template<typename TEnum >
constexpr std::underlying_type< TEnum >::type UnderlyingIntegral (TEnum element) noexcept
 

Type Definition Details:

◆ EnumBitSet

template<typename TEnum >
using EnumBitSet
Initial value:
TBitSet<TEnum, enums::T_EnumIsIterable<TEnum>::End,
enums::T_EnumIsIterable<TEnum>::Begin>

This is a using statement which is available (enabled) for enumerations for which traits struct T_EnumIsIterable is specialized. With this, the interface methods of templated class TBitSet accept and return enumeration elements.

See also
For a quick tutorial on the use of this type, see chapter 3.5 Using Class TBitSet with Iterable Enums of the Programmer's Manual of module ALib Enums.
Template Parameters
TEnumThe enum type to use with class TBitSet.
Note
Other than documented here, this using statement has a second template parameter TEnableIf. This parameter has a default expressions and must not be provided because it is used internally to ensure that only if a specialization of T_EnumIsIterable<TEnum> exists, this type definition becomes available. (..and this is why it was explicitly 'faked out' of this documentation).

Definition at line 37 of file iterablebitset.hpp.

Function Details:

◆ Bootstrap()

ALIB_API void Bootstrap ( )

This namespace function initializes enum records, of built-in types i.e., those of the enumerations found in the header file alib/lang/commonenums.hpp.

This function needs to be called with bootstrapping a process. The standard bootstrap code of ALib, hence the (overloaded) functions alib::Bootstrap will call this function.

Note
In fact, if the module ALib BaseCamp is included, then this function is (almost) empty, because the enumeration records will in this case be resourced in singleton alib::BASECAMP of type BaseCamp.

Multiple invocations of this method are forbidden.

See also
For information about using this method, consult chapter 4.2 Bootstrapping Non-Camp Modules of the ALib Programmer's Manual.

Definition at line 306 of file records.cpp.

Here is the call graph for this function:

◆ GetRecord()

template<typename TEnum >
const T_EnumRecords< TEnum >::Type & GetRecord ( TEnum element)
inline

Returns the enum record for element element of enumeration type TEnum . In debug-compilations an ALib assertion is raised, if no enum record was defined for element.

Internally, references to enum records are stored in a hash map. With that, this method executes in constant time O(1) in the average case.

See also
  • Function TryRecord which returns a pointer to the record and nullptr if no record was defined for element.
  • Class Enum of module ALib Boxing and its method Enum::GetRecord, which allows collecting the necessary run-time information to defer the retrieval of enum records.
Template Parameters
TEnumThe enumeration type. Deduced from given argument.
Parameters
elementThe enum element to search for.
Returns
The record that is associated with element.

◆ Parse()

template<typename TEnum , typename TChar , Case TSensitivity = Case::Ignore, Whitespaces TTrimBeforeConsume = Whitespaces::Trim>
bool Parse ( strings::TSubstring< TChar > & input,
TEnum & result )
inline

Consumes an element value of a C++ enumeration that is equipped with ALib Enum Records of type ERSerializable (or of a derived type) from a given Substring.

In debug-builds, the method asserts that at least one record is defined for TEnum.

For more information consult chapter 4.3.1 Serialization/Deserialization of the Programmer's Manual of module ALib Enums.

Note
This namespace function is applicable to bitwise enums as well. However, only one element name is parsed. To parse multiple elements (ored to one resulting enum value), use sibling function ParseBitwise.
Template Parameters
TEnumThe enumeration type equipped with ALib Enum Recorss of type ERSerializable.
TCharThe character type of the input substring. Deduced by the compiler.
TSensitivityThe sensitivity of the comparison. Defaults to Case::Sensitive.
TTrimBeforeConsumeDetermines if the sub string should be (left-) trimmed before the consume operation. If so, in case of parsing failure, trimming is not restored.
Defaults to Whitespaces::Trim.
Parameters
[in,out]inputThe substring to parse. Passed as reference. On success, the substring will be shortened by the characters consumed. On failure only trimmed characters are consumed.
[out]resultThe result enum element given as reference.
Returns
true if an enum element was successfuly recognized, false otherwise.

Module Dependencies

This method is only available if ALib Strings is included in the ALib Distribution.

◆ ParseBitwise()

template<typename TEnum , typename TChar , Case TSensitivity = Case::Ignore, Whitespaces TTrimBeforeConsume = Whitespaces::Trim, TChar delimiter = ',', bool keepLastDelim = true>
bool ParseBitwise ( strings::TSubstring< TChar > & input,
TEnum & result )
inline

Repeatedly invokes sibling function Parse until delim is not found. The enum element values are or'ed in result.

In debug-builds, the method asserts that at least one record is defined for TEnum.

Note
This method is applicable only to bitwise enums that likewise are equipped with ALib Enum Records of (derived) type ERSerializable.
Template Parameters
TEnumThe enumeration type equipped with ALib Enum Records of (derived) type ERSerializable and furthermore with a specialization of T_EnumIsBitwise.
TCharThe character type of the input substring. Deduced by the compiler.
TSensitivityThe sensitivity of the comparison. Defaults to Case::Ignore.
TTrimBeforeConsumeDetermines if the substring should be (left-) trimmed before and after each consume operation. If so, in case of parsing failure, trimming is not restored.
Defaults to Whitespaces::Trim.
delimiterThe delimiter character of the enum elements.
Defaults to ','.
keepLastDelimIf true , the delimiter will be kept in this substring, if after the delimiter no further enum element was found. If false, the delimiter will be kept.
Defaults to true.
Parameters
[in,out]inputThe substring to parse. Passed as reference. On success, the substring will be shortened by the characters consumed. On failure only trimmed characters are consumed.
[out]resultThe result enum element given as reference.
Returns
true if an enum element was successfuly recognized, false otherwise.

Module Dependencies

This method is only available if ALib Strings is included in the ALib Distribution.

◆ ParseEnumOrTypeBool()

template<typename TEnum , typename TChar , Case TSensitivity = Case::Ignore, Whitespaces TTrimBeforeConsume = Whitespaces::Trim>
bool ParseEnumOrTypeBool ( strings::TSubstring< TChar > & input,
TEnum & result,
TEnum falseValue,
TEnum trueValue )
inline

Convenience method that first uses Parse to try and read an element of a C++ enum. If this is not successful, an enum of type Bool is tried to be read. If this is successful, depending on the value read, the TEnum values given as parameters falseValue and trueValue are assigned. Otherwise false is returned.

In debug-builds, the method asserts that at least one record is defined for TEnum.

See also
For more information consult chapter 4.3.1 Serialization/Deserialization of the Programmer's Manual of module ALib BaseCamp.
Template Parameters
TEnumThe enumeration type equipped with ALib Enum Records of (derived) type ERSerializable.
TCharThe character type of the input substring. Deduced by the compiler.
TSensitivityThe sensitivity of the comparison. Defaults to Case::Ignore.
TTrimBeforeConsumeDetermines if the substring should be (left-) trimmed before and after each consume operation. If so, in case of parsing failure, trimming is not restored.
Defaults to Whitespaces::Trim.
Parameters
trueValueThe TEnum value to use in case of Bool::True was read.
falseValueThe TEnum value to use in case of Bool::False was read.
[in,out]inputThe substring to parse. Passed as reference. On success, the substring will be shortened by the characters consumed. On failure only trimmed characters are consumed.
[out]resultThe result enum element given as reference.
Returns
true if an element of TEnum or Bool could be read, false otherwise.

◆ Shutdown()

ALIB_API void Shutdown ( )

Frees resources and shuts down module ALib Enums. Multiple invocations of this method are forbidden. The standard bootstrap code of ALib, hence the (overloaded) functions alib::Shutdown will call this function.

See also
Sibling function enums::Bootstrap.

Definition at line 297 of file records.cpp.

Here is the call graph for this function:

◆ TryRecord()

template<typename TEnum >
const T_EnumRecords< TEnum >::Type * TryRecord ( TEnum element)
inline

If defined, returns a pointer to the enum record for element element of enumeration type TEnum . If no enum record was defined, nullptr is returned.

See also
  • Function GetRecord which returns a reference and asserts in debug-compilations if no record is defined for element during bootstrap.
  • Class Enum of module ALib Boxing and its method Enum::TryRecord, which allows collecting the necessary run-time information to defer the retrieval of enum records.
Template Parameters
TEnumThe enumeration type. Deduced from given argument.
Parameters
elementThe enum element to search for.
Returns
A pointer to the record that is associated with element, respectively nullptr if no record was defined.

◆ UnderlyingIntegral()

template<typename TEnum >
std::underlying_type< TEnum >::type UnderlyingIntegral ( TEnum element)
constexprnoexcept

Simple alias to nested statment static_cast and type traits std::underlying_type, which

  • is selected by the compiler only if template parameter TEnum represents an enum type, and
  • is probably better readable.
Note
While documented in namespace alib::enums in fact this function resides in namespace alib.
See also
Class Enum introduced with module ALib Boxing.
Template Parameters
TEnumEnumeration type. Deduced by the compiler.
Parameters
elementThe enumeration element.
Returns
true if all bits of testFor are set in tested.