7 if( substitutionVariableStart.
IsEmpty() )
14 int maxReplacements = 50;
18 integer repStart= orig.
IndexOf( substitutionVariableStart, searchStartIdx );
21 buf << orig.
Substring( searchStartIdx, repStart - searchStartIdx );
22 searchStartIdx = repStart;
23 integer varStart= repStart + substitutionVariableStart.
Length();
28 if ( substitutionVariableEnd.
IsEmpty() ) {
33 varLen= idx - varStart;
39 ALIB_WARNING(
"VARIABLES",
"End of substitution variable not found "
40 "(while start was found). Variable name: ",
Name(namebuf) )
44 varLen= idx - varStart;
45 searchStartIdx= idx + substitutionVariableEnd.
Length();
51 buf << substitutionVariableStart;
62 if( replVar.
Try(replVarName) )
63 replVar.
Export( buf, escaper );
70 replVar.
Export( buf, escaper );
76 while( --maxReplacements );
78 if( maxReplacements < 50) {
88 auto it= Tree<Configuration>().types.Find(typeName);
90 "No Meta-Handler found for given variable type \"{}\".\n"
91 "Probably the type was not registered during bootstrap.\n"
92 "Use the macro ALIB_VARIABLES_REGISTER_TYPE in bootstrap phase "
93 "'PrepareConfig' to register your custom types.", typeName)
94 auto* meta= Cursor::Value().meta= *it;
98 meta->construct(Cursor::Value().data, Tree<Configuration>().Pool );
99 Cursor::Value().priority= Priority::NONE;
114 for (
int i = 0; i < Tree<Configuration>().CountPlugins(); ++i) {
115 auto& plugin= *Tree<Configuration>().GetPlugin(i);
116 auto plPrio= plugin.GetPriority();
117 if( Cursor::Value().priority <= plPrio && plugin.Get(varName, buf) ) {
119 Cursor::Value().priority= plPrio;
120 Cursor::Value().meta->imPort( Cursor::Value().data,
GetConfiguration(), plugin.GetEscaper(),
121 substitute(buf, substBuf, &plugin.GetEscaper()) );
125 auto cursor= Tree<Configuration>().Root();
126 if( cursor.GoToChild(
A_CHAR(
"$PRESETS"))
127 && cursor.GoTo(varName).IsEmpty()
128 && cursor->meta !=
nullptr
129 && cursor->priority > Value().priority )
132 "Internal error. This must never happen. ")
134 auto* escaper= cursor->declaration ?
reinterpret_cast<const StringEscaper*
>( cursor->declaration )
136 Cursor::Value().priority= cursor->priority;
138 Cursor::Value().meta->imPort( Cursor::Value().data,
146 if( Cursor::Value().priority <= Priority::DefaultValues && defaultValue.
IsNotEmpty() ) {
149 Cursor::Value().priority= Priority::DefaultValues;
150 Cursor::Value().meta->imPort( Cursor::Value().data,
GetConfiguration(), escaper,
151 substitute( defaultValue, substBuf, &escaper) );
164 const String& defaultValue ) {
166 "Invalid Variable. Not associated with a Configuration. Probably a default constructed "
167 "instance.\nCopy or move a valid Variable object before usage.")
170 "Variable name with placeholder(s) given: ", name )
174 if( GoToCreatedPathIfNotExistent(name) == 0
175 && Cursor::Value().meta !=
nullptr )
178 auto it= Tree<Configuration>().types.Find(typeName);
179 if( it == Tree<Configuration>().types.end() ) {
181 "No Meta-Handler found for given variable type \"{}\".\n"
182 "Probably the type was not registered during bootstrap.\n"
183 "Use the macro ALIB_VARIABLES_REGISTER_TYPE in bootstrap phase "
184 "'PrepareConfig' to register your custom types.", typeName )
186 if( *it != Cursor::Value().meta ) {
188 "Variable \"{}\" redeclared with a different typename.\n"
189 "Previous typename: ", Cursor::Value().meta->typeName(), typeName )
196 Cursor::Value().declaration=
nullptr;
197 create( typeName, defaultValue );
203 "Invalid Variable. Not associated with a Configuration.\n"
204 "Probably a default constructed instance.\n"
205 "Copy or move a valid Variable object before usage.")
208 "Variable descriptor \"{}\" with unset placeholders given.", decl->
Name() )
212 if( 0 == GoToCreatedPathIfNotExistent( decl->
Name() )) {
215 "Variable \"{}\" redeclared with different declaration record pointer.\n"
216 "Declaration records should be singletons and their life-time needs to survive\n"
217 "that of the variable. New record will be ignored.", decl->
Name() )
219 auto it= Tree<Configuration>().types.Find(decl->
typeName);
220 if( it == Tree<Configuration>().types.end() ) {
222 "No Meta-Handler found for given variable type \"{}\".\n"
223 "Probably the type was not registered during bootstrap.\n"
224 "Use the macro ALIB_VARIABLES_REGISTER_TYPE in bootstrap phase "
225 "'PrepareConfig' to register your custom types.",
GetDeclaration()->typeName)
232 Cursor::Value().declaration= decl;
238 if( Cursor::Value().priority > requestedPriority )
240 auto prevPriority= Cursor::Value().priority;
241 Cursor::Value().priority= requestedPriority ;
255 Cursor::node=
nullptr;
260 "Invalid Variable. Not associated with a Configuration. Probably a default constructed "
261 "instance.\nCopy or move a valid Variable object before usage.")
264 if( Cursor::GoToRoot().GoTo( name ).IsEmpty()
269 auto cursor= Tree<Configuration>().Root();
270 if( cursor.GoToChild(
A_CHAR(
"$PRESETS")) && cursor.GoTo(name).IsEmpty() ) {
272 "Internal error. This must never happen.")
274 if( Cursor::Value().priority < cursor->priority) {
276 auto* escaper= cursor->declaration ?
reinterpret_cast<const StringEscaper*
>( cursor->declaration )
279 Cursor::Value().priority= cursor->priority;
280 Cursor::Value().meta->imPort( Cursor::Value().data,
294 || Cursor::Value().declaration == decl,
"CONFIG/VARDECL",
295 "Variable \"{}\" redeclared with different declaration record pointer.\n"
296 "Declaration records should be singletons and their life-time needs to survive\n"
297 "that of the variable. New record will be ignored.", decl->
Name() )
299 if( Cursor::Value().declaration==
nullptr)
300 Cursor::Value().declaration= decl;
309 "Tried to import nulled string for variable \"{}\"",
this )
#define ALIB_WARNING(domain,...)
#define ALIB_ASSERT_WARNING(cond, domain,...)
#define ALIB_ERROR(domain,...)
#define ALIB_ASSERT_ERROR(cond, domain,...)
constexpr integer Length() const
constexpr bool IsEmpty() const
integer IndexOf(TChar needle, integer startIdx=0) const
constexpr bool IsNotNull() const
constexpr bool IsNotEmpty() const
integer IndexOfAny(const TString &needles, integer startIdx=0) const
TString< TChar > Substring(integer regionStart, integer regionLength=MAX_LEN) const
String SubstitutionVariableStart
CString SubstitutionVariableDelimiters
String SubstitutionVariableEnd
const String & DefaultValue() const
const String & TypeName() const
const String & Name() const
bool Define(Priority requestedPriority=Priority::Standard)
void Import(const String &src, Priority priority, const StringEscaper *escaper=nullptr)
AString & Export(AString &dest, const StringEscaper *escaper=nullptr) const
AString & Name(AString &target) const
void create(const String &typeName, const String &defaultValue)
Priority GetPriority() const
bool Try(const String &name)
Variable & Declare(const String &name, const String &typeName, const String &defaultValue=NULL_STRING)
const Declaration * GetDeclaration() const
Configuration & GetConfiguration() const
const String & substitute(const String &importString, AString &buf, const StringEscaper *escaper)
@ Include
Chooses inclusion.
lang::integer integer
Type alias in namespace #"%alib".
strings::util::StringEscaper StringEscaper
Type alias in namespace #"%alib".
strings::TString< character > String
Type alias in namespace #"%alib".
strings::TSubstring< character > Substring
Type alias in namespace #"%alib".
LocalString< 256 > String256
Type alias name for #"TLocalString;TLocalString<character,256>".
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace #"%alib".
LocalString< 512 > String512
Type alias name for #"TLocalString;TLocalString<character,512>".
@ Definition
A variable was defined or re-defined with the same or a higher priority.
@ Creation
A variable was declared for the first time.