This is a pure static type used for parsing enum records from strings. The static fields are initialized with each method of type EnumRecords and therefore implementations of EnumRecordPrototype::Parse can rely on finding these fields properly set.
This concept makes use of the restriction, that the setup of ALib Enum Records must exclusively be done during bootstrapping of a software process, where no multi-threading is active, yet.
If parse errors occur, a std::runtime_error
is thrown.
std
. If (in presence of module ALib BaseCamp) an Exception was thrown, this had to be resourced likewise. The rationale for this design decision is that enum records usually are defined by potentially externalized resources. The maintenance of such resources must not lead to corrupted exceptions that are thrown when parsing those resources. Consequently, the exception messages are using english language and are not externalized. An end user will not be faced with these exception unless an errorneous "roll-out" of a software using malicious externalized resources was performed.The methods of this type perform strict checks about unnecessary whitespaces, '+'
-signs, etc, which also raise an exception. The rationale for this design decision (to not allow unnecessary, but maybe unharmful characters in resources) besides saving memory is, that the occurrence of unnecessary characters, indicates an errorneous maintenance of externalized resources, and such should be detected as soon as possible.
The main interface into this class is given with the overloaded Get methods. Enum Records are usually rather simple structs, consisting of strings, characters, integers and floating point values. If so, a simple list of invocations of Get for each field of the struct has to be placed in implementations of method EnumRecordPrototype::Parse. For the last field, optional parameter isLastField has to be given as true4
. As an example, the following code shows the implementation of Declaration::Parse:
This parse method omits reading the value for inherited field ERSerializable::MinimumRecognitionLength, and sets it to fixed 0
instead. This is often an option when custom enumeration record types are derived from ERSerializable but are not supposed to be deserialized or de-serialization forcing the whole string to read is acceptable. Note that it is still is possible to deserialize elements, but not with abbreviated names.
An implementation for a custom record type might perform more complex parsing operations. For this, some helper methods are publicly provided and finally, the direct use of the substring Input is likewise allowed.
Definition at line 69 of file recordparser.hpp.
#include <recordparser.hpp>
Public Static Field Index: | |
static ALIB_API character | InnerDelimChar |
The delimiter of fields of a record. | |
static ALIB_API Substring | Input |
The remaining input string. | |
static ALIB_API String | OriginalInput |
A backup of the originally given string to parse. | |
static ALIB_API character | OuterDelimChar |
The delimiter of records. | |
static ALIB_API NString | ResourceCategory |
The resource category (if a resourced string was parsed). | |
static ALIB_API NString | ResourceName |
The resource name (if a resourced string was parsed). | |
Public Static Method Index: | |
static ALIB_API void | assertChar (character specificChar, const NCString &where) |
static ALIB_API void | assertEndOfInput () |
Asserts that the Input is empty. | |
static ALIB_API void | assertEndOfRecord () |
Asserts that either Input is empty, or an OuterDelimChar follows. | |
static ALIB_API void | assertNoTrailingWhitespaces (String &token) |
static ALIB_API void | assertNoUnnecessary (character specificChar, const NCString &where) |
static ALIB_API void | assertNoWhitespaces (const NCString &where) |
static ALIB_API void | Delim () |
static ALIB_API void | error (const NCString &what) |
static ALIB_API void | Get (character &result, bool isLastField=false) |
static ALIB_API void | Get (double &result, bool isLastField=false) |
static ALIB_API void | Get (String &result, bool isLastField=false) |
template<typename TEnum > | |
static void | Get (TEnum &result, bool isLastField=false) |
template<typename TIntegral > | |
static void | Get (TIntegral &result, bool isLastField=false) |
static ALIB_API integer | getInteger (bool isLastField) |
static ALIB_API void | Initialize (const String &input, character innerDelim, character outerDelim, const NString &resourceCategory, const NString &resourceName) |
static ALIB_API void | OuterDelim () |
The delimiter of fields of a record.
Definition at line 75 of file recordparser.hpp.
The remaining input string.
Definition at line 72 of file recordparser.hpp.
A backup of the originally given string to parse.
Definition at line 81 of file recordparser.hpp.
The delimiter of records.
Definition at line 78 of file recordparser.hpp.
The resource category (if a resourced string was parsed).
Definition at line 84 of file recordparser.hpp.
The resource name (if a resourced string was parsed).
Definition at line 87 of file recordparser.hpp.
Asserts that either specificChar follows. The character will also be consumed.
specificChar | The character to consume next. |
where | Textual description about what is currently done. |
Asserts that no trailing whitespaces are in token.
token | The string to test for trailing whitespaces. |
Asserts that a specific redundant character is not given, for example a leading '+'
sign for an integral value.
specificChar | The character to check. |
where | Textual description about what is currently done. |
Asserts that no whitespaces follow in input.
where | Textual description about what is currently done. |
|
static |
Removes an InnerDelimChar. The Input is checked for not containing whitespaces before or after the delimiter.
Raises an error.
what | Textual description about what has been tried to do. |
Parses a field of character type.
result | A reference to the record's field to be read. |
isLastField | Has to be given as true , if this is the last field to parse. Defaults to false . |
|
static |
Parses the next floating point field of a record. Accepts '-'
signs, while '+'
is considered an unnecessary token. Furthermore asserts that at least one digit was parsed.
result | A reference to the record's field to be read. |
isLastField | Has to be given as true , if this is the last field to parse. Defaults to false . |
Parses a field of string-type. Parsing ends with an InnerDelimChar. The string is checked for not containing leading or trailing whitespaces.
result | A reference to the record's field to be read. |
isLastField | Has to be given as true , if this is the last field to parse. Defaults to false . |
|
inlinestatic |
Parses an enumeration element value, which has to be given in the source string by its underlying integral value. (It is not possible to parse "named" enumerations in bootstrapping, yet.)
TEnum | The enum type to parse an element from. |
result | A reference to the integer variable to parse. |
isLastField | Has to be given as true , if this is the last field to parse. Defaults to false . |
|
inlinestatic |
Parses an integral field of a record. Accepts '-'
signs, while '+'
is considered an unnecessary token. Furthermore asserts that at least one digit was parsed.
Allows special values min, max and ^N. The latter provides the power of two.
TIntegral | The integer type to parse. Must be statically castable from uint64_t. Deduced by the compiler. |
result | A reference to the record's field to be read. |
isLastField | Has to be given as true , if this is the last field to parse. Defaults to false . |
Used by Get(TIntegral&, bool). Reads special values min, max and ^N. The latter provides the power of two.
isLastField | Has to be given as true , if this is the last field to parse, otherwise false . |
|
inlinestatic |
Initializes this parser. This is done once before reading a resource (or static) string with enum record definitions.
input | The input string. |
innerDelim | The delimiter of fields of a record. |
outerDelim | The delimiter of records. |
resourceCategory | The delimiter of records. |
resourceName | The delimiter of records. |
Definition at line 97 of file recordparser.hpp.
|
static |
Removes an OuterDelimChar. The Input is checked for not containing whitespaces before or after the delimiter.