i_xml.h

Go to the documentation of this file.
00001 
00005 /* Copyright, 2000, 2001 Nevrax Ltd.
00006  *
00007  * This file is part of NEVRAX NEL.
00008  * NEVRAX NEL is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2, or (at your option)
00011  * any later version.
00012 
00013  * NEVRAX NEL is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * General Public License for more details.
00017 
00018  * You should have received a copy of the GNU General Public License
00019  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00021  * MA 02111-1307, USA.
00022  */
00023 
00024 #ifndef NL_I_XML_H
00025 #define NL_I_XML_H
00026 
00027 //#define NL_DONT_USE_EXTERNAL_CODE
00028 #undef NL_DONT_USE_EXTERNAL_CODE
00029 
00030 #ifndef NL_DONT_USE_EXTERNAL_CODE
00031 
00032 #include "types_nl.h"
00033 #include "stream.h"
00034 
00035 // Include from libxml2
00036 #include <libxml/parser.h>
00037 
00038 namespace NLMISC {
00039 
00040 
00041 struct EXmlParsingError : public EStream
00042 {
00043     EXmlParsingError ( const std::string& str ) : EStream( str ) {}
00044 };
00045 
00090 class CIXml : public IStream
00091 {
00092     friend void xmlGenericErrorFuncRead (void *ctx, const char *msg, ...);
00093 public:
00094 
00097     CIXml ();
00098 
00099     // If tryBinaryMode is true, try to open the stream in both, XML and Binary if XML doesn't work.
00100     // In tryBinaryMode, the stream keep a pointer on the input stream passed to init();
00101     CIXml (bool tryBinaryMode);
00102 
00105     virtual ~CIXml ();
00106 
00114     bool            init (IStream &stream);
00115 
00118     void            release ();
00119 
00122     xmlNodePtr      getRootNode () const;
00123 
00126     static xmlNodePtr getFirstChildNode (xmlNodePtr parent, const char *childName);
00127 
00130     static xmlNodePtr getNextChildNode (xmlNodePtr last, const char *childName);
00131 
00134     static xmlNodePtr getFirstChildNode (xmlNodePtr parent, xmlElementType type);
00135 
00138     static xmlNodePtr getNextChildNode (xmlNodePtr last, xmlElementType type);
00139 
00142     static uint     countChildren (xmlNodePtr node, const char *childName);
00143 
00146     static uint     countChildren (xmlNodePtr node, xmlElementType type);
00147 
00153     static bool     getPropertyString (std::string &result, xmlNodePtr node, const char *property);
00154 
00158     static int      getIntProperty(xmlNodePtr node, const char *property, int defaultValue);
00159 
00163     static double   getFloatProperty(xmlNodePtr node, const char *property, float defaultValue);
00164 
00168     static std::string getStringProperty(xmlNodePtr node, const char *property, const std::string& defaultValue);
00169 
00175     static bool     getContentString (std::string &result, xmlNodePtr node);
00176 
00177 private:
00178 
00180     virtual void    serial(uint8 &b);
00181     virtual void    serial(sint8 &b);
00182     virtual void    serial(uint16 &b);
00183     virtual void    serial(sint16 &b);
00184     virtual void    serial(uint32 &b);
00185     virtual void    serial(sint32 &b);
00186     virtual void    serial(uint64 &b);
00187     virtual void    serial(sint64 &b);
00188     virtual void    serial(float &b);
00189     virtual void    serial(double &b);
00190     virtual void    serial(bool &b);
00191 #ifndef NL_OS_CYGWIN
00192     virtual void    serial(char &b);
00193 #endif
00194     virtual void    serial(std::string &b);
00195     virtual void    serial(ucstring &b);
00196     virtual void    serialBuffer(uint8 *buf, uint len);
00197     virtual void    serialBit(bool &bit);
00198 
00199     virtual bool    xmlPushBeginInternal (const char *nodeName);
00200     virtual bool    xmlPushEndInternal ();
00201     virtual bool    xmlPopInternal ();
00202     virtual bool    xmlSetAttribInternal (const char *attribName);
00203     virtual bool    xmlBreakLineInternal ();
00204     virtual bool    xmlCommentInternal (const char *comment);
00205 
00206     // Internal functions
00207     void            serialSeparatedBufferIn ( std::string &value, bool checkSeparator = true );
00208     inline void     flushContentString ();
00209 
00210     // Push has began
00211     bool            _PushBegin;
00212 
00213     // Attribute present
00214     bool            _AttribPresent;
00215 
00216     // Attribute name
00217     std::string     _AttribName;
00218 
00219     // Current libxml node
00220     xmlNodePtr      _CurrentNode;
00221 
00222     // Current libxml header node opened
00223     xmlNodePtr      _CurrentElement;
00224 
00225     // Parser pointer
00226     xmlParserCtxtPtr    _Parser;
00227 
00228     // Current node text
00229     std::string     _ContentString;
00230 
00231     // Current index in the node string
00232     uint            _ContentStringIndex;
00233 
00234     // Error message
00235     std::string     _ErrorString;
00236 
00237     // Try binary mode
00238     bool            _TryBinaryMode;
00239 
00240     // If not NULL, binary mode detected, use this stream in serials
00241     IStream         *_BinaryStream;
00242 };
00243 
00244 
00245 } // NLMISC
00246 
00247 #endif // NL_DONT_USE_EXTERNAL_CODE
00248 
00249 #endif // NL_I_XML_H
00250 
00251 /* End of o_xml.h */

Generated on Thu Jan 7 08:26:22 2010 for NeL by  doxygen 1.6.1