#include <IniFile.h>
Public Member Functions | |
int | FindNextSection (std::string *pSect, std::string prevSect, bool bWarnIfNotfound=true) |
int | GetKey (const char *pSect, const char *pKey, std::string *pStrToRead, bool bWarnIfNotfound=true) |
int | GetKey (const char *pSect, const char *pKey, int *pValue, bool bWarnIfNotfound=true) |
int | GetKey (const char *pSect, const char *pKey, bool *pValue, bool bWarnIfNotfound=true) |
int | GetKey (const char *pSect, const char *pKey, double *pValue, bool bWarnIfNotfound=true) |
int | GetKeyBool (const char *pSect, const char *pKey, bool *pValue, bool bWarnIfNotfound=true) |
int | GetKeyDouble (const char *pSect, const char *pKey, double *pValue, bool bWarnIfNotfound=true) |
int | GetKeyDouble (const char *pSect, const char *pKey, double *pValue, double dDefault, bool bWarnIfNotfound=true) |
int | GetKeyInt (const char *pSect, const char *pKey, int *pValue, bool bWarnIfNotfound=true) |
int | GetKeyLong (const char *pSect, const char *pKey, long *pValue, bool bWarnIfNotfound=true) |
int | GetKeyString (const char *pSect, const char *pKey, std::string *pStrToRead, bool bWarnIfNotfound=true) |
IniFile () | |
IniFile (std::string fileName) | |
int | SetFileName (std::string fileName, std::string strIniFileUsedBy="", bool bCreate=false) |
int | WriteKeyBool (const char *pSect, const char *pKey, bool bValue, bool bWarnIfNotfound=true) |
int | WriteKeyDouble (const char *pSect, const char *pKey, double dValue, int StringLen=12, int decimals=5, bool bWarnIfNotfound=true) |
int | WriteKeyInt (const char *pSect, const char *pKey, int nValue, bool bWarnIfNotfound=true) |
int | WriteKeyString (const char *pSect, const char *pKey, const std::string *pStrToWrite, bool bWarnIfNotfound=true) |
~IniFile () | |
Private Member Functions | |
int | FindKey (const char *skey, bool bWarnIfNotfound=true) |
int | FindNextLine (std::vector< char > &NewLine, int &CharInd) |
int | FindSection (const char *sect, bool bWarnIfNotfound=true) |
int | GetKeyValue (const char *pSect, const char *pKey, char *pBuf, int lenBuf, bool bWarnIfNotfound=true) |
int | ReadLineUntil (FILE *pFile, const char EndChar, std::string &ReadIntoStr) |
int | SkipLineUntil (FILE *pFile, const char EndChar) |
int | WriteKeyValue (const char *pSect, const char *pKey, const char *pBuf, bool bWarnIfNotfound=true) |
Private Attributes | |
FILE * | f |
bool | m_bFileOK |
int | m_CurCharInd |
std::vector< char > | m_CurLine |
std::string | m_fileName |
std::string | m_strIniFileUsedBy |
const int | m_vectorSize |
Used to store persistend program configuration in INI-Files. The INI-File is organized into sections and Keys (variables) like ordinary Windows INI-Files. The write functions create a temporary file in the root directory. If there is no write permission in this directory, they don't work.
IniFile::IniFile | ( | ) |
Default constructor.
Definition at line 28 of file IniFile.cpp.
IniFile::IniFile | ( | std::string | fileName | ) |
IniFile::~IniFile | ( | ) |
Definition at line 43 of file IniFile.cpp.
|
private |
Definition at line 575 of file IniFile.cpp.
|
private |
Definition at line 468 of file IniFile.cpp.
int IniFile::FindNextSection | ( | std::string * | pSect, |
std::string | prevSect, | ||
bool | bWarnIfNotfound = true |
||
) |
Find the section name after the given section. If prevSect is NULL, get the first section name.
pSect | pointer to a null ended string which will contain the section title without '[' and ']'. |
prevSect | pointer to a null ended string contraing the previous section title without '[' and ']'. |
bWarnIfNotfound | print a warning message if the section is not found. If the section is not found, the value of *sect is not defined. |
Definition at line 479 of file IniFile.cpp.
|
private |
Definition at line 533 of file IniFile.cpp.
int IniFile::GetKey | ( | const char * | pSect, |
const char * | pKey, | ||
std::string * | pStrToRead, | ||
bool | bWarnIfNotfound = true |
||
) |
Read character string from INI-File. Like Windows Fn GetProfileString().
pSect | pointer to a null ended string containing the section title without '[' and ']' |
pKey | pointer to a null ended string containing the key |
StrToRead | will contain string read If the section or the key is not found, the value of *pStrToRead remains unchanged |
Definition at line 626 of file IniFile.cpp.
int IniFile::GetKey | ( | const char * | pSect, |
const char * | pKey, | ||
int * | pValue, | ||
bool | bWarnIfNotfound = true |
||
) |
Read integer from INI-File. Like Windows Fn GetProfileInt().
Definition at line 631 of file IniFile.cpp.
int IniFile::GetKey | ( | const char * | pSect, |
const char * | pKey, | ||
bool * | pValue, | ||
bool | bWarnIfNotfound = true |
||
) |
Read boolean from INI-File. The value can be either 'true' or 'false'.
pSect | pointer to a null ended string containing the section title without '[' and ']' |
pKey | pointer to a null ended string containing the key |
pValue | pointer to boolean which will contain the value of the key. If the section or the key is not found, the value of *pValue remains unchanged |
Definition at line 637 of file IniFile.cpp.
int IniFile::GetKey | ( | const char * | pSect, |
const char * | pKey, | ||
double * | pValue, | ||
bool | bWarnIfNotfound = true |
||
) |
Read double from INI-File. Current accuracy: 9 chars!!
pSect | pointer to a null ended string containing the section title without '[' and ']' |
pKey | pointer to a null ended string containing the key |
pValue | pointer to double which will contain the value of the key. If the section or the key is not found, the vlaue of *pValue remains unchanged |
Definition at line 642 of file IniFile.cpp.
int IniFile::GetKeyBool | ( | const char * | pSect, |
const char * | pKey, | ||
bool * | pValue, | ||
bool | bWarnIfNotfound = true |
||
) |
Read boolean from INI-File. The value can be either 'true' or 'false'.
pSect | pointer to a null ended string containing the section title without '[' and ']' |
pKey | pointer to a null ended string containing the key |
pValue | pointer to boolean which will contain the value of the key. If the section or the key is not found, the value of *pValue remains unchanged |
Definition at line 215 of file IniFile.cpp.
int IniFile::GetKeyDouble | ( | const char * | pSect, |
const char * | pKey, | ||
double * | pValue, | ||
bool | bWarnIfNotfound = true |
||
) |
Read double from INI-File. Current accuracy: 9 chars!!
pSect | pointer to a null ended string containing the section title without '[' and ']' |
pKey | pointer to a null ended string containing the key |
pValue | pointer to double which will contain the value of the key. If the section or the key is not found, the vlaue of *pValue remains unchanged |
Definition at line 297 of file IniFile.cpp.
int IniFile::GetKeyDouble | ( | const char * | pSect, |
const char * | pKey, | ||
double * | pValue, | ||
double | dDefault, | ||
bool | bWarnIfNotfound = true |
||
) |
Read double from INI-File. Current accuracy: 9 chars!!
pSect | pointer to a null ended string containing the section title without '[' and ']' |
pKey | pointer to a null ended string containing the key |
pValue | pointer to double which will contain the value of the key. If the section or the key is not found, the vlaue of *pValue remains unchanged |
Definition at line 313 of file IniFile.cpp.
int IniFile::GetKeyInt | ( | const char * | pSect, |
const char * | pKey, | ||
int * | pValue, | ||
bool | bWarnIfNotfound = true |
||
) |
Read integer from INI-File. Like Windows Fn GetProfileInt().
Definition at line 241 of file IniFile.cpp.
int IniFile::GetKeyLong | ( | const char * | pSect, |
const char * | pKey, | ||
long * | pValue, | ||
bool | bWarnIfNotfound = true |
||
) |
Read long from INI-File.
Definition at line 285 of file IniFile.cpp.
int IniFile::GetKeyString | ( | const char * | pSect, |
const char * | pKey, | ||
std::string * | pStrToRead, | ||
bool | bWarnIfNotfound = true |
||
) |
Read character string from INI-File. Like Windows Fn GetProfileString().
pSect | pointer to a null ended string containing the section title without '[' and ']' |
pKey | pointer to a null ended string containing the key |
pStrToRead | will contain string read If the section or the key is not found, the value of *pStrToRead remains unchanged |
Definition at line 373 of file IniFile.cpp.
|
private |
Read character string from INI-File. Like Windows Fn GetProfileString().
pSect | pointer to a null ended string containing the section title without '[' and ']' |
pKey | pointer to a null ended string containing the key |
pBuf | pointer to a character buffer of length lenBuf string which will contain the value of the key. If the section or the key is not found, the vlaue of *pBuf remains unchanged |
lenBuf | the maximal length of szBuf (including terminating \0). |
Definition at line 320 of file IniFile.cpp.
|
private |
Reads chars in line until Endchar into string. return: - Nr of chars read if successful
Definition at line 449 of file IniFile.cpp.
int IniFile::SetFileName | ( | std::string | fileName, |
std::string | strIniFileUsedBy = "" , |
||
bool | bCreate = false |
||
) |
Sets file path of ini-file. Also verifies that file exists.
fileName | file name |
strIniFileUsedBy | the name of the source file using the ini-file. This name will be printed if an error occurs. |
bCreate | if true: create new file if the file does not exist (default: false) |
Definition at line 47 of file IniFile.cpp.
|
private |
Skips chars in line until Endchar. return: - Nr of chars skipped if successful
Definition at line 432 of file IniFile.cpp.
int IniFile::WriteKeyBool | ( | const char * | pSect, |
const char * | pKey, | ||
bool | bValue, | ||
bool | bWarnIfNotfound = true |
||
) |
Read boolean from INI-File. The value writen will be either 'true' or 'false'.
pSect | pointer to a null ended string containing the section title without '[' and ']' |
pKey | pointer to a null ended string containing the key |
pValue | pointer to boolean which will contain the value of the key. If the section or the key is not found, the value of *pValue remains unchanged |
bWarnIfNotfound | print a warning message if the section is not found and therefore is created newly. |
Definition at line 193 of file IniFile.cpp.
int IniFile::WriteKeyDouble | ( | const char * | pSect, |
const char * | pKey, | ||
double | dValue, | ||
int | StringLen = 12 , |
||
int | decimals = 5 , |
||
bool | bWarnIfNotfound = true |
||
) |
Write double to INI-File. Comments in the same line as the variables will be deleted during write operations.
pSect | pointer to a null ended string containing the section title without '[' and ']' |
pKey | pointer to a null ended string containing the key |
dValue | double to write. |
StringLen | total length of string into which the double will be converted |
decimals | of double to store |
bWarnIfNotfound | print a warning message if the section is not found and therefore is created newly. |
Definition at line 207 of file IniFile.cpp.
int IniFile::WriteKeyInt | ( | const char * | pSect, |
const char * | pKey, | ||
int | nValue, | ||
bool | bWarnIfNotfound = true |
||
) |
Write integer to INI-File. Like Windows Fn WriteProfileInt(). Comments in the same line as the variables will be deleted during write operations.
pSect | pointer to a null ended string containing the section title without '[' and ']' |
pKey | pointer to a null ended string containing the key |
nValue | integer to write. |
bWarnIfNotfound | print a warning message if the section is not found and therefore is created newly. |
Definition at line 200 of file IniFile.cpp.
int IniFile::WriteKeyString | ( | const char * | pSect, |
const char * | pKey, | ||
const std::string * | pStrToWrite, | ||
bool | bWarnIfNotfound = true |
||
) |
Write character string to INI-File. Like Windows Fn WriteProfileString(). Comments in the same line as the variables will be deleted during write operations.
pSect | pointer to a null ended string containing the section title without '[' and ']' |
pKey | pointer to a null ended string containing the key |
StrToWrite | null ended string to write. |
bWarnIfNotfound | print a warning message if the section is not found and therefore is created newly. |
Definition at line 71 of file IniFile.cpp.
|
private |
Write character string to INI-File. Like Windows Fn WriteProfileString().
pSect | pointer to a null ended string containing the section title without '[' and ']' |
pKey | pointer to a null ended string containing the key |
pBuf | null ended string to write. |
bWarnIfNotfound | print a warning message if the section is not found and therefore is created newly. |
Definition at line 77 of file IniFile.cpp.
|
private |
|
private |
|
private |