- Cal3D 0.11 API Reference -

tinyxml.h
1 /*
2 www.sourceforge.net/projects/tinyxml
3 Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com)
4 
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any
7 damages arising from the use of this software.
8 
9 Permission is granted to anyone to use this software for any
10 purpose, including commercial applications, and to alter it and
11 redistribute it freely, subject to the following restrictions:
12 
13 1. The origin of this software must not be misrepresented; you must
14 not claim that you wrote the original software. If you use this
15 software in a product, an acknowledgment in the product documentation
16 would be appreciated but is not required.
17 
18 2. Altered source versions must be plainly marked as such, and
19 must not be misrepresented as being the original software.
20 
21 3. This notice may not be removed or altered from any source
22 distribution.
23 */
24 
25 
26 #ifndef TINYXML_INCLUDED
27 #define TINYXML_INCLUDED
28 
29 #ifdef _MSC_VER
30 #pragma warning( disable : 4530 )
31 #pragma warning( disable : 4786 )
32 #endif
33 
34 #include <ctype.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <assert.h>
39 
40 #include "cal3d/platform.h"
41 
42 // Help out windows:
43 #if defined( _DEBUG ) && !defined( DEBUG )
44 #define DEBUG
45 #endif
46 
47 #if defined( DEBUG ) && defined( _MSC_VER )
48 #include <windows.h>
49 #define TIXML_LOG OutputDebugString
50 #else
51 #define TIXML_LOG printf
52 #endif
53 
54 #define TIXML_USE_STL
55 
56 #ifdef TIXML_USE_STL
57  #include <string>
58  #include <iostream>
59  #define TIXML_STRING std::string
60  #define TIXML_ISTREAM std::istream
61  #define TIXML_OSTREAM std::ostream
62 #else
63  #include "tinystr.h"
64  #define TIXML_STRING TiXmlString
65  #define TIXML_OSTREAM TiXmlOutStream
66 #endif
67 
68 namespace cal3d
69 {
70 
71  class TiXmlDocument;
72  class TiXmlElement;
73  class TiXmlComment;
74  class TiXmlUnknown;
75  class TiXmlAttribute;
76  class TiXmlText;
77  class TiXmlDeclaration;
78 
79  class TiXmlParsingData;
80 
81  /* Internal structure for tracking location of items
82  in the XML file.
83  */
84  struct CAL3D_API TiXmlCursor
85  {
86  TiXmlCursor() { Clear(); }
87  void Clear() { row = col = -1; }
88 
89  int row; // 0 based.
90  int col; // 0 based.
91  };
92 
93 
94  // Only used by Attribute::Query functions
95  enum
96  {
97  TIXML_SUCCESS,
98  TIXML_NO_ATTRIBUTE,
99  TIXML_WRONG_TYPE
100  };
101 
124  class CAL3D_API TiXmlBase
125  {
126  friend class TiXmlNode;
127  friend class TiXmlElement;
128  friend class TiXmlDocument;
129 
130  public:
131  TiXmlBase() {}
132  virtual ~TiXmlBase() {}
133 
139  virtual void Print( FILE* cfile, int depth ) const = 0;
140 
147  static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
148 
150  static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
151 
170  int Row() const { return location.row + 1; }
171  int Column() const { return location.col + 1; }
172 
173  protected:
174  // See STL_STRING_BUG
175  // Utility class to overcome a bug.
177  {
178  public:
179  StringToBuffer( const TIXML_STRING& str );
180  ~StringToBuffer();
181  char* buffer;
182  };
183 
184  static const char* SkipWhiteSpace( const char* );
185  inline static bool IsWhiteSpace( int c ) { return ( isspace( c ) || c == '\n' || c == '\r' ); }
186 
187  virtual void StreamOut (TIXML_OSTREAM *) const = 0;
188 
189  #ifdef TIXML_USE_STL
190  static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
191  static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
192  #endif
193 
194  /* Reads an XML name into the string provided. Returns
195  a pointer just past the last character of the name,
196  or 0 if the function has an error.
197  */
198  static const char* ReadName( const char* p, TIXML_STRING* name );
199 
200  /* Reads text. Returns a pointer past the given end tag.
201  Wickedly complex options, but it keeps the (sensitive) code in one place.
202  */
203  static const char* ReadText( const char* in, // where to start
204  TIXML_STRING* text, // the string read
205  bool ignoreWhiteSpace, // whether to keep the white space
206  const char* endTag, // what ends this text
207  bool ignoreCase ); // whether to ignore case in the end tag
208 
209  virtual const char* Parse( const char* p, TiXmlParsingData* data ) = 0;
210 
211  // If an entity has been found, transform it into a character.
212  static const char* GetEntity( const char* in, char* value );
213 
214  // Get a character, while interpreting entities.
215  inline static const char* GetChar( const char* p, char* _value )
216  {
217  assert( p );
218  if ( *p == '&' )
219  {
220  return GetEntity( p, _value );
221  }
222  else
223  {
224  *_value = *p;
225  return p+1;
226  }
227  }
228 
229  // Puts a string to a stream, expanding entities as it goes.
230  // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
231  static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
232 
233  static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
234 
235  // Return true if the next characters in the stream are any of the endTag sequences.
236  static bool StringEqual( const char* p,
237  const char* endTag,
238  bool ignoreCase );
239 
240 
241  enum
242  {
243  TIXML_NO_ERROR = 0,
244  TIXML_ERROR,
245  TIXML_ERROR_OPENING_FILE,
246  TIXML_ERROR_OUT_OF_MEMORY,
247  TIXML_ERROR_PARSING_ELEMENT,
248  TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
249  TIXML_ERROR_READING_ELEMENT_VALUE,
250  TIXML_ERROR_READING_ATTRIBUTES,
251  TIXML_ERROR_PARSING_EMPTY,
252  TIXML_ERROR_READING_END_TAG,
253  TIXML_ERROR_PARSING_UNKNOWN,
254  TIXML_ERROR_PARSING_COMMENT,
255  TIXML_ERROR_PARSING_DECLARATION,
256  TIXML_ERROR_DOCUMENT_EMPTY,
257 
258  TIXML_ERROR_STRING_COUNT
259  };
260  static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
261 
262  TiXmlCursor location;
263 
264  private:
265  struct Entity
266  {
267  const char* str;
268  unsigned int strLength;
269  char chr;
270  };
271  enum
272  {
273  NUM_ENTITY = 5,
274  MAX_ENTITY_LENGTH = 6
275 
276  };
277  static Entity entity[ NUM_ENTITY ];
278  static bool condenseWhiteSpace;
279  };
280 
281 
288  class CAL3D_API TiXmlNode : public TiXmlBase
289  {
290  friend class TiXmlDocument;
291  friend class TiXmlElement;
292 
293  public:
294  #ifdef TIXML_USE_STL
295 
299  friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
300 
317  friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
318 
320  friend std::string& operator<< (std::string& out, const TiXmlNode& base );
321 
322  #else
323  // Used internally, not part of the public API.
324  friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
325  #endif
326 
330  enum NodeType
331  {
332  DOCUMENT,
333  ELEMENT,
334  COMMENT,
335  UNKNOWN,
336  TEXT,
337  DECLARATION,
338  TYPECOUNT
339  };
340 
341  virtual ~TiXmlNode();
342 
355  const char * Value() const { return value.c_str (); }
356 
366  void SetValue(const char * _value) { value = _value;}
367 
368  #ifdef TIXML_USE_STL
369  void SetValue( const std::string& _value )
371  {
372  StringToBuffer buf( _value );
373  SetValue( buf.buffer ? buf.buffer : "" );
374  }
375  #endif
376 
378  void Clear();
379 
381  TiXmlNode* Parent() const { return parent; }
382 
383  TiXmlNode* FirstChild() const { return firstChild; }
384  TiXmlNode* FirstChild( const char * value ) const;
385 
386  TiXmlNode* LastChild() const { return lastChild; }
387  TiXmlNode* LastChild( const char * value ) const;
388 
389  #ifdef TIXML_USE_STL
390  TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
391  TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
392  #endif
393 
410  TiXmlNode* IterateChildren( TiXmlNode* previous ) const;
411 
413  TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ) const;
414 
415  #ifdef TIXML_USE_STL
416  TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
417  #endif
418 
422  TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
423 
424 
434  TiXmlNode* LinkEndChild( TiXmlNode* addThis );
435 
439  TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
440 
444  TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
445 
449  TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
450 
452  bool RemoveChild( TiXmlNode* removeThis );
453 
455  TiXmlNode* PreviousSibling() const { return prev; }
456 
458  TiXmlNode* PreviousSibling( const char * ) const;
459 
460  #ifdef TIXML_USE_STL
461  TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
462  TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
463  #endif
464 
466  TiXmlNode* NextSibling() const { return next; }
467 
469  TiXmlNode* NextSibling( const char * ) const;
470 
475  TiXmlElement* NextSiblingElement() const;
476 
481  TiXmlElement* NextSiblingElement( const char * ) const;
482 
483  #ifdef TIXML_USE_STL
484  TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
485  #endif
486 
488  TiXmlElement* FirstChildElement() const;
489 
491  TiXmlElement* FirstChildElement( const char * value ) const;
492 
493  #ifdef TIXML_USE_STL
494  TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
495  #endif
496 
501  virtual int Type() const { return type; }
502 
506  TiXmlDocument* GetDocument() const;
507 
509  bool NoChildren() const { return !firstChild; }
510 
511  TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; }
512  TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; }
513  TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; }
514  TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; }
515  TiXmlText* ToText() const { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; }
516  TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; }
517 
518  virtual TiXmlNode* Clone() const = 0;
519 
520  void SetUserData( void* user ) { userData = user; }
521  void* GetUserData() { return userData; }
522 
523  protected:
524  TiXmlNode( NodeType type );
525 
526  #ifdef TIXML_USE_STL
527  // The real work of the input operator.
528  virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
529  #endif
530 
531  // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
532  TiXmlNode* Identify( const char* start );
533  void CopyToClone( TiXmlNode* target ) const { target->SetValue (value.c_str() );
534  target->userData = userData; }
535 
536  // Internal Value function returning a TIXML_STRING
537  TIXML_STRING SValue() const { return value ; }
538 
539  TiXmlNode* parent;
540  NodeType type;
541 
542  TiXmlNode* firstChild;
543  TiXmlNode* lastChild;
544 
545  TIXML_STRING value;
546 
547  TiXmlNode* prev;
548  TiXmlNode* next;
549  void* userData;
550  };
551 
552 
560  class CAL3D_API TiXmlAttribute : public TiXmlBase
561  {
562  friend class TiXmlAttributeSet;
563 
564  public:
567  {
568  document = 0;
569  prev = next = 0;
570  }
571 
572  #ifdef TIXML_USE_STL
573  TiXmlAttribute( const std::string& _name, const std::string& _value )
575  {
576  name = _name;
577  value = _value;
578  document = 0;
579  prev = next = 0;
580  }
581  #endif
582 
584  TiXmlAttribute( const char * _name, const char * _value )
585  {
586  name = _name;
587  value = _value;
588  document = 0;
589  prev = next = 0;
590  }
591 
592  const char* Name() const { return name.c_str (); }
593  const char* Value() const { return value.c_str (); }
594  const int IntValue() const;
595  const double DoubleValue() const;
596 
606  int QueryIntValue( int* value ) const;
608  int QueryDoubleValue( double* value ) const;
609 
610  void SetName( const char* _name ) { name = _name; }
611  void SetValue( const char* _value ) { value = _value; }
612 
613  void SetIntValue( int value );
614  void SetDoubleValue( double value );
615 
616  #ifdef TIXML_USE_STL
617  void SetName( const std::string& _name )
619  {
620  StringToBuffer buf( _name );
621  SetName ( buf.buffer ? buf.buffer : "error" );
622  }
624  void SetValue( const std::string& _value )
625  {
626  StringToBuffer buf( _value );
627  SetValue( buf.buffer ? buf.buffer : "error" );
628  }
629  #endif
630 
632  TiXmlAttribute* Next() const;
634  TiXmlAttribute* Previous() const;
635 
636  bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
637  bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
638  bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
639 
640  /* [internal use]
641  Attribtue parsing starts: first letter of the name
642  returns: the next char after the value end quote
643  */
644  virtual const char* Parse( const char* p, TiXmlParsingData* data );
645 
646  // [internal use]
647  virtual void Print( FILE* cfile, int depth ) const;
648 
649  virtual void StreamOut( TIXML_OSTREAM * out ) const;
650  // [internal use]
651  // Set the document pointer so the attribute can report errors.
652  void SetDocument( TiXmlDocument* doc ) { document = doc; }
653 
654  private:
655  TiXmlDocument* document; // A pointer back to a document, for error reporting.
656  TIXML_STRING name;
657  TIXML_STRING value;
658  TiXmlAttribute* prev;
659  TiXmlAttribute* next;
660  };
661 
662 
663  /* A class used to manage a group of attributes.
664  It is only used internally, both by the ELEMENT and the DECLARATION.
665 
666  The set can be changed transparent to the Element and Declaration
667  classes that use it, but NOT transparent to the Attribute
668  which has to implement a next() and previous() method. Which makes
669  it a bit problematic and prevents the use of STL.
670 
671  This version is implemented with circular lists because:
672  - I like circular lists
673  - it demonstrates some independence from the (typical) doubly linked list.
674  */
675  class CAL3D_API TiXmlAttributeSet
676  {
677  public:
680 
681  void Add( TiXmlAttribute* attribute );
682  void Remove( TiXmlAttribute* attribute );
683 
684  TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
685  TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
686  TiXmlAttribute* Find( const char * name ) const;
687 
688  private:
689  TiXmlAttribute sentinel;
690  };
691 
692 
697  class CAL3D_API TiXmlElement : public TiXmlNode
698  {
699  public:
701  TiXmlElement (const char * in_value);
702 
703  #ifdef TIXML_USE_STL
704  TiXmlElement( const std::string& _value ) : TiXmlNode( TiXmlNode::ELEMENT )
706  {
707  firstChild = lastChild = 0;
708  value = _value;
709  }
710  #endif
711 
712  virtual ~TiXmlElement();
713 
717  const char* Attribute( const char* name ) const;
718 
725  const char* Attribute( const char* name, int* i ) const;
726 
733  const char* Attribute( const char* name, double* d ) const;
734 
742  int QueryIntAttribute( const char* name, int* value ) const;
744  int QueryDoubleAttribute( const char* name, double* value ) const;
745 
749  void SetAttribute( const char* name, const char * value );
750 
751  #ifdef TIXML_USE_STL
752  const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); }
753  const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); }
754 
756  void SetAttribute( const std::string& name, const std::string& _value )
757  {
758  StringToBuffer n( name );
759  StringToBuffer v( _value );
760  if ( n.buffer && v.buffer )
761  SetAttribute (n.buffer, v.buffer );
762  }
764  void SetAttribute( const std::string& name, int _value )
765  {
766  StringToBuffer n( name );
767  if ( n.buffer )
768  SetAttribute (n.buffer, _value);
769  }
770  #endif
771 
775  void SetAttribute( const char * name, int value );
776 
779  void RemoveAttribute( const char * name );
780  #ifdef TIXML_USE_STL
781  void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
782  #endif
783 
784  TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
785  TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
786 
787  // [internal use] Creates a new Element and returs it.
788  virtual TiXmlNode* Clone() const;
789  // [internal use]
790 
791  virtual void Print( FILE* cfile, int depth ) const;
792 
793  protected:
794 
795  // Used to be public [internal use]
796  #ifdef TIXML_USE_STL
797  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
798  #endif
799  virtual void StreamOut( TIXML_OSTREAM * out ) const;
800 
801  /* [internal use]
802  Attribtue parsing starts: next char past '<'
803  returns: next char past '>'
804  */
805  virtual const char* Parse( const char* p, TiXmlParsingData* data );
806 
807  /* [internal use]
808  Reads the "value" of the element -- another element, or text.
809  This should terminate with the current end tag.
810  */
811  const char* ReadValue( const char* in, TiXmlParsingData* prevData );
812 
813  private:
814  TiXmlAttributeSet attributeSet;
815  };
816 
817 
820  class CAL3D_API TiXmlComment : public TiXmlNode
821  {
822  public:
824  TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
825  virtual ~TiXmlComment() {}
826 
827  // [internal use] Creates a new Element and returs it.
828  virtual TiXmlNode* Clone() const;
829  // [internal use]
830  virtual void Print( FILE* cfile, int depth ) const;
831  protected:
832  // used to be public
833  #ifdef TIXML_USE_STL
834  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
835  #endif
836  virtual void StreamOut( TIXML_OSTREAM * out ) const;
837  /* [internal use]
838  Attribtue parsing starts: at the ! of the !--
839  returns: next char past '>'
840  */
841  virtual const char* Parse( const char* p, TiXmlParsingData* data );
842  };
843 
844 
847  class CAL3D_API TiXmlText : public TiXmlNode
848  {
849  friend class TiXmlElement;
850  public:
852  TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
853  {
854  SetValue( initValue );
855  }
856  virtual ~TiXmlText() {}
857 
858  #ifdef TIXML_USE_STL
859  TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
861  {
862  SetValue( initValue );
863  }
864  #endif
865 
866  // [internal use]
867  virtual void Print( FILE* cfile, int depth ) const;
868 
869  protected :
870  // [internal use] Creates a new Element and returns it.
871  virtual TiXmlNode* Clone() const;
872  virtual void StreamOut ( TIXML_OSTREAM * out ) const;
873  // [internal use]
874  bool Blank() const; // returns true if all white space and new lines
875  /* [internal use]
876  Attribtue parsing starts: First char of the text
877  returns: next char past '>'
878  */
879  virtual const char* Parse( const char* p, TiXmlParsingData* data );
880  // [internal use]
881  #ifdef TIXML_USE_STL
882  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
883  #endif
884  };
885 
886 
900  class CAL3D_API TiXmlDeclaration : public TiXmlNode
901  {
902  public:
904  TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
905 
906  #ifdef TIXML_USE_STL
907  TiXmlDeclaration( const std::string& _version,
909  const std::string& _encoding,
910  const std::string& _standalone )
911  : TiXmlNode( TiXmlNode::DECLARATION )
912  {
913  version = _version;
914  encoding = _encoding;
915  standalone = _standalone;
916  }
917  #endif
918 
920  TiXmlDeclaration( const char* _version,
921  const char* _encoding,
922  const char* _standalone );
923 
924  virtual ~TiXmlDeclaration() {}
925 
927  const char * Version() const { return version.c_str (); }
929  const char * Encoding() const { return encoding.c_str (); }
931  const char * Standalone() const { return standalone.c_str (); }
932 
933  // [internal use] Creates a new Element and returs it.
934  virtual TiXmlNode* Clone() const;
935  // [internal use]
936  virtual void Print( FILE* cfile, int depth ) const;
937 
938  protected:
939  // used to be public
940  #ifdef TIXML_USE_STL
941  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
942  #endif
943  virtual void StreamOut ( TIXML_OSTREAM * out) const;
944  // [internal use]
945  // Attribtue parsing starts: next char past '<'
946  // returns: next char past '>'
947 
948  virtual const char* Parse( const char* p, TiXmlParsingData* data );
949 
950  private:
951  TIXML_STRING version;
952  TIXML_STRING encoding;
953  TIXML_STRING standalone;
954  };
955 
956 
962  class CAL3D_API TiXmlUnknown : public TiXmlNode
963  {
964  public:
965  TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
966  virtual ~TiXmlUnknown() {}
967 
968  // [internal use]
969  virtual TiXmlNode* Clone() const;
970  // [internal use]
971  virtual void Print( FILE* cfile, int depth ) const;
972  protected:
973  #ifdef TIXML_USE_STL
974  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
975  #endif
976  virtual void StreamOut ( TIXML_OSTREAM * out ) const;
977  /* [internal use]
978  Attribute parsing starts: First char of the text
979  returns: next char past '>'
980  */
981  virtual const char* Parse( const char* p, TiXmlParsingData* data );
982  };
983 
984 
989  class CAL3D_API TiXmlDocument : public TiXmlNode
990  {
991  public:
993  TiXmlDocument();
995  TiXmlDocument( const char * documentName );
996 
997  #ifdef TIXML_USE_STL
998  TiXmlDocument( const std::string& documentName ) :
1000  TiXmlNode( TiXmlNode::DOCUMENT )
1001  {
1002  tabsize = 4;
1003  value = documentName;
1004  error = false;
1005  }
1006  #endif
1007 
1008  virtual ~TiXmlDocument() {}
1009 
1014  bool LoadFile();
1016  bool SaveFile() const;
1018  bool LoadFile( const char * filename );
1020  bool SaveFile( const char * filename ) const;
1021 
1022  #ifdef TIXML_USE_STL
1023  bool LoadFile( const std::string& filename )
1024  {
1025  StringToBuffer f( filename );
1026  return ( f.buffer && LoadFile( f.buffer ));
1027  }
1028  bool SaveFile( const std::string& filename ) const
1029  {
1030  StringToBuffer f( filename );
1031  return ( f.buffer && SaveFile( f.buffer ));
1032  }
1033  #endif
1034 
1037  virtual const char* Parse( const char* p, TiXmlParsingData* data = 0 );
1038 
1043  TiXmlElement* RootElement() const { return FirstChildElement(); }
1044 
1050  bool Error() const { return error; }
1051 
1053  const char * ErrorDesc() const { return errorDesc.c_str (); }
1054 
1058  const int ErrorId() const { return errorId; }
1059 
1067  int ErrorRow() { return errorLocation.row+1; }
1068  int ErrorCol() { return errorLocation.col+1; }
1069 
1090  void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
1091 
1092  int TabSize() const { return tabsize; }
1093 
1097  void ClearError() { error = false;
1098  errorId = 0;
1099  errorDesc = "";
1100  errorLocation.row = errorLocation.col = 0;
1101  //errorLocation.last = 0;
1102  }
1103 
1105  void Print() const { Print( stdout, 0 ); }
1106 
1107  // [internal use]
1108  virtual void Print( FILE* cfile, int depth = 0 ) const;
1109  // [internal use]
1110  void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData );
1111 
1112  protected :
1113  virtual void StreamOut ( TIXML_OSTREAM * out) const;
1114  // [internal use]
1115  virtual TiXmlNode* Clone() const;
1116  #ifdef TIXML_USE_STL
1117  virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1118  #endif
1119 
1120  private:
1121  bool error;
1122  int errorId;
1123  TIXML_STRING errorDesc;
1124  int tabsize;
1125  TiXmlCursor errorLocation;
1126  };
1127 
1128 
1209  class CAL3D_API TiXmlHandle
1210  {
1211  public:
1213  TiXmlHandle( TiXmlNode* node ) { this->node = node; }
1215  TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
1216 
1218  TiXmlHandle FirstChild() const;
1220  TiXmlHandle FirstChild( const char * value ) const;
1222  TiXmlHandle FirstChildElement() const;
1224  TiXmlHandle FirstChildElement( const char * value ) const;
1225 
1229  TiXmlHandle Child( const char* value, int index ) const;
1233  TiXmlHandle Child( int index ) const;
1238  TiXmlHandle ChildElement( const char* value, int index ) const;
1243  TiXmlHandle ChildElement( int index ) const;
1244 
1245  #ifdef TIXML_USE_STL
1246  TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
1247  TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
1248 
1249  TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
1250  TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
1251  #endif
1252 
1254  TiXmlNode* Node() const { return node; }
1256  TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
1258  TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
1259 
1260  private:
1261  TiXmlNode* node;
1262  };
1263 
1264 }
1265 
1266 #endif
1267 
int ErrorCol()
The column where the error occured. See ErrorRow()
Definition: tinyxml.h:1068
void ClearError()
If you have handled the error, it can be reset with this call.
Definition: tinyxml.h:1097
Any tag that tinyXml doesn't recognize is saved as an unknown.
Definition: tinyxml.h:962
bool SaveFile(const std::string &filename) const
< STL std::string version.
Definition: tinyxml.h:1028
TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:383
An XML comment.
Definition: tinyxml.h:820
TiXmlComment()
Constructs an empty comment.
Definition: tinyxml.h:824
A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thi...
Definition: tinyxml.h:1209
Definition: tinyxml.h:675
TiXmlNode * Node() const
Return the handle as a TiXmlNode. This may return null.
Definition: tinyxml.h:1254
void SetValue(const char *_value)
Set the value.
Definition: tinyxml.h:611
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
Definition: tinyxml.h:1053
TiXmlNode * FirstChild(const std::string &_value) const
The last child of this node matching 'value'. Will be null if there are no children.
Definition: tinyxml.h:390
TiXmlAttribute(const char *_name, const char *_value)
Construct an attribute with a name and value.
Definition: tinyxml.h:584
void Print() const
Dump the document to standard out.
Definition: tinyxml.h:1105
TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:455
TiXmlElement * FirstChildElement(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:494
NodeType
The types of XML nodes supported by TinyXml.
Definition: tinyxml.h:330
virtual int Type() const
Query the type (as an enumerated value, above) of this node.
Definition: tinyxml.h:501
int Row() const
Return the position, in the original source file, of this node or attribute.
Definition: tinyxml.h:170
TiXmlAttribute * LastAttribute() const
Access the last attribute in this element.
Definition: tinyxml.h:785
TiXmlElement * NextSiblingElement(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:484
TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:516
XML text.
Definition: tinyxml.h:847
int ErrorRow()
Returns the location (if known) of the error.
Definition: tinyxml.h:1067
TiXmlNode * LastChild(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:391
Definition: tinyxml.h:176
In correct XML the declaration is the first entry in the file.
Definition: tinyxml.h:900
TiXmlHandle(const TiXmlHandle &ref)
Copy constructor.
Definition: tinyxml.h:1215
TiXmlComment * ToComment() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:513
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml.h:509
TiXmlBase is a base class for every class in TinyXml.
Definition: tinyxml.h:124
An attribute is a name-value pair.
Definition: tinyxml.h:560
Always the top level node.
Definition: tinyxml.h:989
TiXmlText * Text() const
Return the handle as a TiXmlText. This may return null.
Definition: tinyxml.h:1258
void SetTabSize(int _tabsize)
By calling this method, with a tab size greater than 0, the row and column of each node and attribute...
Definition: tinyxml.h:1090
TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:511
TiXmlNode * IterateChildren(const std::string &_value, TiXmlNode *previous) const
STL std::string form.
Definition: tinyxml.h:416
TiXmlText(const char *initValue)
Constructor.
Definition: tinyxml.h:852
TiXmlNode * PreviousSibling(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:461
void SetAttribute(const std::string &name, const std::string &_value)
STL std::string form.
Definition: tinyxml.h:756
const char * Encoding() const
Encoding. Will return empty if none was found.
Definition: tinyxml.h:929
TiXmlNode * NextSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:466
const char * Version() const
Version. Will return empty if none was found.
Definition: tinyxml.h:927
TiXmlDeclaration()
Construct an empty declaration.
Definition: tinyxml.h:904
Definition: tinyxmlparser.cpp:46
static void SetCondenseWhiteSpace(bool condense)
The world does not agree on whether white space should be kept or not.
Definition: tinyxml.h:147
TiXmlHandle(TiXmlNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml.h:1213
const char * Standalone() const
Is this a standalone document?
Definition: tinyxml.h:931
TiXmlElement * ToElement() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:512
TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:462
TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:514
TiXmlText * ToText() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:515
TiXmlNode * Parent() const
One step up the DOM.
Definition: tinyxml.h:381
TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
Definition: tinyxml.h:784
TiXmlElement * RootElement() const
Get the root element – the only top level element – of the document.
Definition: tinyxml.h:1043
const int ErrorId() const
Generally, you probably want the error string ( ErrorDesc() ).
Definition: tinyxml.h:1058
void SetValue(const std::string &_value)
STL std::string form.
Definition: tinyxml.h:624
bool Error() const
If an error occurs, Error will be set to true.
Definition: tinyxml.h:1050
TiXmlElement * Element() const
Return the handle as a TiXmlElement. This may return null.
Definition: tinyxml.h:1256
The element is a container class.
Definition: tinyxml.h:697
Definition: tinyxml.h:84
const char * Value() const
Return the value of this attribute.
Definition: tinyxml.h:593
const char * Name() const
Return the name of this attribute.
Definition: tinyxml.h:592
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
Definition: tinyxml.h:355
TiXmlAttribute()
Construct an empty attribute.
Definition: tinyxml.h:566
The parent class for everything in the Document Object Model.
Definition: tinyxml.h:288
static bool IsWhiteSpaceCondensed()
Return the current white space setting.
Definition: tinyxml.h:150
bool LoadFile(const std::string &filename)
Definition: tinyxml.h:1023
void SetName(const char *_name)
Set the name of this attribute.
Definition: tinyxml.h:610
int Column() const
See Row()
Definition: tinyxml.h:171
void RemoveAttribute(const std::string &name)
STL std::string form.
Definition: tinyxml.h:781
void SetValue(const char *_value)
Changes the value of the node.
Definition: tinyxml.h:366

Generated at Thu Sep 4 2014 00:32:52 by The Cal3D Team with Doxygen 1.8.7