#include "keyb.h"
#define TRUESTR "TRUE"
#define FALSESTR "FALSE"
/**
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.
@author Werner Schulte (email : werner@schulte-ac.de, homepage : www.uv-ac.de)
@version 0.2.0 - sc - 05.09.2003
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>
**/
class ScQtIOUtil
{
public:
/** breaks a line of the format
aaa=bbb; ccc
into the strings left, rigth and comment provided
as public QStrings.
@p st1 : the string to be splitted
@return : 0, if OK, negative else
**/
int GetCFGTerm( const QString &st1 );
/** 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.
@p fil : the file to be searched
@p ts : the textstream to be set
@p sectio : the section to be searched
@p 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.
@return : 0, if OK, negative else
**/
int FindSection( QFile *fil=0, QTextStream *ts=0, const QString §io="", bool fromstart=true );
/** 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.
@p fil : the file to be searched
@p ts : the textstream to be set
@p 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.
@return : an empty string,in no section was found
the sections content (e.g. COMMON)
**/
QString &FindNextSection( QFile *fil=0, QTextStream *ts=0, bool fromstart=false );
/** Writes an entry containing a string.
Format is
left=right;
@p ts : the textstream to write to
@p left : entryname which is written
@p right : entrycontent which is written
@return : always 0
**/
int WriteEntry( QTextStream *ts, const QString &left, const QString &right );
/** Writes an entry containing an integer.
Format is
sprintf( "%s=format;\n", left, val ) ;
format specifies the format to be written (printf syntax).
@p ts : the textstream to write to
@p left : entryname which is written
@p val : the value to be written
@p format : the format string to be used
@return : always 0
**/
int WriteEntry( QTextStream *ts, const QString &left, int val, const QString &format );
/** Writes an entry containing an unsigned integer.
Format is
sprintf( "%s=format;\n", left, val ) ;
format specifies the format to be written (printf syntax).
@p ts : the textstream to write to
@p left : entryname which is written
@p val : the value to be written
@p format : the format string to be used
@return : always 0
**/
int WriteEntry( QTextStream *ts, const QString &left, unsigned int val, const QString &format );
/** Writes an entry containing a short.
Format is
sprintf( "%s=format;\n", left, val ) ;
format specifies the format to be written (printf syntax).
@p ts : the textstream to write to
@p left : entryname which is written
@p val : the value to be written
@p format : the format string to be used
@return : always 0
**/
int WriteEntry( QTextStream *ts, const QString &left, short val, const QString &format );
/** Writes an entry containing an unsigned short.
Format is
sprintf( "%s=format;\n", left, val ) ;
format specifies the format to be written (printf syntax).
@p ts : the textstream to write to
@p left : entryname which is written
@p val : the value to be written
@p format : the format string to be used
@return : always 0
**/
int WriteEntry( QTextStream *ts, const QString &left, unsigned short val, const QString &format );
/** Writes an entry containing a long.
Format is
sprintf( "%s=format;\n", left, val ) ;
format specifies the format to be written (printf syntax).
@p ts : the textstream to write to
@p left : entryname which is written
@p val : the value to be written
@p format : the format string to be used
@return : always 0
**/
int WriteEntry( QTextStream *ts, const QString &left, long val, const QString &format );
/** Writes an entry containing an unsigned long.
Format is
sprintf( "%s=format;\n", left, val ) ;
format specifies the format to be written (printf syntax).
@p ts : the textstream to write to
@p left : entryname which is written
@p val : the value to be written
@p format : the format string to be used
@return : always 0
**/
int WriteEntry( QTextStream *ts, const QString &left, unsigned long val, const QString &format );
/** Writes an entry containing a float.
Format is
sprintf( "%s=format;\n", left, val ) ;
format specifies the format to be written (printf syntax).
@p ts : the textstream to write to
@p left : entryname which is written
@p val : the value to be written
@p format : the format string to be used
@return : always 0
**/
int WriteEntry( QTextStream *ts, const QString &left, float val, const QString &format );
/** Writes an entry containing a double.
Format is
sprintf( "%s=format;\n", left, val ) ;
format specifies the format to be written (printf syntax).
@p ts : the textstream to write to
@p left : entryname which is written
@p val : the value to be written
@p format : the format string to be used
@return : always 0
**/
int WriteEntry( QTextStream *ts, const QString &left, double val, const QString &format );
/** Writes an entry containing a boolean.
Format is
sprintf( "%s=TRUE;\n", left ) ; // if bval true
sprintf( "%s=FALSE;\n", left ) ; // if bval false
@p ts : the textstream to write to
@p left : entryname which is written
@p bval : the value to be written
@return : always 0
**/
int WriteEntry( QTextStream *ts, const QString &left, bool bval );
/** Writes an entry containing a QColor info.
Format is
sprintf( "%s=%d,%d,%d\n", left,
col.red(), col.green(), col.blue() );
@p ts : the textstream to write to
@p left : entryname which is written
@p col : the color to be written in rgb format
@return : always 0
**/
int WriteEntry( QTextStream *ts, const QString &left, const QColor &col );
/** Writes an entry containing a QDate info.
Format is
sprintf( "%s=%d,%d,%d\n", left,
dat.year(), dat.month(), dat.day() );
@p ts : the textstream to write to
@p left : entryname which is written
@p col : the date to be written
@return : always 0
**/
int WriteEntry( QTextStream *ts, const QString &left, const QDate &dat );
/** Writes an entry containing a QTime info.
Format is
sprintf( "%s=%d,%d,%d\n", left,
tim.hour(), tim.minute(), tim.second() );
@p ts : the textstream to write to
@p left : entryname which is written
@p col : the time to be written
@return : always 0
**/
int WriteEntry( QTextStream *ts, const QString &left, const QDateTime &dattim );
/** 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() );
@p ts : the textstream to write to
@p left : entryname which is written
@p col : the datetime to be written
@return : always 0
**/
int WriteEntry( QTextStream *ts, const QString &left, const QTime &tim );
/** Converts the string right into the appropriate format.
@p right : the string to be converted (nothing happens here with the string)
@return : the string
**/
QString GetEntryString( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : the char
**/
char GetEntryChar( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : the unsigned signed char
**/
unsigned char GetEntryUChar( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : the int
**/
int GetEntryInt( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : the unsigned int
**/
unsigned int GetEntryUInt( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : the short
**/
short GetEntryShort( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : the unsigned short
**/
unsigned short GetEntryUShort( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : the long
**/
long GetEntryLong( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : the unsigned long
**/
unsigned long GetEntryULong( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : the float
**/
float GetEntryFloat( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : the double
**/
double GetEntryDouble( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : TRUE or FALSE
**/
bool GetEntryBool( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : the QColor
**/
QColor &GetEntryColor( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : the QDate
**/
QDate &GetEntryDate( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : the QTime
**/
QTime &GetEntryTime( const QString &right );
/** Converts the string right into the appropriate format.
@p right : the string to be converted
@return : the QDateTime
**/
QDateTime &GetEntryDateTime( const QString &right );
/** constructor */
ScQtIOUtil();
/** destructor */
~ScQtIOUtil();
QString left, separator, right, comment;
};
#endif
| Generated by: sc on schomep4 on Sun Nov 23 16:54:26 2003, using kdoc 2.0a54. |