ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
recordbootstrap.hpp
Go to the documentation of this file.
1/** ************************************************************************************************
2 * \file
3 * This header file is part of module \alib_enums of the \aliblong.
4 *
5 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_ALIB_ENUMS_RECORDBOOTSTRAP
9#define HPP_ALIB_ENUMS_RECORDBOOTSTRAP 1
10
11#if !defined(HPP_ALIB_SINGLETONS_SINGLETON)
13#endif
14
16
17#if !defined (HPP_ALIB_ENUMS_RECORDS)
18# include "alib/enums/records.hpp"
19#endif
20#if ALIB_STRINGS && !defined (HPP_ALIB_ENUMS_RECORDPARSER)
22#endif
23
24#if ALIB_STRINGS && !defined(HPP_ALIB_STRINGS_SUBSTRING)
26#endif
27
28#if ALIB_CAMP && !defined(HPP_ALIB_LANG_RESOURCES_RESOURCES)
30#endif
31
32#if ALIB_CAMP && !defined(HPP_ALIB_LANG_CAMP)
34#endif
35
36#if ALIB_MONOMEM && !defined (HPP_ALIB_MONOMEM_MONOALLOCATOR)
38#endif
39
40#include <initializer_list>
41
42
43namespace alib { namespace enums {
44
45#if !defined(ALIB_DOX)
46
47template<typename TEnum, typename TEnableIf>
48template <typename... TArgs>
49inline
50void EnumRecords<TEnum, TEnableIf>::Bootstrap( TEnum element, TArgs&&... args) noexcept
51{
53 auto** lastP = records.getPointerToLast();
54 #if ALIB_MONOMEM
55 *lastP= monomem::GlobalAllocator.Emplace<typename detail::EnumRecordHook<TEnum>::Node>(
56 #else
57 *lastP= new typename detail::EnumRecordHook<TEnum>::Node(
58 #endif
59 element, std::forward<TArgs>(args)... );
60
61 detail::setEnumRecord( typeid(TEnum),
62 UnderlyingIntegral(element),
63 &(*lastP)->record );
64 (*lastP)->next= nullptr;
65}
66
67template<typename TEnum, typename TEnableIf>
68inline
69void EnumRecords<TEnum, TEnableIf>::Bootstrap( std::initializer_list<EnumRecords::Initializer> definitions )
70{
72 auto* table = definitions.begin();
74 auto** lastP = records.getPointerToLast();
75 for( size_t i= 0; i!= definitions.size(); ++i)
76 {
77 #if ALIB_MONOMEM
78 *lastP= monomem::GlobalAllocator.Emplace<typename detail::EnumRecordHook<TEnum>::Node>(
79 #else
80 *lastP= new typename detail::EnumRecordHook<TEnum>::Node(
81 #endif
82 table[i].element, table[i].record );
83 detail::setEnumRecord( typeid(TEnum),
84 UnderlyingIntegral(table[i].element),
85 &(*lastP)->record );
86 lastP= &(*lastP)->next;
87 }
88
89 (*lastP)= nullptr;
91}
92
93#if ALIB_STRINGS
94
95 template<typename TEnum, typename TEnableIf>
96 inline
98 character innerDelim,
99 character outerDelim )
100 {
101 EnumRecordParser::Initialize(input, innerDelim, outerDelim, NullNString(), NullNString() );
102
104 auto** lastP = records.getPointerToLast();
105
106 for(;;)
107 {
108 #if ALIB_MONOMEM
109 auto* element= (*lastP= monomem::GlobalAllocator.Emplace<typename detail::EnumRecordHook<TEnum>::Node>() );
110 #else
111 auto* element= (*lastP= new typename detail::EnumRecordHook<TEnum>::Node() );
112 #endif
113
114 EnumRecordParser::Get( element->integral );
115 element->record.Parse();
116
117 detail::setEnumRecord( typeid(TEnum), element->integral,
118 &element->record );
119
120 // next?
121 lastP= &element->next;
122 if( EnumRecordParser::Input.IsEmpty() )
123 break;
125 }
127 (*lastP)= nullptr;
128 }
129#endif
130
131#if ALIB_CAMP
132 template<typename TEnum, typename TEnableIf>
133 inline
134 void EnumRecords<TEnum, TEnableIf>::Bootstrap( lang::resources::ResourcePool& pool,
135 const NString& category,
136 const NString& name,
137 character innerDelim,
138 character outerDelim )
139 {
140 // resources given in the standard, non-indexed way?
141 String input= pool.Get( category, name ALIB_DBG(, false) );
142 if( input.IsNotNull() )
143 {
144 // Note:
145 // The parser is initialized here already. The "inner" call to Bootstrap() will not have
146 // the resource information otherwise.
147 // Double initialization is checked inside the parser's initialize method.
148 // (A little crude but OK!)
149 EnumRecordParser::Initialize(input, innerDelim, outerDelim, category, name );
150 Bootstrap( input, innerDelim, outerDelim );
151 return;
152 }
153
154 // resources given as name0, name1, name2...
155 NString64 nameNr( name);
156 int nr= 0;
158 auto** lastP = records.getPointerToLast();
159 while( (input= pool.Get( category, nameNr.Reset( name)._(nr) ALIB_DBG(, false))).IsNotNull()
160 || nr== 0 )
161 {
162 EnumRecordParser::Initialize(input, innerDelim, outerDelim, category, nameNr );
163
164 auto* element= (*lastP= monomem::GlobalAllocator.Emplace<typename detail::EnumRecordHook<TEnum>::Node>() );
165
166 EnumRecordParser::Get( element->integral );
167 element->record.Parse();
168
169 detail::setEnumRecord( typeid(TEnum), element->integral,
170 &element->record );
171
173 // next
174 lastP= &element->next;
175 ++nr;
176 }
177 (*lastP)= nullptr;
178
179 // check if there are more coming (a gap in numbered definition)
180 #if ALIB_DEBUG
181 for( int i= 0 ; i < 35 ; ++i )
182 {
183 ++nr;
184 if( pool.Get( category, nameNr.Reset( name)._( nr) ALIB_DBG(, false)).IsNotNull() )
185 {
186 ALIB_ERROR( "ENUMS", NString128()
187 << "Detected a \"gap\" in numbering of enum records for type <"
188 << lang::DbgTypeDemangler( typeid(TEnum)).Get() << ">: From index "
189 << nr - i - 1 << " to " << nr - 1 << ".\n"
190 " Resource category/name: " << category << '/' << name << "." )
191 }
192 }
193 #endif
194
195 }
196
197 template<typename TEnum, typename TEnableIf>
198 inline
200 {
201 static_assert( T_Resourced<TEnum>::value,
202 "No specialization for T_Resourced<TEnum> given. Method not applicable." );
203
207 innerDelim, outerDelim );
208 }
209
210 template<typename TEnum, typename TEnableIf>
211 inline
212 void EnumRecords<TEnum, TEnableIf>::Bootstrap( lang::Camp& module,
213 const NString& name,
214 character innerDelim,
215 character outerDelim )
216 {
217 Bootstrap( module.GetResourcePool(), module.ResourceCategory, name, innerDelim, outerDelim );
218 }
219#endif // ALIB_CAMP
220
221#endif // !defined(ALIB_DOX)
222
223}} // namespace [alib::enums]
224
225
226#endif // HPP_ALIB_ENUMS_RECORDBOOTSTRAP
ALIB_FORCE_INLINE T * Emplace(TArgs &&... args)
static TDerivedClass & GetSingleton()
Definition singleton.hpp:61
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:190
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:715
#define ALIB_ERROR(...)
Definition alib.hpp:980
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:644
#define ALIB_DBG(...)
Definition alib.hpp:457
ALIB_API void setEnumRecord(const std::type_info &rtti, integer integral, const void *record)
Definition records.cpp:51
constexpr std::underlying_type< TEnum >::type UnderlyingIntegral(TEnum element) noexcept(true)
ALIB_API void Bootstrap()
@ Get
Denotes to search data.
MonoAllocator GlobalAllocator(8 *1024)
Definition alib.cpp:57
NLocalString< 128 > NString128
Type alias name for TLocalString<nchar,128> .
NLocalString< 64 > NString64
Type alias name for TLocalString<nchar,64> .
strings::TString< nchar > NString
Type alias in namespace alib.
constexpr NString NullNString()
Definition string.hpp:2510
characters::character character
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
static ALIB_API void Get(String &result, bool isLastField=false)
static ALIB_API void assertEndOfInput()
static ALIB_API void OuterDelim()
static ALIB_API Substring Input
static ALIB_API void Initialize(const String &input, character innerDelim, character outerDelim, const NString &resourceCategory, const NString &resourceName)
static void Bootstrap(TEnum element, TArgs &&... args) noexcept
static constexpr ResourcePool * Pool()
static constexpr NString Category()
static constexpr NString Name()