Public Member Functions | Private Member Functions | Private Attributes
IniFile Class Reference

#include <IniFile.h>

List of all members.

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

Detailed Description

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.

sections:
identifcator between '[' and ']', a section headline must not have blanks at the beginning neither right after or before the '[ ]'.
sections contains keys:
identificator followed by '=' and the value, no blanks at the beginning of the line, nor after the '=' sign or between key and '=' sign. the pBuf will contain the eventual blanks after the '=' sign.
example:
        [section1]

        key11=234
        key12=yellow submarine
        key13=13.5

        [section2]

        key21=
        key22=13

Definition at line 61 of file IniFile.h.


Constructor & Destructor Documentation

Default constructor.

Definition at line 28 of file IniFile.cpp.

IniFile::IniFile ( std::string  fileName)

Constructor.

Parameters:
fileNamefile name.

Definition at line 35 of file IniFile.cpp.

Definition at line 43 of file IniFile.cpp.


Member Function Documentation

int IniFile::FindKey ( const char *  skey,
bool  bWarnIfNotfound = true 
) [private]

Definition at line 575 of file IniFile.cpp.

int IniFile::FindNextLine ( std::vector< char > &  NewLine,
int &  CharInd 
) [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.

Parameters:
pSectpointer to a null ended string which will contain the section title without '[' and ']'.
prevSectpointer to a null ended string contraing the previous section title without '[' and ']'.
bWarnIfNotfoundprint 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.

int IniFile::FindSection ( const char *  sect,
bool  bWarnIfNotfound = true 
) [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().

Parameters:
pSectpointer to a null ended string containing the section title without '[' and ']'
pKeypointer to a null ended string containing the key
StrToReadwill 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'.

Parameters:
pSectpointer to a null ended string containing the section title without '[' and ']'
pKeypointer to a null ended string containing the key
pValuepointer 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!!

Parameters:
pSectpointer to a null ended string containing the section title without '[' and ']'
pKeypointer to a null ended string containing the key
pValuepointer 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'.

Parameters:
pSectpointer to a null ended string containing the section title without '[' and ']'
pKeypointer to a null ended string containing the key
pValuepointer 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!!

Parameters:
pSectpointer to a null ended string containing the section title without '[' and ']'
pKeypointer to a null ended string containing the key
pValuepointer 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!!

Parameters:
pSectpointer to a null ended string containing the section title without '[' and ']'
pKeypointer to a null ended string containing the key
pValuepointer 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().

Parameters:
pSectpointer to a null ended string containing the section title without '[' and ']'
pKeypointer to a null ended string containing the key
pStrToReadwill 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.

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().

Parameters:
pSectpointer to a null ended string containing the section title without '[' and ']'
pKeypointer to a null ended string containing the key
pBufpointer 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
lenBufthe maximal length of szBuf (including terminating \0).
Returns:
the length of the string read or RF_E if error

Definition at line 320 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

  • RF_E if end of line (
    ) or end of file before Endchar is found. In this case, the string will contain the chars read so far.

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.

Parameters:
fileNamefile name
strIniFileUsedBythe name of the source file using the ini-file. This name will be printed if an error occurs.
bCreateif true: create new file if the file does not exist (default: false)
Returns:
0 if file exists or new file has been created sucesfully

Definition at line 47 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

  • RF_E if end of line (
    ) or end of file before Endchar is found

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'.

Parameters:
pSectpointer to a null ended string containing the section title without '[' and ']'
pKeypointer to a null ended string containing the key
pValuepointer 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
bWarnIfNotfoundprint 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.

Parameters:
pSectpointer to a null ended string containing the section title without '[' and ']'
pKeypointer to a null ended string containing the key
dValuedouble to write.
StringLentotal length of string into which the double will be converted
decimalsof double to store
bWarnIfNotfoundprint 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.

Parameters:
pSectpointer to a null ended string containing the section title without '[' and ']'
pKeypointer to a null ended string containing the key
nValueinteger to write.
bWarnIfNotfoundprint 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.

Parameters:
pSectpointer to a null ended string containing the section title without '[' and ']'
pKeypointer to a null ended string containing the key
StrToWritenull ended string to write.
bWarnIfNotfoundprint a warning message if the section is not found and therefore is created newly.

Definition at line 71 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().

Parameters:
pSectpointer to a null ended string containing the section title without '[' and ']'
pKeypointer to a null ended string containing the key
pBufnull ended string to write.
bWarnIfNotfoundprint a warning message if the section is not found and therefore is created newly.

Definition at line 77 of file IniFile.cpp.


Member Data Documentation

FILE* IniFile::f [private]

Definition at line 301 of file IniFile.h.

bool IniFile::m_bFileOK [private]

Definition at line 282 of file IniFile.h.

int IniFile::m_CurCharInd [private]

Index of the current character in the current line.

Definition at line 297 of file IniFile.h.

std::vector<char> IniFile::m_CurLine [private]

Vector to store the chars of the most recently read line.

Definition at line 287 of file IniFile.h.

std::string IniFile::m_fileName [private]

Definition at line 299 of file IniFile.h.

std::string IniFile::m_strIniFileUsedBy [private]

Definition at line 300 of file IniFile.h.

const int IniFile::m_vectorSize [private]

Size of the vector CurLine.

Definition at line 292 of file IniFile.h.


The documentation for this class was generated from the following files:


cob_utilities
Author(s): Christian Connette
autogenerated on Sat Jun 8 2019 21:02:25