00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __MorkParser_h__
00030 #define __MorkParser_h__
00031
00032 #include <QMap>
00033 #include <QByteArray>
00034 class QString;
00035
00036
00037
00038 typedef QMap< int, std::string > MorkDict;
00039 typedef QMap< int, int > MorkCells;
00040 typedef QMap< int, MorkCells > MorkRowMap;
00041 typedef QMap< int, MorkRowMap > RowScopeMap;
00042 typedef QMap< int, RowScopeMap > MorkTableMap;
00043 typedef QMap< int, MorkTableMap > TableScopeMap;
00044
00045
00046 const char MorkMagicHeader[] = "// <!-- <mdb:mork:z v=\"1.4\"/> -->";
00047
00048 const char MorkDictColumnMeta[] = "<(a=c)>";
00049
00050
00051 enum MorkErrors
00052 {
00053 NoError = 0,
00054 FailedToOpen,
00055 UnsupportedVersion,
00056 DefectedFormat
00057 };
00058
00059
00060 enum MorkTerm
00061 {
00062 NoneTerm = 0,
00063 DictTerm,
00064 GroupTerm,
00065 TableTerm,
00066 RowTerm,
00067 CellTerm,
00068 CommentTerm,
00069 LiteralTerm
00070 };
00071
00072
00074
00075 class MorkParser
00076 {
00077 public:
00078
00079 MorkParser( int defaultScope = 0x80 );
00080
00083
00084 bool open( const QString &path );
00085
00088
00089 MorkErrors error();
00090
00093
00094 MorkTableMap *getTables( int tableScope );
00095
00098
00099 MorkRowMap *getRows( int rowScope, RowScopeMap *table );
00100
00103
00104 std::string &getValue( int oid );
00105
00108
00109 std::string &getColumn( int oid );
00110
00111 #ifndef QT_NO_DEBUG
00112 void debugWrite( const QString &path );
00113 #endif // QT_NO_DEBUG
00114
00115
00116 protected:
00117
00118 void initVars();
00119
00120 bool isWhiteSpace( char c );
00121 char nextChar();
00122
00123 void parseScopeId( const std::string &TextId, int *Id, int *Scope );
00124 void setCurrentRow( int TableScope, int TableId, int RowScope, int RowId );
00125
00126
00127 bool parse();
00128 bool parseDict();
00129 bool parseComment();
00130 bool parseCell();
00131 bool parseTable();
00132 bool parseMeta( char c );
00133 bool parseRow( int TableId, int TableScope );
00134 bool parseGroup();
00135
00136 protected:
00137
00138
00139 MorkDict columns_;
00140 MorkDict values_;
00141
00142
00143 TableScopeMap mork_;
00144 MorkCells *currentCells_;
00145
00146
00147 MorkErrors error_;
00148
00149
00150 QByteArray morkData_;
00151
00152 int morkPos_;
00153 int nextAddValueId_;
00154 int defaultScope_;
00155
00156
00157 enum { NPColumns, NPValues, NPRows } nowParsing_;
00158
00159 };
00160
00161 #endif // __MorkParser_h__
00162