arsa  2.7
irrXML.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
2 // This file is part of the "Irrlicht Engine" and the "irrXML" project.
3 // For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h
4 
5 #ifndef __IRR_XML_H_INCLUDED__
6 #define __IRR_XML_H_INCLUDED__
7 
8 #include <stdio.h>
9 #include "IrrCompileConfig.h"
10 #include "irrArray.h"
11 #include "irrString.h"
12 
155 namespace irr
156 {
157 namespace io
158 {
161  {
164 
167 
170 
173 
176 
179  };
180 
181 
184  {
187 
190 
193 
197 
200 
203 
206  };
207 
209 
217  {
218  public:
219 
221  virtual ~IFileReadCallBack() {}
222 
224 
227  virtual int read(void* buffer, int sizeToRead) = 0;
228 
230  virtual long getSize() const = 0;
231  };
232 
234 
239  class IXMLBase
240  {
241  };
242 
244 
276  template<class char_type, class super_class>
277  class IIrrXMLReader : public super_class
278  {
279  public:
280 
282  virtual ~IIrrXMLReader() {}
283 
285 
286  virtual bool read() = 0;
287 
289  virtual EXML_NODE getNodeType() const = 0;
290 
292 
295  virtual unsigned int getAttributeCount() const = 0;
296 
298 
300  virtual const char_type* getAttributeName(int idx) const = 0;
301 
303 
305  virtual const char_type* getAttributeValue(int idx) const = 0;
306 
308 
310  virtual const char_type* getAttributeValue(const char_type* name) const = 0;
311 
313 
317  virtual const char_type* getAttributeValueSafe(const char_type* name) const = 0;
318 
320 
324  virtual int getAttributeValueAsInt(const char_type* name, int defaultNotFound=0) const = 0;
325 
327 
331  virtual int getAttributeValueAsInt(int idx, int defaultNotFound=0) const = 0;
332 
334 
338  virtual float getAttributeValueAsFloat(const char_type* name, float defaultNotFound=0.f) const = 0;
339 
341 
345  virtual float getAttributeValueAsFloat(int idx, float defaultNotFound=0.f) const = 0;
346 
348 
350  virtual const char_type* getNodeName() const = 0;
351 
353 
355  virtual const char_type* getNodeData() const = 0;
356 
358  virtual bool isEmptyElement() const = 0;
359 
361 
365  virtual ETEXT_FORMAT getSourceFormat() const = 0;
366 
368 
372  virtual ETEXT_FORMAT getParserFormat() const = 0;
373  };
374 
376  template<class char_type, class super_class>
377  class IIrrXMLWriter : public super_class
378  {
379  public:
380 
382  virtual ~IIrrXMLWriter() {}
383 
385 
388  virtual void writeXMLHeader() = 0;
389 
392 
407  virtual void writeElement(const char_type* name, bool empty=false,
408  const char_type* attr1Name = 0, const char_type* attr1Value = 0,
409  const char_type* attr2Name = 0, const char_type* attr2Value = 0,
410  const char_type* attr3Name = 0, const char_type* attr3Value = 0,
411  const char_type* attr4Name = 0, const char_type* attr4Value = 0,
412  const char_type* attr5Name = 0, const char_type* attr5Value = 0) = 0;
413 
415  virtual void writeElement(const char_type* name, bool empty,
417 
419  virtual void writeComment(const char_type* comment) = 0;
420 
422  virtual void writeClosingTag(const char_type* name) = 0;
423 
425 
428  virtual void writeText(const char_type* text) = 0;
429 
431  virtual void writeLineBreak() = 0;
432  };
433 
434 
435  template <typename T>
436  struct xmlChar
437  {
438  T c;
440  xmlChar<T>(char in) : c(static_cast<T>(in)) {}
441  xmlChar<T>(wchar_t in) : c(static_cast<T>(in)) {}
442 #if defined(__BORLANDC__)
443  // Note - removing explicit for Borland was to get it to even compile.
444  // There haven't been any kind of tests for that besides that.
445  xmlChar<T>(unsigned char in) : c(static_cast<T>(in)) {}
446  xmlChar<T>(unsigned short in) : c(static_cast<T>(in)) {}
447  xmlChar<T>(unsigned int in) : c(static_cast<T>(in)) {}
448  xmlChar<T>(unsigned long in) : c(static_cast<T>(in)) {}
449 #else
450  explicit xmlChar<T>(unsigned char in) : c(static_cast<T>(in)) {}
451 
452 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) // VS compiling without native wchar_t can't have it
453  explicit xmlChar<T>(unsigned short in) : c(static_cast<T>(in)) {}
454 #endif
455  explicit xmlChar<T>(unsigned int in) : c(static_cast<T>(in)) {}
456  explicit xmlChar<T>(unsigned long in) : c(static_cast<T>(in)) {}
457 #endif
458  operator T() const { return c; }
459  void operator=(int t) { c=static_cast<T>(t); }
460  };
461 
463 
466 
468 
471 
473 
479 
481 
487 
489 
495 
496 #ifdef _IRR_COMPILE_WITH_XML_
497 
499 
508 
510 
520 
522 
535  bool deleteCallback = false);
536 
538 
548 
550 
560 
562 
575  bool deleteCallback = false);
576 
577 
579 
588 
590 
600 
602 
616  bool deleteCallback = false);
617 
618 #endif // _IRR_COMPILE_WITH_XML_
619 
641 } // end namespace io
642 } // end namespace irr
643 
644 #endif // __IRR_XML_H_INCLUDED__
645 
End of an xml element such as </foo>.
Definition: irrXML.h:192
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
GLuint GLuint * names
virtual int getAttributeValueAsInt(const char_type *name, int defaultNotFound=0) const =0
Returns the value of an attribute as integer.
virtual ~IIrrXMLWriter()
Destructor.
Definition: irrXML.h:382
virtual float getAttributeValueAsFloat(const char_type *name, float defaultNotFound=0.f) const =0
Returns the value of an attribute as float.
Unknown element.
Definition: irrXML.h:205
An xml comment like <!– I am a comment –> or a DTD definition.
Definition: irrXML.h:199
#define IRRLICHT_API
Set FPU settings.
An xml element such as <foo>.
Definition: irrXML.h:189
Empty class to be used as parent class for IrrXMLReader.
Definition: irrXML.h:239
xmlChar< unsigned int > char32
defines the utf-32 type.
Definition: irrXML.h:470
GLuint const GLchar * name
virtual const char_type * getNodeData() const =0
Returns data of the current node.
Everything in the Irrlicht Engine can be found in this namespace.
Definition: CARSADPad.h:6
virtual ETEXT_FORMAT getParserFormat() const =0
Returns format of the strings returned by the parser.
virtual long getSize() const =0
Returns size of file in bytes on success or -1L on failure.
An xml cdata section like <![CDATA[ this is some CDATA ]]>.
Definition: irrXML.h:202
UTF-16 format, little endian.
Definition: irrXML.h:172
IIrrXMLReader< char, IXMLBase > IrrXMLReader
A UTF-8 or ASCII character xml parser.
Definition: irrXML.h:478
virtual unsigned int getAttributeCount() const =0
Returns attribute count of the current XML node.
Very simple string class with some useful features.
Definition: irrString.h:37
virtual const char_type * getAttributeName(int idx) const =0
Returns name of an attribute.
virtual void writeLineBreak()=0
Writes a line break.
virtual bool isEmptyElement() const =0
Returns if an element is an empty element, like <foo />
UTF-16 format, big endian.
Definition: irrXML.h:169
virtual ~IFileReadCallBack()
Destructor.
Definition: irrXML.h:221
virtual const char_type * getAttributeValue(int idx) const =0
Returns the value of an attribute.
ETEXT_FORMAT
Enumeration of all supported source text file formats.
Definition: irrXML.h:160
xmlChar< unsigned short > char16
defines the utf-16 type.
Definition: irrXML.h:465
UTF-32 format, big endian.
Definition: irrXML.h:175
virtual bool read()=0
Reads forward to the next xml node.
virtual const char_type * getNodeName() const =0
Returns the name of the current node.
IIrrXMLReader< char16, IXMLBase > IrrXMLReaderUTF16
A UTF-16 xml parser.
Definition: irrXML.h:486
virtual int read(void *buffer, int sizeToRead)=0
Reads an amount of bytes from the file.
virtual void writeText(const char_type *text)=0
Writes a text into the file.
GLfloat f
Interface providing easy read access to a XML file.
Definition: irrXML.h:277
GLenum GLsizei GLsizei GLint * values
EXML_NODE
Enumeration for all xml nodes which are parsed by IrrXMLReader.
Definition: irrXML.h:183
IRRLICHT_API IrrXMLReaderUTF32 *IRRCALLCONV createIrrXMLReaderUTF32(const char *filename)
Creates an instance of an UFT-32 xml parser.
virtual EXML_NODE getNodeType() const =0
Returns the type of the current XML node.
#define IRRCALLCONV
virtual ~IIrrXMLReader()
Destructor.
Definition: irrXML.h:282
virtual ETEXT_FORMAT getSourceFormat() const =0
Returns format of the source xml file.
virtual void writeComment(const char_type *comment)=0
Writes a comment into the xml file.
virtual void writeXMLHeader()=0
Writes an xml 1.0 header.
IRRLICHT_API IrrXMLReader *IRRCALLCONV createIrrXMLReader(const char *filename)
Creates an instance of an UFT-8 or ASCII character xml parser.
virtual void writeElement(const char_type *name, bool empty=false, const char_type *attr1Name=0, const char_type *attr1Value=0, const char_type *attr2Name=0, const char_type *attr2Value=0, const char_type *attr3Name=0, const char_type *attr3Value=0, const char_type *attr4Name=0, const char_type *attr4Value=0, const char_type *attr5Name=0, const char_type *attr5Value=0)=0
virtual const char_type * getAttributeValueSafe(const char_type *name) const =0
Returns the value of an attribute in a safe way.
Callback class for file read abstraction.
Definition: irrXML.h:216
Interface providing methods for making it easier to write XML files.
Definition: irrXML.h:377
Self reallocating template array (like stl vector) with additional features.
Definition: irrArray.h:22
IIrrXMLReader< char32, IXMLBase > IrrXMLReaderUTF32
A UTF-32 xml parser.
Definition: irrXML.h:494
IRRLICHT_API IrrXMLReaderUTF16 *IRRCALLCONV createIrrXMLReaderUTF16(const char *filename)
Creates an instance of an UFT-16 xml parser.
void operator=(int t)
Definition: irrXML.h:459
GLuint buffer
UTF-32 format, little endian.
Definition: irrXML.h:178
No xml node. This is usually the node if you did not read anything yet.
Definition: irrXML.h:186
const GLubyte * c
virtual void writeClosingTag(const char_type *name)=0
Writes the closing tag for an element. Like "</foo>".
GLuint in
ASCII, file without byte order mark, or not a text file.
Definition: irrXML.h:163
UTF-8 format.
Definition: irrXML.h:166