Adapter type between class IniFile and class Configuration. INI-file contents usually are fed in with bootstrapping an application and optionally be written out when an application ends (to populate empty INI-files or add new variables to existing ones). For this, an instance of this type is to be created locally each time. In other words, no instance of this type needs to be kept in memory during the life-span of an application.
Definition at line 20 of file inifilefeeder.hpp.
#include <inifilefeeder.hpp>
Public Field Index: | |
| String | DefaultCommentPrefix =A_CHAR("# ") |
| bool | DidNotExistOrWasEmpty =false |
| int | LineWidth = 100 |
Public Method Index: | |
| IniFileFeeder (Configuration &pConfiguration, Priority pPriority=Priority::ConfigFile) | |
| virtual | ~IniFileFeeder () |
| int | AddResourcedSectionComments (ResourcePool &resourcePool, const NString &resourceCategory, const NString &resourceNamePrefix) |
| int | AddResourcedSectionComments (resources::ResourceHolder &resourceHolder, const NString &resourceNamePrefix) |
| bool | Export (const String &path) |
| bool | Export (const Variable &var) |
| void | ExportEnd () |
| Closes and deletes the internal iniFile instance without writing an opened INI-file. | |
| void | ExportEnd (const Path &path) |
| int | ExportStart (const Path &path) |
| int | ExportSubTree (Configuration::Cursor cursor, bool directChildrenOnly=false) |
| int | ExportSubTree (const String &path, bool directChildrenOnly=false) |
| IniFile & | GetIniFile () |
| int | ImportAll () |
| void | ImportEnd () |
| Closes and deletes the internal iniFile instance. | |
| int | ImportSection (const String §ionName) |
| int | ImportSection (const String §ionName, const String &typeName) |
| int | ImportStart (const Path &path) |
| IniFile::Handle | SearchEntry (const String &path) |
| IniFile::Handle | SearchEntry (const Variable &variable) |
| bool | SetWriteBackFlag (const String &path) |
| bool | SetWriteBackFlag (const Variable &var) |
Protected Field Index: | |
| Configuration & | configuration |
| The configuration to work with. Set with construction. | |
| IniFile * | iniFile = nullptr |
| The INI-file. Created with methods ImportStart and ExportStart. | |
| Priority | priority |
| The priority to use to define variables. Set with construction. | |
Protected Method Index: | |
| int | importSection (IniFile::Section §ion) |
|
protected |
The configuration to work with. Set with construction.
Definition at line 24 of file inifilefeeder.hpp.
The prefix that is used for comment lines of sections or variables that have been added 'in code' (variables that have not been read from the file). Comments that were read from the file preserve their prefix. If comments including one of the valid prefixes are added to a variable or section 'in code', such prefix is preserved.
Definition at line 50 of file inifilefeeder.hpp.
| bool alib::variables::IniFileFeeder::DidNotExistOrWasEmpty =false |
This flag may be read after invoking the method ExportStart, which will try to read the file first. If the file could not be opened or is empty, this flag is set. The flag may be used to decide, for example, if a file-comment or section comments should be generated.
Definition at line 56 of file inifilefeeder.hpp.
|
protected |
The INI-file. Created with methods ImportStart and ExportStart.
Definition at line 30 of file inifilefeeder.hpp.
| int alib::variables::IniFileFeeder::LineWidth = 100 |
The desired maximum width of the INI-file. Defaults to 100. This value is used with utility method AddResourcedSectionComments.
Definition at line 43 of file inifilefeeder.hpp.
|
protected |
The priority to use to define variables. Set with construction.
Definition at line 27 of file inifilefeeder.hpp.
|
inline |
Constructor.
| pConfiguration | Stored in the field configuration. |
| pPriority | Stored in the field priority. Defaults to ConfigFile. |
Definition at line 65 of file inifilefeeder.hpp.
|
inlinevirtual |
Virtual destructor. Raises an ALib warning in debug-compilations, if the internal INI-file was not disposed before deletion. Disposal is made with methods ImportEnd and ExportEnd.
Definition at line 72 of file inifilefeeder.hpp.
| int alib::variables::IniFileFeeder::AddResourcedSectionComments | ( | ResourcePool & | resourcePool, |
| const NString & | resourceCategory, | ||
| const NString & | resourceNamePrefix ) |
This is a utility function that reads section comments from externalized string resources.
All sections of the underlying INI-file are processed, but resourced comments are only added in the case that a section's comment string is nulled. This is not the case if a section was read from an INI-file, as even if no comments were given, the field is empty but not nulled. In other words, only sections that have been programmatically added during the run of software are changed
This approach allows a user to remove the comments, without the software restoring them.
The resource names are assembled from given resourceNamePrefix and the section name. The resource strings found are processed using the method AddMarked. This allows using text macros like '@HL' to format the text.
| resourcePool | The resource pool to use. |
| resourceCategory | The category of the resourced comments. |
| resourceNamePrefix | A prefix of the resource name. |
Definition at line 203 of file inifilefeeder.cpp.
|
inline |
This is a shortcut to the overloaded method, accepting a ResourceHolder instead of parameters resourcePool and resourceCategory.
| resourceHolder | A container holding a resource pool and a fixed category. |
| resourceNamePrefix | A prefix of the resource name. |
Definition at line 316 of file inifilefeeder.hpp.
|
inline |
Creates a variable cursor with the given cfg and path and passes it to overloaded method Export Variable&).
| path | The path of the variable to export. |
true if the variable either did not exist yet in the INI-file or if it existed and the write-back mechanism was in place. false otherwise. Definition at line 201 of file inifilefeeder.hpp.
| bool alib::variables::IniFileFeeder::Export | ( | const Variable & | var | ) |
Writes the given variable to the internal INI-file. If an INI-file was previously loaded, only those variables which are not existing in the INI-file are written. This method can thus be used to "populate" an empty INI-file with variables and their resourced or hard-coded default values and this way present all configurable options to an end-user.
Furthermore, a user can specify the word "writeback" (respectively what is resourced with to token "CFGIniWB") to force overwriting the INI-file contents with the current value of the variable.
| var | The variable to export. |
true if the variable either did not exist yet in the INI-file or if it existed and the write-back mechanism was in place. false otherwise. Definition at line 126 of file inifilefeeder.cpp.
|
inline |
Closes and deletes the internal iniFile instance without writing an opened INI-file.
Definition at line 164 of file inifilefeeder.hpp.
|
inline |
Writes the contents of the internal iniFile instance created with ExportStart into an (optionally) different file and then deletes the instance.
| path | The file path for writing. |
Definition at line 169 of file inifilefeeder.hpp.
|
inline |
Creates the internal iniFile instance.
| path | The filepath to the INI-file. |
Definition at line 138 of file inifilefeeder.hpp.
| int alib::variables::IniFileFeeder::ExportSubTree | ( | Configuration::Cursor | cursor, |
| bool | directChildrenOnly = false ) |
Writes all variables below the given Cursor of the Configuration into the iniFile, previously created with ExportStart. If an INI-file was previously loaded, only those variables which are not existing in the INI-file are written. This method can thus be used to "populate" an empty INI-file with default values and this way present all configurable options to an end-user.
Furthermore, a user can specify the word "writeback" (respectively what is resourced with to token "CFGIniWB") to force overwriting the INI-file contents with the current value of the variable.
| cursor | A cursor into the configuration's StringTree. |
| directChildrenOnly | If true, only the direct children of this cursor are written as variables. Defaults to false. |
Definition at line 172 of file inifilefeeder.cpp.
|
inline |
Invokes ExportSubTree(Configuration::Cursor, bool) by creating a cursor from the given path
| path | The path to the subtree (or single variable) to use. |
| directChildrenOnly | If true, only the direct children of this path are written as variables. Defaults to false. |
Definition at line 237 of file inifilefeeder.hpp.
|
inline |
Allows access to the internal INI-file object created with either method ImportStart or ExportStart. In debug-compilations, this method asserts that an INI-file was opened. In release-compilations, a non-existing INI-file leads to undefined behavior.
Definition at line 328 of file inifilefeeder.hpp.
| int alib::variables::IniFileFeeder::ImportAll | ( | ) |
Imports all entries found INI-file into the configuration. Variables which are already declared and have a lower priority definition, will be set with the value found. Otherwise, a preset string is set for the variable.
Definition at line 107 of file inifilefeeder.cpp.
|
inline |
Closes and deletes the internal iniFile instance.
Definition at line 154 of file inifilefeeder.hpp.
| int alib::variables::IniFileFeeder::ImportSection | ( | const String & | sectionName | ) |
Imports all entries in the section named sectionName in the underlying INI-file into the configuration.
| sectionName | The name of the section to import. |
Definition at line 92 of file inifilefeeder.cpp.
| int alib::variables::IniFileFeeder::ImportSection | ( | const String & | sectionName, |
| const String & | typeName ) |
Imports all entries in the section named sectionName in the underlying INI-file into the configuration. This special version of the method accepts parameter typeName and hence declares the variables in case they have not been declared, yet.
| sectionName | The name of the section to import. |
| typeName | The type of the variable to declare. |
Definition at line 32 of file inifilefeeder.cpp.
|
protected |
Implements overloaded methods ImportSection(const String&).
| section | The section to import |
Definition at line 64 of file inifilefeeder.cpp.
|
inline |
Creates the internal iniFile instance.
| path | The filepath to the INI-file. |
Definition at line 118 of file inifilefeeder.hpp.
| IniFile::Handle alib::variables::IniFileFeeder::SearchEntry | ( | const String & | path | ) |
Searches the entry of the internal INI-file that represents the given variable determined by parameter path
| path | The path of the variable to search in the INI-file. |
Definition at line 7 of file inifilefeeder.cpp.
| IniFile::Handle alib::variables::IniFileFeeder::SearchEntry | ( | const Variable & | variable | ) |
Searches the entry of the internal INI-file that represents the given variable
| variable | The variable to search in the INI-file. |
Definition at line 22 of file inifilefeeder.cpp.
| bool alib::variables::IniFileFeeder::SetWriteBackFlag | ( | const String & | path | ) |
This method may be used to set the writeback flag of an entry in the associated INI-file. The flag is only set if the entry was programmatically created (usually with one of the Export-methods of this class) and if it was not present in the INI-file before.
| path | The path of the variable to export. |
true if the variable did exist and was newly added to the INI-file, false otherwise. Definition at line 234 of file inifilefeeder.cpp.
| bool alib::variables::IniFileFeeder::SetWriteBackFlag | ( | const Variable & | var | ) |
Invokes overloaded method SetWriteBackFlag(const String&).
| var | The variable to modifiy. |
true if the variable did exist and was newly added to the INI-file, false otherwise. Definition at line 246 of file inifilefeeder.cpp.