ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
EnumRecords< TEnum, TEnableIf > Struct Template Reference

Description:

template<typename TEnum, typename TEnableIf>
struct alib::enums::EnumRecords< TEnum, TEnableIf >

This is a pure static interface type usable with enumeration types that dispose about a specialization of TMP struct T_EnumRecords .

The type has two main purposes:

  1. Providing overloaded methods Bootstrap which allow to defined enum data records during bootstrapping of ALib and the using software.
  2. Providing an iterator over all records defined for elements of TEnum .

A third purpose, namely to retrieve the default (single) enumeration record for a specific enum element is not provided by this type, but instead offered with likewise templated namespace functions

Note
The rational for this is techical: Using namespace methods, the compiler can deduce template parameter TEnum from the function parameter, which was not possible if the functions were static methods of this templated type.
Attention
While this type becomes available with the inclusion of header file alib/enums/records.hpp , the overloaded Bootstrap methods, which are to be used solely during bootstrap, with single-threaded access to this backend, become available only with further inclusion of header alib/enums/recordbootstrap.hpp , which provides these method's defintion.

The rational for the above is twofold: It reduces header file dependcies from the majority of code that just use enum records and not defne them. Secondly it stresses the fact that the Bootstrap methods must be used only while bootstrapping is done.

See also
Chapter ALib Enum Records of the Programmer's Manual of this module.
Template Parameters
TEnumThe enumeration type that the static methods of this type are to use.
TEnableIfTo be ignored. Used to select this struct only for enum types which have a specialization of T_EnumRecords in place.

Definition at line 263 of file records.hpp.

#include <records.hpp>

Inner Type Index:

struct  ForwardIterator
 
struct  Initializer
 

Public Type Index:

using TIntegral = typename std::underlying_type<TEnum>::type
 
using TRecord = typename T_EnumRecords<TEnum>::Type
 

Public Static Method Index:

template<typename TRecord , typename TAssociated >
static constexpr bool AreOfType ()
 
static ForwardIterator begin ()
 
static void Bootstrap (character innerDelim=',', character outerDelim=',')
 
static void Bootstrap (const String &input, character innerDelim=',', character outerDelim=',')
 
static void Bootstrap (lang::Camp &module, const NString &name, character innerDelim=',', character outerDelim=',')
 
static void Bootstrap (lang::resources::ResourcePool &pool, const NString &category, const NString &name, character innerDelim=',', character outerDelim=',')
 
static void Bootstrap (std::initializer_list< Initializer > definitions)
 
template<typename... TArgs>
static void Bootstrap (TEnum element, TArgs &&... args) noexcept
 
static constexpr ForwardIterator end ()
 

Public Method Index:

 EnumRecords () noexcept=default
 

Type Definition Details:

◆ TIntegral

template<typename TEnum , typename TEnableIf >
using TIntegral = typename std::underlying_type<TEnum>::type

The enum's underlying integer type.

Definition at line 277 of file records.hpp.

◆ TRecord

template<typename TEnum , typename TEnableIf >
using TRecord = typename T_EnumRecords<TEnum>::Type

The enum's associated record type.

Definition at line 280 of file records.hpp.

Constructor(s) / Destructor Details::

◆ EnumRecords()

template<typename TEnum , typename TEnableIf >
EnumRecords ( )
defaultnoexcept

Defaulted constructor.

Method Details:

◆ AreOfType()

template<typename TEnum , typename TEnableIf >
template<typename TRecord , typename TAssociated >
static constexpr bool AreOfType ( )
staticconstexpr

Tests if TEnum has an associated record type that either is or is derived from type TRecord .

Template Parameters
TRecordThe enum record base type required.
TAssociatedDeduced by the compiler. Must not be specified.
Returns
Returns true if the given record type is the same or a base class of the record type associated with the given enum. Otherwise returns false.

◆ begin()

template<typename TEnum , typename TEnableIf >
static ForwardIterator begin ( )
inlinestatic

Returns an iterator referring to the first enum record defined for type TEnum .

Note
Receiving the list of enum records is internally implemented using class Singleton and executes in constant time O(1), in effect almost no time.
Like any other entity in this class, this method is static, apart from a defaulted (empty) constructor, which is provided for the sole purpose of allowing range-based for(:) loops.
Returns
An iterator to the first record defined for enumeration type TEnum .

Definition at line 423 of file records.hpp.

◆ Bootstrap() [1/6]

template<typename TEnum , typename TEnableIf >
static void Bootstrap ( character innerDelim = ',',
character outerDelim = ',' )
inlinestatic

This method is available if TMP struct T_Resourced is specialized for enum type TEnum .
Invokes Bootstrap(ResourcePool&, const NString&, const NString&, character, character)

Availability
This method is available only if ALib BaseCamp is included in the ALib Distribution .
See also
Chapter 4.4.3 Using TMP struct T_Resourced of the Programmer's Manual of this module.
Parameters
innerDelimThe delimiter used for separating the fields of a record. Defaults to ','.
outerDelimThe character delimiting enum records. Defaults to ','.

◆ Bootstrap() [2/6]

template<typename TEnum , typename TEnableIf >
static void Bootstrap ( const String & input,
character innerDelim = ',',
character outerDelim = ',' )
inlinestatic

Reads a list of enum data records from given string input .

The contents (buffer) of the given substring has to be of static nature (by contract). This means that parsing will not create copies of portions of the string but still use them later. Consequently the given string's buffer has to survive the life-cycle of an application.

This is due to the static nature of ALib Enum Records and their creation during bootstrap, either from C++ string literals or ALib Externalized Resources, which comply to the same contract.

Availability
This method is available only if ALib Strings is included in the ALib Distribution .
See also
Chapter 4.4.1 Parsing Enum Records From Strings for a sample of how this method can be invoked.
Parameters
inputThe string used for parsing the enum records to store.
innerDelimThe delimiter used for separating the fields of a record. Defaults to ','.
outerDelimThe character delimiting enum records. Defaults to ','.

◆ Bootstrap() [3/6]

template<typename TEnum , typename TEnableIf >
static void Bootstrap ( lang::Camp & module,
const NString & name,
character innerDelim = ',',
character outerDelim = ',' )
inlinestatic

This method can be used if a set of enum records is resourced using an ALib Camp 's resource instance.

Invokes Bootstrap(ResourcePool&, const NString&, const NString&, character, character) accepting a Camp and using its ResourcePool and field Camp::ResourceCategory .

Note
This is the preferred overload taken with ALib to load built-in enum records. The only exclamation is the use of overload Bootstrap(character, character) for enum record types that require a specialization of T_Resourced to perform "recursive" acquisition of other resources defined by fields of the records.
Availability
This method is available only if module ALib BaseCamp is included in the ALib Distribution .
See also
Chapters 4.4.3 Using TMP struct T_Resourced and 4.4.4 Using Resources In ALib Modules for more information.
Parameters
moduleThe module to use the resource pool and category name from.
nameThe resource name of the externalized name. In the case that a resource with that name does not exist, it is tried to load a resource with index number 0 appended to this name, aiming to parse a single record. On success, the index is incremented until no consecutive resource is found.
innerDelimThe delimiter used for separating the fields of a record. Defaults to ','.
outerDelimThe character delimiting enum records. Defaults to ','.

◆ Bootstrap() [4/6]

template<typename TEnum , typename TEnableIf >
static void Bootstrap ( lang::resources::ResourcePool & pool,
const NString & category,
const NString & name,
character innerDelim = ',',
character outerDelim = ',' )
inlinestatic

Reads a list of enum data records from an (externalized) resource string.

It is possible to provide the record data in two ways:

  • In one resource string: In this case, parameter outerDelim has to specify the delimiter that separates the records.
  • In an array of resource strings: If the resource string as given is not defined, this method appends an integral index starting with 0 to the resource name, parses a single record and increments the index. Parsing ends when a resource with a next higher index is not found.

The second option is recommended for larger enum sets. While the separation causes some overhead in a resource backend, the external (!) management (translation, manipulation, etc.) is most probably simplified with this approach.

Availability
This method is available only if ALib BaseCamp is included in the ALib Distribution .
See also
Chapter 4.4 Resourced/Externalized Enum Records for a sample of how this method can be invoked.
Parameters
poolThe resource pool to receive the string to parse the records from.
categoryThe resource category of the externalized string.
nameThe resource name of the externalized name. In the case that a resource with that name does not exist, it is tried to load a resource with index number 0 appended to this name, aiming to parse a single record. On success, the index is incremented until no consecutive resource is found.
innerDelimThe delimiter used for separating the fields of a record. Defaults to ','.
outerDelimThe character delimiting enum records. Defaults to ','.

◆ Bootstrap() [5/6]

template<typename TEnum , typename TEnableIf >
static void Bootstrap ( std::initializer_list< Initializer > definitions)
inlinestatic

Associates elements of TEnum with records, as specified by the given list of definitions .

The use of inner struct Initializer allows to place the enumeration element together with the construction parameters of the custom record type into one comma-separated argument list, without the need to place extra curly braces around the arguments of the record. (Such would have been necessary if for example std::pair had been used).

Note
It is preferred to use overloaded versions that parse definitions from static string data. This is more efficient in respect to the footprint of an application, and - if strings are resourced - far more flexible.
See also
Chapter 4.1.3 Step 3/3: Initializing The Data for a sample of how this method can be invoked.
Parameters
definitionsList of static enum records to store.

◆ Bootstrap() [6/6]

template<typename TEnum , typename TEnableIf >
template<typename... TArgs>
static void Bootstrap ( TEnum element,
TArgs &&... args )
inlinestaticnoexcept

Defines a record for a single element of TEnum .

Note
This method is rather provided for completeness, than for actual use, because it is preferred to bootstrap enum records as "bulk" data. Furthermore, it is preferred to use overloaded versions that accept static string data used to parse the data from. This is more efficient in respect to the footprint of an application, and - if strings are resourced - far more flexible.
See also
Chapter 4.1.3 Step 3/3: Initializing The Data for a sample of how this method can be invoked.
Template Parameters
TArgsTypes of the variadic arguments args .
Parameters
elementThe enum element.
argsVariadic arguments forwarded to constructor of the custom record to create and store.

◆ end()

template<typename TEnum , typename TEnableIf >
static constexpr ForwardIterator end ( )
inlinestaticconstexpr

Returns an iterator referring to the first element behind the list.

See also
The note documented with sibling method begin.
Returns
The end of the list.

Definition at line 434 of file records.hpp.


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