INI file helper class. More...
#include <IniFile.h>
Classes | |
struct | key |
Public Types | |
enum | errors { noID = -1 } |
Public Member Functions | |
IniFile (std::string const iniPath="") | |
Class constructor. | |
void | CaseSensitive () |
Enable INI case sensitivity. | |
void | CaseInsensitive () |
Disable INI case sensitivity. | |
void | SetPath (std::string const newPath) |
Set INI file path. | |
std::string | GetPath () const |
Get INI file path. | |
bool | ReadFile () |
Read INI file. | |
bool | WriteFile () |
Write INI file. | |
void | Reset () |
Reset the INI file. | |
long | FindKey (std::string const keyname) const |
Find INI key index. | |
long | FindValue (unsigned const keyID, std::string const valuename) const |
Find INI value index. | |
unsigned | GetNumKeys () const |
Get number of keys. | |
unsigned | AddKeyName (std::string const keyname) |
Add INI key. | |
std::string | GetKeyName (unsigned const keyID) const |
Get INI key name. | |
unsigned | GetNumValues (unsigned const keyID) |
Get number of INI values. | |
unsigned | GetNumValues (std::string const keyname) |
Get number of INI values. | |
std::string | GetValueName (unsigned const keyID, unsigned const valueID) const |
Get INI value name. | |
std::string | GetValueName (std::string const keyname, unsigned const valueID) const |
Get INI value name. | |
std::string | GetValue (unsigned const keyID, unsigned const valueID, std::string const defValue="") const |
Get INI value - by index. | |
std::string | GetValue (std::string const keyname, std::string const valuename, std::string const defValue="") const |
Get INI value - generic. | |
int | GetValueI (std::string const keyname, std::string const valuename, int const defValue=0) const |
Get INI value - integer. | |
bool | GetValueB (std::string const keyname, std::string const valuename, bool const defValue=false) const |
Get INI value - boolean. | |
double | GetValueF (std::string const keyname, std::string const valuename, double const defValue=0.0) const |
Get INI value - floating point. | |
unsigned | GetValueV (std::string const keyname, std::string const valuename, char *format,...) |
Get INI value - scanf-style. | |
bool | SetValue (unsigned const keyID, unsigned const valueID, std::string const value) |
Set INI value - by index. | |
bool | SetValue (std::string const keyname, std::string const valuename, std::string const value, bool const create=true) |
Set INI value - generic. | |
bool | SetValueI (std::string const keyname, std::string const valuename, int const value, bool const create=true) |
Set INI value - integer. | |
bool | SetValueB (std::string const keyname, std::string const valuename, bool const value, bool const create=true) |
Set INI value - boolean. | |
bool | SetValueF (std::string const keyname, std::string const valuename, double const value, bool const create=true) |
Set INI value - floating point. | |
bool | SetValueV (std::string const keyname, std::string const valuename, char *format,...) |
Set INI value - printf style. | |
bool | DeleteValue (std::string const keyname, std::string const valuename) |
Delete INI value. | |
bool | DeleteKey (std::string keyname) |
Delete INI key. | |
unsigned | GetNumHeaderComments () |
Number of header comments. | |
void | AddHeaderComment (std::string const comment) |
Add INI header comment. | |
std::string | GetHeaderComment (unsigned const commentID) const |
Get INI header comment. | |
bool | DeleteHeaderComment (unsigned commentID) |
Delete INI header comment. | |
void | DeleteHeaderComments () |
Delete all header comments. | |
unsigned | GetNumKeyComments (unsigned const keyID) const |
Get number of key comments. | |
unsigned | GetNumKeyComments (std::string const keyname) const |
Get number of key comments. | |
bool | AddKeyComment (unsigned const keyID, std::string const comment) |
Add INI key comment. | |
bool | AddKeyComment (std::string const keyname, std::string const comment) |
Add INI key comment. | |
std::string | GetKeyComment (unsigned const keyID, unsigned const commentID) const |
Get INI key comment. | |
std::string | GetKeyComment (std::string const keyname, unsigned const commentID) const |
Get INI key comment. | |
bool | DeleteKeyComment (unsigned const keyID, unsigned const commentID) |
Delete INI key comment. | |
bool | DeleteKeyComment (std::string const keyname, unsigned const commentID) |
Delete INI key comment. | |
bool | DeleteKeyComments (unsigned const keyID) |
Delete all INI key comments. | |
bool | DeleteKeyComments (std::string const keyname) |
Delete all INI key comments. |
INI file helper class.
This class is a helper for handling INI files. It provides a number of useful functions for reading and writing INI keys and their values.
enum IniFile::errors |
IniFile::IniFile | ( | std::string const | iniPath = "" |
) |
Class constructor.
Initializes the INI file object.
iniPath | Contains the path to the INI file. |
void IniFile::AddHeaderComment | ( | std::string const | comment | ) |
Add INI header comment.
Adds a comment to the INI file header. Header comments are those comments before the first key.
comment | Contains the comment text. |
bool IniFile::AddKeyComment | ( | std::string const | keyname, | |
std::string const | comment | |||
) |
Add INI key comment.
Adds a comment to the specified key of the INI file.
keyname | Specifies the name of the key. | |
comment | Contains the text of the comment. |
bool IniFile::AddKeyComment | ( | unsigned const | keyID, | |
std::string const | comment | |||
) |
Add INI key comment.
Adds a comment to the specified key of the INI file.
keyID | Specifies the key index. | |
comment | Contains the text of the comment. |
unsigned IniFile::AddKeyName | ( | std::string const | keyname | ) |
Add INI key.
Inserts the new key (or section) to the INI file.
keyname | Contains the name of the new key. |
void IniFile::CaseInsensitive | ( | ) | [inline] |
Disable INI case sensitivity.
Disables the case sensitivity. All operations on INI file keys and values become case insensitive. This is the default behavior.
void IniFile::CaseSensitive | ( | ) | [inline] |
Enable INI case sensitivity.
Enables the case sensitivity. All operations on INI file keys and values become case sensitive.
bool IniFile::DeleteHeaderComment | ( | unsigned | commentID | ) |
Delete INI header comment.
Delete a comment from the INI file header.
commentID | Specifies the comment line index. |
void IniFile::DeleteHeaderComments | ( | ) | [inline] |
Delete all header comments.
Clears all comments from the INI file header.
bool IniFile::DeleteKey | ( | std::string | keyname | ) |
Delete INI key.
Removes the specified key with all contained values.
keyname | Specifies the name of the key to be removed. |
bool IniFile::DeleteKeyComment | ( | std::string const | keyname, | |
unsigned const | commentID | |||
) |
Delete INI key comment.
Removes the comment related to the specific key of the INI file.
keyname | Specifies the name of the key. | |
commentID | Specifies the comment line index. |
bool IniFile::DeleteKeyComment | ( | unsigned const | keyID, | |
unsigned const | commentID | |||
) |
Delete INI key comment.
Removes the comment related to the specific key of the INI file.
keyID | Specifies the key index. | |
commentID | Specifies the comment line index. |
bool IniFile::DeleteKeyComments | ( | std::string const | keyname | ) |
Delete all INI key comments.
Removes all comments related to the specific key of the INI file.
keyname | Specifies the name of the key. |
bool IniFile::DeleteKeyComments | ( | unsigned const | keyID | ) |
Delete all INI key comments.
Removes all comments related to the specific key of the INI file.
keyID | Specifies the key index. |
bool IniFile::DeleteValue | ( | std::string const | keyname, | |
std::string const | valuename | |||
) |
Delete INI value.
Removes the given value assigned to a specified key.
keyname | Specifies the name of the key that contains the value. | |
valuename | Specifies the name of the value to be removed. |
long IniFile::FindKey | ( | std::string const | keyname | ) | const |
Find INI key index.
Finds an index for the given key name.
keyname | Contains the name of the key. |
long IniFile::FindValue | ( | unsigned const | keyID, | |
std::string const | valuename | |||
) | const |
Find INI value index.
Finds an index for the given value under the given key name.
keyID | Contains the key index. | |
valuename | Contains the name of the value. |
std::string IniFile::GetHeaderComment | ( | unsigned const | commentID | ) | const |
Get INI header comment.
Return a comment from the INI file header.
commentID | Specifies the comment line index. |
std::string IniFile::GetKeyComment | ( | std::string const | keyname, | |
unsigned const | commentID | |||
) | const |
Get INI key comment.
Retrieves the comment related to the specified key of the INI file.
keyname | Specifies the name of the key. | |
commentID | Specifies the comment line index. |
std::string IniFile::GetKeyComment | ( | unsigned const | keyID, | |
unsigned const | commentID | |||
) | const |
Get INI key comment.
Retrieves the comment related to the specified key of the INI file.
keyID | Specifies the key index. | |
commentID | Specifies the comment line index. |
std::string IniFile::GetKeyName | ( | unsigned const | keyID | ) | const |
Get INI key name.
keyID | Specifies the key index. |
unsigned IniFile::GetNumHeaderComments | ( | ) | [inline] |
Number of header comments.
unsigned IniFile::GetNumKeyComments | ( | std::string const | keyname | ) | const |
Get number of key comments.
keyname | Specifies the name of the key. |
unsigned IniFile::GetNumKeyComments | ( | unsigned const | keyID | ) | const |
Get number of key comments.
keyID | Specifies the key index. |
unsigned IniFile::GetNumKeys | ( | ) | const [inline] |
Get number of keys.
unsigned IniFile::GetNumValues | ( | std::string const | keyname | ) |
Get number of INI values.
keyname | Specifies the name of the key. |
unsigned IniFile::GetNumValues | ( | unsigned const | keyID | ) |
Get number of INI values.
keyID | Specifies the key index. |
std::string IniFile::GetPath | ( | ) | const [inline] |
Get INI file path.
std::string IniFile::GetValue | ( | std::string const | keyname, | |
std::string const | valuename, | |||
std::string const | defValue = "" | |||
) | const |
Get INI value - generic.
Retrieves the data of the given INI value associated with the specified key.
keyname | Specifies the name of the key that contains the value. | |
valuename | Specifies the name of the value. | |
defValue | Contains the default value data to be returned if the value does not exist. |
std::string IniFile::GetValue | ( | unsigned const | keyID, | |
unsigned const | valueID, | |||
std::string const | defValue = "" | |||
) | const |
Get INI value - by index.
Retrieves the data of the given INI value associated with the specified key.
keyID | Specifies the key index that contains the value. | |
valueID | Specifies the value index. | |
defValue | Contains the default value data to be returned if the value does not exist. |
bool IniFile::GetValueB | ( | std::string const | keyname, | |
std::string const | valuename, | |||
bool const | defValue = false | |||
) | const [inline] |
Get INI value - boolean.
Retrieves the boolean data of the given INI value associated with the specified key.
keyname | Specifies the name of the key that contains the value. | |
valuename | Specifies the name of the value. | |
defValue | Contains the default value data to be returned if the value does not exist. |
double IniFile::GetValueF | ( | std::string const | keyname, | |
std::string const | valuename, | |||
double const | defValue = 0.0 | |||
) | const |
Get INI value - floating point.
Retrieves the floating point data of the given INI value associated with the specified key.
keyname | Specifies the name of the key that contains the value. | |
valuename | Specifies the name of the value. | |
defValue | Contains the default value data to be returned if the value does not exist. |
int IniFile::GetValueI | ( | std::string const | keyname, | |
std::string const | valuename, | |||
int const | defValue = 0 | |||
) | const |
Get INI value - integer.
Retrieves the integer data of the given INI value associated with the specified key.
keyname | Specifies the name of the key that contains the value. | |
valuename | Specifies the name of the value. | |
defValue | Contains the default value data to be returned if the value does not exist. |
std::string IniFile::GetValueName | ( | std::string const | keyname, | |
unsigned const | valueID | |||
) | const |
Get INI value name.
Retrieves the name of the value associated with the given key.
keyname | Contains the name of the key. | |
valueID | Specifies the value index. |
std::string IniFile::GetValueName | ( | unsigned const | keyID, | |
unsigned const | valueID | |||
) | const |
Get INI value name.
Retrieves the name of the value associated with the given key.
keyID | Specifies the key index. | |
valueID | Specifies the value index. |
unsigned IniFile::GetValueV | ( | std::string const | keyname, | |
std::string const | valuename, | |||
char * | format, | |||
... | ||||
) |
Get INI value - scanf-style.
Parses the data of the given INI value associated with the specified key. Supports scanf-style formatting fields and a variable number of destinations.
keyname | Specifies the name of the key that contains the value. | |
valuename | Specifies the name of the value. | |
format | Contains the data parsing format with printf-style formatting fields. | |
... | Contains a variable number of destination pointers for parsed fields. |
bool IniFile::ReadFile | ( | ) |
Read INI file.
Reads the INI file using the path specified in the constructor.
void IniFile::Reset | ( | ) |
Reset the INI file.
Deletes all stored INI file data.
void IniFile::SetPath | ( | std::string const | newPath | ) | [inline] |
Set INI file path.
Sets the path of the INI file for reading and writing.
newPath | Contains the INI file name. |
bool IniFile::SetValue | ( | std::string const | keyname, | |
std::string const | valuename, | |||
std::string const | value, | |||
bool const | create = true | |||
) |
Set INI value - generic.
Sets the given value of the specified key to text data.
keyname | Specifies the name of the key that contains the value. | |
valuename | Specifies the name of the value. | |
value | Contains the value text. | |
create | Indicates if the value should be added if it does not exist. |
bool IniFile::SetValue | ( | unsigned const | keyID, | |
unsigned const | valueID, | |||
std::string const | value | |||
) |
Set INI value - by index.
Sets the given value of the specified key to text data.
keyID | Specifies the key index that contains the value. | |
valueID | Specifies the value index. | |
value | Contains the value text. |
bool IniFile::SetValueB | ( | std::string const | keyname, | |
std::string const | valuename, | |||
bool const | value, | |||
bool const | create = true | |||
) | [inline] |
Set INI value - boolean.
Sets the given value of the specified key to boolean data.
keyname | Specifies the name of the key that contains the value. | |
valuename | Specifies the name of the value. | |
value | Contains the boolean value. | |
create | Indicates if the value should be added if it does not exist. |
bool IniFile::SetValueF | ( | std::string const | keyname, | |
std::string const | valuename, | |||
double const | value, | |||
bool const | create = true | |||
) |
Set INI value - floating point.
Sets the given value of the specified key to floating point data.
keyname | Specifies the name of the key that contains the value. | |
valuename | Specifies the name of the value. | |
value | Contains the floating point value. | |
create | Indicates if the value should be added if it does not exist. |
bool IniFile::SetValueI | ( | std::string const | keyname, | |
std::string const | valuename, | |||
int const | value, | |||
bool const | create = true | |||
) |
Set INI value - integer.
Sets the given value of the specified key to integer data.
keyname | Specifies the name of the key that contains the value. | |
valuename | Specifies the name of the value. | |
value | Contains the integer value. | |
create | Indicates if the value should be added if it does not exist. |
bool IniFile::SetValueV | ( | std::string const | keyname, | |
std::string const | valuename, | |||
char * | format, | |||
... | ||||
) |
Set INI value - printf style.
Sets the given value of the specified key to text data with formatting field support.
keyname | Specifies the name of the key that contains the value | |
valuename | Specifies the name of the value. | |
format | Contains the value text with printf-style formatting fields. | |
... | Contains a variable number of arguments for formatting fields. |
bool IniFile::WriteFile | ( | ) |
Write INI file.
Writes the INI file using the path specified in the constructor.