8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Configuration MACRO ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
19 module ALib.Variables.IniFile;
20 import ALib.Strings.StdIOStream;
22 import ALib.Exceptions;
25 import ALib.Variables;
28 import ALib.Format.Paragraphs;
50 ALIB_ERROR(
"VARIABLES",
"No INI-file loaded when trying to search data." )
57 String entryName = (sectionSeparator != -1) ? path.
Substring<
NC>(sectionSeparator + 1, path.
Length() - sectionSeparator - 1) : path;
60 return iniFile->SearchEntry(sectionName, entryName);
66 "Variable belongs to different configuration: ", var )
75 ALIB_ERROR(
"VARIABLES",
"No INI-file loaded when trying to import data." )
79 auto* section=
iniFile->SearchSection( sectionName );
80 if(section ==
nullptr) {
81 ALIB_WARNING(
"VARIABLES",
"Section named \"{}\" not found in INI-file.", sectionName )
88 varName.
Reset(sectionName);
93 for (
auto& entry : section->Entries ) {
95 varName << entry.Name;
114 for (
auto& entry : section.
Entries ) {
117 varName << entry.Name;
120 if( var.
Try(varName) ) {
135 ALIB_ERROR(
"VARIABLES",
"No INI-file loaded when trying to import data." )
139 auto* section=
iniFile->SearchSection( sectionName );
140 if(section ==
nullptr) {
141 ALIB_WARNING(
"VARIABLES",
"Section name \"{}\" not found in INI-file.", sectionName )
150 ALIB_ERROR(
"VARIABLES",
"No INI-file loaded when trying to import data." )
169 ALIB_ERROR(
"VARIABLES",
"No INI-file loaded when trying to export data." )
179 String entryName = (sectionSeparator != -1) ? name.
Substring<
NC>(sectionSeparator + 1, name.
Length() - sectionSeparator - 1) : name;
182 auto handle=
iniFile->SearchEntry(sectionName, entryName);
183 auto* entry= handle.EntryPointer;
186 if( !entry ->WriteBack
187 && !handle.SectionPointer->WriteBack )
191 auto sectionIt=
iniFile->SearchOrCreateSection( sectionName );
192 entry =
iniFile->CreateEntry( sectionIt.first, entryName );
194 entry->WriteBack=
true;
204 if(entry->Comments.IsNull()) {
206 if( decl && decl->Comments().IsNotEmpty() )
215 ALIB_ERROR(
"VARIABLES",
"No INI-file loaded when trying to export data." )
221 stit.
SetMaxDepth( directChildrenOnly ? 1 : (std::numeric_limits<unsigned>::max)() );
224 if ( stit.
Node().IsRoot()) {
228 if( stit.
Node().Name().Equals(
A_CHAR(
"$PRESETS")) ) {
245 const NString& resourceCategory,
246 const NString& resourceNamePrefix ) {
248 ALIB_ERROR(
"VARIABLES",
"No INI-file loaded when trying to import data." )
254 for(
auto& section :
iniFile->Sections )
255 if( section.Comments.IsNull() ) {
256 auto& comment= resourcePool.
Get( resourceCategory,
257 NString128() << resourceNamePrefix << section.Name
259 if( comment.IsNull() )
278 "Variable \"{}\" to be marked as 'writeback' not found.", path )
280 if( handle.EntryPointer && handle.EntryPointer->RawValue.IsEmpty() ) {
281 handle.EntryPointer->WriteBack=
true;
290 "Variable belongs to different configuration: ", var)
#define ALIB_WARNING(domain,...)
#define ALIB_ASSERT_WARNING(cond, domain,...)
#define ALIB_ERROR(domain,...)
#define ALIB_LOCK_RECURSIVE_WITH(lock)
#define ALIB_ASSERT_ERROR(cond, domain,...)
void SetMaxDepth(unsigned int newMaxDepth=(std::numeric_limits< unsigned >::max)())
void Initialize(CursorType startNode, lang::Inclusion includeStartNode)
void SetPathGeneration(lang::Switch pathGeneration)
constexpr CharacterType Separator() const noexcept
virtual const String & Get(const NString &category, const NString &name, bool dbgAssert)=0
TAString & _(const TAppendable &src)
void DbgDisableBufferReplacementWarning()
constexpr integer Length() const
void Allocate(TAllocator &allocator, const TString< TChar > ©)
constexpr bool IsNotEmpty() const
integer LastIndexOf(TChar needle, integer startIndex=MAX_LEN) const
TString< TChar > Substring(integer regionStart, integer regionLength=MAX_LEN) const
String DefaultCommentPrefix
int AddResourcedSectionComments(ResourcePool &resourcePool, const NString &resourceCategory, const NString &resourceNamePrefix)
int ExportSubTree(Configuration::Cursor cursor, bool directChildrenOnly=false)
IniFile * iniFile
The INI-file. Created with methods #"ImportStart" and #"ExportStart".
bool SetWriteBackFlag(const String &path)
Configuration & configuration
The configuration to work with. Set with construction.
int ImportSection(const String §ionName)
int importSection(IniFile::Section §ion)
Priority priority
The priority to use to define variables. Set with construction.
bool Export(const Variable &var)
IniFile::Handle SearchEntry(const Variable &variable)
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
bool Try(const String &name)
const Declaration * GetDeclaration() const
Configuration & GetConfiguration() const
@ On
Switch it on, switched on, etc.
@ Include
Chooses inclusion.
strings::TString< nchar > NString
Type alias in namespace alib.
resources::ResourcePool ResourcePool
Type alias in namespace alib.
constexpr CString NEW_LINE
A zero-terminated string containing the new-line character sequence.
constexpr const String EMPTY_STRING
An empty string of the default character type.
LocalString< 4096 > String4K
Type alias name for #"TLocalString;TLocalString<character,4096>".
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>".
NLocalString< 128 > NString128
Type alias name for #"TLocalString;TLocalString<nchar,128>".
format::Paragraphs Paragraphs
Type alias in namespace alib.
strings::TStringLengthResetter< character,lang::HeapAllocator > StringLengthResetter
Type alias in namespace alib.
containers::StringTreeIterator< TTree > StringTreeIterator
Type alias in namespace alib.
A pair of pointers to a section and an entry in the section.
A section of the INI-file.
ListMA< Entry, Recycling::None > Entries
The list of variables of the section.
String Name
The name of the section.