|
ASL
|
A utility to read and write configuration files in INI format.
On destruction, if there was any variable added or modified the file is automatically saved. When reading a variable name it is considered a "section/name" pair.
Example:
Can be read and written with:
The file in that example will be saved if the original color in section main was not "black".
The file can be cheked for correct reading and whether a variable exists:
That last part can also be written as:
#include <asl/IniFile.h>
Public Member Functions | |
| IniFile (const String &path, bool shouldwrite=true) | |
| Opens an INI file from the given path. | |
| ~IniFile () | |
| Destroys the object and save the file if there were modifications. | |
| bool | ok () const |
| Returns true if the file was read correctly. | |
| const String & | fileName () const |
| Returns the file name of this IniFile. | |
| String & | operator[] (const String &name) |
Returns the value associated with the key name in the current section if the name is like section/name then the given section is used. | |
| void | set (const String &name, const String &value) |
| Sets the value for a key like 'section/name'. | |
| const String | operator() (const String &name, const String &defaultVal) const |
Returns the value associated with the key name or defaultVal if it was not found. | |
| void | write (const String &fname="") |
| Writes the file with its modifications; this is done automatically on destruction, just call this if you need the file written before the object is detroyed. | |
| bool | has (const String &name) const |
Returns true if the file contains a key named name. | |
| Array< String > | sectionNames () const |
| Returns the names of sections in the file. | |
| Dic | values () const |
| Returns all keys and values as a map with keys as "section/key". | |
| Dic | values (const String &secname) const |
| Returns a section's keys and values as a map. | |
Returns true if the file contains a key named name.
If the name is like section/name then function tests a variable name in section section.
Returns the value associated with the key name in the current section if the name is like section/name then the given section is used.
In the future this might return a const ref, so that modifications must be made with .set(k, v)