| Irrlicht 3D Engine |

irrXML.h
Go to the documentation of this file.

    00001 // Copyright (C) 2002-2012 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
    00194         EXN_TEXT,
    00195
    00197         EXN_COMMENT,
    00198
    00200         EXN_CDATA,
    00201
    00203         EXN_UNKNOWN
    00204     };
    00205
    00207
    00214     class IFileReadCallBack
    00215     {
    00216     public:
    00217
    00219         virtual ~IFileReadCallBack() {}
    00220
    00222
    00225         virtual int read(void* buffer, int sizeToRead) = 0;
    00226
    00228         virtual long getSize() const = 0;
    00229     };
    00230
    00232
    00237     class IXMLBase
    00238     {
    00239     };
    00240
    00242
    00274     template<class char_type, class super_class>
    00275     class IIrrXMLReader : public super_class
    00276     {
    00277     public:
    00278
    00280         virtual ~IIrrXMLReader() {}
    00281
    00283
    00284         virtual bool read() = 0;
    00285
    00287         virtual EXML_NODE getNodeType() const = 0;
    00288
    00290
    00293         virtual unsigned int getAttributeCount() const = 0;
    00294
    00296
    00298         virtual const char_type* getAttributeName(int idx) const = 0;
    00299
    00301
    00303         virtual const char_type* getAttributeValue(int idx) const = 0;
    00304
    00306
    00308         virtual const char_type* getAttributeValue(const char_type* name) const = 0;
    00309
    00311
    00315         virtual const char_type* getAttributeValueSafe(const char_type* name) const = 0;
    00316
    00318
    00321         virtual int getAttributeValueAsInt(const char_type* name) const = 0;
    00322
    00324
    00327         virtual int getAttributeValueAsInt(int idx) const = 0;
    00328
    00330
    00333         virtual float getAttributeValueAsFloat(const char_type* name) const = 0;
    00334
    00336
    00339         virtual float getAttributeValueAsFloat(int idx) const = 0;
    00340
    00342
    00344         virtual const char_type* getNodeName() const = 0;
    00345
    00347
    00349         virtual const char_type* getNodeData() const = 0;
    00350
    00352         virtual bool isEmptyElement() const = 0;
    00353
    00355
    00359         virtual ETEXT_FORMAT getSourceFormat() const = 0;
    00360
    00362
    00366         virtual ETEXT_FORMAT getParserFormat() const = 0;
    00367     };
    00368
    00369
    00370     template <typename T>
    00371     struct xmlChar
    00372     {
    00373         T c;
    00374         xmlChar<T>() {}
    00375         xmlChar<T>(char in) : c(static_cast<T>(in)) {}
    00376         xmlChar<T>(wchar_t in) : c(static_cast<T>(in)) {}
    00377 #if defined(__BORLANDC__)
    00378         // Note - removing explicit for borland was to get it to even compile.
    00379         // There haven't been any kind of tests for that besides that.
    00380         xmlChar<T>(unsigned char in) : c(static_cast<T>(in)) {}
    00381         xmlChar<T>(unsigned short in) : c(static_cast<T>(in)) {}
    00382         xmlChar<T>(unsigned int in) : c(static_cast<T>(in)) {}
    00383         xmlChar<T>(unsigned long in) : c(static_cast<T>(in)) {}
    00384 #else
    00385         explicit xmlChar<T>(unsigned char in) : c(static_cast<T>(in)) {}
    00386         explicit xmlChar<T>(unsigned short in) : c(static_cast<T>(in)) {}
    00387         explicit xmlChar<T>(unsigned int in) : c(static_cast<T>(in)) {}
    00388         explicit xmlChar<T>(unsigned long in) : c(static_cast<T>(in)) {}
    00389 #endif
    00390         operator T() const { return c; }
    00391         void operator=(int t) { c=static_cast<T>(t); }
    00392     };
    00393
    00395
    00397     typedef xmlChar<unsigned short> char16;
    00398
    00400
    00402     typedef xmlChar<unsigned int> char32;
    00403
    00405
    00410     typedef IIrrXMLReader<char, IXMLBase> IrrXMLReader;
    00411
    00413
    00418     typedef IIrrXMLReader<char16, IXMLBase> IrrXMLReaderUTF16;
    00419
    00421
    00426     typedef IIrrXMLReader<char32, IXMLBase> IrrXMLReaderUTF32;
    00427
    00428
    00430
    00438     IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(const char* filename);
    00439
    00441
    00450     IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(FILE* file);
    00451
    00453
    00465     IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(IFileReadCallBack* callback,
    00466                                                                 bool deleteCallback = false);
    00467
    00469
    00478     IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(const char* filename);
    00479
    00481
    00490     IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(FILE* file);
    00491
    00493
    00505     IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(IFileReadCallBack* callback,
    00506                                                                         bool deleteCallback = false);
    00507
    00508
    00510
    00518     IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(const char* filename);
    00519
    00521
    00530     IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(FILE* file);
    00531
    00533
    00546     IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(IFileReadCallBack* callback,
    00547                                                                         bool deleteCallback = false);
    00548
    00549
    00571 } // end namespace io
    00572 } // end namespace irr
    00573
    00574 #endif // __IRR_XML_H_INCLUDED__
    00575