vrshoot

view libs/assimp/irrXML/irrXML.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 // Copyright (C) 2002-2005 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
5 #ifndef __IRR_XML_H_INCLUDED__
6 #define __IRR_XML_H_INCLUDED__
8 #include <stdio.h>
10 /** \mainpage irrXML 1.2 API documentation
11 <div align="center"><img src="logobig.png" ></div>
13 \section intro Introduction
15 Welcome to the irrXML API documentation.
16 Here you'll find any information you'll need to develop applications with
17 irrXML. If you look for a tutorial on how to start, take a look at the \ref irrxmlexample,
18 at the homepage of irrXML at <A HREF="http://xml.irrlicht3d.org" >xml.irrlicht3d.org</A>
19 or into the SDK in the directory \example.
21 irrXML is intended to be a high speed and easy-to-use XML Parser for C++, and
22 this documentation is an important part of it. If you have any questions or
23 suggestions, just send a email to the author of the engine, Nikolaus Gebhardt
24 (niko (at) irrlicht3d.org). For more informations about this parser, see \ref history.
26 \section features Features
28 irrXML provides forward-only, read-only
29 access to a stream of non validated XML data. It was fully implemented by
30 Nikolaus Gebhardt. Its current features are:
32 - It it fast as lighting and has very low memory usage. It was
33 developed with the intention of being used in 3D games, as it already has been.
34 - irrXML is very small: It only consists of 60 KB of code and can be added easily
35 to your existing project.
36 - Of course, it is platform independent and works with lots of compilers.
37 - It is able to parse ASCII, UTF-8, UTF-16 and UTF-32 text files, both in
38 little and big endian format.
39 - Independent of the input file format, the parser can return all strings in ASCII, UTF-8,
40 UTF-16 and UTF-32 format.
41 - With its optional file access abstraction it has the advantage that it can read not
42 only from files but from any type of data (memory, network, ...). For example when
43 used with the Irrlicht Engine, it directly reads from compressed .zip files.
44 - Just like the Irrlicht Engine for which it was originally created, it is extremely easy
45 to use.
46 - It has no external dependencies, it does not even need the STL.
48 Although irrXML has some strenghts, it currently also has the following limitations:
50 - The input xml file is not validated and assumed to be correct.
52 \section irrxmlexample Example
54 The following code demonstrates the basic usage of irrXML. A simple xml
55 file like this is parsed:
56 \code
57 <?xml version="1.0"?>
58 <config>
59 <!-- This is a config file for the mesh viewer -->
60 <model file="dwarf.dea" />
61 <messageText caption="Irrlicht Engine Mesh Viewer">
62 Welcome to the Mesh Viewer of the &quot;Irrlicht Engine&quot;.
63 </messageText>
64 </config>
65 \endcode
67 The code for parsing this file would look like this:
68 \code
69 #include <irrXML.h>
70 using namespace irr; // irrXML is located in the namespace irr::io
71 using namespace io;
73 #include <string> // we use STL strings to store data in this example
75 void main()
76 {
77 // create the reader using one of the factory functions
79 IrrXMLReader* xml = createIrrXMLReader("config.xml");
81 // strings for storing the data we want to get out of the file
82 std::string modelFile;
83 std::string messageText;
84 std::string caption;
86 // parse the file until end reached
88 while(xml && xml->read())
89 {
90 switch(xml->getNodeType())
91 {
92 case EXN_TEXT:
93 // in this xml file, the only text which occurs is the messageText
94 messageText = xml->getNodeData();
95 break;
96 case EXN_ELEMENT:
97 {
98 if (!strcmp("model", xml->getNodeName()))
99 modelFile = xml->getAttributeValue("file");
100 else
101 if (!strcmp("messageText", xml->getNodeName()))
102 caption = xml->getAttributeValue("caption");
103 }
104 break;
105 }
106 }
108 // delete the xml parser after usage
109 delete xml;
110 }
111 \endcode
113 \section howto How to use
115 Simply add the source files in the /src directory of irrXML to your project. Done.
117 \section license License
119 The irrXML license is based on the zlib license. Basicly, this means you can do with
120 irrXML whatever you want:
122 Copyright (C) 2002-2005 Nikolaus Gebhardt
124 This software is provided 'as-is', without any express or implied
125 warranty. In no event will the authors be held liable for any damages
126 arising from the use of this software.
128 Permission is granted to anyone to use this software for any purpose,
129 including commercial applications, and to alter it and redistribute it
130 freely, subject to the following restrictions:
132 1. The origin of this software must not be misrepresented; you must not
133 claim that you wrote the original software. If you use this software
134 in a product, an acknowledgment in the product documentation would be
135 appreciated but is not required.
137 2. Altered source versions must be plainly marked as such, and must not be
138 misrepresented as being the original software.
140 3. This notice may not be removed or altered from any source distribution.
142 \section history History
144 As lots of references in this documentation and the source show, this xml
145 parser has originally been a part of the
146 <A HREF="http://irrlicht.sourceforge.net" >Irrlicht Engine</A>. But because
147 the parser has become very useful with the latest release, people asked for a
148 separate version of it, to be able to use it in non Irrlicht projects. With
149 irrXML 1.0, this has now been done.
150 */
152 namespace irr
153 {
154 namespace io
155 {
156 //! Enumeration of all supported source text file formats
157 enum ETEXT_FORMAT
158 {
159 //! ASCII, file without byte order mark, or not a text file
160 ETF_ASCII,
162 //! UTF-8 format
163 ETF_UTF8,
165 //! UTF-16 format, big endian
166 ETF_UTF16_BE,
168 //! UTF-16 format, little endian
169 ETF_UTF16_LE,
171 //! UTF-32 format, big endian
172 ETF_UTF32_BE,
174 //! UTF-32 format, little endian
175 ETF_UTF32_LE
176 };
179 //! Enumeration for all xml nodes which are parsed by IrrXMLReader
180 enum EXML_NODE
181 {
182 //! No xml node. This is usually the node if you did not read anything yet.
183 EXN_NONE,
185 //! A xml element, like <foo>
186 EXN_ELEMENT,
188 //! End of an xml element, like </foo>
189 EXN_ELEMENT_END,
191 //! Text within a xml element: <foo> this is the text. </foo>
192 EXN_TEXT,
194 //! An xml comment like &lt;!-- I am a comment --&gt; or a DTD definition.
195 EXN_COMMENT,
197 //! An xml cdata section like &lt;![CDATA[ this is some CDATA ]]&gt;
198 EXN_CDATA,
200 //! Unknown element.
201 EXN_UNKNOWN
202 };
204 //! Callback class for file read abstraction.
205 /** With this, it is possible to make the xml parser read in other things
206 than just files. The Irrlicht engine is using this for example to
207 read xml from compressed .zip files. To make the parser read in
208 any other data, derive a class from this interface, implement the
209 two methods to read your data and give a pointer to an instance of
210 your implementation when calling createIrrXMLReader(),
211 createIrrXMLReaderUTF16() or createIrrXMLReaderUTF32() */
212 class IFileReadCallBack
213 {
214 public:
216 //! virtual destructor
217 virtual ~IFileReadCallBack() {};
219 //! Reads an amount of bytes from the file.
220 /** \param buffer: Pointer to buffer where to read bytes will be written to.
221 \param sizeToRead: Amount of bytes to read from the file.
222 \return Returns how much bytes were read. */
223 virtual int read(void* buffer, int sizeToRead) = 0;
225 //! Returns size of file in bytes
226 virtual int getSize() = 0;
227 };
229 //! Empty class to be used as parent class for IrrXMLReader.
230 /** If you need another class as base class for the xml reader, you can do this by creating
231 the reader using for example new CXMLReaderImpl<char, YourBaseClass>(yourcallback);
232 The Irrlicht Engine for example needs IUnknown as base class for every object to
233 let it automaticly reference countend, hence it replaces IXMLBase with IUnknown.
234 See irrXML.cpp on how this can be done in detail. */
235 class IXMLBase
236 {
237 };
239 //! Interface providing easy read access to a XML file.
240 /** You can create an instance of this reader using one of the factory functions
241 createIrrXMLReader(), createIrrXMLReaderUTF16() and createIrrXMLReaderUTF32().
242 If using the parser from the Irrlicht Engine, please use IFileSystem::createXMLReader()
243 instead.
244 For a detailed intro how to use the parser, see \ref irrxmlexample and \ref features.
246 The typical usage of this parser looks like this:
247 \code
248 #include <irrXML.h>
249 using namespace irr; // irrXML is located in the namespace irr::io
250 using namespace io;
252 void main()
253 {
254 // create the reader using one of the factory functions
255 IrrXMLReader* xml = createIrrXMLReader("config.xml");
257 if (xml == 0)
258 return; // file could not be opened
260 // parse the file until end reached
261 while(xml->read())
262 {
263 // based on xml->getNodeType(), do something.
264 }
266 // delete the xml parser after usage
267 delete xml;
268 }
269 \endcode
270 See \ref irrxmlexample for a more detailed example.
271 */
272 template<class char_type, class super_class>
273 class IIrrXMLReader : public super_class
274 {
275 public:
277 //! Destructor
278 virtual ~IIrrXMLReader() {};
280 //! Reads forward to the next xml node.
281 /** \return Returns false, if there was no further node. */
282 virtual bool read() = 0;
284 //! Returns the type of the current XML node.
285 virtual EXML_NODE getNodeType() const = 0;
287 //! Returns attribute count of the current XML node.
288 /** This is usually
289 non null if the current node is EXN_ELEMENT, and the element has attributes.
290 \return Returns amount of attributes of this xml node. */
291 virtual int getAttributeCount() const = 0;
293 //! Returns name of an attribute.
294 /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
295 \return Name of the attribute, 0 if an attribute with this index does not exist. */
296 virtual const char_type* getAttributeName(int idx) const = 0;
298 //! Returns the value of an attribute.
299 /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
300 \return Value of the attribute, 0 if an attribute with this index does not exist. */
301 virtual const char_type* getAttributeValue(int idx) const = 0;
303 //! Returns the value of an attribute.
304 /** \param name: Name of the attribute.
305 \return Value of the attribute, 0 if an attribute with this name does not exist. */
306 virtual const char_type* getAttributeValue(const char_type* name) const = 0;
308 //! Returns the value of an attribute in a safe way.
309 /** Like getAttributeValue(), but does not
310 return 0 if the attribute does not exist. An empty string ("") is returned then.
311 \param name: Name of the attribute.
312 \return Value of the attribute, and "" if an attribute with this name does not exist */
313 virtual const char_type* getAttributeValueSafe(const char_type* name) const = 0;
315 //! Returns the value of an attribute as integer.
316 /** \param name Name of the attribute.
317 \return Value of the attribute as integer, and 0 if an attribute with this name does not exist or
318 the value could not be interpreted as integer. */
319 virtual int getAttributeValueAsInt(const char_type* name) const = 0;
321 //! Returns the value of an attribute as integer.
322 /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
323 \return Value of the attribute as integer, and 0 if an attribute with this index does not exist or
324 the value could not be interpreted as integer. */
325 virtual int getAttributeValueAsInt(int idx) const = 0;
327 //! Returns the value of an attribute as float.
328 /** \param name: Name of the attribute.
329 \return Value of the attribute as float, and 0 if an attribute with this name does not exist or
330 the value could not be interpreted as float. */
331 virtual float getAttributeValueAsFloat(const char_type* name) const = 0;
333 //! Returns the value of an attribute as float.
334 /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
335 \return Value of the attribute as float, and 0 if an attribute with this index does not exist or
336 the value could not be interpreted as float. */
337 virtual float getAttributeValueAsFloat(int idx) const = 0;
339 //! Returns the name of the current node.
340 /** Only non null, if the node type is EXN_ELEMENT.
341 \return Name of the current node or 0 if the node has no name. */
342 virtual const char_type* getNodeName() const = 0;
344 //! Returns data of the current node.
345 /** Only non null if the node has some
346 data and it is of type EXN_TEXT or EXN_UNKNOWN. */
347 virtual const char_type* getNodeData() const = 0;
349 //! Returns if an element is an empty element, like <foo />
350 virtual bool isEmptyElement() const = 0;
352 //! Returns format of the source xml file.
353 /** It is not necessary to use
354 this method because the parser will convert the input file format
355 to the format wanted by the user when creating the parser. This
356 method is useful to get/display additional informations. */
357 virtual ETEXT_FORMAT getSourceFormat() const = 0;
359 //! Returns format of the strings returned by the parser.
360 /** This will be UTF8 for example when you created a parser with
361 IrrXMLReaderUTF8() and UTF32 when it has been created using
362 IrrXMLReaderUTF32. It should not be necessary to call this
363 method and only exists for informational purposes. */
364 virtual ETEXT_FORMAT getParserFormat() const = 0;
365 };
368 //! defines the utf-16 type.
369 /** Not using wchar_t for this because
370 wchar_t has 16 bit on windows and 32 bit on other operating systems. */
371 typedef unsigned short char16;
373 //! defines the utf-32 type.
374 /** Not using wchar_t for this because
375 wchar_t has 16 bit on windows and 32 bit on other operating systems. */
376 typedef unsigned long char32;
378 //! A UTF-8 or ASCII character xml parser.
379 /** This means that all character data will be returned in 8 bit ASCII or UTF-8 by this parser.
380 The file to read can be in any format, it will be converted to UTF-8 if it is not
381 in this format.
382 Create an instance of this with createIrrXMLReader();
383 See IIrrXMLReader for description on how to use it. */
384 typedef IIrrXMLReader<char, IXMLBase> IrrXMLReader;
386 //! A UTF-16 xml parser.
387 /** This means that all character data will be returned in UTF-16 by this parser.
388 The file to read can be in any format, it will be converted to UTF-16 if it is not
389 in this format.
390 Create an instance of this with createIrrXMLReaderUTF16();
391 See IIrrXMLReader for description on how to use it. */
392 typedef IIrrXMLReader<char16, IXMLBase> IrrXMLReaderUTF16;
394 //! A UTF-32 xml parser.
395 /** This means that all character data will be returned in UTF-32 by this parser.
396 The file to read can be in any format, it will be converted to UTF-32 if it is not
397 in this format.
398 Create an instance of this with createIrrXMLReaderUTF32();
399 See IIrrXMLReader for description on how to use it. */
400 typedef IIrrXMLReader<char32, IXMLBase> IrrXMLReaderUTF32;
403 //! Creates an instance of an UFT-8 or ASCII character xml parser.
404 /** This means that all character data will be returned in 8 bit ASCII or UTF-8.
405 The file to read can be in any format, it will be converted to UTF-8 if it is not in this format.
406 If you are using the Irrlicht Engine, it is better not to use this function but
407 IFileSystem::createXMLReaderUTF8() instead.
408 \param filename: Name of file to be opened.
409 \return Returns a pointer to the created xml parser. This pointer should be
410 deleted using 'delete' after no longer needed. Returns 0 if an error occured
411 and the file could not be opened. */
412 IrrXMLReader* createIrrXMLReader(const char* filename);
414 //! Creates an instance of an UFT-8 or ASCII character xml parser.
415 /** This means that all character data will be returned in 8 bit ASCII or UTF-8. The file to read can
416 be in any format, it will be converted to UTF-8 if it is not in this format.
417 If you are using the Irrlicht Engine, it is better not to use this function but
418 IFileSystem::createXMLReaderUTF8() instead.
419 \param file: Pointer to opened file, must have been opened in binary mode, e.g.
420 using fopen("foo.bar", "wb"); The file will not be closed after it has been read.
421 \return Returns a pointer to the created xml parser. This pointer should be
422 deleted using 'delete' after no longer needed. Returns 0 if an error occured
423 and the file could not be opened. */
424 IrrXMLReader* createIrrXMLReader(FILE* file);
426 //! Creates an instance of an UFT-8 or ASCII character xml parser.
427 /** This means that all character data will be returned in 8 bit ASCII or UTF-8. The file to read can
428 be in any format, it will be converted to UTF-8 if it is not in this format.
429 If you are using the Irrlicht Engine, it is better not to use this function but
430 IFileSystem::createXMLReaderUTF8() instead.
431 \param callback: Callback for file read abstraction. Implement your own
432 callback to make the xml parser read in other things than just files. See
433 IFileReadCallBack for more information about this.
434 \return Returns a pointer to the created xml parser. This pointer should be
435 deleted using 'delete' after no longer needed. Returns 0 if an error occured
436 and the file could not be opened. */
437 IrrXMLReader* createIrrXMLReader(IFileReadCallBack* callback);
439 //! Creates an instance of an UFT-16 xml parser.
440 /** This means that
441 all character data will be returned in UTF-16. The file to read can
442 be in any format, it will be converted to UTF-16 if it is not in this format.
443 If you are using the Irrlicht Engine, it is better not to use this function but
444 IFileSystem::createXMLReader() instead.
445 \param filename: Name of file to be opened.
446 \return Returns a pointer to the created xml parser. This pointer should be
447 deleted using 'delete' after no longer needed. Returns 0 if an error occured
448 and the file could not be opened. */
449 IrrXMLReaderUTF16* createIrrXMLReaderUTF16(const char* filename);
451 //! Creates an instance of an UFT-16 xml parser.
452 /** This means that all character data will be returned in UTF-16. The file to read can
453 be in any format, it will be converted to UTF-16 if it is not in this format.
454 If you are using the Irrlicht Engine, it is better not to use this function but
455 IFileSystem::createXMLReader() instead.
456 \param file: Pointer to opened file, must have been opened in binary mode, e.g.
457 using fopen("foo.bar", "wb"); The file will not be closed after it has been read.
458 \return Returns a pointer to the created xml parser. This pointer should be
459 deleted using 'delete' after no longer needed. Returns 0 if an error occured
460 and the file could not be opened. */
461 IrrXMLReaderUTF16* createIrrXMLReaderUTF16(FILE* file);
463 //! Creates an instance of an UFT-16 xml parser.
464 /** This means that all character data will be returned in UTF-16. The file to read can
465 be in any format, it will be converted to UTF-16 if it is not in this format.
466 If you are using the Irrlicht Engine, it is better not to use this function but
467 IFileSystem::createXMLReader() instead.
468 \param callback: Callback for file read abstraction. Implement your own
469 callback to make the xml parser read in other things than just files. See
470 IFileReadCallBack for more information about this.
471 \return Returns a pointer to the created xml parser. This pointer should be
472 deleted using 'delete' after no longer needed. Returns 0 if an error occured
473 and the file could not be opened. */
474 IrrXMLReaderUTF16* createIrrXMLReaderUTF16(IFileReadCallBack* callback);
477 //! Creates an instance of an UFT-32 xml parser.
478 /** This means that all character data will be returned in UTF-32. The file to read can
479 be in any format, it will be converted to UTF-32 if it is not in this format.
480 If you are using the Irrlicht Engine, it is better not to use this function but
481 IFileSystem::createXMLReader() instead.
482 \param filename: Name of file to be opened.
483 \return Returns a pointer to the created xml parser. This pointer should be
484 deleted using 'delete' after no longer needed. Returns 0 if an error occured
485 and the file could not be opened. */
486 IrrXMLReaderUTF32* createIrrXMLReaderUTF32(const char* filename);
488 //! Creates an instance of an UFT-32 xml parser.
489 /** This means that all character data will be returned in UTF-32. The file to read can
490 be in any format, it will be converted to UTF-32 if it is not in this format.
491 if you are using the Irrlicht Engine, it is better not to use this function but
492 IFileSystem::createXMLReader() instead.
493 \param file: Pointer to opened file, must have been opened in binary mode, e.g.
494 using fopen("foo.bar", "wb"); The file will not be closed after it has been read.
495 \return Returns a pointer to the created xml parser. This pointer should be
496 deleted using 'delete' after no longer needed. Returns 0 if an error occured
497 and the file could not be opened. */
498 IrrXMLReaderUTF32* createIrrXMLReaderUTF32(FILE* file);
500 //! Creates an instance of an UFT-32 xml parser.
501 /** This means that
502 all character data will be returned in UTF-32. The file to read can
503 be in any format, it will be converted to UTF-32 if it is not in this format.
504 If you are using the Irrlicht Engine, it is better not to use this function but
505 IFileSystem::createXMLReader() instead.
506 \param callback: Callback for file read abstraction. Implement your own
507 callback to make the xml parser read in other things than just files. See
508 IFileReadCallBack for more information about this.
509 \return Returns a pointer to the created xml parser. This pointer should be
510 deleted using 'delete' after no longer needed. Returns 0 if an error occured
511 and the file could not be opened. */
512 IrrXMLReaderUTF32* createIrrXMLReaderUTF32(IFileReadCallBack* callback);
515 /*! \file irrxml.h
516 \brief Header file of the irrXML, the Irrlicht XML parser.
518 This file includes everything needed for using irrXML,
519 the XML parser of the Irrlicht Engine. To use irrXML,
520 you only need to include this file in your project:
522 \code
523 #include <irrXML.h>
524 \endcode
526 It is also common to use the two namespaces in which irrXML is included,
527 directly after #including irrXML.h:
529 \code
530 #include <irrXML.h>
531 using namespace irr;
532 using namespace io;
533 \endcode
534 */
536 } // end namespace io
537 } // end namespace irr
539 #endif // __IRR_XML_H_INCLUDED__