ALib C++ Library
Library Version: 2412 R0
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#pragma once
12
14
15#include "alib/enums/records.hpp"
18#if ALIB_CAMP
21#endif
22#if ALIB_MONOMEM
24#endif
25
26#include <initializer_list>
27
29
30namespace alib { namespace enums {
31
32#if !DOXYGEN
33
34template<typename TEnum, typename TEnableIf>
35template <typename... TArgs>
36inline
37void EnumRecords<TEnum, TEnableIf>::Bootstrap( TEnum element, TArgs&&... args) noexcept
38{
40 auto** lastP = records.getPointerToLast();
41 #if ALIB_MONOMEM
43 #else
44 *lastP= HeapAllocator()()
45 #endif
46 .New<typename detail::EnumRecordHook<TEnum>::Node>(element, std::forward<TArgs>(args)... );
47
48 detail::setEnumRecord( typeid(TEnum), integer(element), &(*lastP)->record );
49 (*lastP)->next= nullptr;
50}
51
52template<typename TEnum, typename TEnableIf>
53inline
54void EnumRecords<TEnum, TEnableIf>::Bootstrap( std::initializer_list<EnumRecords::Initializer> definitions )
55{
57 auto* table = definitions.begin();
59 auto** lastP = records.getPointerToLast();
60 for( size_t i= 0; i!= definitions.size(); ++i)
61 {
62 #if ALIB_MONOMEM
64 #else
65 *lastP= HeapAllocator()()
66 #endif
67 .New<typename detail::EnumRecordHook<TEnum>::Node>(table[i].element, table[i].record );
68
69 detail::setEnumRecord( typeid(TEnum), integer(table[i].element), &(*lastP)->record );
70 lastP= &(*lastP)->next;
71 }
72
73 (*lastP)= nullptr;
75}
76
77 template<typename TEnum, typename TEnableIf>
78 inline
80 character innerDelim,
81 character outerDelim )
82 {
83 EnumRecordParser::Initialize(input, innerDelim, outerDelim, NULL_NSTRING, NULL_NSTRING );
84
86 auto** lastP = records.getPointerToLast();
87
88 for(;;)
89 {
90 #if ALIB_MONOMEM
91 auto* element= (*lastP= monomem::GLOBAL_ALLOCATOR()
92 #else
93 auto* element= (*lastP= HeapAllocator()()
94 #endif
95 .New<typename detail::EnumRecordHook<TEnum>::Node>() );
96 EnumRecordParser::Get( element->integral );
97 element->record.Parse();
98
99 detail::setEnumRecord( typeid(TEnum), integer(element->integral), &element->record );
100
101 // next?
102 lastP= &element->next;
103 if( EnumRecordParser::Input.IsEmpty() )
104 break;
106 }
108 (*lastP)= nullptr;
109 }
110
111#if ALIB_CAMP
112 template<typename TEnum, typename TEnableIf>
113 inline
114 void EnumRecords<TEnum, TEnableIf>::Bootstrap( lang::resources::ResourcePool& pool,
115 const NString& category,
116 const NString& name,
117 character innerDelim,
118 character outerDelim )
119 {
120 // resources given in the standard, non-indexed way?
121 String input= pool.Get( category, name ALIB_DBG(, false) );
122 if( input.IsNotNull() )
123 {
124 // Note:
125 // The parser is initialized here already. The "inner" call to Bootstrap() will not have
126 // the resource information otherwise.
127 // Double initialization is checked inside the parser's initialize method.
128 // (A little crude but OK!)
129 EnumRecordParser::Initialize(input, innerDelim, outerDelim, category, name );
130 Bootstrap( input, innerDelim, outerDelim );
131 return;
132 }
133
134 // resources given as name0, name1, name2...
135 NString64 nameNr( name);
136 int nr= 0;
138 auto** lastP = records.getPointerToLast();
139 while( (input= pool.Get( category, nameNr.Reset( name)._(nr) ALIB_DBG(, false))).IsNotNull()
140 || nr== 0 )
141 {
142 EnumRecordParser::Initialize(input, innerDelim, outerDelim, category, nameNr );
143
144 auto* element= (*lastP= monomem::GLOBAL_ALLOCATOR().New<typename detail::EnumRecordHook<TEnum>::Node>());
145
146 EnumRecordParser::Get( element->integral );
147 element->record.Parse();
148
149 detail::setEnumRecord( typeid(TEnum), integer(element->integral), &element->record );
150
152 // next
153 lastP= &element->next;
154 ++nr;
155 }
156 (*lastP)= nullptr;
157
158 // check if there are more coming (a gap in numbered definition)
159 #if ALIB_DEBUG
160 for( int i= 0 ; i < 35 ; ++i )
161 {
162 ++nr;
163 if( pool.Get( category, nameNr.Reset( name)._( nr) ALIB_DBG(, false)).IsNotNull() )
164 {
165 ALIB_ERROR( "ENUMS", NString128()
166 << "Detected a \"gap\" in numbering of enum records for type <"
167 << lang::DbgTypeDemangler( typeid(TEnum)).Get() << ">: From index "
168 << nr - i - 1 << " to " << nr - 1 << ".\n"
169 " Resource category/name: " << category << '/' << name << "." )
170 }
171 }
172 #endif
173
174 }
175
176 template<typename TEnum, typename TEnableIf>
177 inline
179 {
180 static_assert( T_Resourced<TEnum>::value,
181 "No specialization for T_Resourced<TEnum> given. Method not applicable." );
182
186 innerDelim, outerDelim );
187 }
188
189 template<typename TEnum, typename TEnableIf>
190 inline
191 void EnumRecords<TEnum, TEnableIf>::Bootstrap( lang::Camp& module,
192 const NString& name,
193 character innerDelim,
194 character outerDelim )
195 {
196 Bootstrap( module.GetResourcePool(), module.ResourceCategory, name, innerDelim, outerDelim );
197 }
198#endif // ALIB_CAMP
199
200#endif // !DOXYGEN
201
202}} // namespace [alib::enums]
203
205
206#endif // HPP_ALIB_ENUMS_RECORDBOOTSTRAP
207
static TDerivedClass & GetSingleton()
Definition singleton.hpp:59
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:223
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:849
#define ALIB_ERROR(...)
Definition alib.hpp:1267
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:760
#define ALIB_DBG(...)
Definition alib.hpp:390
ALIB_API void setEnumRecord(const std::type_info &rtti, integer integral, const void *record)
Definition records.cpp:50
void Bootstrap()
Definition records.cpp:306
constexpr bool IsNotNull(const T &t)
Definition alib.hpp:1054
@ Get
Denotes to search data.
ALIB_API MonoAllocator GLOBAL_ALLOCATOR
Definition alib.cpp:69
NLocalString< 128 > NString128
Type alias name for TLocalString<nchar,128>.
constexpr NString NULL_NSTRING
A nulled string of the narrow character type.
Definition string.hpp:2558
NLocalString< 64 > NString64
Type alias name for TLocalString<nchar,64>.
strings::TString< nchar > NString
Type alias in namespace alib.
characters::character character
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
lang::HeapAllocator HeapAllocator
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:273
static ALIB_API void Get(String &result, bool isLastField=false)
static ALIB_API void assertEndOfInput()
Asserts that the Input is empty.
static ALIB_API void OuterDelim()
static ALIB_API Substring Input
The remaining input string.
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()