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