ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
records.cpp
2
3namespace {
4#if ALIB_MONOMEM && ALIB_CONTAINERS
5 #if DOXYGEN
6 /// Global directory to find enum records.
8 EnumRecordKey, const void*,
11 #else
13 EnumRecordKey, const void*,
16 3.0, 6.0 );
17 #endif //if DOXYGEN
18#else
19 std::unordered_map< EnumRecordKey, const void*,
22#endif
23}
24
25void setEnumRecord( const std::type_info& rtti, integer elementValue, const void* record ) {
26 #if ALIB_MONOMEM && ALIB_CONTAINERS
27 ENUM_RECORD_MAP.EmplaceIfNotExistent( EnumRecordKey(rtti, elementValue ), record );
28 #else
29 ENUM_RECORD_MAP.try_emplace( EnumRecordKey(rtti, elementValue ), record );
30 #endif
31}
32
33const void* getEnumRecord( const std::type_info& rtti, integer elementValue ) {
34
35#if ALIB_MONOMEM && ALIB_CONTAINERS
36 auto it= ENUM_RECORD_MAP.Find( EnumRecordKey( rtti, elementValue ) );
37#else
38 auto it= ENUM_RECORD_MAP.find( EnumRecordKey( rtti, elementValue ) );
39#endif
40 if ( it != ENUM_RECORD_MAP.end() )
41 return it->second;
42
43 return nullptr;
44}
45
46#if ALIB_MONOMEM && ALIB_CONTAINERS
48 EnumRecordKey, const void*,
49 EnumRecordKey::Hash,
50 EnumRecordKey::EqualTo >& getInternalRecordMap() { return ENUM_RECORD_MAP; }
51#else
52std::unordered_map< EnumRecordKey, const void*,
53 EnumRecordKey::Hash,
54 EnumRecordKey::EqualTo >& getInternalRecordMap() { return ENUM_RECORD_MAP; }
55#endif
56
57
58} // namespace [alib::enumrecords::detail]
59
60
61//##################################################################################################
62// Implementation of parsing methods of built-in record types.
63//##################################################################################################
64namespace alib::enumrecords {
69
70
71
72//##################################################################################################
73// EnumRecordPrototype (Doxygen only)
74//##################################################################################################
75
76#if DOXYGEN
77/// This is the reference documentation module \alib_enumrecords.<br>
78/// Extensive documentation for this namespace is provided with the
79/// #"alib_mod_enums;Programmer's Manual" of that module.
80namespace alib::enumrecords {
81//==================================================================================================
82/// This struct is \b not part of the library but only provided with the documentation of this
83/// \alibmod_nl.
84///
85/// The struct prototypes that module \alib_enumrecords_nl expects from custom types that are
86/// associated to enumerations as the type of #"alib_enums_records;ALib Enum Records".
87///
88/// Usually, enum records are rather simple structs with fields of scalar or
89/// \https{POD types,en.cppreference.com/w/cpp/types/is_pod} like, \c int, \c double or
90/// #"^String" and this way remain POD types themselves.
91///
92/// When parsed or otherwise initialized, String members do not need to copy data to an
93/// own buffer, because the input string for parsing
94/// an instance, as well as the parameters of alternative constructors, are deemed to be static data.
95///
96/// The life-cycle of instances of enumeration record is from bootstrapping an application
97/// to its termination. After creation, the data cannot be modified.
98//==================================================================================================
100{
101 /// Default constructor leaving the record undefined. For efficiency, this usually does
102 /// not initialize fields, as those will be overwritten by a subsequent invocation to #".Parse".
103 ///
104 /// This constructor is only needed when method #".Parse" is given. Note that it is advised to
105 /// provide the parsing option and this way also this constructor.
106 EnumRecordPrototype() noexcept = default;
107
108 /// Constructor accepting all necessary arguments to completely define the record.
109 /// This constructor is needed only in the case that records should be defined in a statical
110 /// way which is an alternative to implementing the definition by parsing an (externalized)
111 /// initialization strings. Static definition can be performed with method
112 /// #"EnumRecords;Bootstrap(std::initializer_list<Initializer> definitions)"
113 /// but is not recommended, and the definition from parsable stings is preferred.
114 ///
115 /// Note that the parameter's passed when this constructor is invoked, have to be of
116 /// "static nature". For example, the buffers and contents of passed string values are
117 /// deemed to survive the life-cycle of an application. Usually, C++ string literals are passed.
118 ///
119 /// @param myArg1 Assigned to the first custom field.
120 /// @param myArg2 Assigned to the second custom field.
121 /// @param ... Further parameters, assigned to further fields.
122 EnumRecordPrototype( const MyType1& myArg1, MyType2 myArg2, ... ) noexcept;
123
124 /// Implementation has to parse the fields of this record from static interface struct
125 /// #"bootstrap::EnumRecordParser".
126 ///
127 /// For - usually simple - enum records, the process of parsing is limited to reading
128 /// values separated by delimiters. Convenient methods to do so are given by static type
129 /// #"bootstrap::EnumRecordParser". More complex parsing logic may be implemented by
130 /// using the "parser" substring found with #"EnumRecordParser::Input" and further
131 /// of its entities.<br>
132 /// Please refer to the documentation of #"bootstrap::EnumRecordParser" for all details.
133 /// A source code sample is given in chapter #"alib_enums_records_resourced_parsing" of the
134 /// Programmer's Manual of the module \alib_enumrecords_nl.
135 ///
136 /// The contents (buffer) of the string parsed is by contract of static nature. This means
137 /// that no copies of portions need to be allocated when used as a field value of string-type.
138 /// This is in alignment with the static nature of #"alib_enums_records;ALib Enum Records"
139 /// and their creation during bootstrap, either from C++ string literals or
140 /// #"alib_mod_resources;ALib Externalized Resources", which comply to the same contract.
141 ///
142 /// By the same token, in case of an error, an implementation should raise an exception in
143 /// debug-compilations, as parsing is deemed to succeed on static data, even if externalized.
145 void Parse() noexcept;
146}; // EnumRecordPrototype
147
148} // namespace [alib::enumrecords]
149#endif // DOXYGEN
#define ALIB_DLL
HashMap< MonoAllocator, EnumRecordKey, const void *, EnumRecordKey::Hash, EnumRecordKey::EqualTo > ENUM_RECORD_MAP
Global directory to find enum records.
Definition records.cpp:10
Details of namespace #"alib::enumrecords;2".
void setEnumRecord(const std::type_info &rtti, integer elementValue, const void *record)
Definition records.cpp:25
const void * getEnumRecord(const std::type_info &rtti, integer elementValue)
Definition records.cpp:33
HashMap< MonoAllocator, EnumRecordKey, const void *, EnumRecordKey::Hash, EnumRecordKey::EqualTo > & getInternalRecordMap()
Definition records.cpp:50
TMonoAllocator< lang::HeapAllocator > GLOBAL_ALLOCATOR
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
lang::integer integer
Type alias in namespace #"%alib".
Definition integers.hpp:149
containers::HashMap< TAllocator, TKey, TMapped, THash, TEqual, THashCaching, TRecycling > HashMap
Type alias in namespace #"%alib".
String EnumElementName
The name of the enum element.
Definition records.hpp:423
static void Get(String &result, bool isLastField=false)