10# if !defined (HPP_ALIB_CONFIG_CONFIGURATION)
13# if !defined(HPP_ALIB_CONFIG_CONFIG)
17# if !defined(HPP_ALIB_CAMP_MESSAGE_REPORT)
21# if !defined(HPP_ALIB_MONOMEM_HASHSET)
25# if !defined (HPP_ALIB_LANG_CAMP_INLINES)
65 InMemoryPlugin* defaultPlugin= GetPluginTypeSafe<InMemoryPlugin>( Priorities::DefaultValues );
67 "Utility method FetchFromDefault used without default plugin in place." )
71 for(
auto& section : defaultPlugin->
sections )
76 for(
auto entryIt= section.entries.begin() ; entryIt != section.entries.end() ; ++entryIt )
78 if( !dest.
Load( variable.
Declare( section.name, entryIt->Name() ),
true ) )
80 defaultPlugin->
Load ( variable );
81 dest.
Store( variable );
109 if ( variable.
Priority() == Priorities::NONE
126 if( externalizedValue.
IsNull() )
130 ALIB_ERROR(
"CONFIG",
"Trying to store an undefined variable." )
131 return Priorities::NONE;
134 if ( variable.
Size() > 1 && variable.
Delim() ==
'\0' )
136 ALIB_ERROR(
"CONFIG",
"Trying to store variable {!Q} which has multiple values "
137 "set but no delimiter defined.", variable.
Fullname() )
138 return Priorities::NONE;
146 if ( variable.
Priority() <= Priorities::NONE )
150 if ( ppp.plugin->Load( variable,
true ) )
156 if( variable.
Priority() == Priorities::ProtectedValues )
159 return Priorities::NONE;
164 if ( variable.
Priority() == Priorities::NONE )
169 if ( ppp.priority <= variable.
Priority()
170 && ppp.plugin->Store( variable, externalizedValue ) )
177 return Priorities::NONE;
188 "Utility method StoreDefault used without default plugin in place." )
211 "Utility method Protect used without default plugin in place." )
213 variable.
SetPriority( Priorities::ProtectedValues );
221 "Utility method LoadFromString used without default plugin in place." )
223 return variable.
Size();
236 return Priorities::NONE;
242 if ( ppp.plugin->Load( variable ) )
244 priority= ppp.priority;
249 if ( !substitute || priority == Priorities::NONE )
254 for (
int valueNo= 0; valueNo < variable.
Size(); ++valueNo )
257 int maxReplacements = 50;
266 searchStartIdx= repStart;
279 varLen= idx - varStart;
280 repLen= idx - repStart;
287 ALIB_WARNING(
"CONFIG",
"End of substitution variable not found (while start was found). "
288 "Variable name: {} Value: {!Q}.",
293 varLen= idx - varStart;
309 if (catSeparatorIdx >= 0 )
311 replVarCategory= replVarName.
Substring<
false>( 0, catSeparatorIdx );
312 replVarName = replVarName.
Substring ( catSeparatorIdx + 1);
335 valBuffer.
Reset(value);
339 valBuffer.
Delete<
false>( repStart, repLen );
344 while( --maxReplacements );
347 if( maxReplacements <= 0 )
349 ALIB_WARNING(
"CONFIG",
"Too many substitutions in variable {!Q}. "
350 "Probably a recursive variable definition?", variable.
Fullname() )
378 : config (configuration)
379 , sectionName (pSectionName)
381 , variablesFound(&allocator)
386 virtual ~IteratorImpl()
override
392 void ResetToSection(
const String& pSectionName )
override
394 sectionName= pSectionName;
395 variablesFound.
Reset();
407 virtual bool Next()
override
412 while( pluginIt ==
nullptr )
420 pluginIt= config.
GetPlugin( nextPlugin++ )->GetIterator( sectionName );
424 if( !pluginIt->
Next(Actual) )
436 Actual.SetConfig( &config );
446 return new IteratorImpl( *
this, sectionName );
virtual bool Next(Variable &variable)=0
XTernalizer * StringConverter
virtual bool Store(Variable &variable)
virtual ALIB_API bool Load(Variable &variable, bool searchOnly=false)=0
ALIB_API Configuration(lang::CreateDefaults addPlugins)
ALIB_API integer LoadFromString(Variable &variable, const String &externalizedValue)
CString SubstitutionVariableDelimiters
ALIB_API Priorities Load(Variable &variable)
std::vector< String > TrueValues
String SubstitutionVariableEnd
String SubstitutionVariableStart
ALIB_API Priorities Store(Variable &variable, const String &externalizedValue=nullptr)
ALIB_API bool IsTrue(const String &value)
ALIB_API Iterator * GetIterator(const String §ionName)
ALIB_API Priorities Protect(Variable &variable, const String &externalizedValue=nullptr)
ALIB_API Priorities StoreDefault(Variable &variable, const String &externalizedValue=nullptr)
ALIB_API int FetchFromDefault(ConfigurationPlugin &dest, const String §ion=NullString())
ALIB_API Priorities loadImpl(Variable &variable, bool substitute)
virtual ALIB_API bool Load(Variable &variable, bool searchOnly=false) override
const String & DefaultValue() const
ALIB_API const String & Fullname()
void SetPriority(Priorities priority)
ALIB_API void ReplaceValue(int idx, const String &replacement)
ALIB_API Variable & Declare(const VariableDecl &declaration, const Box &replacements)
const String & Name() const
const String & GetString(int idx=0)
Variable & ClearValues(int startIdx=0)
Priorities Priority() const
ALIB_API Variable & Reset(lang::CurrentData nameAndCategory=lang::CurrentData::Clear)
void SetConfig(Configuration *config)
virtual ALIB_API void LoadFromString(Variable &variable, const String &src)
const String & GetResource(const NString &name)
void InsertPlugin(TPlugin *plugin, TPriorities priority, lang::Responsibility responsibility=lang::Responsibility::KeepWithSender)
TPlugin * GetPlugin(integer number)
std::vector< Slot > plugins
InsertIfNotExistent(const KeyType &key, const MappedType &mapped)
ALIB_API void Reset(const Snapshot &snapshot=Snapshot())
TAString & Delete(integer regionStart, integer regionLength=MAX_LEN)
TAString & ReplaceSubstring(const TString< TChar > &src, integer regionStart, integer regionLength)
void DbgDisableBufferReplacementWarning()
constexpr bool IsNull() const
integer IndexOf(TChar needle, integer startIdx=0) const
constexpr bool IsEmpty() const
constexpr bool IsNotEmpty() const
constexpr integer Length() const
constexpr bool IsNotNull() const
integer IndexOfAny(const TString &needles, integer startIdx=0) const
TString< TChar > Substring(integer regionStart, integer regionLength=MAX_LEN) const
bool Equals(const TString< TChar > &rhs) const
#define ALIB_WARNING(...)
#define ALIB_ASSERT_ERROR(cond,...)
@ Include
Chooses inclusion.
@ Yes
Create default values.
@ Transfer
Transfers responsibility to the receiving party.
constexpr String NullString()
strings::TString< character > String
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
config::InMemoryPlugin InMemoryPlugin
Type alias in namespace alib.