nux-0.9.48
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 /* 00024 www.sourceforge.net/projects/tinyxml 00025 Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com) 00026 00027 This software is provided 'as-is', without any express or implied 00028 warranty. In no event will the authors be held liable for any 00029 damages arising from the use of this software. 00030 00031 Permission is granted to anyone to use this software for any 00032 purpose, including commercial applications, and to alter it and 00033 redistribute it freely, subject to the following restrictions: 00034 00035 1. The origin of this software must not be misrepresented; you must 00036 not claim that you wrote the original software. If you use this 00037 software in a product, an acknowledgment in the product documentation 00038 would be appreciated but is not required. 00039 00040 2. Altered source versions must be plainly marked as such, and 00041 must not be misrepresented as being the original software. 00042 00043 3. This notice may not be removed or altered from any source 00044 distribution. 00045 */ 00046 00047 00048 #ifndef TINYXML_INCLUDED 00049 #define TINYXML_INCLUDED 00050 00051 #ifdef _MSC_VER 00052 #pragma warning( push ) 00053 #pragma warning( disable : 4530 ) 00054 #pragma warning( disable : 4786 ) 00055 #endif 00056 00057 #include <ctype.h> 00058 #include <stdio.h> 00059 #include <stdlib.h> 00060 #include <string.h> 00061 #include <assert.h> 00062 00063 // Help out windows: 00064 #if (defined( _DEBUG ) || defined(NUX_DEBUG)) && !defined( DEBUG ) 00065 #define DEBUG 00066 #endif 00067 00068 #ifdef TIXML_USE_STL 00069 #include <string> 00070 #include <iostream> 00071 #include <sstream> 00072 #define TIXML_STRING std::string 00073 #else 00074 #include "tinystr.h" 00075 #define TIXML_STRING TiXmlString 00076 #endif 00077 00078 // Deprecated library function hell. Compilers want to use the 00079 // new safe versions. This probably doesn't fully address the problem, 00080 // but it gets closer. There are too many compilers for me to fully 00081 // test. If you get compilation troubles, undefine TIXML_SAFE 00082 #define TIXML_SAFE 00083 00084 #ifdef TIXML_SAFE 00085 #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) 00086 // Microsoft visual studio, version 2005 and higher. 00087 #define TIXML_SNPRINTF _snprintf_s 00088 #define TIXML_SNSCANF _snscanf_s 00089 #define TIXML_SSCANF sscanf_s 00090 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 ) 00091 // Microsoft visual studio, version 6 and higher. 00092 //#pragma message( "Using _sn* functions." ) 00093 #define TIXML_SNPRINTF _snprintf 00094 #define TIXML_SNSCANF _snscanf 00095 #define TIXML_SSCANF sscanf 00096 #elif defined(__GNUC__) && (__GNUC__ >= 3 ) 00097 // GCC version 3 and higher.s 00098 //#warning( "Using sn* functions." ) 00099 #define TIXML_SNPRINTF snprintf 00100 #define TIXML_SNSCANF snscanf 00101 #define TIXML_SSCANF sscanf 00102 #else 00103 #define TIXML_SSCANF sscanf 00104 #endif 00105 #endif 00106 00107 class TiXmlDocument; 00108 class TiXmlElement; 00109 class TiXmlComment; 00110 class TiXmlUnknown; 00111 class TiXmlAttribute; 00112 class TiXmlText; 00113 class TiXmlDeclaration; 00114 class TiXmlParsingData; 00115 00116 const int TIXML_MAJOR_VERSION = 2; 00117 const int TIXML_MINOR_VERSION = 5; 00118 const int TIXML_PATCH_VERSION = 3; 00119 00120 /* Internal structure for tracking location of items 00121 in the XML file. 00122 */ 00123 struct TiXmlCursor 00124 { 00125 TiXmlCursor() 00126 { 00127 Clear(); 00128 } 00129 void Clear() 00130 { 00131 row = col = -1; 00132 } 00133 00134 int row; // 0 based. 00135 int col; // 0 based. 00136 }; 00137 00138 00157 class TiXmlVisitor 00158 { 00159 public: 00160 virtual ~TiXmlVisitor() {} 00161 00163 virtual bool VisitEnter ( const TiXmlDocument& /*doc*/ ) 00164 { 00165 return true; 00166 } 00168 virtual bool VisitExit ( const TiXmlDocument& /*doc*/ ) 00169 { 00170 return true; 00171 } 00172 00174 virtual bool VisitEnter ( const TiXmlElement& /*element*/, const TiXmlAttribute* /*firstAttribute*/ ) 00175 { 00176 return true; 00177 } 00179 virtual bool VisitExit ( const TiXmlElement& /*element*/ ) 00180 { 00181 return true; 00182 } 00183 00185 virtual bool Visit ( const TiXmlDeclaration& /*declaration*/ ) 00186 { 00187 return true; 00188 } 00190 virtual bool Visit ( const TiXmlText& /*text*/ ) 00191 { 00192 return true; 00193 } 00195 virtual bool Visit ( const TiXmlComment& /*comment*/ ) 00196 { 00197 return true; 00198 } 00200 virtual bool Visit ( const TiXmlUnknown& /*unknown*/ ) 00201 { 00202 return true; 00203 } 00204 }; 00205 00206 // Only used by Attribute::Query functions 00207 enum 00208 { 00209 TIXML_SUCCESS, 00210 TIXML_NO_ATTRIBUTE, 00211 TIXML_WRONG_TYPE 00212 }; 00213 00214 00215 // Used by the parsing routines. 00216 enum TiXmlEncoding 00217 { 00218 TIXML_ENCODING_UNKNOWN, 00219 TIXML_ENCODING_UTF8, 00220 TIXML_ENCODING_LEGACY 00221 }; 00222 00223 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN; 00224 00247 class TiXmlBase 00248 { 00249 friend class TiXmlNode; 00250 friend class TiXmlElement; 00251 friend class TiXmlDocument; 00252 00253 public: 00254 TiXmlBase() : userData (0) {} 00255 virtual ~TiXmlBase() {} 00256 00266 virtual void Print ( FILE *cfile, int depth ) const = 0; 00267 00274 static void SetCondenseWhiteSpace ( bool condense ) 00275 { 00276 condenseWhiteSpace = condense; 00277 } 00278 00280 static bool IsWhiteSpaceCondensed() 00281 { 00282 return condenseWhiteSpace; 00283 } 00284 00303 int Row() const 00304 { 00305 return location.row + 1; 00306 } 00307 int Column() const 00308 { 00309 return location.col + 1; 00310 } 00311 00312 void SetUserData ( void *user ) 00313 { 00314 userData = user; 00315 } 00316 void *GetUserData() 00317 { 00318 return userData; 00319 } 00320 const void *GetUserData() const 00321 { 00322 return userData; 00323 } 00324 00325 // Table that returs, for a given lead byte, the total number of bytes 00326 // in the UTF-8 sequence. 00327 static const int utf8ByteTable[256]; 00328 00329 virtual const char *Parse ( const char *p, 00330 TiXmlParsingData *data, 00331 TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; 00332 00336 static void EncodeString ( const TIXML_STRING &str, TIXML_STRING *out ); 00337 00338 enum 00339 { 00340 TIXML_NO_ERROR = 0, 00341 TIXML_ERROR, 00342 TIXML_ERROR_OPENING_FILE, 00343 TIXML_ERROR_OUT_OF_MEMORY, 00344 TIXML_ERROR_PARSING_ELEMENT, 00345 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, 00346 TIXML_ERROR_READING_ELEMENT_VALUE, 00347 TIXML_ERROR_READING_ATTRIBUTES, 00348 TIXML_ERROR_PARSING_EMPTY, 00349 TIXML_ERROR_READING_END_TAG, 00350 TIXML_ERROR_PARSING_UNKNOWN, 00351 TIXML_ERROR_PARSING_COMMENT, 00352 TIXML_ERROR_PARSING_DECLARATION, 00353 TIXML_ERROR_DOCUMENT_EMPTY, 00354 TIXML_ERROR_EMBEDDED_NULL, 00355 TIXML_ERROR_PARSING_CDATA, 00356 TIXML_ERROR_DOCUMENT_TOP_ONLY, 00357 00358 TIXML_ERROR_STRING_COUNT 00359 }; 00360 00361 protected: 00362 00363 static const char *SkipWhiteSpace ( const char *, TiXmlEncoding encoding ); 00364 inline static bool IsWhiteSpace ( char c ) 00365 { 00366 return ( isspace ( (unsigned char) c ) || c == '\n' || c == '\r' ); 00367 } 00368 inline static bool IsWhiteSpace ( int c ) 00369 { 00370 if ( c < 256 ) 00371 return IsWhiteSpace ( (char) c ); 00372 00373 return false; // Again, only truly correct for English/Latin...but usually works. 00374 } 00375 00376 #ifdef TIXML_USE_STL 00377 static bool StreamWhiteSpace ( std::istream *in, TIXML_STRING *tag ); 00378 static bool StreamTo ( std::istream *in, int character, TIXML_STRING *tag ); 00379 #endif 00380 00381 /* Reads an XML name into the string provided. Returns 00382 a pointer just past the last character of the name, 00383 or 0 if the function has an error. 00384 */ 00385 static const char *ReadName ( const char *p, TIXML_STRING *name, TiXmlEncoding encoding ); 00386 00387 /* Reads text. Returns a pointer past the given end tag. 00388 Wickedly complex options, but it keeps the (sensitive) code in one place. 00389 */ 00390 static const char *ReadText ( const char *in, // where to start 00391 TIXML_STRING *text, // the string read 00392 bool ignoreWhiteSpace, // whether to keep the white space 00393 const char *endTag, // what ends this text 00394 bool ignoreCase, // whether to ignore case in the end tag 00395 TiXmlEncoding encoding ); // the current encoding 00396 00397 // If an entity has been found, transform it into a character. 00398 static const char *GetEntity ( const char *in, char *value, int *length, TiXmlEncoding encoding ); 00399 00400 // Get a character, while interpreting entities. 00401 // The length can be from 0 to 4 bytes. 00402 inline static const char *GetChar ( const char *p, char *_value, int *length, TiXmlEncoding encoding ) 00403 { 00404 assert ( p ); 00405 00406 if ( encoding == TIXML_ENCODING_UTF8 ) 00407 { 00408 *length = utf8ByteTable[ * ( (const unsigned char *) p) ]; 00409 assert ( *length >= 0 && *length < 5 ); 00410 } 00411 else 00412 { 00413 *length = 1; 00414 } 00415 00416 if ( *length == 1 ) 00417 { 00418 if ( *p == '&' ) 00419 return GetEntity ( p, _value, length, encoding ); 00420 00421 *_value = *p; 00422 return p + 1; 00423 } 00424 else if ( *length ) 00425 { 00426 //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe), 00427 // and the null terminator isn't needed 00428 for ( int i = 0; p[i] && i < *length; ++i ) 00429 { 00430 _value[i] = p[i]; 00431 } 00432 00433 return p + (*length); 00434 } 00435 else 00436 { 00437 // Not valid text. 00438 return 0; 00439 } 00440 } 00441 00442 // Return true if the next characters in the stream are any of the endTag sequences. 00443 // Ignore case only works for english, and should only be relied on when comparing 00444 // to English words: StringEqual( p, "version", true ) is fine. 00445 static bool StringEqual ( const char *p, 00446 const char *endTag, 00447 bool ignoreCase, 00448 TiXmlEncoding encoding ); 00449 00450 static const char *errorString[ TIXML_ERROR_STRING_COUNT ]; 00451 00452 TiXmlCursor location; 00453 00455 void *userData; 00456 00457 // None of these methods are reliable for any language except English. 00458 // Good for approximation, not great for accuracy. 00459 static int IsAlpha ( unsigned char anyByte, TiXmlEncoding encoding ); 00460 static int IsAlphaNum ( unsigned char anyByte, TiXmlEncoding encoding ); 00461 inline static int ToLower ( int v, TiXmlEncoding encoding ) 00462 { 00463 if ( encoding == TIXML_ENCODING_UTF8 ) 00464 { 00465 if ( v < 128 ) return tolower ( v ); 00466 00467 return v; 00468 } 00469 else 00470 { 00471 return tolower ( v ); 00472 } 00473 } 00474 static void ConvertUTF32ToUTF8 ( unsigned long input, char *output, int *length ); 00475 00476 private: 00477 TiXmlBase ( const TiXmlBase & ); // not implemented. 00478 void operator= ( const TiXmlBase &base ); // not allowed. 00479 00480 struct Entity 00481 { 00482 const char *str; 00483 unsigned int strLength; 00484 char chr; 00485 }; 00486 enum 00487 { 00488 NUM_ENTITY = 5, 00489 MAX_ENTITY_LENGTH = 6 00490 00491 }; 00492 static Entity entity[ NUM_ENTITY ]; 00493 static bool condenseWhiteSpace; 00494 }; 00495 00496 00503 class TiXmlNode : public TiXmlBase 00504 { 00505 friend class TiXmlDocument; 00506 friend class TiXmlElement; 00507 00508 public: 00509 #ifdef TIXML_USE_STL 00510 00514 friend std::istream &operator >> (std::istream &in, TiXmlNode &base); 00515 00532 friend std::ostream &operator<< (std::ostream &out, const TiXmlNode &base); 00533 00535 friend std::string &operator<< (std::string &out, const TiXmlNode &base ); 00536 00537 #endif 00538 00542 enum NodeType 00543 { 00544 DOCUMENT, 00545 ELEMENT, 00546 COMMENT, 00547 UNKNOWN, 00548 TEXT, 00549 DECLARATION, 00550 TYPECOUNT 00551 }; 00552 00553 virtual ~TiXmlNode(); 00554 00567 const char *Value() const 00568 { 00569 return value.c_str (); 00570 } 00571 00572 #ifdef TIXML_USE_STL 00573 00577 const std::string &ValueStr() const 00578 { 00579 return value; 00580 } 00581 #endif 00582 00583 const TIXML_STRING &ValueTStr() const 00584 { 00585 return value; 00586 } 00587 00597 void SetValue (const char *_value) 00598 { 00599 value = _value; 00600 } 00601 00602 #ifdef TIXML_USE_STL 00603 00604 void SetValue ( const std::string &_value ) 00605 { 00606 value = _value; 00607 } 00608 #endif 00609 00611 void Clear(); 00612 00614 TiXmlNode *Parent() 00615 { 00616 return parent; 00617 } 00618 const TiXmlNode *Parent() const 00619 { 00620 return parent; 00621 } 00622 00623 const TiXmlNode *FirstChild() const 00624 { 00625 return firstChild; 00626 } 00627 TiXmlNode *FirstChild() 00628 { 00629 return firstChild; 00630 } 00631 const TiXmlNode *FirstChild ( const char *value ) const; 00632 00633 TiXmlNode *FirstChild ( const char *_value ) 00634 { 00635 // Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe) 00636 // call the method, cast the return back to non-const. 00637 return const_cast< TiXmlNode * > ( (const_cast< const TiXmlNode * > (this) )->FirstChild ( _value ) ); 00638 } 00639 const TiXmlNode *LastChild() const 00640 { 00641 return lastChild; 00642 } 00643 TiXmlNode *LastChild() 00644 { 00645 return lastChild; 00646 } 00647 00648 const TiXmlNode *LastChild ( const char *value ) const; 00649 TiXmlNode *LastChild ( const char *_value ) 00650 { 00651 return const_cast< TiXmlNode * > ( (const_cast< const TiXmlNode * > (this) )->LastChild ( _value ) ); 00652 } 00653 00654 #ifdef TIXML_USE_STL 00655 const TiXmlNode *FirstChild ( const std::string &_value ) const 00656 { 00657 return FirstChild (_value.c_str () ); 00658 } 00659 TiXmlNode *FirstChild ( const std::string &_value ) 00660 { 00661 return FirstChild (_value.c_str () ); 00662 } 00663 const TiXmlNode *LastChild ( const std::string &_value ) const 00664 { 00665 return LastChild (_value.c_str () ); 00666 } 00667 TiXmlNode *LastChild ( const std::string &_value ) 00668 { 00669 return LastChild (_value.c_str () ); 00670 } 00671 #endif 00672 00689 const TiXmlNode *IterateChildren ( const TiXmlNode *previous ) const; 00690 TiXmlNode *IterateChildren ( const TiXmlNode *previous ) 00691 { 00692 return const_cast< TiXmlNode * > ( (const_cast< const TiXmlNode * > (this) )->IterateChildren ( previous ) ); 00693 } 00694 00696 const TiXmlNode *IterateChildren ( const char *value, const TiXmlNode *previous ) const; 00697 TiXmlNode *IterateChildren ( const char *_value, const TiXmlNode *previous ) 00698 { 00699 return const_cast< TiXmlNode * > ( (const_cast< const TiXmlNode * > (this) )->IterateChildren ( _value, previous ) ); 00700 } 00701 00702 #ifdef TIXML_USE_STL 00703 const TiXmlNode *IterateChildren ( const std::string &_value, const TiXmlNode *previous ) const 00704 { 00705 return IterateChildren (_value.c_str (), previous); 00706 } 00707 TiXmlNode *IterateChildren ( const std::string &_value, const TiXmlNode *previous ) 00708 { 00709 return IterateChildren (_value.c_str (), previous); 00710 } 00711 #endif 00712 00716 TiXmlNode *InsertEndChild ( const TiXmlNode &addThis ); 00717 00718 00728 TiXmlNode *LinkEndChild ( TiXmlNode *addThis ); 00729 00733 TiXmlNode *InsertBeforeChild ( TiXmlNode *beforeThis, const TiXmlNode &addThis ); 00734 00738 TiXmlNode *InsertAfterChild ( TiXmlNode *afterThis, const TiXmlNode &addThis ); 00739 00743 TiXmlNode *ReplaceChild ( TiXmlNode *replaceThis, const TiXmlNode &withThis ); 00744 00746 bool RemoveChild ( TiXmlNode *removeThis ); 00747 00749 const TiXmlNode *PreviousSibling() const 00750 { 00751 return prev; 00752 } 00753 TiXmlNode *PreviousSibling() 00754 { 00755 return prev; 00756 } 00757 00759 const TiXmlNode *PreviousSibling ( const char * ) const; 00760 TiXmlNode *PreviousSibling ( const char *_prev ) 00761 { 00762 return const_cast< TiXmlNode * > ( (const_cast< const TiXmlNode * > (this) )->PreviousSibling ( _prev ) ); 00763 } 00764 00765 #ifdef TIXML_USE_STL 00766 const TiXmlNode *PreviousSibling ( const std::string &_value ) const 00767 { 00768 return PreviousSibling (_value.c_str () ); 00769 } 00770 TiXmlNode *PreviousSibling ( const std::string &_value ) 00771 { 00772 return PreviousSibling (_value.c_str () ); 00773 } 00774 const TiXmlNode *NextSibling ( const std::string &_value) const 00775 { 00776 return NextSibling (_value.c_str () ); 00777 } 00778 TiXmlNode *NextSibling ( const std::string &_value) 00779 { 00780 return NextSibling (_value.c_str () ); 00781 } 00782 #endif 00783 00785 const TiXmlNode *NextSibling() const 00786 { 00787 return next; 00788 } 00789 TiXmlNode *NextSibling() 00790 { 00791 return next; 00792 } 00793 00795 const TiXmlNode *NextSibling ( const char * ) const; 00796 TiXmlNode *NextSibling ( const char *_next ) 00797 { 00798 return const_cast< TiXmlNode * > ( (const_cast< const TiXmlNode * > (this) )->NextSibling ( _next ) ); 00799 } 00800 00805 const TiXmlElement *NextSiblingElement() const; 00806 TiXmlElement *NextSiblingElement() 00807 { 00808 return const_cast< TiXmlElement * > ( (const_cast< const TiXmlNode * > (this) )->NextSiblingElement() ); 00809 } 00810 00815 const TiXmlElement *NextSiblingElement ( const char * ) const; 00816 TiXmlElement *NextSiblingElement ( const char *_next ) 00817 { 00818 return const_cast< TiXmlElement * > ( (const_cast< const TiXmlNode * > (this) )->NextSiblingElement ( _next ) ); 00819 } 00820 00821 #ifdef TIXML_USE_STL 00822 const TiXmlElement *NextSiblingElement ( const std::string &_value) const 00823 { 00824 return NextSiblingElement (_value.c_str () ); 00825 } 00826 TiXmlElement *NextSiblingElement ( const std::string &_value) 00827 { 00828 return NextSiblingElement (_value.c_str () ); 00829 } 00830 #endif 00831 00833 const TiXmlElement *FirstChildElement() const; 00834 TiXmlElement *FirstChildElement() 00835 { 00836 return const_cast< TiXmlElement * > ( (const_cast< const TiXmlNode * > (this) )->FirstChildElement() ); 00837 } 00838 00840 const TiXmlElement *FirstChildElement ( const char *_value ) const; 00841 TiXmlElement *FirstChildElement ( const char *_value ) 00842 { 00843 return const_cast< TiXmlElement * > ( (const_cast< const TiXmlNode * > (this) )->FirstChildElement ( _value ) ); 00844 } 00845 00846 #ifdef TIXML_USE_STL 00847 const TiXmlElement *FirstChildElement ( const std::string &_value ) const 00848 { 00849 return FirstChildElement (_value.c_str () ); 00850 } 00851 TiXmlElement *FirstChildElement ( const std::string &_value ) 00852 { 00853 return FirstChildElement (_value.c_str () ); 00854 } 00855 #endif 00856 00861 int Type() const 00862 { 00863 return type; 00864 } 00865 00869 const TiXmlDocument *GetDocument() const; 00870 TiXmlDocument *GetDocument() 00871 { 00872 return const_cast< TiXmlDocument * > ( (const_cast< const TiXmlNode * > (this) )->GetDocument() ); 00873 } 00874 00876 bool NoChildren() const 00877 { 00878 return !firstChild; 00879 } 00880 00881 virtual const TiXmlDocument *ToDocument() const 00882 { 00883 return 0; 00884 } 00885 virtual const TiXmlElement *ToElement() const 00886 { 00887 return 0; 00888 } 00889 virtual const TiXmlComment *ToComment() const 00890 { 00891 return 0; 00892 } 00893 virtual const TiXmlUnknown *ToUnknown() const 00894 { 00895 return 0; 00896 } 00897 virtual const TiXmlText *ToText() const 00898 { 00899 return 0; 00900 } 00901 virtual const TiXmlDeclaration *ToDeclaration() const 00902 { 00903 return 0; 00904 } 00905 00906 virtual TiXmlDocument *ToDocument() 00907 { 00908 return 0; 00909 } 00910 virtual TiXmlElement *ToElement() 00911 { 00912 return 0; 00913 } 00914 virtual TiXmlComment *ToComment() 00915 { 00916 return 0; 00917 } 00918 virtual TiXmlUnknown *ToUnknown() 00919 { 00920 return 0; 00921 } 00922 virtual TiXmlText *ToText() 00923 { 00924 return 0; 00925 } 00926 virtual TiXmlDeclaration *ToDeclaration() 00927 { 00928 return 0; 00929 } 00930 00934 virtual TiXmlNode *Clone() const = 0; 00935 00958 virtual bool Accept ( TiXmlVisitor *visitor ) const = 0; 00959 00960 protected: 00961 TiXmlNode ( NodeType _type ); 00962 00963 // Copy to the allocated object. Shared functionality between Clone, Copy constructor, 00964 // and the assignment operator. 00965 void CopyTo ( TiXmlNode *target ) const; 00966 00967 #ifdef TIXML_USE_STL 00968 // The real work of the input operator. 00969 virtual void StreamIn ( std::istream *in, TIXML_STRING *tag ) = 0; 00970 #endif 00971 00972 // Figure out what is at *p, and parse it. Returns null if it is not an xml node. 00973 TiXmlNode *Identify ( const char *start, TiXmlEncoding encoding ); 00974 00975 TiXmlNode *parent; 00976 NodeType type; 00977 00978 TiXmlNode *firstChild; 00979 TiXmlNode *lastChild; 00980 00981 TIXML_STRING value; 00982 00983 TiXmlNode *prev; 00984 TiXmlNode *next; 00985 00986 private: 00987 TiXmlNode ( const TiXmlNode & ); // not implemented. 00988 void operator= ( const TiXmlNode &base ); // not allowed. 00989 }; 00990 00991 00999 class TiXmlAttribute : public TiXmlBase 01000 { 01001 friend class TiXmlAttributeSet; 01002 01003 public: 01005 TiXmlAttribute() : TiXmlBase() 01006 { 01007 document = 0; 01008 prev = next = 0; 01009 } 01010 01011 #ifdef TIXML_USE_STL 01012 01013 TiXmlAttribute ( const std::string &_name, const std::string &_value ) 01014 { 01015 name = _name; 01016 value = _value; 01017 document = 0; 01018 prev = next = 0; 01019 } 01020 #endif 01021 01023 TiXmlAttribute ( const char *_name, const char *_value ) 01024 { 01025 name = _name; 01026 value = _value; 01027 document = 0; 01028 prev = next = 0; 01029 } 01030 01031 const char *Name() const 01032 { 01033 return name.c_str(); 01034 } 01035 const char *Value() const 01036 { 01037 return value.c_str(); 01038 } 01039 #ifdef TIXML_USE_STL 01040 const std::string &ValueStr() const 01041 { 01042 return value; 01043 } 01044 #endif 01045 int IntValue() const; 01046 double DoubleValue() const; 01047 01048 // Get the tinyxml string representation 01049 const TIXML_STRING &NameTStr() const 01050 { 01051 return name; 01052 } 01053 01063 int QueryIntValue ( int *_value ) const; 01065 int QueryDoubleValue ( double *_value ) const; 01066 01067 void SetName ( const char *_name ) 01068 { 01069 name = _name; 01070 } 01071 void SetValue ( const char *_value ) 01072 { 01073 value = _value; 01074 } 01075 01076 void SetIntValue ( int _value ); 01077 void SetDoubleValue ( double _value ); 01078 01079 #ifdef TIXML_USE_STL 01080 01081 void SetName ( const std::string &_name ) 01082 { 01083 name = _name; 01084 } 01086 void SetValue ( const std::string &_value ) 01087 { 01088 value = _value; 01089 } 01090 #endif 01091 01093 const TiXmlAttribute *Next() const; 01094 TiXmlAttribute *Next() 01095 { 01096 return const_cast< TiXmlAttribute * > ( (const_cast< const TiXmlAttribute * > (this) )->Next() ); 01097 } 01098 01100 const TiXmlAttribute *Previous() const; 01101 TiXmlAttribute *Previous() 01102 { 01103 return const_cast< TiXmlAttribute * > ( (const_cast< const TiXmlAttribute * > (this) )->Previous() ); 01104 } 01105 01106 bool operator== ( const TiXmlAttribute &rhs ) const 01107 { 01108 return rhs.name == name; 01109 } 01110 bool operator< ( const TiXmlAttribute &rhs ) const 01111 { 01112 return name < rhs.name; 01113 } 01114 bool operator> ( const TiXmlAttribute &rhs ) const 01115 { 01116 return name > rhs.name; 01117 } 01118 01119 /* Attribute parsing starts: first letter of the name 01120 returns: the next char after the value end quote 01121 */ 01122 virtual const char *Parse ( const char *p, TiXmlParsingData *data, TiXmlEncoding encoding ); 01123 01124 // Prints this Attribute to a FILE stream. 01125 virtual void Print ( FILE *cfile, int depth ) const 01126 { 01127 Print ( cfile, depth, 0 ); 01128 } 01129 void Print ( FILE *cfile, int depth, TIXML_STRING *str ) const; 01130 01131 // [internal use] 01132 // Set the document pointer so the attribute can report errors. 01133 void SetDocument ( TiXmlDocument *doc ) 01134 { 01135 document = doc; 01136 } 01137 01138 private: 01139 TiXmlAttribute ( const TiXmlAttribute & ); // not implemented. 01140 void operator= ( const TiXmlAttribute &base ); // not allowed. 01141 01142 TiXmlDocument *document; // A pointer back to a document, for error reporting. 01143 TIXML_STRING name; 01144 TIXML_STRING value; 01145 TiXmlAttribute *prev; 01146 TiXmlAttribute *next; 01147 }; 01148 01149 01150 /* A class used to manage a group of attributes. 01151 It is only used internally, both by the ELEMENT and the DECLARATION. 01152 01153 The set can be changed transparent to the Element and Declaration 01154 classes that use it, but NOT transparent to the Attribute 01155 which has to implement a next() and previous() method. Which makes 01156 it a bit problematic and prevents the use of STL. 01157 01158 This version is implemented with circular lists because: 01159 - I like circular lists 01160 - it demonstrates some independence from the (typical) doubly linked list. 01161 */ 01162 class TiXmlAttributeSet 01163 { 01164 public: 01165 TiXmlAttributeSet(); 01166 ~TiXmlAttributeSet(); 01167 01168 void Add ( TiXmlAttribute *attribute ); 01169 void Remove ( TiXmlAttribute *attribute ); 01170 01171 const TiXmlAttribute *First() const 01172 { 01173 return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; 01174 } 01175 TiXmlAttribute *First() 01176 { 01177 return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; 01178 } 01179 const TiXmlAttribute *Last() const 01180 { 01181 return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; 01182 } 01183 TiXmlAttribute *Last() 01184 { 01185 return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; 01186 } 01187 01188 const TiXmlAttribute *Find ( const char *_name ) const; 01189 TiXmlAttribute *Find ( const char *_name ) 01190 { 01191 return const_cast< TiXmlAttribute * > ( (const_cast< const TiXmlAttributeSet * > (this) )->Find ( _name ) ); 01192 } 01193 #ifdef TIXML_USE_STL 01194 const TiXmlAttribute *Find ( const std::string &_name ) const; 01195 TiXmlAttribute *Find ( const std::string &_name ) 01196 { 01197 return const_cast< TiXmlAttribute * > ( (const_cast< const TiXmlAttributeSet * > (this) )->Find ( _name ) ); 01198 } 01199 01200 #endif 01201 01202 private: 01203 //*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element), 01204 //*ME: this class must be also use a hidden/disabled copy-constructor !!! 01205 TiXmlAttributeSet ( const TiXmlAttributeSet & ); // not allowed 01206 void operator= ( const TiXmlAttributeSet & ); // not allowed (as TiXmlAttribute) 01207 01208 TiXmlAttribute sentinel; 01209 }; 01210 01211 01216 class TiXmlElement : public TiXmlNode 01217 { 01218 public: 01220 TiXmlElement (const char *in_value); 01221 01222 #ifdef TIXML_USE_STL 01223 01224 TiXmlElement ( const std::string &_value ); 01225 #endif 01226 01227 TiXmlElement ( const TiXmlElement & ); 01228 01229 void operator= ( const TiXmlElement &base ); 01230 01231 virtual ~TiXmlElement(); 01232 01236 const char *Attribute ( const char *name ) const; 01237 01244 const char *Attribute ( const char *name, int *i ) const; 01245 01252 const char *Attribute ( const char *name, double *d ) const; 01253 01261 int QueryIntAttribute ( const char *name, int *_value ) const; 01263 int QueryDoubleAttribute ( const char *name, double *_value ) const; 01265 int QueryFloatAttribute ( const char *name, float *_value ) const 01266 { 01267 double d; 01268 int result = QueryDoubleAttribute ( name, &d ); 01269 01270 if ( result == TIXML_SUCCESS ) 01271 { 01272 *_value = (float) d; 01273 } 01274 01275 return result; 01276 } 01277 01278 #ifdef TIXML_USE_STL 01279 01287 template< typename T > int QueryValueAttribute ( const std::string &name, T *outValue ) const 01288 { 01289 const TiXmlAttribute *node = attributeSet.Find ( name ); 01290 01291 if ( !node ) 01292 return TIXML_NO_ATTRIBUTE; 01293 01294 std::stringstream sstream ( node->ValueStr() ); 01295 sstream >> *outValue; 01296 01297 if ( !sstream.fail() ) 01298 return TIXML_SUCCESS; 01299 01300 return TIXML_WRONG_TYPE; 01301 } 01302 /* 01303 This is - in theory - a bug fix for "QueryValueAtribute returns truncated std::string" 01304 but template specialization is hard to get working cross-compiler. Leaving the bug for now. 01305 01306 // The above will fail for std::string because the space character is used as a seperator. 01307 // Specialize for strings. Bug [ 1695429 ] QueryValueAtribute returns truncated std::string 01308 template<> int QueryValueAttribute( const std::string& name, std::string* outValue ) const 01309 { 01310 const TiXmlAttribute* node = attributeSet.Find( name ); 01311 if ( !node ) 01312 return TIXML_NO_ATTRIBUTE; 01313 *outValue = node->ValueStr(); 01314 return TIXML_SUCCESS; 01315 } 01316 */ 01317 #endif 01318 01322 void SetAttribute ( const char *name, const char *_value ); 01323 01324 #ifdef TIXML_USE_STL 01325 const std::string *Attribute ( const std::string &name ) const; 01326 const std::string *Attribute ( const std::string &name, int *i ) const; 01327 const std::string *Attribute ( const std::string &name, double *d ) const; 01328 int QueryIntAttribute ( const std::string &name, int *_value ) const; 01329 int QueryDoubleAttribute ( const std::string &name, double *_value ) const; 01330 01332 void SetAttribute ( const std::string &name, const std::string &_value ); 01334 void SetAttribute ( const std::string &name, int _value ); 01335 #endif 01336 01340 void SetAttribute ( const char *name, int value ); 01341 01345 void SetDoubleAttribute ( const char *name, double value ); 01346 01349 void RemoveAttribute ( const char *name ); 01350 #ifdef TIXML_USE_STL 01351 void RemoveAttribute ( const std::string &name ) 01352 { 01353 RemoveAttribute (name.c_str () ); 01354 } 01355 #endif 01356 01357 const TiXmlAttribute *FirstAttribute() const 01358 { 01359 return attributeSet.First(); 01360 } 01361 TiXmlAttribute *FirstAttribute() 01362 { 01363 return attributeSet.First(); 01364 } 01365 const TiXmlAttribute *LastAttribute() const 01366 { 01367 return attributeSet.Last(); 01368 } 01369 TiXmlAttribute *LastAttribute() 01370 { 01371 return attributeSet.Last(); 01372 } 01373 01406 const char *GetText() const; 01407 01409 virtual TiXmlNode *Clone() const; 01410 // Print the Element to a FILE stream. 01411 virtual void Print ( FILE *cfile, int depth ) const; 01412 01413 /* Attribtue parsing starts: next char past '<' 01414 returns: next char past '>' 01415 */ 01416 virtual const char *Parse ( const char *p, TiXmlParsingData *data, TiXmlEncoding encoding ); 01417 01418 virtual const TiXmlElement *ToElement() const 01419 { 01420 return this; 01421 } 01422 virtual TiXmlElement *ToElement() 01423 { 01424 return this; 01425 } 01426 01429 virtual bool Accept ( TiXmlVisitor *visitor ) const; 01430 01431 protected: 01432 01433 void CopyTo ( TiXmlElement *target ) const; 01434 void ClearThis(); // like clear, but initializes 'this' object as well 01435 01436 // Used to be public [internal use] 01437 #ifdef TIXML_USE_STL 01438 virtual void StreamIn ( std::istream *in, TIXML_STRING *tag ); 01439 #endif 01440 /* [internal use] 01441 Reads the "value" of the element -- another element, or text. 01442 This should terminate with the current end tag. 01443 */ 01444 const char *ReadValue ( const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding ); 01445 01446 private: 01447 01448 TiXmlAttributeSet attributeSet; 01449 }; 01450 01451 01454 class TiXmlComment : public TiXmlNode 01455 { 01456 public: 01458 TiXmlComment() : TiXmlNode ( TiXmlNode::COMMENT ) {} 01460 TiXmlComment ( const char *_value ) : TiXmlNode ( TiXmlNode::COMMENT ) 01461 { 01462 SetValue ( _value ); 01463 } 01464 TiXmlComment ( const TiXmlComment & ); 01465 void operator= ( const TiXmlComment &base ); 01466 01467 virtual ~TiXmlComment() {} 01468 01470 virtual TiXmlNode *Clone() const; 01471 // Write this Comment to a FILE stream. 01472 virtual void Print ( FILE *cfile, int depth ) const; 01473 01474 /* Attribtue parsing starts: at the ! of the !-- 01475 returns: next char past '>' 01476 */ 01477 virtual const char *Parse ( const char *p, TiXmlParsingData *data, TiXmlEncoding encoding ); 01478 01479 virtual const TiXmlComment *ToComment() const 01480 { 01481 return this; 01482 } 01483 virtual TiXmlComment *ToComment() 01484 { 01485 return this; 01486 } 01487 01490 virtual bool Accept ( TiXmlVisitor *visitor ) const; 01491 01492 protected: 01493 void CopyTo ( TiXmlComment *target ) const; 01494 01495 // used to be public 01496 #ifdef TIXML_USE_STL 01497 virtual void StreamIn ( std::istream *in, TIXML_STRING *tag ); 01498 #endif 01499 // virtual void StreamOut( TIXML_OSTREAM * out ) const; 01500 01501 private: 01502 01503 }; 01504 01505 01511 class TiXmlText : public TiXmlNode 01512 { 01513 friend class TiXmlElement; 01514 public: 01519 TiXmlText (const char *initValue ) : TiXmlNode (TiXmlNode::TEXT) 01520 { 01521 SetValue ( initValue ); 01522 cdata = false; 01523 } 01524 virtual ~TiXmlText() {} 01525 01526 #ifdef TIXML_USE_STL 01527 01528 TiXmlText ( const std::string &initValue ) : TiXmlNode (TiXmlNode::TEXT) 01529 { 01530 SetValue ( initValue ); 01531 cdata = false; 01532 } 01533 #endif 01534 01535 TiXmlText ( const TiXmlText © ) : TiXmlNode ( TiXmlNode::TEXT ) 01536 { 01537 copy.CopyTo ( this ); 01538 } 01539 void operator= ( const TiXmlText &base ) 01540 { 01541 base.CopyTo ( this ); 01542 } 01543 01544 // Write this text object to a FILE stream. 01545 virtual void Print ( FILE *cfile, int depth ) const; 01546 01548 bool CDATA() const 01549 { 01550 return cdata; 01551 } 01553 void SetCDATA ( bool _cdata ) 01554 { 01555 cdata = _cdata; 01556 } 01557 01558 virtual const char *Parse ( const char *p, TiXmlParsingData *data, TiXmlEncoding encoding ); 01559 01560 virtual const TiXmlText *ToText() const 01561 { 01562 return this; 01563 } 01564 virtual TiXmlText *ToText() 01565 { 01566 return this; 01567 } 01568 01571 virtual bool Accept ( TiXmlVisitor *content ) const; 01572 01573 protected : 01575 virtual TiXmlNode *Clone() const; 01576 void CopyTo ( TiXmlText *target ) const; 01577 01578 bool Blank() const; // returns true if all white space and new lines 01579 // [internal use] 01580 #ifdef TIXML_USE_STL 01581 virtual void StreamIn ( std::istream *in, TIXML_STRING *tag ); 01582 #endif 01583 01584 private: 01585 bool cdata; // true if this should be input and output as a CDATA style text element 01586 }; 01587 01588 01602 class TiXmlDeclaration : public TiXmlNode 01603 { 01604 public: 01606 TiXmlDeclaration() : TiXmlNode ( TiXmlNode::DECLARATION ) {} 01607 01608 #ifdef TIXML_USE_STL 01609 01610 TiXmlDeclaration ( const std::string &_version, 01611 const std::string &_encoding, 01612 const std::string &_standalone ); 01613 #endif 01614 01616 TiXmlDeclaration ( const char *_version, 01617 const char *_encoding, 01618 const char *_standalone ); 01619 01620 TiXmlDeclaration ( const TiXmlDeclaration © ); 01621 void operator= ( const TiXmlDeclaration © ); 01622 01623 virtual ~TiXmlDeclaration() {} 01624 01626 const char *Version() const 01627 { 01628 return version.c_str (); 01629 } 01631 const char *Encoding() const 01632 { 01633 return encoding.c_str (); 01634 } 01636 const char *Standalone() const 01637 { 01638 return standalone.c_str (); 01639 } 01640 01642 virtual TiXmlNode *Clone() const; 01643 // Print this declaration to a FILE stream. 01644 virtual void Print ( FILE *cfile, int depth, TIXML_STRING *str ) const; 01645 virtual void Print ( FILE *cfile, int depth ) const 01646 { 01647 Print ( cfile, depth, 0 ); 01648 } 01649 01650 virtual const char *Parse ( const char *p, TiXmlParsingData *data, TiXmlEncoding encoding ); 01651 01652 virtual const TiXmlDeclaration *ToDeclaration() const 01653 { 01654 return this; 01655 } 01656 virtual TiXmlDeclaration *ToDeclaration() 01657 { 01658 return this; 01659 } 01660 01663 virtual bool Accept ( TiXmlVisitor *visitor ) const; 01664 01665 protected: 01666 void CopyTo ( TiXmlDeclaration *target ) const; 01667 // used to be public 01668 #ifdef TIXML_USE_STL 01669 virtual void StreamIn ( std::istream *in, TIXML_STRING *tag ); 01670 #endif 01671 01672 private: 01673 01674 TIXML_STRING version; 01675 TIXML_STRING encoding; 01676 TIXML_STRING standalone; 01677 }; 01678 01679 01687 class TiXmlUnknown : public TiXmlNode 01688 { 01689 public: 01690 TiXmlUnknown() : TiXmlNode ( TiXmlNode::UNKNOWN ) {} 01691 virtual ~TiXmlUnknown() {} 01692 01693 TiXmlUnknown ( const TiXmlUnknown © ) : TiXmlNode ( TiXmlNode::UNKNOWN ) 01694 { 01695 copy.CopyTo ( this ); 01696 } 01697 void operator= ( const TiXmlUnknown © ) 01698 { 01699 copy.CopyTo ( this ); 01700 } 01701 01703 virtual TiXmlNode *Clone() const; 01704 // Print this Unknown to a FILE stream. 01705 virtual void Print ( FILE *cfile, int depth ) const; 01706 01707 virtual const char *Parse ( const char *p, TiXmlParsingData *data, TiXmlEncoding encoding ); 01708 01709 virtual const TiXmlUnknown *ToUnknown() const 01710 { 01711 return this; 01712 } 01713 virtual TiXmlUnknown *ToUnknown() 01714 { 01715 return this; 01716 } 01717 01720 virtual bool Accept ( TiXmlVisitor *content ) const; 01721 01722 protected: 01723 void CopyTo ( TiXmlUnknown *target ) const; 01724 01725 #ifdef TIXML_USE_STL 01726 virtual void StreamIn ( std::istream *in, TIXML_STRING *tag ); 01727 #endif 01728 01729 private: 01730 01731 }; 01732 01733 01738 class TiXmlDocument : public TiXmlNode 01739 { 01740 public: 01742 TiXmlDocument(); 01744 TiXmlDocument ( const char *documentName ); 01745 01746 #ifdef TIXML_USE_STL 01747 01748 TiXmlDocument ( const std::string &documentName ); 01749 #endif 01750 01751 TiXmlDocument ( const TiXmlDocument © ); 01752 void operator= ( const TiXmlDocument © ); 01753 01754 virtual ~TiXmlDocument() {} 01755 01760 bool LoadFile ( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); 01762 bool SaveFile() const; 01764 bool LoadFile ( const char *filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); 01766 bool SaveFile ( const char *filename ) const; 01772 bool LoadFile ( FILE *, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); 01774 bool SaveFile ( FILE * ) const; 01775 01776 #ifdef TIXML_USE_STL 01777 bool LoadFile ( const std::string &filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ) 01778 { 01779 // StringToBuffer f( filename ); 01780 // return ( f.buffer && LoadFile( f.buffer, encoding )); 01781 return LoadFile ( filename.c_str(), encoding ); 01782 } 01783 bool SaveFile ( const std::string &filename ) const 01784 { 01785 // StringToBuffer f( filename ); 01786 // return ( f.buffer && SaveFile( f.buffer )); 01787 return SaveFile ( filename.c_str() ); 01788 } 01789 #endif 01790 01795 virtual const char *Parse ( const char *p, TiXmlParsingData *data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); 01796 01801 const TiXmlElement *RootElement() const 01802 { 01803 return FirstChildElement(); 01804 } 01805 TiXmlElement *RootElement() 01806 { 01807 return FirstChildElement(); 01808 } 01809 01815 bool Error() const 01816 { 01817 return error; 01818 } 01819 01821 const char *ErrorDesc() const 01822 { 01823 return errorDesc.c_str (); 01824 } 01825 01829 int ErrorId() const 01830 { 01831 return errorId; 01832 } 01833 01841 int ErrorRow() const 01842 { 01843 return errorLocation.row + 1; 01844 } 01845 int ErrorCol() const 01846 { 01847 return errorLocation.col + 1; 01848 } 01849 01874 void SetTabSize ( int _tabsize ) 01875 { 01876 tabsize = _tabsize; 01877 } 01878 01879 int TabSize() const 01880 { 01881 return tabsize; 01882 } 01883 01887 void ClearError() 01888 { 01889 error = false; 01890 errorId = 0; 01891 errorDesc = ""; 01892 errorLocation.row = errorLocation.col = 0; 01893 //errorLocation.last = 0; 01894 } 01895 01897 void Print() const 01898 { 01899 Print ( stdout, 0 ); 01900 } 01901 01902 /* Write the document to a string using formatted printing ("pretty print"). This 01903 will allocate a character array (new char[]) and return it as a pointer. The 01904 calling code pust call delete[] on the return char* to avoid a memory leak. 01905 */ 01906 //char* PrintToMemory() const; 01907 01909 virtual void Print ( FILE *cfile, int depth = 0 ) const; 01910 // [internal use] 01911 void SetError ( int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding ); 01912 01913 virtual const TiXmlDocument *ToDocument() const 01914 { 01915 return this; 01916 } 01917 virtual TiXmlDocument *ToDocument() 01918 { 01919 return this; 01920 } 01921 01924 virtual bool Accept ( TiXmlVisitor *content ) const; 01925 01926 protected : 01927 // [internal use] 01928 virtual TiXmlNode *Clone() const; 01929 #ifdef TIXML_USE_STL 01930 virtual void StreamIn ( std::istream *in, TIXML_STRING *tag ); 01931 #endif 01932 01933 private: 01934 void CopyTo ( TiXmlDocument *target ) const; 01935 01936 bool error; 01937 int errorId; 01938 TIXML_STRING errorDesc; 01939 int tabsize; 01940 TiXmlCursor errorLocation; 01941 bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write. 01942 }; 01943 01944 02025 class TiXmlHandle 02026 { 02027 public: 02029 TiXmlHandle ( TiXmlNode *_node ) 02030 { 02031 this->node = _node; 02032 } 02034 TiXmlHandle ( const TiXmlHandle &ref ) 02035 { 02036 this->node = ref.node; 02037 } 02038 TiXmlHandle operator= ( const TiXmlHandle &ref ) 02039 { 02040 this->node = ref.node; 02041 return *this; 02042 } 02043 02045 TiXmlHandle FirstChild() const; 02047 TiXmlHandle FirstChild ( const char *value ) const; 02049 TiXmlHandle FirstChildElement() const; 02051 TiXmlHandle FirstChildElement ( const char *value ) const; 02052 02056 TiXmlHandle Child ( const char *value, int index ) const; 02060 TiXmlHandle Child ( int index ) const; 02065 TiXmlHandle ChildElement ( const char *value, int index ) const; 02070 TiXmlHandle ChildElement ( int index ) const; 02071 02072 #ifdef TIXML_USE_STL 02073 TiXmlHandle FirstChild ( const std::string &_value ) const 02074 { 02075 return FirstChild ( _value.c_str() ); 02076 } 02077 TiXmlHandle FirstChildElement ( const std::string &_value ) const 02078 { 02079 return FirstChildElement ( _value.c_str() ); 02080 } 02081 02082 TiXmlHandle Child ( const std::string &_value, int index ) const 02083 { 02084 return Child ( _value.c_str(), index ); 02085 } 02086 TiXmlHandle ChildElement ( const std::string &_value, int index ) const 02087 { 02088 return ChildElement ( _value.c_str(), index ); 02089 } 02090 #endif 02091 02094 TiXmlNode *ToNode() const 02095 { 02096 return node; 02097 } 02100 TiXmlElement *ToElement() const 02101 { 02102 return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); 02103 } 02106 TiXmlText *ToText() const 02107 { 02108 return ( ( node && node->ToText() ) ? node->ToText() : 0 ); 02109 } 02112 TiXmlUnknown *ToUnknown() const 02113 { 02114 return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); 02115 } 02116 02120 TiXmlNode *Node() const 02121 { 02122 return ToNode(); 02123 } 02127 TiXmlElement *Element() const 02128 { 02129 return ToElement(); 02130 } 02134 TiXmlText *Text() const 02135 { 02136 return ToText(); 02137 } 02141 TiXmlUnknown *Unknown() const 02142 { 02143 return ToUnknown(); 02144 } 02145 02146 private: 02147 TiXmlNode *node; 02148 }; 02149 02150 02170 class TiXmlPrinter : public TiXmlVisitor 02171 { 02172 public: 02173 TiXmlPrinter() : depth ( 0 ), simpleTextPrint ( false ), 02174 buffer(), indent ( " " ), lineBreak ( "\n" ) {} 02175 02176 virtual bool VisitEnter ( const TiXmlDocument &doc ); 02177 virtual bool VisitExit ( const TiXmlDocument &doc ); 02178 02179 virtual bool VisitEnter ( const TiXmlElement &element, const TiXmlAttribute *firstAttribute ); 02180 virtual bool VisitExit ( const TiXmlElement &element ); 02181 02182 virtual bool Visit ( const TiXmlDeclaration &declaration ); 02183 virtual bool Visit ( const TiXmlText &text ); 02184 virtual bool Visit ( const TiXmlComment &comment ); 02185 virtual bool Visit ( const TiXmlUnknown &unknown ); 02186 02190 void SetIndent ( const char *_indent ) 02191 { 02192 indent = _indent ? _indent : "" ; 02193 } 02195 const char *Indent() 02196 { 02197 return indent.c_str(); 02198 } 02203 void SetLineBreak ( const char *_lineBreak ) 02204 { 02205 lineBreak = _lineBreak ? _lineBreak : ""; 02206 } 02208 const char *LineBreak() 02209 { 02210 return lineBreak.c_str(); 02211 } 02212 02216 void SetStreamPrinting() 02217 { 02218 indent = ""; 02219 lineBreak = ""; 02220 } 02222 const char *CStr() 02223 { 02224 return buffer.c_str(); 02225 } 02227 size_t Size() 02228 { 02229 return buffer.size(); 02230 } 02231 02232 #ifdef TIXML_USE_STL 02233 02234 const std::string &Str() 02235 { 02236 return buffer; 02237 } 02238 #endif 02239 02240 private: 02241 void DoIndent() 02242 { 02243 for ( int i = 0; i < depth; ++i ) 02244 buffer += indent; 02245 } 02246 void DoLineBreak() 02247 { 02248 buffer += lineBreak; 02249 } 02250 02251 int depth; 02252 bool simpleTextPrint; 02253 TIXML_STRING buffer; 02254 TIXML_STRING indent; 02255 TIXML_STRING lineBreak; 02256 }; 02257 02258 02259 #ifdef _MSC_VER 02260 #pragma warning( pop ) 02261 #endif 02262 02263 #endif 02264