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.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." )
51 return std::pair<IniFile::Section*, IniFile::Entry*>(
nullptr,
nullptr);
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 pair=
iniFile->SearchEntry(sectionName, entryName);
183 auto* entry= pair.second;
186 if( !entry->WriteBack && !pair.first->WriteBack )
190 auto sectionIt=
iniFile->SearchOrCreateSection( sectionName );
191 entry =
iniFile->CreateEntry( sectionIt.first, entryName );
201 if(entry->Comments.IsNull()) {
203 if( decl && decl->Comments().IsNotEmpty() )
212 ALIB_ERROR(
"VARIABLES",
"No INI-file loaded when trying to export data." )
217 if( !cursor.IsRoot() ) {
226 stit.
SetMaxDepth( directChildrenOnly ? 0 : (std::numeric_limits<unsigned>::max)() );
229 if( stit.
Node().Name().Equals(
A_CHAR(
"$PRESETS")) ) {
246 const NString& resourceCategory,
247 const NString& resourceNamePrefix ) {
249 ALIB_ERROR(
"VARIABLES",
"No INI-file loaded when trying to import data." )
255 for(
auto& section :
iniFile->Sections )
256 if( section.Comments.IsNull() ) {
257 auto& comment= resourcePool.
Get( resourceCategory,
258 NString128() << resourceNamePrefix << section.Name
260 if( comment.IsNull() )
279 "Variable \"{}\" to be marked as 'writeback' not found.", path )
281 if( entry.second && entry.second->RawValue.IsEmpty() ) {
282 entry.second->WriteBack=
true;
291 "Variable belongs to different configuration: ", var)
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
constexpr bool IsNotEmpty() const
integer LastIndexOf(TChar needle, integer startIndex=MAX_LEN) const
void Allocate(TAllocator &allocator, const TString< TChar > ©)
TString< TChar > Substring(integer regionStart, integer regionLength=MAX_LEN) const
String DefaultCommentPrefix
ALIB_DLL std::pair< IniFile::Section *, IniFile::Entry * > SearchEntry(const Variable &variable)
ALIB_DLL int AddResourcedSectionComments(ResourcePool &resourcePool, const NString &resourceCategory, const NString &resourceNamePrefix)
ALIB_DLL int ExportSubTree(Configuration::Cursor cursor, bool directChildrenOnly=false)
IniFile * iniFile
The INI-file. Created with methods ImportStart and ExportStart.
ALIB_DLL bool SetWriteBackFlag(const String &path)
Configuration & configuration
The configuration to work with. Set with construction.
ALIB_DLL int ImportSection(const String §ionName)
ALIB_DLL int importSection(IniFile::Section §ion)
Priority priority
The priority to use to define variables. Set with construction.
ALIB_DLL bool Export(const Variable &var)
ALIB_DLL bool Define(Priority requestedPriority=Priority::Standard)
ALIB_DLL 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
#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,...)
@ On
Switch it on, switched on, etc.
@ Exclude
Chooses exclusion.
strings::TStringLengthResetter< character,lang::HeapAllocator > StringLengthResetter
Type alias in namespace alib.
NLocalString< 128 > NString128
Type alias name for TLocalString<nchar,128>.
LocalString< 256 > String256
Type alias name for TLocalString<character,256>.
LocalString< 4096 > String4K
Type alias name for TLocalString<character,4096>.
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.
strings::TString< nchar > NString
Type alias in namespace alib.
format::Paragraphs Paragraphs
Type alias in namespace alib.
resources::ResourcePool ResourcePool
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
containers::StringTreeIterator< TTree > StringTreeIterator
Type alias in namespace alib.
strings::TSubstring< character > Substring
Type alias in namespace alib.
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.