Scheduler
tinyxml.cpp
Go to the documentation of this file.
1 
10 /*
11 www.sourceforge.net/projects/tinyxml
12 Original code by Lee Thomason (www.grinninglizard.com)
13 
14 This software is provided 'as-is', without any express or implied
15 warranty. In no event will the authors be held liable for any
16 damages arising from the use of this software.
17 
18 Permission is granted to anyone to use this software for any
19 purpose, including commercial applications, and to alter it and
20 redistribute it freely, subject to the following restrictions:
21 
22 1. The origin of this software must not be misrepresented; you must
23 not claim that you wrote the original software. If you use this
24 software in a product, an acknowledgment in the product documentation
25 would be appreciated but is not required.
26 
27 2. Altered source versions must be plainly marked as such, and
28 must not be misrepresented as being the original software.
29 
30 3. This notice may not be removed or altered from any source
31 distribution.
32 */
33 
34 #include <ctype.h>
35 
36 #ifdef TIXML_USE_STL
37 #include <sstream>
38 #include <iostream>
39 #endif
40 
41 #include "tinyxml.h"
42 
43 FILE* TiXmlFOpen( const char* filename, const char* mode );
44 
45 bool TiXmlBase::condenseWhiteSpace = true;
46 
47 // Microsoft compiler security
48 FILE* TiXmlFOpen( const char* filename, const char* mode )
49 {
50  #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
51  FILE* fp = 0;
52  errno_t err = fopen_s( &fp, filename, mode );
53  if ( !err && fp )
54  return fp;
55  return 0;
56  #else
57  return fopen( filename, mode );
58  #endif
59 }
60 
61 void TiXmlBase::EncodeString( const TIXML_STRING& str, TIXML_STRING* outString )
62 {
63  int i=0;
64 
65  while( i<(int)str.length() )
66  {
67  unsigned char c = (unsigned char) str[i];
68 
69  if ( c == '&'
70  && i < ( (int)str.length() - 2 )
71  && str[i+1] == '#'
72  && str[i+2] == 'x' )
73  {
74  // Hexadecimal character reference.
75  // Pass through unchanged.
76  // &#xA9; -- copyright symbol, for example.
77  //
78  // The -1 is a bug fix from Rob Laveaux. It keeps
79  // an overflow from happening if there is no ';'.
80  // There are actually 2 ways to exit this loop -
81  // while fails (error case) and break (semicolon found).
82  // However, there is no mechanism (currently) for
83  // this function to return an error.
84  while ( i<(int)str.length()-1 )
85  {
86  outString->append( str.c_str() + i, 1 );
87  ++i;
88  if ( str[i] == ';' )
89  break;
90  }
91  }
92  else if ( c == '&' )
93  {
94  outString->append( entity[0].str, entity[0].strLength );
95  ++i;
96  }
97  else if ( c == '<' )
98  {
99  outString->append( entity[1].str, entity[1].strLength );
100  ++i;
101  }
102  else if ( c == '>' )
103  {
104  outString->append( entity[2].str, entity[2].strLength );
105  ++i;
106  }
107  else if ( c == '\"' )
108  {
109  outString->append( entity[3].str, entity[3].strLength );
110  ++i;
111  }
112  else if ( c == '\'' )
113  {
114  outString->append( entity[4].str, entity[4].strLength );
115  ++i;
116  }
117  else if ( c < 32 )
118  {
119  // Easy pass at non-alpha/numeric/symbol
120  // Below 32 is symbolic.
121  char buf[ 32 ];
122 
123  #if defined(TIXML_SNPRINTF)
124  TIXML_SNPRINTF( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) );
125  #else
126  sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) );
127  #endif
128 
129  //*ME: warning C4267: convert 'size_t' to 'int'
130  //*ME: Int-Cast to make compiler happy ...
131  outString->append( buf, (int)strlen( buf ) );
132  ++i;
133  }
134  else
135  {
136  //char realc = (char) c;
137  //outString->append( &realc, 1 );
138  *outString += (char) c; // somewhat more efficient function call.
139  ++i;
140  }
141  }
142 }
143 
144 
146 {
147  parent = 0;
148  type = _type;
149  firstChild = 0;
150  lastChild = 0;
151  prev = 0;
152  next = 0;
153 }
154 
155 
157 {
158  TiXmlNode* node = firstChild;
159  TiXmlNode* temp = 0;
160 
161  while ( node )
162  {
163  temp = node;
164  node = node->next;
165  delete temp;
166  }
167 }
168 
169 
170 void TiXmlNode::CopyTo( TiXmlNode* target ) const
171 {
172  target->SetValue (value.c_str() );
173  target->userData = userData;
174  target->location = location;
175 }
176 
177 
179 {
180  TiXmlNode* node = firstChild;
181  TiXmlNode* temp = 0;
182 
183  while ( node )
184  {
185  temp = node;
186  node = node->next;
187  delete temp;
188  }
189 
190  firstChild = 0;
191  lastChild = 0;
192 }
193 
194 
196 {
197  assert( node->parent == 0 || node->parent == this );
198  assert( node->GetDocument() == 0 || node->GetDocument() == this->GetDocument() );
199 
200  if ( node->Type() == TiXmlNode::TINYXML_DOCUMENT )
201  {
202  delete node;
203  if ( GetDocument() )
205  return 0;
206  }
207 
208  node->parent = this;
209 
210  node->prev = lastChild;
211  node->next = 0;
212 
213  if ( lastChild )
214  lastChild->next = node;
215  else
216  firstChild = node; // it was an empty list.
217 
218  lastChild = node;
219  return node;
220 }
221 
222 
224 {
225  if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT )
226  {
227  if ( GetDocument() )
229  return 0;
230  }
231  TiXmlNode* node = addThis.Clone();
232  if ( !node )
233  return 0;
234 
235  return LinkEndChild( node );
236 }
237 
238 
240 {
241  if ( !beforeThis || beforeThis->parent != this ) {
242  return 0;
243  }
244  if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT )
245  {
246  if ( GetDocument() )
248  return 0;
249  }
250 
251  TiXmlNode* node = addThis.Clone();
252  if ( !node )
253  return 0;
254  node->parent = this;
255 
256  node->next = beforeThis;
257  node->prev = beforeThis->prev;
258  if ( beforeThis->prev )
259  {
260  beforeThis->prev->next = node;
261  }
262  else
263  {
264  assert( firstChild == beforeThis );
265  firstChild = node;
266  }
267  beforeThis->prev = node;
268  return node;
269 }
270 
271 
273 {
274  if ( !afterThis || afterThis->parent != this ) {
275  return 0;
276  }
277  if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT )
278  {
279  if ( GetDocument() )
281  return 0;
282  }
283 
284  TiXmlNode* node = addThis.Clone();
285  if ( !node )
286  return 0;
287  node->parent = this;
288 
289  node->prev = afterThis;
290  node->next = afterThis->next;
291  if ( afterThis->next )
292  {
293  afterThis->next->prev = node;
294  }
295  else
296  {
297  assert( lastChild == afterThis );
298  lastChild = node;
299  }
300  afterThis->next = node;
301  return node;
302 }
303 
304 
305 TiXmlNode* TiXmlNode::ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis )
306 {
307  if ( !replaceThis )
308  return 0;
309 
310  if ( replaceThis->parent != this )
311  return 0;
312 
313  if ( withThis.ToDocument() ) {
314  // A document can never be a child. Thanks to Noam.
315  TiXmlDocument* document = GetDocument();
316  if ( document )
318  return 0;
319  }
320 
321  TiXmlNode* node = withThis.Clone();
322  if ( !node )
323  return 0;
324 
325  node->next = replaceThis->next;
326  node->prev = replaceThis->prev;
327 
328  if ( replaceThis->next )
329  replaceThis->next->prev = node;
330  else
331  lastChild = node;
332 
333  if ( replaceThis->prev )
334  replaceThis->prev->next = node;
335  else
336  firstChild = node;
337 
338  delete replaceThis;
339  node->parent = this;
340  return node;
341 }
342 
343 
345 {
346  if ( !removeThis ) {
347  return false;
348  }
349 
350  if ( removeThis->parent != this )
351  {
352  assert( 0 );
353  return false;
354  }
355 
356  if ( removeThis->next )
357  removeThis->next->prev = removeThis->prev;
358  else
359  lastChild = removeThis->prev;
360 
361  if ( removeThis->prev )
362  removeThis->prev->next = removeThis->next;
363  else
364  firstChild = removeThis->next;
365 
366  delete removeThis;
367  return true;
368 }
369 
370 const TiXmlNode* TiXmlNode::FirstChild( const char * _value ) const
371 {
372  const TiXmlNode* node;
373  for ( node = firstChild; node; node = node->next )
374  {
375  if ( strcmp( node->Value(), _value ) == 0 )
376  return node;
377  }
378  return 0;
379 }
380 
381 
382 const TiXmlNode* TiXmlNode::LastChild( const char * _value ) const
383 {
384  const TiXmlNode* node;
385  for ( node = lastChild; node; node = node->prev )
386  {
387  if ( strcmp( node->Value(), _value ) == 0 )
388  return node;
389  }
390  return 0;
391 }
392 
393 
394 const TiXmlNode* TiXmlNode::IterateChildren( const TiXmlNode* previous ) const
395 {
396  if ( !previous )
397  {
398  return FirstChild();
399  }
400  else
401  {
402  assert( previous->parent == this );
403  return previous->NextSibling();
404  }
405 }
406 
407 
408 const TiXmlNode* TiXmlNode::IterateChildren( const char * val, const TiXmlNode* previous ) const
409 {
410  if ( !previous )
411  {
412  return FirstChild( val );
413  }
414  else
415  {
416  assert( previous->parent == this );
417  return previous->NextSibling( val );
418  }
419 }
420 
421 
422 const TiXmlNode* TiXmlNode::NextSibling( const char * _value ) const
423 {
424  const TiXmlNode* node;
425  for ( node = next; node; node = node->next )
426  {
427  if ( strcmp( node->Value(), _value ) == 0 )
428  return node;
429  }
430  return 0;
431 }
432 
433 
434 const TiXmlNode* TiXmlNode::PreviousSibling( const char * _value ) const
435 {
436  const TiXmlNode* node;
437  for ( node = prev; node; node = node->prev )
438  {
439  if ( strcmp( node->Value(), _value ) == 0 )
440  return node;
441  }
442  return 0;
443 }
444 
445 
446 void TiXmlElement::RemoveAttribute( const char * name )
447 {
448  #ifdef TIXML_USE_STL
449  TIXML_STRING str( name );
450  TiXmlAttribute* node = attributeSet.Find( str );
451  #else
452  TiXmlAttribute* node = attributeSet.Find( name );
453  #endif
454  if ( node )
455  {
456  attributeSet.Remove( node );
457  delete node;
458  }
459 }
460 
462 {
463  const TiXmlNode* node;
464 
465  for ( node = FirstChild();
466  node;
467  node = node->NextSibling() )
468  {
469  if ( node->ToElement() )
470  return node->ToElement();
471  }
472  return 0;
473 }
474 
475 
476 const TiXmlElement* TiXmlNode::FirstChildElement( const char * _value ) const
477 {
478  const TiXmlNode* node;
479 
480  for ( node = FirstChild( _value );
481  node;
482  node = node->NextSibling( _value ) )
483  {
484  if ( node->ToElement() )
485  return node->ToElement();
486  }
487  return 0;
488 }
489 
490 
492 {
493  const TiXmlNode* node;
494 
495  for ( node = NextSibling();
496  node;
497  node = node->NextSibling() )
498  {
499  if ( node->ToElement() )
500  return node->ToElement();
501  }
502  return 0;
503 }
504 
505 
506 const TiXmlElement* TiXmlNode::NextSiblingElement( const char * _value ) const
507 {
508  const TiXmlNode* node;
509 
510  for ( node = NextSibling( _value );
511  node;
512  node = node->NextSibling( _value ) )
513  {
514  if ( node->ToElement() )
515  return node->ToElement();
516  }
517  return 0;
518 }
519 
520 
522 {
523  const TiXmlNode* node;
524 
525  for( node = this; node; node = node->parent )
526  {
527  if ( node->ToDocument() )
528  return node->ToDocument();
529  }
530  return 0;
531 }
532 
533 
534 TiXmlElement::TiXmlElement (const char * _value)
536 {
537  firstChild = lastChild = 0;
538  value = _value;
539 }
540 
541 
542 #ifdef TIXML_USE_STL
543 TiXmlElement::TiXmlElement( const std::string& _value )
545 {
546  firstChild = lastChild = 0;
547  value = _value;
548 }
549 #endif
550 
551 
554 {
555  firstChild = lastChild = 0;
556  copy.CopyTo( this );
557 }
558 
559 
561 {
562  ClearThis();
563  base.CopyTo( this );
564  return *this;
565 }
566 
567 
569 {
570  ClearThis();
571 }
572 
573 
575 {
576  Clear();
577  while( attributeSet.First() )
578  {
579  TiXmlAttribute* node = attributeSet.First();
580  attributeSet.Remove( node );
581  delete node;
582  }
583 }
584 
585 
586 const char* TiXmlElement::Attribute( const char* name ) const
587 {
588  const TiXmlAttribute* node = attributeSet.Find( name );
589  if ( node )
590  return node->Value();
591  return 0;
592 }
593 
594 
595 #ifdef TIXML_USE_STL
596 const std::string* TiXmlElement::Attribute( const std::string& name ) const
597 {
598  const TiXmlAttribute* attrib = attributeSet.Find( name );
599  if ( attrib )
600  return &attrib->ValueStr();
601  return 0;
602 }
603 #endif
604 
605 
606 const char* TiXmlElement::Attribute( const char* name, int* i ) const
607 {
608  const TiXmlAttribute* attrib = attributeSet.Find( name );
609  const char* result = 0;
610 
611  if ( attrib ) {
612  result = attrib->Value();
613  if ( i ) {
614  attrib->QueryIntValue( i );
615  }
616  }
617  return result;
618 }
619 
620 
621 #ifdef TIXML_USE_STL
622 const std::string* TiXmlElement::Attribute( const std::string& name, int* i ) const
623 {
624  const TiXmlAttribute* attrib = attributeSet.Find( name );
625  const std::string* result = 0;
626 
627  if ( attrib ) {
628  result = &attrib->ValueStr();
629  if ( i ) {
630  attrib->QueryIntValue( i );
631  }
632  }
633  return result;
634 }
635 #endif
636 
637 
638 const char* TiXmlElement::Attribute( const char* name, double* d ) const
639 {
640  const TiXmlAttribute* attrib = attributeSet.Find( name );
641  const char* result = 0;
642 
643  if ( attrib ) {
644  result = attrib->Value();
645  if ( d ) {
646  attrib->QueryDoubleValue( d );
647  }
648  }
649  return result;
650 }
651 
652 
653 #ifdef TIXML_USE_STL
654 const std::string* TiXmlElement::Attribute( const std::string& name, double* d ) const
655 {
656  const TiXmlAttribute* attrib = attributeSet.Find( name );
657  const std::string* result = 0;
658 
659  if ( attrib ) {
660  result = &attrib->ValueStr();
661  if ( d ) {
662  attrib->QueryDoubleValue( d );
663  }
664  }
665  return result;
666 }
667 #endif
668 
669 
670 int TiXmlElement::QueryIntAttribute( const char* name, int* ival ) const
671 {
672  const TiXmlAttribute* attrib = attributeSet.Find( name );
673  if ( !attrib )
674  return TIXML_NO_ATTRIBUTE;
675  return attrib->QueryIntValue( ival );
676 }
677 
678 
679 int TiXmlElement::QueryUnsignedAttribute( const char* name, unsigned* value ) const
680 {
681  const TiXmlAttribute* node = attributeSet.Find( name );
682  if ( !node )
683  return TIXML_NO_ATTRIBUTE;
684 
685  int ival = 0;
686  int result = node->QueryIntValue( &ival );
687  *value = (unsigned)ival;
688  return result;
689 }
690 
691 
692 int TiXmlElement::QueryBoolAttribute( const char* name, bool* bval ) const
693 {
694  const TiXmlAttribute* node = attributeSet.Find( name );
695  if ( !node )
696  return TIXML_NO_ATTRIBUTE;
697 
698  int result = TIXML_WRONG_TYPE;
699  if ( StringEqual( node->Value(), "true", true, TIXML_ENCODING_UNKNOWN )
700  || StringEqual( node->Value(), "yes", true, TIXML_ENCODING_UNKNOWN )
701  || StringEqual( node->Value(), "1", true, TIXML_ENCODING_UNKNOWN ) )
702  {
703  *bval = true;
704  result = TIXML_SUCCESS;
705  }
706  else if ( StringEqual( node->Value(), "false", true, TIXML_ENCODING_UNKNOWN )
707  || StringEqual( node->Value(), "no", true, TIXML_ENCODING_UNKNOWN )
708  || StringEqual( node->Value(), "0", true, TIXML_ENCODING_UNKNOWN ) )
709  {
710  *bval = false;
711  result = TIXML_SUCCESS;
712  }
713  return result;
714 }
715 
716 
717 
718 #ifdef TIXML_USE_STL
719 int TiXmlElement::QueryIntAttribute( const std::string& name, int* ival ) const
720 {
721  const TiXmlAttribute* attrib = attributeSet.Find( name );
722  if ( !attrib )
723  return TIXML_NO_ATTRIBUTE;
724  return attrib->QueryIntValue( ival );
725 }
726 #endif
727 
728 
729 int TiXmlElement::QueryDoubleAttribute( const char* name, double* dval ) const
730 {
731  const TiXmlAttribute* attrib = attributeSet.Find( name );
732  if ( !attrib )
733  return TIXML_NO_ATTRIBUTE;
734  return attrib->QueryDoubleValue( dval );
735 }
736 
737 
738 #ifdef TIXML_USE_STL
739 int TiXmlElement::QueryDoubleAttribute( const std::string& name, double* dval ) const
740 {
741  const TiXmlAttribute* attrib = attributeSet.Find( name );
742  if ( !attrib )
743  return TIXML_NO_ATTRIBUTE;
744  return attrib->QueryDoubleValue( dval );
745 }
746 #endif
747 
748 
749 void TiXmlElement::SetAttribute( const char * name, int val )
750 {
751  TiXmlAttribute* attrib = attributeSet.FindOrCreate( name );
752  if ( attrib ) {
753  attrib->SetIntValue( val );
754  }
755 }
756 
757 
758 #ifdef TIXML_USE_STL
759 void TiXmlElement::SetAttribute( const std::string& name, int val )
760 {
761  TiXmlAttribute* attrib = attributeSet.FindOrCreate( name );
762  if ( attrib ) {
763  attrib->SetIntValue( val );
764  }
765 }
766 #endif
767 
768 
769 void TiXmlElement::SetDoubleAttribute( const char * name, double val )
770 {
771  TiXmlAttribute* attrib = attributeSet.FindOrCreate( name );
772  if ( attrib ) {
773  attrib->SetDoubleValue( val );
774  }
775 }
776 
777 
778 #ifdef TIXML_USE_STL
779 void TiXmlElement::SetDoubleAttribute( const std::string& name, double val )
780 {
781  TiXmlAttribute* attrib = attributeSet.FindOrCreate( name );
782  if ( attrib ) {
783  attrib->SetDoubleValue( val );
784  }
785 }
786 #endif
787 
788 
789 void TiXmlElement::SetAttribute( const char * cname, const char * cvalue )
790 {
791  TiXmlAttribute* attrib = attributeSet.FindOrCreate( cname );
792  if ( attrib ) {
793  attrib->SetValue( cvalue );
794  }
795 }
796 
797 
798 #ifdef TIXML_USE_STL
799 void TiXmlElement::SetAttribute( const std::string& _name, const std::string& _value )
800 {
801  TiXmlAttribute* attrib = attributeSet.FindOrCreate( _name );
802  if ( attrib ) {
803  attrib->SetValue( _value );
804  }
805 }
806 #endif
807 
808 
809 void TiXmlElement::Print( FILE* cfile, int depth ) const
810 {
811  int i;
812  assert( cfile );
813  for ( i=0; i<depth; i++ ) {
814  fprintf( cfile, " " );
815  }
816 
817  fprintf( cfile, "<%s", value.c_str() );
818 
819  const TiXmlAttribute* attrib;
820  for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() )
821  {
822  fprintf( cfile, " " );
823  attrib->Print( cfile, depth );
824  }
825 
826  // There are 3 different formatting approaches:
827  // 1) An element without children is printed as a <foo /> node
828  // 2) An element with only a text child is printed as <foo> text </foo>
829  // 3) An element with children is printed on multiple lines.
830  TiXmlNode* node;
831  if ( !firstChild )
832  {
833  fprintf( cfile, " />" );
834  }
835  else if ( firstChild == lastChild && firstChild->ToText() )
836  {
837  fprintf( cfile, ">" );
838  firstChild->Print( cfile, depth + 1 );
839  fprintf( cfile, "</%s>", value.c_str() );
840  }
841  else
842  {
843  fprintf( cfile, ">" );
844 
845  for ( node = firstChild; node; node=node->NextSibling() )
846  {
847  if ( !node->ToText() )
848  {
849  fprintf( cfile, "\n" );
850  }
851  node->Print( cfile, depth+1 );
852  }
853  fprintf( cfile, "\n" );
854  for( i=0; i<depth; ++i ) {
855  fprintf( cfile, " " );
856  }
857  fprintf( cfile, "</%s>", value.c_str() );
858  }
859 }
860 
861 
862 void TiXmlElement::CopyTo( TiXmlElement* target ) const
863 {
864  // superclass:
865  TiXmlNode::CopyTo( target );
866 
867  // Element class:
868  // Clone the attributes, then clone the children.
869  const TiXmlAttribute* attribute = 0;
870  for( attribute = attributeSet.First();
871  attribute;
872  attribute = attribute->Next() )
873  {
874  target->SetAttribute( attribute->Name(), attribute->Value() );
875  }
876 
877  TiXmlNode* node = 0;
878  for ( node = firstChild; node; node = node->NextSibling() )
879  {
880  target->LinkEndChild( node->Clone() );
881  }
882 }
883 
884 bool TiXmlElement::Accept( TiXmlVisitor* visitor ) const
885 {
886  if ( visitor->VisitEnter( *this, attributeSet.First() ) )
887  {
888  for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
889  {
890  if ( !node->Accept( visitor ) )
891  break;
892  }
893  }
894  return visitor->VisitExit( *this );
895 }
896 
897 
899 {
900  TiXmlElement* clone = new TiXmlElement( Value() );
901  if ( !clone )
902  return 0;
903 
904  CopyTo( clone );
905  return clone;
906 }
907 
908 
909 const char* TiXmlElement::GetText() const
910 {
911  const TiXmlNode* child = this->FirstChild();
912  if ( child ) {
913  const TiXmlText* childText = child->ToText();
914  if ( childText ) {
915  return childText->Value();
916  }
917  }
918  return 0;
919 }
920 
921 
923 {
924  tabsize = 4;
925  useMicrosoftBOM = false;
926  ClearError();
927 }
928 
930 {
931  tabsize = 4;
932  useMicrosoftBOM = false;
933  value = documentName;
934  ClearError();
935 }
936 
937 
938 #ifdef TIXML_USE_STL
939 TiXmlDocument::TiXmlDocument( const std::string& documentName ) : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT )
940 {
941  tabsize = 4;
942  useMicrosoftBOM = false;
943  value = documentName;
944  ClearError();
945 }
946 #endif
947 
948 
950 {
951  copy.CopyTo( this );
952 }
953 
954 
956 {
957  Clear();
958  copy.CopyTo( this );
959  return *this;
960 }
961 
962 
964 {
965  return LoadFile( Value(), encoding );
966 }
967 
968 
970 {
971  return SaveFile( Value() );
972 }
973 
974 bool TiXmlDocument::LoadFile( const char* _filename, TiXmlEncoding encoding )
975 {
976  TIXML_STRING filename( _filename );
977  value = filename;
978 
979  // reading in binary mode so that tinyxml can normalize the EOL
980  FILE* file = TiXmlFOpen( value.c_str (), "rb" );
981 
982  if ( file )
983  {
984  bool result = LoadFile( file, encoding );
985  fclose( file );
986  return result;
987  }
988  else
989  {
991  return false;
992  }
993 }
994 
995 bool TiXmlDocument::LoadFile( FILE* file, TiXmlEncoding encoding )
996 {
997  if ( !file )
998  {
1000  return false;
1001  }
1002 
1003  // Delete the existing data:
1004  Clear();
1005  location.Clear();
1006 
1007  // Get the file size, so we can pre-allocate the string. HUGE speed impact.
1008  long length = 0;
1009  fseek( file, 0, SEEK_END );
1010  length = ftell( file );
1011  fseek( file, 0, SEEK_SET );
1012 
1013  // Strange case, but good to handle up front.
1014  if ( length <= 0 )
1015  {
1017  return false;
1018  }
1019 
1020  // Subtle bug here. TinyXml did use fgets. But from the XML spec:
1021  // 2.11 End-of-Line Handling
1022  // <snip>
1023  // <quote>
1024  // ...the XML processor MUST behave as if it normalized all line breaks in external
1025  // parsed entities (including the document entity) on input, before parsing, by translating
1026  // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to
1027  // a single #xA character.
1028  // </quote>
1029  //
1030  // It is not clear fgets does that, and certainly isn't clear it works cross platform.
1031  // Generally, you expect fgets to translate from the convention of the OS to the c/unix
1032  // convention, and not work generally.
1033 
1034  /*
1035  while( fgets( buf, sizeof(buf), file ) )
1036  {
1037  data += buf;
1038  }
1039  */
1040 
1041  char* buf = new char[ length+1 ];
1042  buf[0] = 0;
1043 
1044  if ( fread( buf, length, 1, file ) != 1 ) {
1045  delete [] buf;
1047  return false;
1048  }
1049 
1050  // Process the buffer in place to normalize new lines. (See comment above.)
1051  // Copies from the 'p' to 'q' pointer, where p can advance faster if
1052  // a newline-carriage return is hit.
1053  //
1054  // Wikipedia:
1055  // Systems based on ASCII or a compatible character set use either LF (Line feed, '\n', 0x0A, 10 in decimal) or
1056  // CR (Carriage return, '\r', 0x0D, 13 in decimal) individually, or CR followed by LF (CR+LF, 0x0D 0x0A)...
1057  // * LF: Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, FreeBSD, etc.), BeOS, Amiga, RISC OS, and others
1058  // * CR+LF: DEC RT-11 and most other early non-Unix, non-IBM OSes, CP/M, MP/M, DOS, OS/2, Microsoft Windows, Symbian OS
1059  // * CR: Commodore 8-bit machines, Apple II family, Mac OS up to version 9 and OS-9
1060 
1061  const char* p = buf; // the read head
1062  char* q = buf; // the write head
1063  const char CR = 0x0d;
1064  const char LF = 0x0a;
1065 
1066  buf[length] = 0;
1067  while( *p ) {
1068  assert( p < (buf+length) );
1069  assert( q <= (buf+length) );
1070  assert( q <= p );
1071 
1072  if ( *p == CR ) {
1073  *q++ = LF;
1074  p++;
1075  if ( *p == LF ) { // check for CR+LF (and skip LF)
1076  p++;
1077  }
1078  }
1079  else {
1080  *q++ = *p++;
1081  }
1082  }
1083  assert( q <= (buf+length) );
1084  *q = 0;
1085 
1086  Parse( buf, 0, encoding );
1087 
1088  delete [] buf;
1089  return !Error();
1090 }
1091 
1092 
1093 bool TiXmlDocument::SaveFile( const char * filename ) const
1094 {
1095  // The old c stuff lives on...
1096  FILE* fp = TiXmlFOpen( filename, "w" );
1097  if ( fp )
1098  {
1099  bool result = SaveFile( fp );
1100  fclose( fp );
1101  return result;
1102  }
1103  return false;
1104 }
1105 
1106 
1107 bool TiXmlDocument::SaveFile( FILE* fp ) const
1108 {
1109  if ( useMicrosoftBOM )
1110  {
1111  const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
1112  const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
1113  const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
1114 
1115  fputc( TIXML_UTF_LEAD_0, fp );
1116  fputc( TIXML_UTF_LEAD_1, fp );
1117  fputc( TIXML_UTF_LEAD_2, fp );
1118  }
1119  Print( fp, 0 );
1120  return (ferror(fp) == 0);
1121 }
1122 
1123 
1124 void TiXmlDocument::CopyTo( TiXmlDocument* target ) const
1125 {
1126  TiXmlNode::CopyTo( target );
1127 
1128  target->error = error;
1129  target->errorId = errorId;
1130  target->errorDesc = errorDesc;
1131  target->tabsize = tabsize;
1132  target->errorLocation = errorLocation;
1133  target->useMicrosoftBOM = useMicrosoftBOM;
1134 
1135  TiXmlNode* node = 0;
1136  for ( node = firstChild; node; node = node->NextSibling() )
1137  {
1138  target->LinkEndChild( node->Clone() );
1139  }
1140 }
1141 
1142 
1144 {
1145  TiXmlDocument* clone = new TiXmlDocument();
1146  if ( !clone )
1147  return 0;
1148 
1149  CopyTo( clone );
1150  return clone;
1151 }
1152 
1153 
1154 void TiXmlDocument::Print( FILE* cfile, int depth ) const
1155 {
1156  assert( cfile );
1157  for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
1158  {
1159  node->Print( cfile, depth );
1160  fprintf( cfile, "\n" );
1161  }
1162 }
1163 
1164 
1165 bool TiXmlDocument::Accept( TiXmlVisitor* visitor ) const
1166 {
1167  if ( visitor->VisitEnter( *this ) )
1168  {
1169  for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
1170  {
1171  if ( !node->Accept( visitor ) )
1172  break;
1173  }
1174  }
1175  return visitor->VisitExit( *this );
1176 }
1177 
1178 
1180 {
1181  // We are using knowledge of the sentinel. The sentinel
1182  // have a value or name.
1183  if ( next->value.empty() && next->name.empty() )
1184  return 0;
1185  return next;
1186 }
1187 
1188 /*
1189 TiXmlAttribute* TiXmlAttribute::Next()
1190 {
1191  // We are using knowledge of the sentinel. The sentinel
1192  // have a value or name.
1193  if ( next->value.empty() && next->name.empty() )
1194  return 0;
1195  return next;
1196 }
1197 */
1198 
1200 {
1201  // We are using knowledge of the sentinel. The sentinel
1202  // have a value or name.
1203  if ( prev->value.empty() && prev->name.empty() )
1204  return 0;
1205  return prev;
1206 }
1207 
1208 /*
1209 TiXmlAttribute* TiXmlAttribute::Previous()
1210 {
1211  // We are using knowledge of the sentinel. The sentinel
1212  // have a value or name.
1213  if ( prev->value.empty() && prev->name.empty() )
1214  return 0;
1215  return prev;
1216 }
1217 */
1218 
1219 void TiXmlAttribute::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const
1220 {
1221  TIXML_STRING n, v;
1222 
1223  EncodeString( name, &n );
1224  EncodeString( value, &v );
1225 
1226  if (value.find ('\"') == TIXML_STRING::npos) {
1227  if ( cfile ) {
1228  fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() );
1229  }
1230  if ( str ) {
1231  (*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\"";
1232  }
1233  }
1234  else {
1235  if ( cfile ) {
1236  fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() );
1237  }
1238  if ( str ) {
1239  (*str) += n; (*str) += "='"; (*str) += v; (*str) += "'";
1240  }
1241  }
1242 }
1243 
1244 
1245 int TiXmlAttribute::QueryIntValue( int* ival ) const
1246 {
1247  if ( TIXML_SSCANF( value.c_str(), "%d", ival ) == 1 )
1248  return TIXML_SUCCESS;
1249  return TIXML_WRONG_TYPE;
1250 }
1251 
1252 int TiXmlAttribute::QueryDoubleValue( double* dval ) const
1253 {
1254  if ( TIXML_SSCANF( value.c_str(), "%lf", dval ) == 1 )
1255  return TIXML_SUCCESS;
1256  return TIXML_WRONG_TYPE;
1257 }
1258 
1260 {
1261  char buf [64];
1262  #if defined(TIXML_SNPRINTF)
1263  TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value);
1264  #else
1265  sprintf (buf, "%d", _value);
1266  #endif
1267  SetValue (buf);
1268 }
1269 
1270 void TiXmlAttribute::SetDoubleValue( double _value )
1271 {
1272  char buf [256];
1273  #if defined(TIXML_SNPRINTF)
1274  TIXML_SNPRINTF( buf, sizeof(buf), "%g", _value);
1275  #else
1276  sprintf (buf, "%g", _value);
1277  #endif
1278  SetValue (buf);
1279 }
1280 
1282 {
1283  return atoi (value.c_str ());
1284 }
1285 
1287 {
1288  return atof (value.c_str ());
1289 }
1290 
1291 
1293 {
1294  copy.CopyTo( this );
1295 }
1296 
1297 
1299 {
1300  Clear();
1301  base.CopyTo( this );
1302  return *this;
1303 }
1304 
1305 
1306 void TiXmlComment::Print( FILE* cfile, int depth ) const
1307 {
1308  assert( cfile );
1309  for ( int i=0; i<depth; i++ )
1310  {
1311  fprintf( cfile, " " );
1312  }
1313  fprintf( cfile, "<!--%s-->", value.c_str() );
1314 }
1315 
1316 
1317 void TiXmlComment::CopyTo( TiXmlComment* target ) const
1318 {
1319  TiXmlNode::CopyTo( target );
1320 }
1321 
1322 
1323 bool TiXmlComment::Accept( TiXmlVisitor* visitor ) const
1324 {
1325  return visitor->Visit( *this );
1326 }
1327 
1328 
1330 {
1331  TiXmlComment* clone = new TiXmlComment();
1332 
1333  if ( !clone )
1334  return 0;
1335 
1336  CopyTo( clone );
1337  return clone;
1338 }
1339 
1340 
1341 void TiXmlText::Print( FILE* cfile, int depth ) const
1342 {
1343  assert( cfile );
1344  if ( cdata )
1345  {
1346  int i;
1347  fprintf( cfile, "\n" );
1348  for ( i=0; i<depth; i++ ) {
1349  fprintf( cfile, " " );
1350  }
1351  fprintf( cfile, "<![CDATA[%s]]>\n", value.c_str() ); // unformatted output
1352  }
1353  else
1354  {
1355  TIXML_STRING buffer;
1356  EncodeString( value, &buffer );
1357  fprintf( cfile, "%s", buffer.c_str() );
1358  }
1359 }
1360 
1361 
1362 void TiXmlText::CopyTo( TiXmlText* target ) const
1363 {
1364  TiXmlNode::CopyTo( target );
1365  target->cdata = cdata;
1366 }
1367 
1368 
1369 bool TiXmlText::Accept( TiXmlVisitor* visitor ) const
1370 {
1371  return visitor->Visit( *this );
1372 }
1373 
1374 
1376 {
1377  TiXmlText* clone = 0;
1378  clone = new TiXmlText( "" );
1379 
1380  if ( !clone )
1381  return 0;
1382 
1383  CopyTo( clone );
1384  return clone;
1385 }
1386 
1387 
1388 TiXmlDeclaration::TiXmlDeclaration( const char * _version,
1389  const char * _encoding,
1390  const char * _standalone )
1392 {
1393  version = _version;
1394  encoding = _encoding;
1395  standalone = _standalone;
1396 }
1397 
1398 
1399 #ifdef TIXML_USE_STL
1400 TiXmlDeclaration::TiXmlDeclaration( const std::string& _version,
1401  const std::string& _encoding,
1402  const std::string& _standalone )
1404 {
1405  version = _version;
1406  encoding = _encoding;
1407  standalone = _standalone;
1408 }
1409 #endif
1410 
1411 
1414 {
1415  copy.CopyTo( this );
1416 }
1417 
1418 
1420 {
1421  Clear();
1422  copy.CopyTo( this );
1423  return *this;
1424 }
1425 
1426 
1427 void TiXmlDeclaration::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const
1428 {
1429  if ( cfile ) fprintf( cfile, "<?xml " );
1430  if ( str ) (*str) += "<?xml ";
1431 
1432  if ( !version.empty() ) {
1433  if ( cfile ) fprintf (cfile, "version=\"%s\" ", version.c_str ());
1434  if ( str ) { (*str) += "version=\""; (*str) += version; (*str) += "\" "; }
1435  }
1436  if ( !encoding.empty() ) {
1437  if ( cfile ) fprintf (cfile, "encoding=\"%s\" ", encoding.c_str ());
1438  if ( str ) { (*str) += "encoding=\""; (*str) += encoding; (*str) += "\" "; }
1439  }
1440  if ( !standalone.empty() ) {
1441  if ( cfile ) fprintf (cfile, "standalone=\"%s\" ", standalone.c_str ());
1442  if ( str ) { (*str) += "standalone=\""; (*str) += standalone; (*str) += "\" "; }
1443  }
1444  if ( cfile ) fprintf( cfile, "?>" );
1445  if ( str ) (*str) += "?>";
1446 }
1447 
1448 
1450 {
1451  TiXmlNode::CopyTo( target );
1452 
1453  target->version = version;
1454  target->encoding = encoding;
1455  target->standalone = standalone;
1456 }
1457 
1458 
1460 {
1461  return visitor->Visit( *this );
1462 }
1463 
1464 
1466 {
1467  TiXmlDeclaration* clone = new TiXmlDeclaration();
1468 
1469  if ( !clone )
1470  return 0;
1471 
1472  CopyTo( clone );
1473  return clone;
1474 }
1475 
1476 
1477 void TiXmlUnknown::Print( FILE* cfile, int depth ) const
1478 {
1479  for ( int i=0; i<depth; i++ )
1480  fprintf( cfile, " " );
1481  fprintf( cfile, "<%s>", value.c_str() );
1482 }
1483 
1484 
1485 void TiXmlUnknown::CopyTo( TiXmlUnknown* target ) const
1486 {
1487  TiXmlNode::CopyTo( target );
1488 }
1489 
1490 
1491 bool TiXmlUnknown::Accept( TiXmlVisitor* visitor ) const
1492 {
1493  return visitor->Visit( *this );
1494 }
1495 
1496 
1498 {
1499  TiXmlUnknown* clone = new TiXmlUnknown();
1500 
1501  if ( !clone )
1502  return 0;
1503 
1504  CopyTo( clone );
1505  return clone;
1506 }
1507 
1508 
1510 {
1511  sentinel.next = &sentinel;
1512  sentinel.prev = &sentinel;
1513 }
1514 
1515 
1517 {
1518  assert( sentinel.next == &sentinel );
1519  assert( sentinel.prev == &sentinel );
1520 }
1521 
1522 
1524 {
1525  #ifdef TIXML_USE_STL
1526  assert( !Find( TIXML_STRING( addMe->Name() ) ) ); // Shouldn't be multiply adding to the set.
1527  #else
1528  assert( !Find( addMe->Name() ) ); // Shouldn't be multiply adding to the set.
1529  #endif
1530 
1531  addMe->next = &sentinel;
1532  addMe->prev = sentinel.prev;
1533 
1534  sentinel.prev->next = addMe;
1535  sentinel.prev = addMe;
1536 }
1537 
1539 {
1540  TiXmlAttribute* node;
1541 
1542  for( node = sentinel.next; node != &sentinel; node = node->next )
1543  {
1544  if ( node == removeMe )
1545  {
1546  node->prev->next = node->next;
1547  node->next->prev = node->prev;
1548  node->next = 0;
1549  node->prev = 0;
1550  return;
1551  }
1552  }
1553  assert( 0 ); // we tried to remove a non-linked attribute.
1554 }
1555 
1556 
1557 #ifdef TIXML_USE_STL
1558 TiXmlAttribute* TiXmlAttributeSet::Find( const std::string& name ) const
1559 {
1560  for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next )
1561  {
1562  if ( node->name == name )
1563  return node;
1564  }
1565  return 0;
1566 }
1567 
1568 TiXmlAttribute* TiXmlAttributeSet::FindOrCreate( const std::string& _name )
1569 {
1570  TiXmlAttribute* attrib = Find( _name );
1571  if ( !attrib ) {
1572  attrib = new TiXmlAttribute();
1573  Add( attrib );
1574  attrib->SetName( _name );
1575  }
1576  return attrib;
1577 }
1578 #endif
1579 
1580 
1581 TiXmlAttribute* TiXmlAttributeSet::Find( const char* name ) const
1582 {
1583  for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next )
1584  {
1585  if ( strcmp( node->name.c_str(), name ) == 0 )
1586  return node;
1587  }
1588  return 0;
1589 }
1590 
1591 
1593 {
1594  TiXmlAttribute* attrib = Find( _name );
1595  if ( !attrib ) {
1596  attrib = new TiXmlAttribute();
1597  Add( attrib );
1598  attrib->SetName( _name );
1599  }
1600  return attrib;
1601 }
1602 
1603 
1604 #ifdef TIXML_USE_STL
1605 std::istream& operator>> (std::istream & in, TiXmlNode & base)
1606 {
1607  TIXML_STRING tag;
1608  tag.reserve( 8 * 1000 );
1609  base.StreamIn( &in, &tag );
1610 
1611  base.Parse( tag.c_str(), 0, TIXML_DEFAULT_ENCODING );
1612  return in;
1613 }
1614 #endif
1615 
1616 
1617 #ifdef TIXML_USE_STL
1618 std::ostream& operator<< (std::ostream & out, const TiXmlNode & base)
1619 {
1620  TiXmlPrinter printer;
1621  printer.SetStreamPrinting();
1622  base.Accept( &printer );
1623  out << printer.Str();
1624 
1625  return out;
1626 }
1627 
1628 
1629 std::string& operator<< (std::string& out, const TiXmlNode& base )
1630 {
1631  TiXmlPrinter printer;
1632  printer.SetStreamPrinting();
1633  base.Accept( &printer );
1634  out.append( printer.Str() );
1635 
1636  return out;
1637 }
1638 #endif
1639 
1640 
1642 {
1643  if ( node )
1644  {
1645  TiXmlNode* child = node->FirstChild();
1646  if ( child )
1647  return TiXmlHandle( child );
1648  }
1649  return TiXmlHandle( 0 );
1650 }
1651 
1652 
1654 {
1655  if ( node )
1656  {
1657  TiXmlNode* child = node->FirstChild( value );
1658  if ( child )
1659  return TiXmlHandle( child );
1660  }
1661  return TiXmlHandle( 0 );
1662 }
1663 
1664 
1666 {
1667  if ( node )
1668  {
1669  TiXmlElement* child = node->FirstChildElement();
1670  if ( child )
1671  return TiXmlHandle( child );
1672  }
1673  return TiXmlHandle( 0 );
1674 }
1675 
1676 
1678 {
1679  if ( node )
1680  {
1681  TiXmlElement* child = node->FirstChildElement( value );
1682  if ( child )
1683  return TiXmlHandle( child );
1684  }
1685  return TiXmlHandle( 0 );
1686 }
1687 
1688 
1690 {
1691  if ( node )
1692  {
1693  int i;
1694  TiXmlNode* child = node->FirstChild();
1695  for ( i=0;
1696  child && i<count;
1697  child = child->NextSibling(), ++i )
1698  {
1699  // nothing
1700  }
1701  if ( child )
1702  return TiXmlHandle( child );
1703  }
1704  return TiXmlHandle( 0 );
1705 }
1706 
1707 
1708 TiXmlHandle TiXmlHandle::Child( const char* value, int count ) const
1709 {
1710  if ( node )
1711  {
1712  int i;
1713  TiXmlNode* child = node->FirstChild( value );
1714  for ( i=0;
1715  child && i<count;
1716  child = child->NextSibling( value ), ++i )
1717  {
1718  // nothing
1719  }
1720  if ( child )
1721  return TiXmlHandle( child );
1722  }
1723  return TiXmlHandle( 0 );
1724 }
1725 
1726 
1728 {
1729  if ( node )
1730  {
1731  int i;
1732  TiXmlElement* child = node->FirstChildElement();
1733  for ( i=0;
1734  child && i<count;
1735  child = child->NextSiblingElement(), ++i )
1736  {
1737  // nothing
1738  }
1739  if ( child )
1740  return TiXmlHandle( child );
1741  }
1742  return TiXmlHandle( 0 );
1743 }
1744 
1745 
1746 TiXmlHandle TiXmlHandle::ChildElement( const char* value, int count ) const
1747 {
1748  if ( node )
1749  {
1750  int i;
1751  TiXmlElement* child = node->FirstChildElement( value );
1752  for ( i=0;
1753  child && i<count;
1754  child = child->NextSiblingElement( value ), ++i )
1755  {
1756  // nothing
1757  }
1758  if ( child )
1759  return TiXmlHandle( child );
1760  }
1761  return TiXmlHandle( 0 );
1762 }
1763 
1764 
1766 {
1767  return true;
1768 }
1769 
1771 {
1772  return true;
1773 }
1774 
1775 bool TiXmlPrinter::VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute )
1776 {
1777  DoIndent();
1778  buffer += "<";
1779  buffer += element.Value();
1780 
1781  for( const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() )
1782  {
1783  buffer += " ";
1784  attrib->Print( 0, 0, &buffer );
1785  }
1786 
1787  if ( !element.FirstChild() )
1788  {
1789  buffer += " />";
1790  DoLineBreak();
1791  }
1792  else
1793  {
1794  buffer += ">";
1795  if ( element.FirstChild()->ToText()
1796  && element.LastChild() == element.FirstChild()
1797  && element.FirstChild()->ToText()->CDATA() == false )
1798  {
1799  simpleTextPrint = true;
1800  // no DoLineBreak()!
1801  }
1802  else
1803  {
1804  DoLineBreak();
1805  }
1806  }
1807  ++depth;
1808  return true;
1809 }
1810 
1811 
1813 {
1814  --depth;
1815  if ( !element.FirstChild() )
1816  {
1817  // nothing.
1818  }
1819  else
1820  {
1821  if ( simpleTextPrint )
1822  {
1823  simpleTextPrint = false;
1824  }
1825  else
1826  {
1827  DoIndent();
1828  }
1829  buffer += "</";
1830  buffer += element.Value();
1831  buffer += ">";
1832  DoLineBreak();
1833  }
1834  return true;
1835 }
1836 
1837 
1838 bool TiXmlPrinter::Visit( const TiXmlText& text )
1839 {
1840  if ( text.CDATA() )
1841  {
1842  DoIndent();
1843  buffer += "<![CDATA[";
1844  buffer += text.Value();
1845  buffer += "]]>";
1846  DoLineBreak();
1847  }
1848  else if ( simpleTextPrint )
1849  {
1850  TIXML_STRING str;
1851  TiXmlBase::EncodeString( text.ValueTStr(), &str );
1852  buffer += str;
1853  }
1854  else
1855  {
1856  DoIndent();
1857  TIXML_STRING str;
1858  TiXmlBase::EncodeString( text.ValueTStr(), &str );
1859  buffer += str;
1860  DoLineBreak();
1861  }
1862  return true;
1863 }
1864 
1865 
1866 bool TiXmlPrinter::Visit( const TiXmlDeclaration& declaration )
1867 {
1868  DoIndent();
1869  declaration.Print( 0, 0, &buffer );
1870  DoLineBreak();
1871  return true;
1872 }
1873 
1874 
1875 bool TiXmlPrinter::Visit( const TiXmlComment& comment )
1876 {
1877  DoIndent();
1878  buffer += "<!--";
1879  buffer += comment.Value();
1880  buffer += "-->";
1881  DoLineBreak();
1882  return true;
1883 }
1884 
1885 
1886 bool TiXmlPrinter::Visit( const TiXmlUnknown& unknown )
1887 {
1888  DoIndent();
1889  buffer += "<";
1890  buffer += unknown.Value();
1891  buffer += ">";
1892  DoLineBreak();
1893  return true;
1894 }
1895 
const TiXmlAttribute * First() const
Definition: tinyxml.h:921
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
Definition: tinyxml.cpp:1465
virtual bool Accept(TiXmlVisitor *visitor) const
Definition: tinyxml.cpp:884
virtual ~TiXmlElement()
Definition: tinyxml.cpp:568
TiXmlComment()
Constructs an empty comment.
Definition: tinyxml.h:1175
const TIXML_STRING & ValueTStr() const
Definition: tinyxml.h:506
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
Definition: tinyxml.cpp:898
bool Error() const
Definition: tinyxml.h:1469
double DoubleValue() const
Return the value of this attribute, converted to a double.
Definition: tinyxml.cpp:1286
int IntValue() const
Return the value of this attribute, converted to an integer.
Definition: tinyxml.cpp:1281
TiXmlNode * prev
Definition: tinyxml.h:772
int QueryBoolAttribute(const char *name, bool *_value) const
Definition: tinyxml.cpp:692
TiXmlHandle FirstChild() const
Return a handle to the first child node.
Definition: tinyxml.cpp:1641
void CopyTo(TiXmlUnknown *target) const
Definition: tinyxml.cpp:1485
int Type() const
Definition: tinyxml.h:693
TiXmlNode * firstChild
Definition: tinyxml.h:767
TiXmlElement & operator=(const TiXmlElement &base)
Definition: tinyxml.cpp:560
void SetDoubleAttribute(const char *name, double value)
Definition: tinyxml.cpp:769
TiXmlAttribute * FindOrCreate(const char *_name)
Definition: tinyxml.cpp:1592
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.cpp:1477
list temp
Definition: bigtemp.py:9
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
Definition: tinyxml.cpp:1375
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
Definition: tinyxml.cpp:1427
void ClearThis()
Definition: tinyxml.cpp:574
const unsigned char TIXML_UTF_LEAD_2
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Definition: tinyxml.cpp:305
void SetName(const char *_name)
Set the name of this attribute.
Definition: tinyxml.h:844
void CopyTo(TiXmlComment *target) const
Definition: tinyxml.cpp:1317
TiXmlDocument()
Create an empty document, that has no name.
Definition: tinyxml.cpp:922
void ClearError()
Definition: tinyxml.h:1520
const char * Value() const
Return the value of this attribute.
Definition: tinyxml.h:821
TiXmlComment & operator=(const TiXmlComment &base)
Definition: tinyxml.cpp:1298
int QueryIntValue(int *_value) const
Definition: tinyxml.cpp:1245
void Clear()
Definition: tinyxml.h:111
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.cpp:809
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Definition: tinyxml.cpp:963
void SetValue(const char *_value)
Definition: tinyxml.h:517
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Definition: tinyxml.cpp:223
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
Definition: tinyxml.cpp:1770
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Definition: tinyxml.cpp:239
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
Definition: tinyxml.h:143
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
Definition: tinyxml.cpp:1665
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Definition: tinyxml.cpp:195
const TiXmlNode * LastChild() const
Definition: tinyxml.h:540
const char * Name() const
Return the name of this attribute.
Definition: tinyxml.h:820
void SetDoubleValue(double _value)
Set the value from a double.
Definition: tinyxml.cpp:1270
void * userData
Field containing a generic user pointer.
Definition: tinyxml.h:385
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.cpp:1306
virtual bool Accept(TiXmlVisitor *visitor) const =0
void Print() const
Definition: tinyxml.h:1528
const TiXmlEncoding TIXML_DEFAULT_ENCODING
Definition: tinyxml.h:179
TiXmlHandle ChildElement(const char *value, int index) const
Definition: tinyxml.cpp:1746
virtual bool Accept(TiXmlVisitor *content) const
Definition: tinyxml.cpp:1491
TiXmlCursor location
Definition: tinyxml.h:382
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:531
string filename
Definition: aging.py:5
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
Definition: tinyxml.cpp:1179
const unsigned char TIXML_UTF_LEAD_1
TiXmlAttribute * Find(const char *_name) const
Definition: tinyxml.cpp:1581
void RemoveAttribute(const char *name)
Definition: tinyxml.cpp:446
virtual TiXmlNode * Clone() const
Definition: tinyxml.cpp:1143
void SetAttribute(const char *name, const char *_value)
Definition: tinyxml.cpp:789
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.cpp:1341
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.h:879
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
Definition: tinyxml.cpp:969
#define TIXML_SNPRINTF
Definition: tinyxml2.cpp:101
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml.cpp:461
TiXmlEncoding
Definition: tinyxml.h:172
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
Definition: tinyxml.cpp:1252
FILE * TiXmlFOpen(const char *filename, const char *mode)
Definition: tinyxml.cpp:48
TiXmlElement(const char *in_value)
Construct an element.
Definition: tinyxml.cpp:534
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:623
const unsigned char TIXML_UTF_LEAD_0
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Definition: tinyxml.cpp:272
Log & operator<<(Log &log, T data)
Definition: log.h:38
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:707
TiXmlHandle Child(const char *value, int index) const
Definition: tinyxml.cpp:1708
void Add(TiXmlAttribute *attribute)
Definition: tinyxml.cpp:1523
const TiXmlDocument * GetDocument() const
Definition: tinyxml.cpp:521
bool CDATA() const
Queries whether this represents text using a CDATA section.
Definition: tinyxml.h:1252
virtual bool Accept(TiXmlVisitor *visitor) const
Definition: tinyxml.cpp:1323
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
Definition: tinyxml.cpp:1199
const TiXmlElement * NextSiblingElement() const
Definition: tinyxml.cpp:491
TiXmlDeclaration & operator=(const TiXmlDeclaration &copy)
Definition: tinyxml.cpp:1419
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
Definition: tinyxml.cpp:1765
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
TiXmlNode * parent
Definition: tinyxml.h:764
int QueryIntAttribute(const char *name, int *_value) const
Definition: tinyxml.cpp:670
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
virtual bool Accept(TiXmlVisitor *content) const
Definition: tinyxml.cpp:1165
TiXmlNode(NodeType _type)
Definition: tinyxml.cpp:145
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
Definition: tinyxml.cpp:61
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:710
void CopyTo(TiXmlNode *target) const
Definition: tinyxml.cpp:170
void SetIntValue(int _value)
Set the value from an integer.
Definition: tinyxml.cpp:1259
virtual TiXmlNode * Clone() const
Creates a copy of this Unknown and returns it.
Definition: tinyxml.cpp:1497
TiXmlNode * next
Definition: tinyxml.h:773
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
Definition: tinyxml.h:145
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
Definition: tinyxml.cpp:729
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
Definition: tinyxml.cpp:394
const char * Value() const
Definition: tinyxml.h:496
TiXmlDocument & operator=(const TiXmlDocument &copy)
Definition: tinyxml.cpp:955
void CopyTo(TiXmlText *target) const
Definition: tinyxml.cpp:1362
virtual TiXmlNode * Clone() const
Returns a copy of this Comment.
Definition: tinyxml.cpp:1329
void CopyTo(TiXmlElement *target) const
Definition: tinyxml.cpp:862
virtual bool Accept(TiXmlVisitor *visitor) const
Definition: tinyxml.cpp:1459
NodeType type
Definition: tinyxml.h:765
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
Definition: tinyxml.cpp:344
TIXML_STRING value
Definition: tinyxml.h:770
const char * GetText() const
Definition: tinyxml.cpp:909
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:706
void Remove(TiXmlAttribute *attribute)
Definition: tinyxml.cpp:1538
void Clear()
Delete all the children of this node. Does not affect &#39;this&#39;.
Definition: tinyxml.cpp:178
void SetValue(const char *_value)
Set the value.
Definition: tinyxml.h:845
int QueryUnsignedAttribute(const char *name, unsigned *_value) const
QueryUnsignedAttribute examines the attribute - see QueryIntAttribute().
Definition: tinyxml.cpp:679
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:640
TiXmlNode * lastChild
Definition: tinyxml.h:768
TiXmlDeclaration()
Construct an empty declaration.
Definition: tinyxml.h:1298
#define TIXML_SSCANF
Definition: tinyxml2.cpp:109
void SetStreamPrinting()
Definition: tinyxml.h:1780
const char * Attribute(const char *name) const
Definition: tinyxml.cpp:586
virtual void Print(FILE *cfile, int depth) const =0
virtual ~TiXmlNode()
Definition: tinyxml.cpp:156
virtual bool Accept(TiXmlVisitor *content) const
Definition: tinyxml.cpp:1369
virtual TiXmlNode * Clone() const =0
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
Definition: tinyxml.cpp:1866
void CopyTo(TiXmlDeclaration *target) const
Definition: tinyxml.cpp:1449
#define TIXML_STRING
Definition: tinyxml.h:62
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
Definition: tinyxml.h:153