IrrlichtEngine
irrXML.h
Go to the documentation of this file.
00001 // Copyright (C) 2002-2011 Nikolaus Gebhardt
00002 // This file is part of the "Irrlicht Engine" and the "irrXML" project.
00003 // For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h
00004 
00005 #ifndef __IRR_XML_H_INCLUDED__
00006 #define __IRR_XML_H_INCLUDED__
00007 
00008 #include <stdio.h>
00009 #include "IrrCompileConfig.h"
00010 
00153 namespace irr
00154 {
00155 namespace io
00156 {
00158         enum ETEXT_FORMAT
00159         {
00161                 ETF_ASCII,
00162 
00164                 ETF_UTF8,
00165 
00167                 ETF_UTF16_BE,
00168 
00170                 ETF_UTF16_LE,
00171 
00173                 ETF_UTF32_BE,
00174 
00176                 ETF_UTF32_LE
00177         };
00178 
00179 
00181         enum EXML_NODE
00182         {
00184                 EXN_NONE,
00185 
00187                 EXN_ELEMENT,
00188 
00190                 EXN_ELEMENT_END,
00191 
00193                 EXN_TEXT,
00194 
00196                 EXN_COMMENT,
00197 
00199                 EXN_CDATA,
00200 
00202                 EXN_UNKNOWN
00203         };
00204 
00206 
00213         class IFileReadCallBack
00214         {
00215         public:
00216 
00218                 virtual ~IFileReadCallBack() {}
00219 
00221 
00224                 virtual int read(void* buffer, int sizeToRead) = 0;
00225 
00227                 virtual long getSize() const = 0;
00228         };
00229 
00231 
00236         class IXMLBase
00237         {
00238         };
00239 
00241 
00273         template<class char_type, class super_class>
00274         class IIrrXMLReader : public super_class
00275         {
00276         public:
00277 
00279                 virtual ~IIrrXMLReader() {}
00280 
00282 
00283                 virtual bool read() = 0;
00284 
00286                 virtual EXML_NODE getNodeType() const = 0;
00287 
00289 
00292                 virtual unsigned int getAttributeCount() const = 0;
00293 
00295 
00297                 virtual const char_type* getAttributeName(int idx) const = 0;
00298 
00300 
00302                 virtual const char_type* getAttributeValue(int idx) const = 0;
00303 
00305 
00307                 virtual const char_type* getAttributeValue(const char_type* name) const = 0;
00308 
00310 
00314                 virtual const char_type* getAttributeValueSafe(const char_type* name) const = 0;
00315 
00317 
00320                 virtual int getAttributeValueAsInt(const char_type* name) const = 0;
00321 
00323 
00326                 virtual int getAttributeValueAsInt(int idx) const = 0;
00327 
00329 
00332                 virtual float getAttributeValueAsFloat(const char_type* name) const = 0;
00333 
00335 
00338                 virtual float getAttributeValueAsFloat(int idx) const = 0;
00339 
00341 
00343                 virtual const char_type* getNodeName() const = 0;
00344 
00346 
00348                 virtual const char_type* getNodeData() const = 0;
00349 
00351                 virtual bool isEmptyElement() const = 0;
00352 
00354 
00358                 virtual ETEXT_FORMAT getSourceFormat() const = 0;
00359 
00361 
00365                 virtual ETEXT_FORMAT getParserFormat() const = 0;
00366         };
00367 
00368 
00369         template <typename T>
00370         struct xmlChar
00371         {
00372                 T c;
00373                 xmlChar<T>() {}
00374                 xmlChar<T>(char in) : c(static_cast<T>(in)) {}
00375                 xmlChar<T>(wchar_t in) : c(static_cast<T>(in)) {}
00376                 explicit xmlChar<T>(unsigned char in) : c(static_cast<T>(in)) {}
00377                 explicit xmlChar<T>(unsigned short in) : c(static_cast<T>(in)) {}
00378                 explicit xmlChar<T>(unsigned int in) : c(static_cast<T>(in)) {}
00379                 explicit xmlChar<T>(unsigned long in) : c(static_cast<T>(in)) {}
00380                 operator T() const { return c; }
00381                 void operator=(int t) { c=static_cast<T>(t); }
00382         };
00383 
00385 
00387         typedef xmlChar<unsigned short> char16;
00388 
00390 
00392         typedef xmlChar<unsigned int> char32;
00393 
00395 
00400         typedef IIrrXMLReader<char, IXMLBase> IrrXMLReader;
00401 
00403 
00408         typedef IIrrXMLReader<char16, IXMLBase> IrrXMLReaderUTF16;
00409 
00411 
00416         typedef IIrrXMLReader<char32, IXMLBase> IrrXMLReaderUTF32;
00417 
00418 
00420 
00428         IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(const char* filename);
00429 
00431 
00440         IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(FILE* file);
00441 
00443 
00455         IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(IFileReadCallBack* callback,
00456                                                                                                                                 bool deleteCallback = false);
00457 
00459 
00468         IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(const char* filename);
00469 
00471 
00480         IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(FILE* file);
00481 
00483 
00495         IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(IFileReadCallBack* callback,
00496                                                                                                                                                 bool deleteCallback = false);
00497 
00498 
00500 
00508         IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(const char* filename);
00509 
00511 
00520         IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(FILE* file);
00521 
00523 
00536         IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(IFileReadCallBack* callback,
00537                                                                                                                                                 bool deleteCallback = false);
00538 
00539 
00561 } // end namespace io
00562 } // end namespace irr
00563 
00564 #endif // __IRR_XML_H_INCLUDED__
00565