|
UTF8 - Simple Library for Internationalization
|
Operations on INI files. More...
#include <ini.h>
Public Member Functions | |
| IniFile (const std::string &name) | |
| Constructor based on an existing or new INI file. | |
| IniFile () | |
| Default constructor uses a temporary file. | |
| IniFile (const IniFile &p) | |
| Copy constructor. | |
| ~IniFile () | |
| Destructor. | |
| IniFile & | operator= (const IniFile &) |
| Assignment operator. | |
| const std::string & | File () const |
| Return file name associated with this object. | |
| void | File (const std::string &filename) |
| Set the file name associated with this object. | |
| size_t | GetString (char *value, size_t len, const std::string &key, const std::string §ion, const std::string &defval=std::string()) const |
| Get a string key. | |
| std::string | GetString (const std::string &key, const std::string §ion, const std::string &defval=std::string()) const |
| Return a string key. | |
| int | GetInt (const std::string &key, const std::string §ion, int defval=0) const |
| Return an integer key. | |
| double | GetDouble (const std::string &key, const std::string §ion, double defval=0.) const |
| Return a floating point value. | |
| bool | GetBool (const std::string &key, const std::string §ion, bool defval=false) const |
| Return a boolean key. | |
| bool | HasKey (const std::string &key, const std::string §ion) const |
| Check for key existence. | |
| bool | PutString (const std::string &key, const std::string &value, const std::string §ion) |
| Write a string key. | |
| bool | PutInt (const std::string &key, long value, const std::string §ion) |
| Write an integer key. | |
| bool | PutBool (const std::string &key, bool value, const std::string §ion) |
| Write a boolean key. | |
| bool | PutDouble (const std::string &key, double value, const std::string §ion, int dec=2) |
| Write a floating point value key. | |
| bool | DeleteKey (const std::string &key, const std::string §ion) |
| Delete a key. | |
| bool | DeleteSection (const std::string §ion) |
| Delete an entire section. | |
| bool | CopySection (const IniFile &from_file, const std::string &from_sect, const std::string &to_sect=std::string()) |
| Copy all keys from one section to another. | |
| bool | HasSection (const std::string §ion) |
| Return true if profile contains a non empty section with the given name. | |
| int | GetKeys (char *buffer, size_t sz, const std::string §ion) |
| Retrieve names of all keys in a section. | |
| size_t | GetKeys (std::deque< std::string > &keys, const std::string §ion) |
| Retrieve names of all keys in a section. | |
| size_t | GetSections (char *sects, size_t sz) |
| Return the names of all sections in the INI file. | |
| size_t | GetSections (std::deque< std::string > §ions) |
| Return the names of all sections in the INI file. | |
Operations on INI files.
Provides a handy object oriented encapsulation of functions needed to manipulate INI (profile) files.
|
explicit |
Constructor based on an existing or new INI file.
Constructor.
| utf8::IniFile::IniFile | ( | ) |
Default constructor uses a temporary file.
Creates a temporary file as filename.
| utf8::IniFile::~IniFile | ( | ) |
Destructor.
Destructor. If this was a temporary file it is deleted now.
| bool utf8::IniFile::CopySection | ( | const IniFile & | from_file, |
| const std::string & | from_sect, | ||
| const std::string & | to_sect = std::string() |
||
| ) |
Copy all keys from one section to another.
Copy a whole section form another INI file.
| from_file | source INI file |
| from_sect | source section |
| to_sect | destination section |
If to_sec is empty the destination section is the same as the source section.
The previous content of destination section is erased.
| bool utf8::IniFile::DeleteKey | ( | const std::string & | key, |
| const std::string & | section | ||
| ) |
Delete a key.
| key | key name |
| section | section name |
| bool utf8::IniFile::DeleteSection | ( | const std::string & | section | ) |
Delete an entire section.
| section | section name |
| void utf8::IniFile::File | ( | const std::string & | fname | ) |
Set the file name associated with this object.
Changes the file associated with this object.
If previous one was a temporary file, it is deleted now (loosing all settings in the process).
| fname | New file name. If empty it creates a temporary file. |
| bool utf8::IniFile::GetBool | ( | const std::string & | key, |
| const std::string & | section, | ||
| bool | defval = false |
||
| ) | const |
Return a boolean key.
True values can be specified by any of "on", "yes", "true" or "1".
Anything else is considered as FALSE. Strings are case-insensitive.
| key | key name |
| section | section name |
| defval | default value if key is missing |
| double utf8::IniFile::GetDouble | ( | const std::string & | key, |
| const std::string & | section, | ||
| double | defval = 0. |
||
| ) | const |
Return a floating point value.
| key | key name |
| section | section name |
| defval | default value if key is missing |
| int utf8::IniFile::GetInt | ( | const std::string & | key, |
| const std::string & | section, | ||
| int | defval = 0 |
||
| ) | const |
Return an integer key.
| key | key name |
| section | section name |
| defval | default value if key is missing |
| int utf8::IniFile::GetKeys | ( | char * | keys, |
| size_t | sz, | ||
| const std::string & | section | ||
| ) |
Retrieve names of all keys in a section.
Key names are returned as null-terminated strings followed by one final null.
| keys | buffer for returned keys |
| sz | size of buffer |
| section | section name |
| size_t utf8::IniFile::GetKeys | ( | std::deque< std::string > & | keys, |
| const std::string & | section | ||
| ) |
Retrieve names of all keys in a section.
Key names are returned as a deque array.
| keys | container for returned keys |
| section | section name |
| size_t utf8::IniFile::GetSections | ( | char * | sects, |
| size_t | sz | ||
| ) |
Return the names of all sections in the INI file.
Section names are returned as null-terminated strings followed by one final null.
| sects | buffer for returned keys |
| sz | size of buffer |
The number of sections returned is the total number of sections in the INI file even if the buffer is too small to hold sections' names.
| size_t utf8::IniFile::GetSections | ( | std::deque< std::string > & | sects | ) |
Return the names of all sections in the INI file.
Section names are returned as a deque of strings.
| sects | deque of sections |
| size_t utf8::IniFile::GetString | ( | char * | value, |
| size_t | len, | ||
| const std::string & | key, | ||
| const std::string & | section, | ||
| const std::string & | defval = std::string() |
||
| ) | const |
Get a string key.
| value | buffer for returned string |
| len | length of buffer |
| key | key name |
| section | section name |
| defval | default value |
| std::string utf8::IniFile::GetString | ( | const std::string & | key, |
| const std::string & | section, | ||
| const std::string & | defval = std::string () |
||
| ) | const |
Return a string key.
| key | key name |
| section | section name |
| defval | default value |
| bool utf8::IniFile::HasKey | ( | const std::string & | key, |
| const std::string & | section | ||
| ) | const |
Check for key existence.
Return true if specified key exists in the INI file.
| bool utf8::IniFile::HasSection | ( | const std::string & | section | ) |
Return true if profile contains a non empty section with the given name.
| section | section name |
Assignment operator.
Assignment operator performs a file copy of the passed object.
| bool utf8::IniFile::PutBool | ( | const std::string & | key, |
| bool | value, | ||
| const std::string & | section | ||
| ) |
Write a boolean key.
Boolean values are encoded as "On" "Off" strings.
| key | key name |
| section | section name |
| value | key value |
| bool utf8::IniFile::PutDouble | ( | const std::string & | key, |
| double | value, | ||
| const std::string & | section, | ||
| int | dec = 2 |
||
| ) |
Write a floating point value key.
| key | key name |
| value | key value |
| section | section name |
| dec | number of decimals |
| bool utf8::IniFile::PutInt | ( | const std::string & | key, |
| long | value, | ||
| const std::string & | section | ||
| ) |
Write an integer key.
| key | key name |
| value | key value |
| section | section name |
| bool utf8::IniFile::PutString | ( | const std::string & | key, |
| const std::string & | value, | ||
| const std::string & | section | ||
| ) |
Write a string key.
| value | key value |
| key | key name |
| section | section name |