|
| File () |
|
| File (const std::string &rsFullFileName, TdOpenInifileMode openMode) |
|
virtual | ~File () |
|
int | getAsBlob (eut::Blob *&prBlob) |
|
std::string | getFileName () |
|
int | getKeyValue (std::string &rsValue, std::string *psSection, std::string *psKey) |
|
int | getLine (Line *&prRetVal, std::size_t nPosition, ptl::SeekMode eMode) |
|
int | getLine (Line *&prRetVal, std::string *psSection, std::string *psKey=0) |
|
int | insertLine (Line *pIniLine, ptl::InsertPosition eInsertPosition=ptl::InsertCURRENT, ptl::VH eBeforeBehind=ptl::BEHIND) |
|
int | makeLines (eut::Blob *pBlob) |
|
int | refresh () |
|
int | removeKey (const std::string &rsSection, const std::string &rsKey) |
|
int | removeLine (ptl::ElementPosition eFirstLastCurrent=ptl::CURRENT_POS) |
|
void | setFullFileName (const std::string &rsFullFileName) |
|
int | setKeyValue (const std::string &rsSection, const std::string &rsKey, const std::string &rsValue) |
|
int | store () |
|
An INI file contains information for programs.
An INI file can contain sections with variables and values and comments. The information can be created, read and maintained with ini::File.
Code snippets
In the following an INI file "test.ini" is created:
#include <iostream>
int main(int argc, char *argv[])
{
int t_iErr = 0;
try
{
}
{
std::cout <<
"Error :" << ERR.what() <<
"ErrNo.:" << ERR.
error() << std::endl;
}
if ( ! t_iErr ) t_iErr = t_pIniFile->
setKeyValue(
"[Section 1]",
"Key 1.1",
"Value 1.1" );
if ( ! t_iErr ) t_iErr = t_pIniFile->
setKeyValue(
"[Section 1]",
"Key 1.2",
"Value 1.2" );
if ( ! t_iErr ) t_iErr = t_pIniFile->
setKeyValue(
"[Section 2]",
"Key 2.1",
"Value 2.1" );
if ( ! t_iErr ) t_iErr = t_pIniFile->
setKeyValue(
"[Section 2]",
"Key 2.2",
"Value 2.2" );
try
{
t_pCommentLine =
new ini::Line(
"; comment 1" );
}
{
std::cout <<
"Error :" << ERR.what() <<
"ErrNo.:" << ERR.
error() << std::endl;
}
if ( ! t_iErr )
{
t_iErr = t_pIniFile->
insertLine( t_pCommentLine );
}
if ( ! t_iErr ) t_iErr = t_pIniFile->
setKeyValue(
"",
"Lonly Key 1",
"Value 1" );
if ( ! t_iErr ) t_iErr = t_pIniFile->
store();
delete t_pIniFile; t_pIniFile = 0;
}
Header for ErrorNException
This exception class has an integer attribute for an error number in addition to the message.
Definition EuException.h:73
int error() const
Definition EuException.h:276
An INI file contains information for programs.
Definition IniFile.h:313
int insertLine(Line *pIniLine, ptl::InsertPosition eInsertPosition=ptl::InsertCURRENT, ptl::VH eBeforeBehind=ptl::BEHIND)
int setKeyValue(const std::string &rsSection, const std::string &rsKey, const std::string &rsValue)
Is a comment line, but also superclass for Section and Key.
Definition IniLine.h:77
const TdOpenInifileMode bCreateInifile
Definition IniFileTypes.h:213
The INI file "test.ini" has the following contents:
[Section 1]
Key 1.1=Value 1.1
Key 1.2=Value 1.2
[Section 2]
Key 2.1=Value 2.1
Key 2.2=Value 2.2
; comment 1
Lonly Key 1=Value 1
In the INI file "test.ini" the key "Key 1.2" is fetched from the section "[Section 1]", displayed and changed to "new Value":
#include <iostream>
int main(int argc, char *argv[])
{
int t_iErr = 0;
try
{
}
{
std::cout <<
"Error :" << ERR.what() <<
"ErrNo.:" << ERR.
error() << std::endl;
}
std::string t_sValue,
t_sSection2( "[Section 1]" ),
t_sKey( "Key 1.2" );
t_iErr = t_pIniFile->
getKeyValue( t_sValue, & t_sSection2, & t_sKey );
if ( ! t_iErr ) std::cout << "The value from 'Section 1', 'Key 1.2' is: " << t_sValue << std::endl;
if ( ! t_iErr ) t_iErr = t_pIniFile->
setKeyValue(
"[Section 1]",
"Key 1.2",
"new Value" );
if ( ! t_iErr ) t_iErr = t_pIniFile->
store();
delete t_pIniFile; t_pIniFile = 0;
}
int getKeyValue(std::string &rsValue, std::string *psSection, std::string *psKey)
const TdOpenInifileMode bOpenInifile
Definition IniFileTypes.h:227
The INI file "test.ini" now has the following content:
[Section 1]
Key 1.1=Value 1.1
Key 1.2=new Value
[Section 2]
Key 2.1=Value 2.1
Key 2.2=Value 2.2
; comment 1
Lonly Key 1=Value 1
All entries can be identified...
#include <iostream>
int main(int argc, char *argv[])
{
int t_iErr = 0;
try
{
}
{
std::cout <<
"Error :" << ERR.what() <<
"ErrNo.:" << ERR.
error() << std::endl;
}
std::cout <<
"############# " << t_pIniFile->
getFileName() <<
" #############" << std::endl;
while ( t_pShowLine )
{
std::cout << t_pShowLine->
getText() << std::endl;
{
while ( t_pShowSectionLine )
{
std::cout << t_pShowSectionLine->
getText() << std::endl;
}
}
}
std::cout << "####################################" << std::endl;
std::cout << "ErrNo.:" << t_iErr << std::endl;
delete t_pIniFile; t_pIniFile = 0;
}
std::string getFileName()
int getLine(Line *&prRetVal, std::size_t nPosition, ptl::SeekMode eMode)
LINE_TYPE getType() const
std::string getText() const
A section can only appear once in an INI file, is enclosed in square brackets and usually has variabl...
Definition IniSection.h:86
int getSectionLine(Line *&prRetVal, std::size_t nPosition, ptl::SeekMode eMode)
@ ERR_RANGE
Definition EuToolErrors.h:116
@ IniSECTION
Definition IniFileTypes.h:154
@ RANGE
Definition PtlListErrors.h:214
@ CURRENT
Definition PtlListTypes.h:402
@ START
Definition PtlListTypes.h:380
... and results in the following output:
############# test.ini #############
[Section 1]
Key 1.1=Value 1.1
Key 1.2=new Value
[Section 2]
Key 2.1=Value 2.1
Key 2.2=Value 2.2
; comment 1
Lonly Key 1=Value 1
####################################
ErrNo.:0
- Author
- Helmut Jakoby
- Copyright
- © 1995 Helmut Jakoby