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

FXXmlReader.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                  XML file reader object                                       *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2003 by Mathew Robertson.   All Rights Reserved.                *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************/
00022 #ifndef FXXMLREADER_H
00023 #define FXXMLREADER_H
00024 
00025 #ifndef FXBASEOBJECT_H
00026 #include "FXBaseObject.h"
00027 #endif
00028 namespace FXEX {
00029 
00030 /**
00031  * This XML reader is designed to generate FOX events for each valid XML tag.
00032  *
00033  * Each time a tag is encountered, any previous non-tagged data is forwarded as a
00034  * FOX message, then the tag is forwarded. It is up to the target to validate the
00035  * occurances of the tags themselves and to transpose any type of data content.
00036  * The target is often the FXXmlParser object.
00037  */
00038 class FXAPI FXXmlReader : public FXBaseObject {
00039   FXDECLARE(FXXmlReader)
00040 
00041 private:
00042   FXStream *stream;
00043   FXbool    tagMode;
00044   FXbool    state;
00045   FXString  tag;
00046   FXString  content;
00047 
00048 protected:
00049   /// for serialization
00050   FXXmlReader() : FXBaseObject() {}
00051 
00052   /// get the next item from the stream
00053   FXbool getNext(FXchar &c);
00054 
00055   /// generate a 'read error' event
00056   void readError(FXint errval);
00057 
00058 public:
00059   /// these are the error numbers that can be generated during parsing
00060   enum {
00061     ERROR_NONE=0,
00062     ERROR_UNMATCHED_CLOSE_BRACE,
00063     ERROR_LAST
00064     };
00065 
00066 public:
00067   enum {
00068     ID_XML_READER=FXBaseObject::ID_LAST,
00069     ID_LAST
00070     };
00071 
00072 public:
00073   long onParse(FXObject*,FXSelector,void*);
00074   long onGetIntValue(FXObject*,FXSelector,void*);
00075   long onSetIntValue(FXObject*,FXSelector,void*);
00076 
00077 public:
00078   /// create a reader for the incoming stream
00079   FXXmlReader(FXApp* a,FXStream* s,FXObject* tgt,FXSelector sel);
00080 
00081   /// indicates the state, whether the parser is currently allowed to parse
00082   FXbool getState() { return state; }
00083 
00084   /// set to new stream
00085   void setStream(FXStream *s) { stream=s; }
00086 
00087   /// returns the stream being used
00088   FXStream* getStream() { return stream; }
00089 
00090   /// start/continue parsing the data stream
00091   FXbool parse();
00092 
00093   /// stop parsing the stream
00094   void stop() { state=FALSE; }
00095 
00096   /// cleanup
00097   virtual ~FXXmlReader();
00098   };
00099 
00100 } // namespace FXEX
00101 #endif // FXXMLREADER_H