|
|
This Class provides some methods used reading config and data files organized in sections.
It is normally inherited by classes providing config- and data- file access.
It contains mainly various methods to read and write the differnt data formats.
The following global variables are used.
// GetCfgTerm sets this variables // format is // abc=defg; comment // or // abc=d,e,f; comment // the left part is stored in the string left, while // the right parts is stored in right. // the comment is stored in the comment string. QString left, separator, right, comment; |
A typical source code part is as follows.
// Read all Section lines
while ( !ts->eof() )
{
xstr = ts->readLine();
if ( ts->eof() )
break;
qstr = xstr;
if ((xstr != (char)lattenzaun)&&(xstr != (char)linefeed)&&
(xstr != (char)cr)&&(xstr != (char)blank)&&(xstr != (char)eckigeklammerauf))
{
// found an entry, disassemble it to its parts
GetCFGTerm( qstr );
if ( EXPORTPATHSTR == left )
qdata->config.exportpathstr = GetEntryString( right );
else if ( AUTOSAVESTR == left )
qdata->config.autosave = GetEntryInt( right );
...
}
...
}
pre>
|
| int GetCFGTerm ( const QString &st1 )
| GetCFGTerm |
breaks a line of the format
aaa=bbb; ccc
into the strings left, rigth and comment provided
as public QStrings.
st1 : the string to be splitted
Returns: : 0, if OK, negative else
| int FindSection ( QFile *fil=0, QTextStream *ts=0, const QString §io="", bool fromstart=true )
| FindSection |
searches for the section sectio in the file fil
and sets then textstream to the next line (first data)
A Section has the format [section] and must start the line.
fil : the file to be searched
ts : the textstream to be set
sectio : the section to be searched
fromstart : defines, whether the method searches from the start of the
file or goes ahead where it has been found the last time. Note
that this can have an major impact to runtime, if the config file
is orgarnized that way.
Returns: : 0, if OK, negative else
| QString & FindNextSection ( QFile *fil=0, QTextStream *ts=0, bool fromstart=false )
| FindNextSection |
searches for the next section found in the file fil
and sets then textstream to the next line (first data)
A Section has the format [section] and must start the line.
fil : the file to be searched
ts : the textstream to be set
fromstart : defines, whether the method searches from the start of the
file or goes ahead where it has been found the last time. Note
that this can have an major impact to runtime, if the config file
is orgarnized that way.
Returns: : an empty string,in no section was found
the sections content (e.g. COMMON)
| int WriteEntry ( QTextStream *ts, const QString &left, const QString &right )
| WriteEntry |
Writes an entry containing a string.
Format is
left=right;
ts : the textstream to write to
left : entryname which is written
right : entrycontent which is written
Returns: : always 0
| int WriteEntry ( QTextStream *ts, const QString &left, int val, const QString &format )
| WriteEntry |
Writes an entry containing an integer.
Format is
sprintf( "%s=format;\n", left, val ) ; |
format specifies the format to be written (printf syntax).
ts : the textstream to write to
left : entryname which is written
val : the value to be written
format : the format string to be used
Returns: : always 0
| int WriteEntry ( QTextStream *ts, const QString &left, unsigned int val, const QString &format )
| WriteEntry |
Writes an entry containing an unsigned integer.
Format is
sprintf( "%s=format;\n", left, val ) ; |
format specifies the format to be written (printf syntax).
ts : the textstream to write to
left : entryname which is written
val : the value to be written
format : the format string to be used
Returns: : always 0
| int WriteEntry ( QTextStream *ts, const QString &left, short val, const QString &format )
| WriteEntry |
Writes an entry containing a short.
Format is
sprintf( "%s=format;\n", left, val ) ; |
format specifies the format to be written (printf syntax).
ts : the textstream to write to
left : entryname which is written
val : the value to be written
format : the format string to be used
Returns: : always 0
| int WriteEntry ( QTextStream *ts, const QString &left, unsigned short val, const QString &format )
| WriteEntry |
Writes an entry containing an unsigned short.
Format is
sprintf( "%s=format;\n", left, val ) ; |
format specifies the format to be written (printf syntax).
ts : the textstream to write to
left : entryname which is written
val : the value to be written
format : the format string to be used
Returns: : always 0
| int WriteEntry ( QTextStream *ts, const QString &left, long val, const QString &format )
| WriteEntry |
Writes an entry containing a long.
Format is
sprintf( "%s=format;\n", left, val ) ; |
format specifies the format to be written (printf syntax).
ts : the textstream to write to
left : entryname which is written
val : the value to be written
format : the format string to be used
Returns: : always 0
| int WriteEntry ( QTextStream *ts, const QString &left, unsigned long val, const QString &format )
| WriteEntry |
Writes an entry containing an unsigned long.
Format is
sprintf( "%s=format;\n", left, val ) ; |
format specifies the format to be written (printf syntax).
ts : the textstream to write to
left : entryname which is written
val : the value to be written
format : the format string to be used
Returns: : always 0
| int WriteEntry ( QTextStream *ts, const QString &left, float val, const QString &format )
| WriteEntry |
Writes an entry containing a float.
Format is
sprintf( "%s=format;\n", left, val ) ; |
format specifies the format to be written (printf syntax).
ts : the textstream to write to
left : entryname which is written
val : the value to be written
format : the format string to be used
Returns: : always 0
| int WriteEntry ( QTextStream *ts, const QString &left, double val, const QString &format )
| WriteEntry |
Writes an entry containing a double.
Format is
sprintf( "%s=format;\n", left, val ) ; |
format specifies the format to be written (printf syntax).
ts : the textstream to write to
left : entryname which is written
val : the value to be written
format : the format string to be used
Returns: : always 0
| int WriteEntry ( QTextStream *ts, const QString &left, bool bval )
| WriteEntry |
Writes an entry containing a boolean.
Format is
sprintf( "%s=TRUE;\n", left ) ; // if bval true sprintf( "%s=FALSE;\n", left ) ; // if bval false |
ts : the textstream to write to
left : entryname which is written
bval : the value to be written
Returns: : always 0
| int WriteEntry ( QTextStream *ts, const QString &left, const QColor &col )
| WriteEntry |
Writes an entry containing a QColor info.
Format is
sprintf( "%s=%d,%d,%d\n", left, col.red(), col.green(), col.blue() ); |
ts : the textstream to write to
left : entryname which is written
col : the color to be written in rgb format
Returns: : always 0
| int WriteEntry ( QTextStream *ts, const QString &left, const QDate &dat )
| WriteEntry |
Writes an entry containing a QDate info.
Format is
sprintf( "%s=%d,%d,%d\n", left, dat.year(), dat.month(), dat.day() ); |
ts : the textstream to write to
left : entryname which is written
col : the date to be written
Returns: : always 0
| int WriteEntry ( QTextStream *ts, const QString &left, const QDateTime &dattim )
| WriteEntry |
Writes an entry containing a QTime info.
Format is
sprintf( "%s=%d,%d,%d\n", left, tim.hour(), tim.minute(), tim.second() ); |
ts : the textstream to write to
left : entryname which is written
col : the time to be written
Returns: : always 0
| int WriteEntry ( QTextStream *ts, const QString &left, const QTime &tim )
| WriteEntry |
Writes an entry containing a QDateTime info.
Format is
sprintf( "%s=%d,%d,%d,%d,%d,%d\n", left, dattim.date().year(), dattim.date().month(), dattim.date().day(), dattim.time().hour(), dattim.time().minute(), dattim.time().second() ); |
ts : the textstream to write to
left : entryname which is written
col : the datetime to be written
Returns: : always 0
| QString GetEntryString ( const QString &right )
| GetEntryString |
Converts the string right into the appropriate format.
right : the string to be converted (nothing happens here with the string)
Returns: : the string
| char GetEntryChar ( const QString &right )
| GetEntryChar |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : the char
| unsigned char GetEntryUChar ( const QString &right )
| GetEntryUChar |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : the unsigned signed char
| int GetEntryInt ( const QString &right )
| GetEntryInt |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : the int
| unsigned int GetEntryUInt ( const QString &right )
| GetEntryUInt |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : the unsigned int
| short GetEntryShort ( const QString &right )
| GetEntryShort |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : the short
| unsigned short GetEntryUShort ( const QString &right )
| GetEntryUShort |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : the unsigned short
| long GetEntryLong ( const QString &right )
| GetEntryLong |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : the long
| unsigned long GetEntryULong ( const QString &right )
| GetEntryULong |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : the unsigned long
| float GetEntryFloat ( const QString &right )
| GetEntryFloat |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : the float
| double GetEntryDouble ( const QString &right )
| GetEntryDouble |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : the double
| bool GetEntryBool ( const QString &right )
| GetEntryBool |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : TRUE or FALSE
| QColor & GetEntryColor ( const QString &right )
| GetEntryColor |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : the QColor
| QDate & GetEntryDate ( const QString &right )
| GetEntryDate |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : the QDate
| QTime & GetEntryTime ( const QString &right )
| GetEntryTime |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : the QTime
| QDateTime & GetEntryDateTime ( const QString &right )
| GetEntryDateTime |
Converts the string right into the appropriate format.
right : the string to be converted
Returns: : the QDateTime
| ScQtIOUtil ()
| ScQtIOUtil |
| ~ScQtIOUtil ()
| ~ScQtIOUtil |
| QString left | left |
| QString separator | separator |
| QString right | right |
| QString comment | comment |