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:
- Providing overloaded methods Bootstrap which allow to defined enum data records during bootstrapping of ALib and the using software.
- 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 rationale 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 rationale 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
-
TEnum | The enumeration type that the static methods of this type are to use. |
TEnableIf | To be ignored. Used to select this struct only for enum types which have a specialization of T_EnumRecords in place. |
Definition at line 255 of file records.hpp.
|
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 () |
|
template<typename TEnum , typename TEnableIf >
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
-
input | The string used for parsing the enum records to store. |
innerDelim | The delimiter used for separating the fields of a record. Defaults to ',' . |
outerDelim | The character delimiting enum records. Defaults to ',' . |
template<typename TEnum , typename TEnableIf >
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
-
pool | The resource pool to receive the string to parse the records from. |
category | The resource category of the externalized string. |
name | The 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. |
innerDelim | The delimiter used for separating the fields of a record. Defaults to ',' . |
outerDelim | The character delimiting enum records. Defaults to ',' . |
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 placing 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
-
definitions | List of static enum records to store. |