#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, double *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, int *pValue, bool bWarnIfNotfound=true) |
int | GetKey (const char *pSect, const char *pKey, std::string *pStrToRead, 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, double dDefault, bool bWarnIfNotfound=true) |
int | GetKeyDouble (const char *pSect, const char *pKey, double *pValue, 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 (std::string fileName) | |
IniFile () | |
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.
[section1] key11=234 key12=yellow submarine key13=13.5 [section2] key21= key22=13
Definition at line 97 of file IniFile.h.
IniFile::IniFile | ( | ) |
Default constructor.
Definition at line 64 of file IniFile.cpp.
IniFile::IniFile | ( | std::string | fileName | ) |
IniFile::~IniFile | ( | ) |
Definition at line 79 of file IniFile.cpp.
int IniFile::FindKey | ( | const char * | skey, | |
bool | bWarnIfNotfound = true | |||
) | [private] |
Definition at line 611 of file IniFile.cpp.
int IniFile::FindNextLine | ( | std::vector< char > & | NewLine, | |
int & | CharInd | |||
) | [private] |
Definition at line 504 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 515 of file IniFile.cpp.
int IniFile::FindSection | ( | const char * | sect, | |
bool | bWarnIfNotfound = true | |||
) | [private] |
Definition at line 569 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 678 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 673 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 667 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 662 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 251 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 349 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 333 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 277 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 321 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 409 of file IniFile.cpp.
int IniFile::GetKeyValue | ( | const char * | pSect, | |
const char * | pKey, | |||
char * | pBuf, | |||
int | lenBuf, | |||
bool | bWarnIfNotfound = true | |||
) | [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 ). |
Definition at line 356 of file IniFile.cpp.
int IniFile::ReadLineUntil | ( | FILE * | pFile, | |
const char | EndChar, | |||
std::string & | ReadIntoStr | |||
) | [private] |
Reads chars in line until Endchar into string. return: - Nr of chars read if successful
Definition at line 485 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 83 of file IniFile.cpp.
int IniFile::SkipLineUntil | ( | FILE * | pFile, | |
const char | EndChar | |||
) | [private] |
Skips chars in line until Endchar. return: - Nr of chars skipped if successful
Definition at line 468 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 229 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 243 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 236 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 107 of file IniFile.cpp.
int IniFile::WriteKeyValue | ( | const char * | pSect, | |
const char * | pKey, | |||
const char * | pBuf, | |||
bool | bWarnIfNotfound = true | |||
) | [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 113 of file IniFile.cpp.
FILE* IniFile::f [private] |
bool IniFile::m_bFileOK [private] |
int IniFile::m_CurCharInd [private] |
std::vector<char> IniFile::m_CurLine [private] |
std::string IniFile::m_fileName [private] |
std::string IniFile::m_strIniFileUsedBy [private] |
const int IniFile::m_vectorSize [private] |