8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
19 module ALib.Variables;
20 import ALib.EnumRecords;
21 import ALib.EnumRecords.Bootstrap;
24 import ALib.Resources;
26 import ALib.Variables.Plugins;
30 import ALib.Camp.Base;
72 Entry& entry= node.data;
102 std::array<Token, 10> tokenBuf;
105 for (
size_t i = 0; i < tokenBuf.size(); i+= 2 )
127 "{} remaining registered listeners when destruction configuration.",
listeners.size() )
135 const String& variableName,
136 const String& pathPrefixGiven,
137 const String& pathSubstring ) {
140 ALIB_ASSERT_ERROR( variable==
nullptr || &variable->
AsCursor().Tree() ==
this ,
"VARIABLES",
"Given variable does not belong to this configuration.")
141 ALIB_ASSERT_ERROR( subTree ==
nullptr || subTree->IsValid() ,
"VARIABLES",
"Invalid cursor given." )
142 ALIB_ASSERT_ERROR( subTree ==
nullptr || &subTree ->Tree() ==
this ,
"VARIABLES",
"Given cursor does not belong to this configuration.")
153 variable ? variable->
AsCursor().Export() : ConstCursorHandle(),
154 subTree ? subTree-> Export() : ConstCursorHandle(),
158 listeners.back().variableName << variableName;
159 listeners.back().pathPrefix << pathPrefix;
160 listeners.back().pathSubstring<< pathSubstring;
167 if( it->listener == listener
168 && it->event == event
169 && it->variable == ( variable ? variable->
AsCursor().Export() : ConstCursorHandle() )
170 && it->subTree == ( subTree ? subTree ->Export() : ConstCursorHandle() )
171 && it->variableName .Equals( variableName )
172 && it->pathPrefix .Equals( pathPrefix )
173 && it->pathSubstring.Equals( pathSubstring ) )
179 ALIB_WARNING(
"VARIABLES",
"Listener with matching set of parameters not found with "
192 if( it->listener == listener ) {
204 const String& variablePathGiven,
207 const String* variablePath= &variablePathGiven;
209 if( event == it->event ) {
212 && ( it->variableName .IsNotEmpty()
213 || it->pathPrefix .IsNotEmpty()
214 || it->pathSubstring.IsNotEmpty() ) )
216 variablePathBuffer << variable;
217 variablePath= &variablePathBuffer;
220 if( ( it->variable .IsValid() && ( it->variable == variable.
AsCursor().Export() ) )
221 || ( it->subTree .IsValid() && ( variable.
AsCursor().Distance(
ImportCursor(it->subTree) ) >= 0 ) )
222 || ( it->variableName .IsNotEmpty() && it->variableName.Equals(variable.
AsCursor().Name()) )
223 || ( it->pathPrefix .IsNotEmpty() && variablePath->
StartsWith(it->pathPrefix) )
224 || ( it->pathSubstring.IsNotEmpty() && variablePath->
IndexOf(it->pathSubstring) >= 0 )
227 it->listener->Notify( variable,
237 cursor.GoToCreateChildIfNotExistent(
A_CHAR(
"$PRESETS"));
241 if( cursor.GoTo(name).IsNotEmpty() )
244 auto& entry= *cursor;
245 if( entry.priority > priority )
249 entry.meta->destruct( entry.data,
Pool );
250 Pool().Free( entry.data, entry.meta->size() );
253 entry.priority= Priority::NONE;
257 if( !cursor.HasChildren() )
265 cursor.GoToCreatedPathIfNotExistent(name);
269 auto& entry= *cursor;
270 if( entry.data ==
nullptr ) {
273 "Variable type 'S' not registered. This usually cannot happen." )
274 auto* meta= entry.meta= *it;
278 meta->construct( cursor->data,
Pool );
279 entry.priority= priority;
282 if( entry.priority <= priority ) {
283 entry.priority = priority;
284 entry.declaration=
reinterpret_cast<const Declaration*
>( escaper );
292 const Box& replacements ) {
296 const Box* replacementPtr;
303 const auto* boxes= replacements.
Unbox<
Boxes*>();
304 replacementPtr = boxes->
data();
305 qtyReplacements= boxes->Size();
309 replacementPtr = boxes->
data();
310 qtyReplacements= boxes->Size();
314 replacementPtr = boxes->
data();
315 qtyReplacements= boxes->Size();
317 replacementPtr = &replacements;
325 for (
integer replCnt= 0; replCnt< qtyReplacements ; ++replCnt )
326 if ( !replacementPtr->
IsType<
void>() ) {
327 String64 search(
"%"); search.
_( replCnt + 1 );
328 replace.
Reset( *( replacementPtr + replCnt) );
340 String1K bufComments;
ALIB_DBG( bufComments .DbgDisableBufferReplacementWarning() );
346 for (
integer replCnt= 0; replCnt< qtyReplacements ; ++replCnt )
347 if ( !replacementPtr->
IsType<
void>() ) {
348 String64 search(
"%"); search.
_( replCnt + 1 );
349 replace.
Reset( *( replacementPtr + replCnt) );
372 return {
false, int8_t(-1)};
375 if ( it.first .Match(value) )
return {
false, index};
376 if ( it.second.Match(value) )
return {true , index};
379 return {
false, int8_t(-1)};
388 for( int8_t index=0 ; index < idxRequested && it !=
BooleanTokens.end() ; ++index )
395 (!value ? it->first : it->second).GetExportName( dest );
400DOX_MARKER( [DOX_VARIABLES_DELETE_SAMPLE] )
405if( cs.GoTo(path).IsNotEmpty() )
413DOX_MARKER( [DOX_VARIABLES_DELETE_SAMPLE] )
436 TAString<nchar, lang::HeapAllocator>& target,
const variables::Variable& variable ) {
437#if ALIB_CHARACTERS_WIDE
442 variable.Name(target);
449#if ALIB_CHARACTERS_WIDE
450 variable.Name(target);
Placeholder data
The data that we encapsulate.
TElementType * UnboxArray() const
integer UnboxLength() const
constexpr CharacterType Separator() const noexcept
TCursor< true > ConstCursor
Cursor ImportCursor(CursorHandle handle)
void DbgSetDCSName(const char *name) const
AllocatorType & GetAllocator() noexcept
StringTree(AllocatorType &allocator, CharacterType pathSeparator)
void InsertPlugin(ConfigurationPlugin *plugin, lang::Responsibility responsibility=lang::Responsibility::KeepWithSender)
void free(void *mem, size_t size)
ALIB_DLL integer SearchAndReplace(TChar needle, TChar replacement, integer startIdx=0, integer endIdx=strings::MAX_LEN)
TAString & _(const TAppendable &src)
void DbgDisableBufferReplacementWarning()
constexpr bool IsEmpty() const
TChar CharAtStart() const
integer IndexOf(TChar needle, integer startIdx=0) const
constexpr bool IsNotNull() const
void Allocate(TAllocator &allocator, const TString< TChar > ©)
TString< TChar > Substring(integer regionStart, integer regionLength=MAX_LEN) const
constexpr bool IsNull() const
bool StartsWith(const TString &needle) const
TSubstring & Trim(const TCString< TChar > &whiteSpaces=CStringConstantsTraits< TChar >::DefaultWhitespaces())
ALIB_DLL bool DeletePath(const String &path)
ALIB_DLL void notifyListeners(int event, const Variable &variable, const String &variablePath, Priority previousPriority)
ALIB_DLL AString & WriteBooleanToken(bool value, int8_t index, AString &dest)
ConfigurationPlugin * cliPlugin
A default plugin created and inserted with construction.
ListMA< std::pair< Token, Token >, Recycling::None > BooleanTokens
TypesHashTable types
A hashtable for the registered types. Key is the type name, value is the VMeta singleton.
ALIB_DLL const Declaration * StoreDeclaration(const Declaration *orig, const Box &replacements)
RDHashTable replacementDeclarations
ALIB_DLL int MonitorStop(ConfigurationListener *listener)
ConfigurationPlugin * environmentPlugin
A default plugin created and inserted with construction.
friend class Variable
Type alias in namespace alib.
ListMA< ListenerRecord > listeners
The list of registered listeners.
ALIB_DLL ~Configuration()
Destructor.
ALIB_DLL void presetImportString(const String &name, const String &value, const StringEscaper *escaper, Priority priority)
ALIB_DLL Configuration(MonoAllocator &allocator, lang::CreateDefaults createDefaults=lang::CreateDefaults::Yes)
ALIB_DLL std::pair< bool, int8_t > ParseBooleanToken(const String &src)
ALIB_DLL void registerListener(ConfigurationListener *listener, lang::ContainerOp insertOrRemove, int event, const Variable *variable, const StringTree::Cursor *subTree, const String &variableName, const String &pathPrefix, const String &pathSubstring)
VMeta * meta
The virtual handler instance for this variable.
VDATA * data
The list hook of values.
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
#define ALIB_WARNING(domain,...)
#define ALIB_ASSERT_WARNING(cond, domain,...)
#define ALIB_ASSERT_ERROR(cond, domain,...)
ContainerOp
Denotes standard container operations.
@ Insert
Denotes insertions.
CreateDefaults
Denotes whether default entities should be created or not.
@ Yes
Create default values.
void LoadResourcedTokens(camp::Camp &module, const NString &resourceName, strings::util::Token *target, int dbgSizeVerifier, character outerSeparator=',', character innerSeparator=' ')
containers::detail::StringTreeBase< MonoAllocator, Entry, ConfigNodeHandler, Recycling::Private > TTree
A shortcut to the base class of the base class of class Configuration.
strings::util::StringEscaper StringEscaper
Type alias in namespace alib.
strings::util::Token Token
Type alias in namespace alib.
LocalString< 256 > String256
Type alias name for TLocalString<character,256>.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
camp::Basecamp BASECAMP
The singleton instance of ALib Camp class Basecamp.
LocalString< 128 > String128
Type alias name for TLocalString<character,128>.
LocalString< 64 > String64
Type alias name for TLocalString<character,64>.
boxing::TBoxes< lang::HeapAllocator > Boxes
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
boxing::TBoxes< PoolAllocator > BoxesPA
Type alias in namespace alib.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
boxing::Box Box
Type alias in namespace alib.
LocalString< 1024 > String1K
Type alias name for TLocalString<character,1024>.
boxing::TBoxes< MonoAllocator > BoxesMA
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
strings::TAString< character, PoolAllocator > AStringPA
Type alias in namespace alib.
strings::TSubstring< character > Substring
Type alias in namespace alib.
typename ConfigNodeHandler::CharacterType CharacterType
String EnumElementName
The name of the enum element.
static ALIB_DLL void Get(String &result, bool isLastField=false)
void operator()(TAString< TChar > &target, const TAppendable &src)
Event
The type of change that imposes the notification of a listener.
Record used to manage registered listeners.
ALIB_DLL void Parse()
Implementation of EnumRecordPrototype::Parse.
int Priority
The precedence of an operator in respect to other binary operators.
static ALIB_DLL void FreeNode(TTree::Node &node, TTree &tree)