kstars
#include <ksparser.h>
Public Types | |
enum | DataTypes { D_QSTRING, D_INT, D_FLOAT, D_DOUBLE, D_SKIP } |
Public Member Functions | |
KSParser (const QString &filename, const char comment_char, const QList< QPair< QString, DataTypes > > &sequence, const char delimiter= ',') | |
KSParser (const QString &filename, const char comment_char, const QList< QPair< QString, DataTypes > > &sequence, const QList< int > &widths) | |
bool | HasNextRow () |
QHash< QString, QVariant > | ReadNextRow () |
void | SetProgress (QString msg, int total_lines, int step_size) |
void | ShowProgress () |
Static Public Attributes | |
static const double | EBROKEN_DOUBLE = 0.0 |
static const float | EBROKEN_FLOAT = 0.0 |
static const int | EBROKEN_INT = 0 |
static const QString | EBROKEN_QSTRING = "Null" |
Detailed Description
Generic class for text file parsers used in KStars.
Read rows using ReadCSVRow() regardless of the type of parser. Usage: 1) initialize KSParser 2) while (KSParserObject.HasNextRow()) { QHash < Qstring, QVariant > read_stuff = KSParserObject.ReadNextRow(); ... do what you need to do... ... }
Debugging Information: In case of read errors, the parsers emit a warning. In case of conversion errors, the warnings are toggled by setting const bool KSParser::parser_debug_mode_ = true; in ksparser.cpp
In case of failure, the parser returns a Dummy Row. So if you see the string "Null" in the returned QHash, it signifies the parserencountered an unexpected error.
Definition at line 49 of file ksparser.h.
Member Enumeration Documentation
enum KSParser::DataTypes |
DataTypes for building sequence D_QSTRING QString Type D_INT Integer Type D_FLOAT Floating Point Type D_DOUBLE Double PRecision Type D_SKIP Unused Field.
This string is not converted from QString
Enumerator | |
---|---|
D_QSTRING | |
D_INT | |
D_FLOAT | |
D_DOUBLE | |
D_SKIP |
Definition at line 67 of file ksparser.h.
Constructor & Destructor Documentation
KSParser::KSParser | ( | const QString & | filename, |
const char | comment_char, | ||
const QList< QPair< QString, DataTypes > > & | sequence, | ||
const char | delimiter = ',' |
||
) |
Returns a CSV parsing instance of a KSParser type object.
Behavior: 1) In case of attempt to read a non existent file, will return dummy row (not empty) 2) In case of incomplete row, the whole row is ignored 3) In case of missing values, parser will return empty string, or 0 or 0.0 4) If you keep reading ignoring the HasNextRow you get dummy rows
- Parameters
-
filename Full Path (Dir + Filename) of source file comment_char Character signifying a comment line sequence QList of QPairs of the form "field name,data type" delimiter separate on which character. default ','
Definition at line 28 of file ksparser.cpp.
KSParser::KSParser | ( | const QString & | filename, |
const char | comment_char, | ||
const QList< QPair< QString, DataTypes > > & | sequence, | ||
const QList< int > & | widths | ||
) |
Returns a Fixed Width parsing instance of a KSParser type object.
Usage: Important! The last value in width sequence is taken till the end of line by default. This is done as the last line may or may not be padded on the right. Important! For backward compatibility, all string outputs are not trimmed. Hence reading "hello " will return "hello " not "hello" If you need trimmed values like "hello" , use QString.trimmed()
Behavior: 1) In case of attempt to read a non existent file, will return dummy row (not empty!) 2) In case of missing fields at the end, the line length is smaller than expected so it is skipped. 3) If an integer or floating point value is empty (e.g. " ") it is replaced by 0 or 0.0 4) If you keep reading the file ignoring the HasNextRow(), you get Dummy Rows
- Parameters
-
filename Full Path (Dir + Filename) of source file comment_char Character signifying a comment line sequence QList of QPairs of the form "field name,data type" widths width sequence. Last value is line.length() by default Hence, sequence.length() should be (width.length()+1)
Definition at line 42 of file ksparser.cpp.
Member Function Documentation
bool KSParser::HasNextRow | ( | ) |
Returns True if there are more rows to be read.
- Returns
- bool
Definition at line 218 of file ksparser.cpp.
QHash< QString, QVariant > KSParser::ReadNextRow | ( | ) |
Generic function used to read the next row of a text file.
The contructor changes the function pointer to the appropriate function. Returns the row as <"column name", value>
- Returns
- QHash< QString, QVariant >
Definition at line 56 of file ksparser.cpp.
void KSParser::SetProgress | ( | QString | msg, |
int | total_lines, | ||
int | step_size | ||
) |
Wrapper function for KSFileReader setProgress.
- Parameters
-
msg What message to display total_lines Total number of lines in file step_size Size of step in emitting progress
- Returns
- void
Definition at line 222 of file ksparser.cpp.
void KSParser::ShowProgress | ( | ) |
Wrapper function for KSFileReader showProgress.
- Returns
- void
Definition at line 227 of file ksparser.cpp.
Member Data Documentation
|
static |
These are the values used in case of error in conversion.
Definition at line 54 of file ksparser.h.
|
static |
Definition at line 55 of file ksparser.h.
|
static |
Definition at line 56 of file ksparser.h.
|
static |
Definition at line 57 of file ksparser.h.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.