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         explicit xmlChar<T>(unsigned char in) : c(static_cast<T>(in)) {}
00378         explicit xmlChar<T>(unsigned short in) : c(static_cast<T>(in)) {}
00379         explicit xmlChar<T>(unsigned int in) : c(static_cast<T>(in)) {}
00380         explicit xmlChar<T>(unsigned long in) : c(static_cast<T>(in)) {}
00381         operator T() const { return c; }
00382         void operator=(int t) { c=static_cast<T>(t); }
00383     };
00384 
00386 
00388     typedef xmlChar<unsigned short> char16;
00389 
00391 
00393     typedef xmlChar<unsigned int> char32;
00394 
00396 
00401     typedef IIrrXMLReader<char, IXMLBase> IrrXMLReader;
00402 
00404 
00409     typedef IIrrXMLReader<char16, IXMLBase> IrrXMLReaderUTF16;
00410 
00412 
00417     typedef IIrrXMLReader<char32, IXMLBase> IrrXMLReaderUTF32;
00418 
00419 
00421 
00429     IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(const char* filename);
00430 
00432 
00441     IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(FILE* file);
00442 
00444 
00456     IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(IFileReadCallBack* callback,
00457                                                                 bool deleteCallback = false);
00458 
00460 
00469     IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(const char* filename);
00470 
00472 
00481     IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(FILE* file);
00482 
00484 
00496     IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(IFileReadCallBack* callback,
00497                                                                         bool deleteCallback = false);
00498 
00499 
00501 
00509     IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(const char* filename);
00510 
00512 
00521     IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(FILE* file);
00522 
00524 
00537     IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(IFileReadCallBack* callback,
00538                                                                         bool deleteCallback = false);
00539 
00540 
00562 } // end namespace io
00563 } // end namespace irr
00564 
00565 #endif // __IRR_XML_H_INCLUDED__
00566