00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00028
00029 #define YASAGUI_PARSER_INCLUDE
00030
00031 #include <yasagui/yasagui.h>
00032 #include <qobject.h>
00033 #include <qtextstream.h>
00034 #include <qfile.h>
00035
00036 #include "translations.h"
00037 #include "config.h"
00038 #include "datatypes.h"
00039
00041 class YSet;
00042 class YObject;
00043
00044
00046 class YInputParser
00047 {
00048 public:
00049 YInputParser()
00050 {}
00051 virtual ~YInputParser()
00052 {}
00053 virtual int CheckSectionStart(const CONFIG_STRING sectionkey)=0;
00054 virtual int SectionEnd() { return 0; }
00055 virtual int NewSection(const CONFIG_STRING newsectionkey, YObject &entry)=0;
00056 virtual int NewSectionSet(const CONFIG_STRING newsectionkey, YSet &set)=0;
00057 virtual int ReadContentString(QString &target)=0;
00058 virtual int ReadContentInt(int &target)=0;
00059 virtual int ReadContentObject(YDerivedObject &target)=0;
00060 virtual int ReadContentState(bool &target)=0;
00061 };
00062
00064 class YXMLInputParser : public YInputParser
00065 {
00066 QFile file;
00067 QString key;
00068 QString keyerror;
00069 QString doctype;
00070 CONFIG_STRING sectionkey;
00071 bool cancelparsing;
00072 QTextStream *configstream;
00073 int linenumber;
00074 int columnnumber;
00075 int SetConfig();
00076 int GetConfig();
00077 int ReadInterpretedChar(QChar &b);
00078 bool CheckEndingDelimiter(QChar &b);
00079 bool CheckNewLine(QChar &b);
00080 bool CheckOpeningTag(QChar &b);
00081 bool CheckClosingTag(QChar &b);
00082 bool CheckTag(QChar &b);
00083 int IgnoreSpaces(QChar &b);
00084 int ReadStartKey(QString &key);
00085 int ReadEndKey(QString &key);
00086 int ReadString(QString &target, QChar &c);
00087 bool CheckEnd();
00088 int ReadHeader();
00089 int ReadFinal();
00090 int ParseSection(YObject &yconfig);
00091 void ParseError(int &retvalue);
00092
00093 public:
00094 YXMLInputParser(const QString &dt) :
00095 doctype(dt.lower()),
00096 sectionkey(0),
00097 cancelparsing(true),
00098 configstream(0),
00099 linenumber(0),
00100 columnnumber(0)
00101 {}
00102 virtual ~YXMLInputParser()
00103 {}
00104 virtual int CheckSectionStart(const CONFIG_STRING sectionkey);
00105 virtual int NewSection(const CONFIG_STRING sectionkey, YObject &entry);
00106 virtual int NewSectionSet(const CONFIG_STRING sectionkey, YSet &set);
00107 virtual int ReadContentString(QString &target);
00108 virtual int ReadContentInt(int &target);
00109 virtual int ReadContentObject(YDerivedObject &target);
00110 virtual int ReadContentState(bool &target);
00111 int Parse(const QString &filename, YObject &yobject);
00112 };
00113
00114
00115
00116
00117
00118
00119
00121 class YOutputParser
00122 {
00123 public: YOutputParser()
00124 {}
00125 virtual int WriteContentString(const CONFIG_STRING key, const QString &s) =0;
00126 virtual int WriteContentInt(const CONFIG_STRING key, int value) =0;
00127 virtual int WriteContentObject(const CONFIG_STRING key, const YDerivedObject &object) =0;
00128 virtual int WriteContentState(const CONFIG_STRING key, bool state) =0;
00129
00130 virtual int NewSection(const CONFIG_STRING newsectionsetkey, YObject &yobject ) =0;
00131 virtual int NewSectionSet(const CONFIG_STRING newsectionkey, YSet &yset ) =0;
00132 virtual int SectionEnd() { return 0; }
00133 };
00134
00136 class YXMLOutputParser : public YOutputParser
00137 {
00138 int hierarchy;
00139 QTextStream *configstream;
00140 int WriteKey(const CONFIG_STRING key, const QString &str);
00141 int WriteStartKey(const CONFIG_STRING key);
00142 int WriteEndKey(const CONFIG_STRING key);
00143 inline int WriteTabs();
00144 inline int WriteNewLine();
00145 inline int WriteSetStartKey(const CONFIG_STRING key);
00146 inline int WriteSetEndKey(const CONFIG_STRING key);
00147 virtual int WriteHeader();
00148 virtual int WriteFinal();
00149 void SPrintfInt64(QString &str, unsigned INT64 time);
00150 public:
00151 YXMLOutputParser() :
00152 hierarchy(0),
00153 configstream(0)
00154 {}
00155 virtual int WriteContentString(const CONFIG_STRING key, const QString &s);
00156 virtual int WriteContentInt(const CONFIG_STRING key, int value);
00157 virtual int WriteContentObject(const CONFIG_STRING key, const YDerivedObject &object);
00158 virtual int WriteContentState(const CONFIG_STRING key, bool state);
00159
00160 virtual int NewSection(const CONFIG_STRING newsectionsetkey, YObject &yobject );
00161 virtual int NewSectionSet(const CONFIG_STRING newsectionkey, YSet &yset );
00162 virtual int Parse(YObject &yobject, const QString &filename);
00163 };
00164
00165
00167 #endif // ifndef YASAGUI_PARSER_INCLUDE