Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Examples  

parser.h

Go to the documentation of this file.
00001 
00002 //
00003 // YASA XML configuration parser
00004 //
00005 // Project: Yasa 2
00006 // Author : Jan Blumenthal
00007 // Start  : 2002/02/28
00008 // $Header: /sources/yasa/yasagui/parser.h,v 1.4 2003/01/24 15:47:42 bj Exp $
00009 //
00011 //
00012 // This program is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU General Public License as published by
00014 // the Free Software Foundation; either version 2 of the License, or
00015 // (at your option) any later version.
00016 //
00017 // This program is distributed in the hope that it will be useful,
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU General Public License
00023 // along with this program (See the included file COPYING);
00024 // if not, write to the Free Software Foundation, Inc.,
00025 // 675 Mass Ave, Cambridge, MA 02139, USA.
00026 //
00028 #ifndef YASAGUI_PARSER_INCLUDE
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

Generated on Thu Feb 13 23:43:55 2003 for Yasa by doxygen1.3-rc3