|
| CSimpleIniTempl (bool a_bIsUtf8=false, bool a_bMultiKey=false, bool a_bMultiLine=false) |
|
| ~CSimpleIniTempl () |
|
void | Reset () |
|
bool | IsEmpty () const |
|
SI_Error | LoadFile (const char *a_pszFile) |
|
SI_Error | LoadFile (FILE *a_fpFile) |
|
SI_Error | LoadData (const std::string &a_strData) |
|
SI_Error | LoadData (const char *a_pData, size_t a_uDataLen) |
|
SI_Error | SaveFile (const char *a_pszFile, bool a_bAddSignature=true) const |
|
SI_Error | SaveFile (FILE *a_pFile, bool a_bAddSignature=false) const |
|
SI_Error | Save (OutputWriter &a_oOutput, bool a_bAddSignature=false) const |
|
SI_Error | Save (std::string &a_sBuffer, bool a_bAddSignature=false) const |
|
void | GetAllSections (TNamesDepend &a_names) const |
|
bool | GetAllKeys (const SI_CHAR *a_pSection, TNamesDepend &a_names) const |
|
bool | GetAllValues (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, TNamesDepend &a_values) const |
|
int | GetSectionSize (const SI_CHAR *a_pSection) const |
|
const TKeyVal * | GetSection (const SI_CHAR *a_pSection) const |
|
bool | SectionExists (const SI_CHAR *a_pSection) const |
|
bool | KeyExists (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey) const |
|
const SI_CHAR * | GetValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, const SI_CHAR *a_pDefault=NULL, bool *a_pHasMultiple=NULL) const |
|
long | GetLongValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, long a_nDefault=0, bool *a_pHasMultiple=NULL) const |
|
double | GetDoubleValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, double a_nDefault=0, bool *a_pHasMultiple=NULL) const |
|
bool | GetBoolValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, bool a_bDefault=false, bool *a_pHasMultiple=NULL) const |
|
SI_Error | SetValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, const SI_CHAR *a_pValue, const SI_CHAR *a_pComment=NULL, bool a_bForceReplace=false) |
|
SI_Error | SetLongValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, long a_nValue, const SI_CHAR *a_pComment=NULL, bool a_bUseHex=false, bool a_bForceReplace=false) |
|
SI_Error | SetDoubleValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, double a_nValue, const SI_CHAR *a_pComment=NULL, bool a_bForceReplace=false) |
|
SI_Error | SetBoolValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, bool a_bValue, const SI_CHAR *a_pComment=NULL, bool a_bForceReplace=false) |
|
bool | Delete (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, bool a_bRemoveEmpty=false) |
|
bool | DeleteValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, const SI_CHAR *a_pValue, bool a_bRemoveEmpty=false) |
|
Converter | GetConverter () const |
|
|
void | SetUnicode (bool a_bIsUtf8=true) |
|
bool | IsUnicode () const |
|
void | SetMultiKey (bool a_bAllowMultiKey=true) |
|
bool | IsMultiKey () const |
|
void | SetMultiLine (bool a_bAllowMultiLine=true) |
|
bool | IsMultiLine () const |
|
void | SetSpaces (bool a_bSpaces=true) |
|
bool | UsingSpaces () const |
|
void | SetQuotes (bool a_bParseQuotes=true) |
|
bool | UsingQuotes () const |
|
void | SetAllowKeyOnly (bool a_bAllowKeyOnly=true) |
|
bool | GetAllowKeyOnly () const |
|
template<class SI_CHAR, class SI_STRLESS, class SI_CONVERTER>
class CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >
Simple INI file reader.
This can be instantiated with the choice of unicode or native characterset, and case sensitive or insensitive comparisons of section and key names. The supported combinations are pre-defined with the following typedefs:
Interface | Case-sensitive | Typedef |
char | No | CSimpleIniA |
char | Yes | CSimpleIniCaseA |
wchar_t | No | CSimpleIniW |
wchar_t | Yes | CSimpleIniCaseW |
Note that using other types for the SI_CHAR is supported. For instance, unsigned char, unsigned short, etc. Note that where the alternative type is a different size to char/wchar_t you may need to supply new helper classes for SI_STRLESS and SI_CONVERTER.
template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
bool CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::Delete |
( |
const SI_CHAR * |
a_pSection, |
|
|
const SI_CHAR * |
a_pKey, |
|
|
bool |
a_bRemoveEmpty = false |
|
) |
| |
Delete an entire section, or a key from a section. Note that the data returned by GetSection is invalid and must not be used after anything has been deleted from that section using this method. Note when multiple keys is enabled, this will delete all keys with that name; to selectively delete individual key/values, use DeleteValue.
- Parameters
-
a_pSection | Section to delete key from, or if a_pKey is NULL, the section to remove. |
a_pKey | Key to remove from the section. Set to NULL to remove the entire section. |
a_bRemoveEmpty | If the section is empty after this key has been deleted, should the empty section be removed? |
- Returns
- true Key or section was deleted.
-
false Key or section was not found.
template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
bool CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::DeleteValue |
( |
const SI_CHAR * |
a_pSection, |
|
|
const SI_CHAR * |
a_pKey, |
|
|
const SI_CHAR * |
a_pValue, |
|
|
bool |
a_bRemoveEmpty = false |
|
) |
| |
Delete an entire section, or a key from a section. If value is provided, only remove keys with the value. Note that the data returned by GetSection is invalid and must not be used after anything has been deleted from that section using this method. Note when multiple keys is enabled, all keys with the value will be deleted.
- Parameters
-
a_pSection | Section to delete key from, or if a_pKey is NULL, the section to remove. |
a_pKey | Key to remove from the section. Set to NULL to remove the entire section. |
a_pValue | Value of key to remove from the section. Set to NULL to remove all keys. |
a_bRemoveEmpty | If the section is empty after this key has been deleted, should the empty section be removed? |
- Returns
- true Key/value or section was deleted.
-
false Key/value or section was not found.
template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
Retrieve all unique key names in a section. The sort order of the returned strings is NOT DEFINED. You can sort the names into the load order if desired. Search this file for ".sort" for an example. Only unique key names are returned.
NOTE! This structure contains only pointers to strings. The actual string data is stored in memory owned by CSimpleIni. Ensure that the CSimpleIni object is not destroyed or Reset() while these strings are in use!
- Parameters
-
a_pSection | Section to request data for |
a_names | List that will receive all of the key names. See note above! |
- Returns
- true Section was found.
-
false Matching section was not found.
template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
Retrieve all section names. The list is returned as an STL vector of names and can be iterated or searched as necessary. Note that the sort order of the returned strings is NOT DEFINED. You can sort the names into the load order if desired. Search this file for ".sort" for an example.
NOTE! This structure contains only pointers to strings. The actual string data is stored in memory owned by CSimpleIni. Ensure that the CSimpleIni object is not destroyed or Reset() while these pointers are in use!
- Parameters
-
a_names | Vector that will receive all of the section names. See note above! |
template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
bool CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::GetAllValues |
( |
const SI_CHAR * |
a_pSection, |
|
|
const SI_CHAR * |
a_pKey, |
|
|
TNamesDepend & |
a_values |
|
) |
| const |
Retrieve all values for a specific key. This method can be used when multiple keys are both enabled and disabled. Note that the sort order of the returned strings is NOT DEFINED. You can sort the names into the load order if desired. Search this file for ".sort" for an example.
NOTE! The returned values are pointers to string data stored in memory owned by CSimpleIni. Ensure that the CSimpleIni object is not destroyed or Reset while you are using this pointer!
- Parameters
-
a_pSection | Section to search |
a_pKey | Key to search for |
a_values | List to return if the key is not found |
- Returns
- true Key was found.
-
false Matching section/key was not found.
template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
bool CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::GetBoolValue |
( |
const SI_CHAR * |
a_pSection, |
|
|
const SI_CHAR * |
a_pKey, |
|
|
bool |
a_bDefault = false , |
|
|
bool * |
a_pHasMultiple = NULL |
|
) |
| const |
Retrieve a boolean value for a specific key. If multiple keys are enabled (see SetMultiKey) then only the first value associated with that key will be returned, see GetAllValues for getting all values with multikey.
Strings starting with "t", "y", "on" or "1" are returned as logically true. Strings starting with "f", "n", "of" or "0" are returned as logically false. For all other values the default is returned. Character comparisons are case-insensitive.
- Parameters
-
a_pSection | Section to search |
a_pKey | Key to search for |
a_bDefault | Value to return if the key is not found |
a_pHasMultiple | Optionally receive notification of if there are multiple entries for this key. |
- Returns
- a_nDefault Key was not found in the section
-
other Value of the key
template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
const SI_CHAR * CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::GetValue |
( |
const SI_CHAR * |
a_pSection, |
|
|
const SI_CHAR * |
a_pKey, |
|
|
const SI_CHAR * |
a_pDefault = NULL , |
|
|
bool * |
a_pHasMultiple = NULL |
|
) |
| const |
Retrieve the value for a specific key. If multiple keys are enabled (see SetMultiKey) then only the first value associated with that key will be returned, see GetAllValues for getting all values with multikey.
NOTE! The returned value is a pointer to string data stored in memory owned by CSimpleIni. Ensure that the CSimpleIni object is not destroyed or Reset while you are using this pointer!
- Parameters
-
a_pSection | Section to search |
a_pKey | Key to search for |
a_pDefault | Value to return if the key is not found |
a_pHasMultiple | Optionally receive notification of if there are multiple entries for this key. |
- Returns
- a_pDefault Key was not found in the section
-
other Value of the key
template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
Save the INI data. The data will be written to the output device in a format appropriate to the current data, selected by:
SI_CHAR | FORMAT |
char | same format as when loaded (MBCS or UTF-8) |
wchar_t | UTF-8 |
other | UTF-8 |
Note that comments from the original data is preserved as per the documentation on comments. The order of the sections and values from the original file will be preserved.
Any data prepended or appended to the output device must use the the same format (MBCS or UTF-8). You may use the GetConverter() method to convert text to the correct format regardless of the output format being used by SimpleIni.
To add a BOM to UTF-8 data, write it out manually at the very beginning like is done in SaveFile when a_bUseBOM is true.
- Parameters
-
a_oOutput | Output writer to write the data to. |
a_bAddSignature | Prepend the UTF-8 BOM if the output data is in UTF-8 format. If it is not UTF-8 then this value is ignored. Do not set this to true if anything has already been written to the OutputWriter. |
- Returns
- SI_Error See error definitions
template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
void CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::SetMultiKey |
( |
bool |
a_bAllowMultiKey = true | ) |
|
|
inline |
Should multiple identical keys be permitted in the file. If set to false then the last value encountered will be used as the value of the key. If set to true, then all values will be available to be queried. For example, with the following input:
[section]
test=value1
test=value2
Then with SetMultiKey(true), both of the values "value1" and "value2" will be returned for the key test. If SetMultiKey(false) is used, then the value for "test" will only be "value2". This value may be changed at any time.
- Parameters
-
a_bAllowMultiKey | Allow multi-keys in the source? |
template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
void CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::SetUnicode |
( |
bool |
a_bIsUtf8 = true | ) |
|
|
inline |
Set the storage format of the INI data. This affects both the loading and saving of the INI data using all of the Load/Save API functions. This value cannot be changed after any INI data has been loaded.
If the file is not set to Unicode (UTF-8), then the data encoding is assumed to be the OS native encoding. This encoding is the system locale on Linux/Unix and the legacy MBCS encoding on Windows NT/2K/XP. If the storage format is set to Unicode then the file will be loaded as UTF-8 encoded data regardless of the native file encoding. If SI_CHAR == char then all of the char* parameters take and return UTF-8 encoded data regardless of the system locale.
- Parameters
-
a_bIsUtf8 | Assume UTF-8 encoding for the source? |