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 97 of file IniFile.h.


Constructor & Destructor Documentation

Default constructor.

Definition at line 64 of file IniFile.cpp.

IniFile::IniFile ( std::string  fileName)

Constructor.

Parameters:
fileNamefile name.

Definition at line 71 of file IniFile.cpp.

Definition at line 79 of file IniFile.cpp.


Member Function Documentation

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.

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 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,
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 662 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,
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 673 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 678 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 251 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 333 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 349 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().

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

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

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

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

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

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

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

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

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

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

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 113 of file IniFile.cpp.


Member Data Documentation

FILE* IniFile::f [private]

Definition at line 337 of file IniFile.h.

bool IniFile::m_bFileOK [private]

Definition at line 318 of file IniFile.h.

int IniFile::m_CurCharInd [private]

Index of the current character in the current line.

Definition at line 333 of file IniFile.h.

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

Definition at line 323 of file IniFile.h.

std::string IniFile::m_fileName [private]

Definition at line 335 of file IniFile.h.

std::string IniFile::m_strIniFileUsedBy [private]

Definition at line 336 of file IniFile.h.

const int IniFile::m_vectorSize [private]

Size of the vector CurLine.

Definition at line 328 of file IniFile.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


cob_utilities
Author(s): Christian Connette
autogenerated on Fri Mar 1 2013 17:46:19