[1505] | 1 | #define TIXML_USE_TICPP |
---|
| 2 | |
---|
[739] | 3 | /* |
---|
| 4 | http://code.google.com/p/ticpp/ |
---|
| 5 | Copyright (c) 2006 Ryan Pusztai, Ryan Mulder |
---|
| 6 | |
---|
| 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of |
---|
| 8 | this software and associated documentation files (the "Software"), to deal in |
---|
| 9 | the Software without restriction, including without limitation the rights to |
---|
| 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
---|
| 11 | the Software, and to permit persons to whom the Software is furnished to do so, |
---|
| 12 | subject to the following conditions: |
---|
| 13 | |
---|
| 14 | The above copyright notice and this permission notice shall be included in all |
---|
| 15 | copies or substantial portions of the Software. |
---|
| 16 | |
---|
| 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
---|
| 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
---|
| 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
---|
| 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
---|
| 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
---|
| 23 | */ |
---|
| 24 | |
---|
[1625] | 25 | /* |
---|
| 26 | Modifications by the orxonox team: |
---|
| 27 | In function: void Document::Parse( const std::string& xml, bool throwIfParseError, TiXmlEncoding encoding ) |
---|
| 28 | change: Added row and column number to the error description. |
---|
| 29 | author: Reto Grieder |
---|
| 30 | */ |
---|
| 31 | |
---|
[739] | 32 | #ifdef TIXML_USE_TICPP |
---|
| 33 | |
---|
| 34 | #include "ticpp.h" |
---|
| 35 | #include "ticpprc.h" |
---|
| 36 | #include "tinyxml.h" |
---|
| 37 | #include <sstream> |
---|
| 38 | |
---|
| 39 | using namespace ticpp; |
---|
| 40 | |
---|
| 41 | // In the following Visitor functions, casting away const should be safe, as the object can only be referred to by a const & |
---|
| 42 | bool Visitor::VisitEnter( const TiXmlDocument& doc ) |
---|
| 43 | { |
---|
| 44 | return VisitEnter( Document( const_cast< TiXmlDocument* >( &doc ) ) ); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | bool Visitor::VisitExit( const TiXmlDocument& doc ) |
---|
| 48 | { |
---|
| 49 | return VisitEnter( Document( const_cast< TiXmlDocument* >( &doc ) ) ); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | bool Visitor::VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ) |
---|
| 53 | { |
---|
| 54 | if ( 0 != firstAttribute ) |
---|
| 55 | { |
---|
| 56 | Attribute attribute( const_cast< TiXmlAttribute* >( firstAttribute ) ); |
---|
| 57 | return VisitEnter( Element( const_cast< TiXmlElement* >( &element ) ), &attribute ); |
---|
| 58 | } |
---|
| 59 | else |
---|
| 60 | { |
---|
| 61 | return VisitEnter( Element( const_cast< TiXmlElement* >( &element ) ), 0 ); |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | bool Visitor::VisitExit( const TiXmlElement& element ) |
---|
| 66 | { |
---|
| 67 | return VisitExit( Element( const_cast< TiXmlElement* >( &element ) ) ); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | bool Visitor::Visit( const TiXmlDeclaration& declaration ) |
---|
| 71 | { |
---|
| 72 | return Visit( Declaration( const_cast< TiXmlDeclaration* >( &declaration ) ) ); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | bool Visitor::Visit( const TiXmlStylesheetReference& stylesheet ) |
---|
| 76 | { |
---|
| 77 | return Visit( StylesheetReference( const_cast< TiXmlStylesheetReference* >( &stylesheet ) ) ); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | bool Visitor::Visit( const TiXmlText& text ) |
---|
| 81 | { |
---|
| 82 | return Visit( Text( const_cast< TiXmlText* >( &text ) ) ); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | bool Visitor::Visit( const TiXmlComment& comment ) |
---|
| 86 | { |
---|
| 87 | return Visit( Comment( const_cast< TiXmlComment* >( &comment ) ) ); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | Attribute::Attribute() |
---|
| 91 | { |
---|
| 92 | SetTiXmlPointer( new TiXmlAttribute() ); |
---|
| 93 | m_impRC->InitRef(); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | Attribute::Attribute( TiXmlAttribute* attribute ) |
---|
| 97 | { |
---|
| 98 | SetTiXmlPointer( attribute ); |
---|
| 99 | m_impRC->IncRef(); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | Attribute::Attribute( const std::string& name, const std::string& value ) |
---|
| 103 | { |
---|
| 104 | SetTiXmlPointer( new TiXmlAttribute( name, value ) ); |
---|
| 105 | m_impRC->InitRef(); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | void Attribute::operator=( const Attribute& copy ) |
---|
| 109 | { |
---|
| 110 | // Dropping the reference to the old object |
---|
| 111 | this->m_impRC->DecRef(); |
---|
| 112 | |
---|
| 113 | // Pointing to the new Object |
---|
| 114 | SetTiXmlPointer( copy.m_tiXmlPointer ); |
---|
| 115 | |
---|
| 116 | // The internal tixml pointer changed in the above line |
---|
| 117 | this->m_impRC->IncRef(); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | Attribute::Attribute( const Attribute& copy ) : Base() |
---|
| 121 | { |
---|
| 122 | // Dropping the reference to the old object |
---|
| 123 | this->m_impRC->DecRef(); |
---|
| 124 | |
---|
| 125 | // Pointing to the new Object |
---|
| 126 | SetTiXmlPointer( copy.m_tiXmlPointer ); |
---|
| 127 | |
---|
| 128 | // The internal tixml pointer changed in the above line |
---|
| 129 | this->m_impRC->IncRef(); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | Attribute::~Attribute() |
---|
| 133 | { |
---|
| 134 | m_impRC->DecRef(); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | std::string Attribute::Value() const |
---|
| 138 | { |
---|
| 139 | ValidatePointer(); |
---|
| 140 | return m_tiXmlPointer->ValueStr(); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | std::string Attribute::Name() const |
---|
| 144 | { |
---|
| 145 | ValidatePointer(); |
---|
| 146 | return m_tiXmlPointer->Name(); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | Attribute* Attribute::Next( bool throwIfNoAttribute ) const |
---|
| 150 | { |
---|
| 151 | ValidatePointer(); |
---|
| 152 | TiXmlAttribute* attribute = m_tiXmlPointer->Next(); |
---|
| 153 | if ( 0 == attribute ) |
---|
| 154 | { |
---|
| 155 | if ( throwIfNoAttribute ) |
---|
| 156 | { |
---|
| 157 | TICPPTHROW( "No more attributes found" ) |
---|
| 158 | } |
---|
| 159 | else |
---|
| 160 | { |
---|
| 161 | return 0; |
---|
| 162 | } |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | Attribute* temp = new Attribute( attribute ); |
---|
| 166 | m_spawnedWrappers.push_back( temp ); |
---|
| 167 | |
---|
| 168 | return temp; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | Attribute* Attribute::Previous( bool throwIfNoAttribute ) const |
---|
| 172 | { |
---|
| 173 | ValidatePointer(); |
---|
| 174 | TiXmlAttribute* attribute = m_tiXmlPointer->Previous(); |
---|
| 175 | if ( 0 == attribute ) |
---|
| 176 | { |
---|
| 177 | if ( throwIfNoAttribute ) |
---|
| 178 | { |
---|
| 179 | TICPPTHROW( "No more attributes found" ) |
---|
| 180 | } |
---|
| 181 | else |
---|
| 182 | { |
---|
| 183 | return 0; |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | Attribute* temp = new Attribute( attribute ); |
---|
| 188 | m_spawnedWrappers.push_back( temp ); |
---|
| 189 | |
---|
| 190 | return temp; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | void Attribute::IterateNext( const std::string&, Attribute** next ) const |
---|
| 194 | { |
---|
| 195 | *next = Next( false ); |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | void Attribute::IteratePrevious( const std::string&, Attribute** previous ) const |
---|
| 199 | { |
---|
| 200 | *previous = Previous( false ); |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | void Attribute::Print( FILE* file, int depth ) const |
---|
| 204 | { |
---|
| 205 | ValidatePointer(); |
---|
| 206 | m_tiXmlPointer->Print( file, depth ); |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | void Attribute::SetTiXmlPointer( TiXmlAttribute* newPointer ) |
---|
| 210 | { |
---|
| 211 | m_tiXmlPointer = newPointer; |
---|
| 212 | SetImpRC( newPointer ); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | //***************************************************************************** |
---|
| 216 | |
---|
| 217 | Node* Node::NodeFactory( TiXmlNode* tiXmlNode, bool throwIfNull, bool rememberSpawnedWrapper ) const |
---|
| 218 | { |
---|
| 219 | if ( 0 == tiXmlNode ) |
---|
| 220 | { |
---|
| 221 | if ( throwIfNull ) |
---|
| 222 | { |
---|
| 223 | TICPPTHROW( "tiXmlNode is NULL" ) |
---|
| 224 | } |
---|
| 225 | else |
---|
| 226 | { |
---|
| 227 | return 0; |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | Node* temp; |
---|
| 232 | switch ( tiXmlNode->Type() ) |
---|
| 233 | { |
---|
| 234 | case TiXmlNode::DOCUMENT: |
---|
| 235 | temp = new Document( tiXmlNode->ToDocument() ); |
---|
| 236 | break; |
---|
| 237 | |
---|
| 238 | case TiXmlNode::ELEMENT: |
---|
| 239 | temp = new Element( tiXmlNode->ToElement() ); |
---|
| 240 | break; |
---|
| 241 | |
---|
| 242 | case TiXmlNode::COMMENT: |
---|
| 243 | temp = new Comment( tiXmlNode->ToComment() ); |
---|
| 244 | break; |
---|
| 245 | |
---|
| 246 | case TiXmlNode::TEXT: |
---|
| 247 | temp = new Text( tiXmlNode->ToText() ); |
---|
| 248 | break; |
---|
| 249 | |
---|
| 250 | case TiXmlNode::DECLARATION: |
---|
| 251 | temp = new Declaration( tiXmlNode->ToDeclaration() ); |
---|
| 252 | break; |
---|
| 253 | |
---|
| 254 | case TiXmlNode::STYLESHEETREFERENCE: |
---|
| 255 | temp = new StylesheetReference( tiXmlNode->ToStylesheetReference() ); |
---|
| 256 | break; |
---|
| 257 | |
---|
| 258 | default: |
---|
| 259 | TICPPTHROW( "Type is unsupported" ) |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | if ( rememberSpawnedWrapper ) |
---|
| 263 | { |
---|
| 264 | m_spawnedWrappers.push_back( temp ); |
---|
| 265 | } |
---|
| 266 | return temp; |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | |
---|
| 270 | std::string Node::Value() const |
---|
| 271 | { |
---|
| 272 | return GetTiXmlPointer()->ValueStr(); |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | void Node::Clear() |
---|
| 276 | { |
---|
| 277 | GetTiXmlPointer()->Clear(); |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | Node* Node::Parent( bool throwIfNoParent ) const |
---|
| 281 | { |
---|
| 282 | TiXmlNode* parent = GetTiXmlPointer()->Parent(); |
---|
| 283 | if ( ( 0 == parent ) && throwIfNoParent ) |
---|
| 284 | { |
---|
| 285 | TICPPTHROW( "No parent exists" ); |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | return NodeFactory( parent, false ); |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | Node* Node::FirstChild( bool throwIfNoChildren ) const |
---|
| 292 | { |
---|
| 293 | return FirstChild( "", throwIfNoChildren ); |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | Node* Node::FirstChild( const std::string& value, bool throwIfNoChildren ) const |
---|
| 297 | { |
---|
| 298 | return FirstChild( value.c_str(), throwIfNoChildren ); |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | Node* Node::FirstChild( const char* value, bool throwIfNoChildren ) const |
---|
| 302 | { |
---|
| 303 | TiXmlNode* childNode; |
---|
| 304 | if ( 0 == strlen( value ) ) |
---|
| 305 | { |
---|
| 306 | childNode = GetTiXmlPointer()->FirstChild(); |
---|
| 307 | } |
---|
| 308 | else |
---|
| 309 | { |
---|
| 310 | childNode = GetTiXmlPointer()->FirstChild( value ); |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | if ( ( 0 == childNode ) && throwIfNoChildren ) |
---|
| 314 | { |
---|
| 315 | TICPPTHROW( "Child with the value of \"" << value << "\" not found" ); |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | return NodeFactory( childNode, false ); |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | Node* Node::LastChild( bool throwIfNoChildren ) const |
---|
| 322 | { |
---|
| 323 | return LastChild( "", throwIfNoChildren ); |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | Node* Node::LastChild( const std::string& value, bool throwIfNoChildren ) const |
---|
| 327 | { |
---|
| 328 | return LastChild( value.c_str(), throwIfNoChildren ); |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | Node* Node::LastChild( const char* value, bool throwIfNoChildren ) const |
---|
| 332 | { |
---|
| 333 | TiXmlNode* childNode; |
---|
| 334 | if ( 0 == strlen( value ) ) |
---|
| 335 | { |
---|
| 336 | childNode = GetTiXmlPointer()->LastChild(); |
---|
| 337 | } |
---|
| 338 | else |
---|
| 339 | { |
---|
| 340 | childNode = GetTiXmlPointer()->LastChild( value ); |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | if ( ( 0 == childNode ) && throwIfNoChildren ) |
---|
| 344 | { |
---|
| 345 | TICPPTHROW( "Child with the value of \"" << value << "\" not found" ); |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | return NodeFactory( childNode, false ); |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | Node* Node::IterateChildren ( Node* previous ) const |
---|
| 352 | { |
---|
| 353 | TiXmlNode* pointer; |
---|
| 354 | if ( 0 == previous ) |
---|
| 355 | { |
---|
| 356 | pointer = GetTiXmlPointer()->IterateChildren( 0 ); |
---|
| 357 | } |
---|
| 358 | else |
---|
| 359 | { |
---|
| 360 | pointer = GetTiXmlPointer()->IterateChildren( previous->GetTiXmlPointer() ); |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | return NodeFactory( pointer, false ); |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | Node* Node::IterateChildren( const std::string& value, Node* previous ) const |
---|
| 367 | { |
---|
| 368 | TiXmlNode* pointer; |
---|
| 369 | if ( 0 == previous ) |
---|
| 370 | { |
---|
| 371 | pointer = GetTiXmlPointer()->IterateChildren( value, 0 ); |
---|
| 372 | } |
---|
| 373 | else |
---|
| 374 | { |
---|
| 375 | pointer = GetTiXmlPointer()->IterateChildren( value, previous->GetTiXmlPointer() ); |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | return NodeFactory( pointer, false ); |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | Node* Node::InsertEndChild( Node& addThis ) |
---|
| 382 | { |
---|
| 383 | if ( addThis.Type() == TiXmlNode::DOCUMENT ) |
---|
| 384 | { |
---|
| 385 | TICPPTHROW( "Node is a Document and can't be inserted" ); |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | // Increment reference count when adding to the tree |
---|
| 389 | addThis.m_impRC->IncRef(); |
---|
| 390 | |
---|
| 391 | TiXmlNode* pointer = GetTiXmlPointer()->InsertEndChild( *addThis.GetTiXmlPointer() ); |
---|
| 392 | if ( 0 == pointer ) |
---|
| 393 | { |
---|
| 394 | TICPPTHROW( "Node can't be inserted" ); |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | return NodeFactory( pointer ); |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | Node* Node::LinkEndChild( Node* childNode ) |
---|
| 401 | { |
---|
| 402 | if ( childNode->Type() == TiXmlNode::DOCUMENT ) |
---|
| 403 | { |
---|
| 404 | TICPPTHROW( "Node is a Document and can't be linked" ); |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | // Increment reference count when adding to the tree |
---|
| 408 | childNode->m_impRC->IncRef(); |
---|
| 409 | |
---|
| 410 | if ( 0 == GetTiXmlPointer()->LinkEndChild( childNode->GetTiXmlPointer() ) ) |
---|
| 411 | { |
---|
| 412 | TICPPTHROW( "Node can't be linked" ); |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | return childNode; |
---|
| 416 | } |
---|
| 417 | |
---|
| 418 | Node* Node::InsertBeforeChild( Node* beforeThis, Node& addThis ) |
---|
| 419 | { |
---|
| 420 | if ( addThis.Type() == TiXmlNode::DOCUMENT ) |
---|
| 421 | { |
---|
| 422 | TICPPTHROW( "Node is a Document and can't be inserted" ); |
---|
| 423 | } |
---|
| 424 | |
---|
| 425 | // Increment reference count when adding to the tree |
---|
| 426 | addThis.m_impRC->IncRef(); |
---|
| 427 | |
---|
| 428 | TiXmlNode* pointer = GetTiXmlPointer()->InsertBeforeChild( beforeThis->GetTiXmlPointer(), *addThis.GetTiXmlPointer() ); |
---|
| 429 | if ( 0 == pointer ) |
---|
| 430 | { |
---|
| 431 | TICPPTHROW( "Node can't be inserted" ); |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | return NodeFactory( pointer ); |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | Node* Node::InsertAfterChild( Node* afterThis, Node& addThis ) |
---|
| 438 | { |
---|
| 439 | if ( addThis.Type() == TiXmlNode::DOCUMENT ) |
---|
| 440 | { |
---|
| 441 | TICPPTHROW( "Node is a Document and can't be inserted" ); |
---|
| 442 | } |
---|
| 443 | |
---|
| 444 | // Increment reference count when adding to the tree |
---|
| 445 | addThis.m_impRC->IncRef(); |
---|
| 446 | |
---|
| 447 | TiXmlNode* pointer = GetTiXmlPointer()->InsertAfterChild( afterThis->GetTiXmlPointer(), *addThis.GetTiXmlPointer() ); |
---|
| 448 | if ( 0 == pointer ) |
---|
| 449 | { |
---|
| 450 | TICPPTHROW( "Node can't be inserted" ); |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | return NodeFactory( pointer ); |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | Node* Node::ReplaceChild( Node* replaceThis, Node& withThis ) |
---|
| 457 | { |
---|
| 458 | if ( withThis.Type() == TiXmlNode::DOCUMENT ) |
---|
| 459 | { |
---|
| 460 | TICPPTHROW( "Node is a Document and can't be inserted" ); |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | // Increment reference count when adding to the tree |
---|
| 464 | withThis.m_impRC->IncRef(); |
---|
| 465 | |
---|
| 466 | TiXmlNode* pointer = GetTiXmlPointer()->ReplaceChild( replaceThis->GetTiXmlPointer(), *withThis.GetTiXmlPointer() ); |
---|
| 467 | if ( 0 == pointer ) |
---|
| 468 | { |
---|
| 469 | TICPPTHROW( "Node can't be inserted" ); |
---|
| 470 | } |
---|
| 471 | |
---|
| 472 | return NodeFactory( pointer ); |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | void Node::RemoveChild( Node* removeThis ) |
---|
| 476 | { |
---|
| 477 | if ( !GetTiXmlPointer()->RemoveChild( removeThis->GetTiXmlPointer() ) ) |
---|
| 478 | { |
---|
| 479 | TICPPTHROW( "Node to remove (" << removeThis->Value() << ") is not a child of this Node (" << Value() << ")" ) |
---|
| 480 | } |
---|
| 481 | } |
---|
| 482 | |
---|
| 483 | Node* Node::PreviousSibling( bool throwIfNoSiblings ) const |
---|
| 484 | { |
---|
| 485 | return PreviousSibling( "", throwIfNoSiblings ); |
---|
| 486 | } |
---|
| 487 | |
---|
| 488 | Node* Node::PreviousSibling( const std::string& value, bool throwIfNoSiblings ) const |
---|
| 489 | { |
---|
| 490 | return PreviousSibling( value.c_str(), throwIfNoSiblings ); |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | Node* Node::PreviousSibling( const char* value, bool throwIfNoSiblings ) const |
---|
| 494 | { |
---|
| 495 | TiXmlNode* sibling; |
---|
| 496 | if ( 0 == strlen( value ) ) |
---|
| 497 | { |
---|
| 498 | sibling = GetTiXmlPointer()->PreviousSibling(); |
---|
| 499 | } |
---|
| 500 | else |
---|
| 501 | { |
---|
| 502 | sibling = GetTiXmlPointer()->PreviousSibling( value ); |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | if ( ( 0 == sibling ) && throwIfNoSiblings ) |
---|
| 506 | { |
---|
| 507 | TICPPTHROW( "No Siblings found with value, '" << value << "', Prior to this Node (" << Value() << ")" ) |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | return NodeFactory( sibling, false ); |
---|
| 511 | } |
---|
| 512 | |
---|
| 513 | Node* Node::NextSibling( bool throwIfNoSiblings ) const |
---|
| 514 | { |
---|
| 515 | return NextSibling( "", throwIfNoSiblings ); |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | Node* Node::NextSibling( const std::string& value, bool throwIfNoSiblings ) const |
---|
| 519 | { |
---|
| 520 | return NextSibling( value.c_str(), throwIfNoSiblings ); |
---|
| 521 | } |
---|
| 522 | |
---|
| 523 | Node* Node::NextSibling( const char* value, bool throwIfNoSiblings ) const |
---|
| 524 | { |
---|
| 525 | TiXmlNode* sibling; |
---|
| 526 | if ( 0 == strlen( value ) ) |
---|
| 527 | { |
---|
| 528 | sibling = GetTiXmlPointer()->NextSibling(); |
---|
| 529 | } |
---|
| 530 | else |
---|
| 531 | { |
---|
| 532 | sibling = GetTiXmlPointer()->NextSibling( value ); |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | if ( ( 0 == sibling ) && throwIfNoSiblings ) |
---|
| 536 | { |
---|
| 537 | TICPPTHROW( "No Siblings found with value, '" << value << "', After this Node (" << Value() << ")" ) |
---|
| 538 | } |
---|
| 539 | |
---|
| 540 | return NodeFactory( sibling, false ); |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | Element* Node::NextSiblingElement( bool throwIfNoSiblings ) const |
---|
| 544 | { |
---|
| 545 | return NextSiblingElement( "", throwIfNoSiblings ); |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | Element* Node::NextSiblingElement( const std::string& value, bool throwIfNoSiblings ) const |
---|
| 549 | { |
---|
| 550 | return NextSiblingElement( value.c_str(), throwIfNoSiblings ); |
---|
| 551 | } |
---|
| 552 | |
---|
| 553 | Element* Node::NextSiblingElement( const char* value, bool throwIfNoSiblings ) const |
---|
| 554 | { |
---|
| 555 | TiXmlElement* sibling; |
---|
| 556 | if ( 0 == strlen( value ) ) |
---|
| 557 | { |
---|
| 558 | sibling = GetTiXmlPointer()->NextSiblingElement(); |
---|
| 559 | } |
---|
| 560 | else |
---|
| 561 | { |
---|
| 562 | sibling = GetTiXmlPointer()->NextSiblingElement( value ); |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | if ( 0 == sibling ) |
---|
| 566 | { |
---|
| 567 | if ( throwIfNoSiblings ) |
---|
| 568 | { |
---|
| 569 | TICPPTHROW( "No Element Siblings found with value, '" << value << "', After this Node (" << Value() << ")" ) |
---|
| 570 | } |
---|
| 571 | else |
---|
| 572 | { |
---|
| 573 | return 0; |
---|
| 574 | } |
---|
| 575 | } |
---|
| 576 | |
---|
| 577 | Element* temp = new Element( sibling ); |
---|
| 578 | m_spawnedWrappers.push_back( temp ); |
---|
| 579 | |
---|
| 580 | return temp; |
---|
| 581 | } |
---|
| 582 | |
---|
| 583 | Element* Node::FirstChildElement( bool throwIfNoChildren ) const |
---|
| 584 | { |
---|
| 585 | return FirstChildElement( "", throwIfNoChildren ); |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | Element* Node::FirstChildElement( const std::string& value, bool throwIfNoChildren ) const |
---|
| 589 | { |
---|
| 590 | return FirstChildElement( value.c_str(), throwIfNoChildren ); |
---|
| 591 | } |
---|
| 592 | |
---|
| 593 | Element* Node::FirstChildElement( const char* value, bool throwIfNoChildren ) const |
---|
| 594 | { |
---|
| 595 | TiXmlElement* element; |
---|
| 596 | if ( 0 == strlen( value ) ) |
---|
| 597 | { |
---|
| 598 | element = GetTiXmlPointer()->FirstChildElement(); |
---|
| 599 | } |
---|
| 600 | else |
---|
| 601 | { |
---|
| 602 | element = GetTiXmlPointer()->FirstChildElement( value ); |
---|
| 603 | } |
---|
| 604 | |
---|
| 605 | if ( 0 == element ) |
---|
| 606 | { |
---|
| 607 | if( throwIfNoChildren ) |
---|
| 608 | { |
---|
| 609 | TICPPTHROW( "Element (" << Value() << ") does NOT contain a child with the value of '" << value << "'" ) |
---|
| 610 | } |
---|
| 611 | else |
---|
| 612 | { |
---|
| 613 | return 0; |
---|
| 614 | } |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | Element* temp = new Element( element ); |
---|
| 618 | m_spawnedWrappers.push_back( temp ); |
---|
| 619 | |
---|
| 620 | return temp; |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | int Node::Type() const |
---|
| 624 | { |
---|
| 625 | return GetTiXmlPointer()->Type(); |
---|
| 626 | } |
---|
| 627 | |
---|
| 628 | Document* Node::GetDocument( bool throwIfNoDocument ) const |
---|
| 629 | { |
---|
| 630 | TiXmlDocument* doc = GetTiXmlPointer()->GetDocument(); |
---|
| 631 | if ( 0 == doc ) |
---|
| 632 | { |
---|
| 633 | if( throwIfNoDocument ) |
---|
| 634 | { |
---|
| 635 | TICPPTHROW( "This node (" << Value() << ") is not linked under a document" ) |
---|
| 636 | } |
---|
| 637 | else |
---|
| 638 | { |
---|
| 639 | return 0; |
---|
| 640 | } |
---|
| 641 | } |
---|
| 642 | Document* temp = new Document( doc ); |
---|
| 643 | m_spawnedWrappers.push_back( temp ); |
---|
| 644 | |
---|
| 645 | return temp; |
---|
| 646 | } |
---|
| 647 | |
---|
| 648 | bool Node::NoChildren() const |
---|
| 649 | { |
---|
| 650 | return GetTiXmlPointer()->NoChildren(); |
---|
| 651 | } |
---|
| 652 | |
---|
| 653 | Document* Node::ToDocument() const |
---|
| 654 | { |
---|
| 655 | TiXmlDocument* doc = GetTiXmlPointer()->ToDocument(); |
---|
| 656 | if ( 0 == doc ) |
---|
| 657 | { |
---|
| 658 | TICPPTHROW( "This node (" << Value() << ") is not a Document" ) |
---|
| 659 | } |
---|
| 660 | Document* temp = new Document( doc ); |
---|
| 661 | m_spawnedWrappers.push_back( temp ); |
---|
| 662 | |
---|
| 663 | return temp; |
---|
| 664 | } |
---|
| 665 | |
---|
| 666 | Element* Node::ToElement() const |
---|
| 667 | { |
---|
| 668 | TiXmlElement* doc = GetTiXmlPointer()->ToElement(); |
---|
| 669 | if ( 0 == doc ) |
---|
| 670 | { |
---|
| 671 | TICPPTHROW( "This node (" << Value() << ") is not a Element" ) |
---|
| 672 | } |
---|
| 673 | Element* temp = new Element( doc ); |
---|
| 674 | m_spawnedWrappers.push_back( temp ); |
---|
| 675 | |
---|
| 676 | return temp; |
---|
| 677 | } |
---|
| 678 | |
---|
| 679 | Comment* Node::ToComment() const |
---|
| 680 | { |
---|
| 681 | TiXmlComment* doc = GetTiXmlPointer()->ToComment(); |
---|
| 682 | if ( 0 == doc ) |
---|
| 683 | { |
---|
| 684 | TICPPTHROW( "This node (" << Value() << ") is not a Comment" ) |
---|
| 685 | } |
---|
| 686 | Comment* temp = new Comment( doc ); |
---|
| 687 | m_spawnedWrappers.push_back( temp ); |
---|
| 688 | |
---|
| 689 | return temp; |
---|
| 690 | } |
---|
| 691 | |
---|
| 692 | Text* Node::ToText() const |
---|
| 693 | { |
---|
| 694 | TiXmlText* doc = GetTiXmlPointer()->ToText(); |
---|
| 695 | if ( 0 == doc ) |
---|
| 696 | { |
---|
| 697 | TICPPTHROW( "This node (" << Value() << ") is not a Text" ) |
---|
| 698 | } |
---|
| 699 | Text* temp = new Text( doc ); |
---|
| 700 | m_spawnedWrappers.push_back( temp ); |
---|
| 701 | |
---|
| 702 | return temp; |
---|
| 703 | } |
---|
| 704 | |
---|
| 705 | Declaration* Node::ToDeclaration() const |
---|
| 706 | { |
---|
| 707 | TiXmlDeclaration* doc = GetTiXmlPointer()->ToDeclaration(); |
---|
| 708 | if ( 0 == doc ) |
---|
| 709 | { |
---|
| 710 | TICPPTHROW( "This node (" << Value() << ") is not a Declaration" ) |
---|
| 711 | } |
---|
| 712 | Declaration* temp = new Declaration( doc ); |
---|
| 713 | m_spawnedWrappers.push_back( temp ); |
---|
| 714 | |
---|
| 715 | return temp; |
---|
| 716 | } |
---|
| 717 | |
---|
| 718 | StylesheetReference* Node::ToStylesheetReference() const |
---|
| 719 | { |
---|
| 720 | TiXmlStylesheetReference* doc = GetTiXmlPointer()->ToStylesheetReference(); |
---|
| 721 | if ( 0 == doc ) |
---|
| 722 | { |
---|
| 723 | TICPPTHROW( "This node (" << Value() << ") is not a StylesheetReference" ) |
---|
| 724 | } |
---|
| 725 | StylesheetReference* temp = new StylesheetReference( doc ); |
---|
| 726 | m_spawnedWrappers.push_back( temp ); |
---|
| 727 | |
---|
| 728 | return temp; |
---|
| 729 | } |
---|
| 730 | |
---|
| 731 | std::auto_ptr< Node > Node::Clone() const |
---|
| 732 | { |
---|
| 733 | TiXmlNode* node = GetTiXmlPointer()->Clone(); |
---|
| 734 | if ( 0 == node ) |
---|
| 735 | { |
---|
| 736 | TICPPTHROW( "Node could not be cloned" ); |
---|
| 737 | } |
---|
| 738 | std::auto_ptr< Node > temp( NodeFactory( node, false, false ) ); |
---|
| 739 | |
---|
| 740 | // Take ownership of the memory from TiXml |
---|
| 741 | temp->m_impRC->InitRef(); |
---|
| 742 | |
---|
| 743 | return temp; |
---|
| 744 | } |
---|
| 745 | |
---|
| 746 | bool Node::Accept( TiXmlVisitor* visitor ) const |
---|
| 747 | { |
---|
| 748 | return GetTiXmlPointer()->Accept( visitor ); |
---|
| 749 | } |
---|
| 750 | |
---|
| 751 | //***************************************************************************** |
---|
| 752 | |
---|
| 753 | Comment::Comment() |
---|
| 754 | : NodeImp< TiXmlComment >( new TiXmlComment() ) |
---|
| 755 | { |
---|
| 756 | m_impRC->InitRef(); |
---|
| 757 | } |
---|
| 758 | |
---|
| 759 | Comment::Comment( TiXmlComment* comment ) |
---|
| 760 | : NodeImp< TiXmlComment >( comment ) |
---|
| 761 | { |
---|
| 762 | } |
---|
| 763 | |
---|
| 764 | Comment::Comment( const std::string& comment ) |
---|
| 765 | : NodeImp< TiXmlComment >( new TiXmlComment() ) |
---|
| 766 | { |
---|
| 767 | m_impRC->InitRef(); |
---|
| 768 | m_tiXmlPointer->SetValue( comment ); |
---|
| 769 | } |
---|
| 770 | |
---|
| 771 | //***************************************************************************** |
---|
| 772 | |
---|
| 773 | Text::Text() |
---|
| 774 | : NodeImp< TiXmlText >( new TiXmlText("") ) |
---|
| 775 | { |
---|
| 776 | m_impRC->InitRef(); |
---|
| 777 | } |
---|
| 778 | |
---|
| 779 | |
---|
| 780 | Text::Text( const std::string& value ) |
---|
| 781 | : NodeImp< TiXmlText >( new TiXmlText( value ) ) |
---|
| 782 | { |
---|
| 783 | m_impRC->InitRef(); |
---|
| 784 | } |
---|
| 785 | |
---|
| 786 | Text::Text( TiXmlText* text ) |
---|
| 787 | : NodeImp< TiXmlText >( text ) |
---|
| 788 | { |
---|
| 789 | } |
---|
| 790 | |
---|
| 791 | |
---|
| 792 | //***************************************************************************** |
---|
| 793 | |
---|
| 794 | Document::Document() |
---|
| 795 | : NodeImp< TiXmlDocument >( new TiXmlDocument() ) |
---|
| 796 | { |
---|
| 797 | m_impRC->InitRef(); |
---|
| 798 | } |
---|
| 799 | |
---|
| 800 | Document::Document( TiXmlDocument* document ) |
---|
| 801 | : NodeImp< TiXmlDocument >( document ) |
---|
| 802 | { |
---|
| 803 | } |
---|
| 804 | |
---|
| 805 | Document::Document( const char* documentName ) |
---|
| 806 | : NodeImp< TiXmlDocument >( new TiXmlDocument( documentName ) ) |
---|
| 807 | { |
---|
| 808 | m_impRC->InitRef(); |
---|
| 809 | } |
---|
| 810 | |
---|
| 811 | Document::Document( const std::string& documentName ) |
---|
| 812 | : NodeImp< TiXmlDocument >( new TiXmlDocument( documentName ) ) |
---|
| 813 | { |
---|
| 814 | m_impRC->InitRef(); |
---|
| 815 | } |
---|
| 816 | |
---|
| 817 | void Document::LoadFile( TiXmlEncoding encoding ) |
---|
| 818 | { |
---|
| 819 | if ( !m_tiXmlPointer->LoadFile( encoding ) ) |
---|
| 820 | { |
---|
| 821 | TICPPTHROW( "Couldn't load " << m_tiXmlPointer->Value() ); |
---|
| 822 | } |
---|
| 823 | } |
---|
| 824 | |
---|
| 825 | void Document::SaveFile( void ) const |
---|
| 826 | { |
---|
| 827 | if ( !m_tiXmlPointer->SaveFile() ) |
---|
| 828 | { |
---|
| 829 | TICPPTHROW( "Couldn't save " << m_tiXmlPointer->Value() ); |
---|
| 830 | } |
---|
| 831 | } |
---|
| 832 | |
---|
| 833 | void Document::LoadFile( const std::string& filename, TiXmlEncoding encoding ) |
---|
| 834 | { |
---|
| 835 | if ( !m_tiXmlPointer->LoadFile( filename.c_str(), encoding ) ) |
---|
| 836 | { |
---|
| 837 | TICPPTHROW( "Couldn't load " << filename ); |
---|
| 838 | } |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | void Document::LoadFile( const char* filename, TiXmlEncoding encoding ) |
---|
| 842 | { |
---|
| 843 | if ( !m_tiXmlPointer->LoadFile( filename, encoding ) ) |
---|
| 844 | { |
---|
| 845 | TICPPTHROW( "Couldn't load " << filename ); |
---|
| 846 | } |
---|
| 847 | } |
---|
| 848 | |
---|
| 849 | void Document::SaveFile( const std::string& filename ) const |
---|
| 850 | { |
---|
| 851 | if ( !m_tiXmlPointer->SaveFile( filename.c_str() ) ) |
---|
| 852 | { |
---|
| 853 | TICPPTHROW( "Couldn't save " << filename ); |
---|
| 854 | } |
---|
| 855 | } |
---|
| 856 | |
---|
| 857 | void Document::Parse( const std::string& xml, bool throwIfParseError, TiXmlEncoding encoding ) |
---|
| 858 | { |
---|
| 859 | m_tiXmlPointer->Parse( xml.c_str(), 0, encoding ); |
---|
| 860 | if( throwIfParseError && m_tiXmlPointer->Error() ) |
---|
| 861 | { |
---|
[1625] | 862 | TICPPTHROW( "Error parsing xml: " << m_tiXmlPointer->ErrorDesc() |
---|
| 863 | << " In row " << m_tiXmlPointer->ErrorRow() << ", column " << m_tiXmlPointer->ErrorCol() << "."); |
---|
[739] | 864 | } |
---|
| 865 | } |
---|
| 866 | |
---|
| 867 | //***************************************************************************** |
---|
| 868 | |
---|
| 869 | Element::Element() |
---|
| 870 | : NodeImp< TiXmlElement >( new TiXmlElement( "DefaultValueCausedByCreatingAnElementWithNoParameters" ) ) |
---|
| 871 | { |
---|
| 872 | m_impRC->InitRef(); |
---|
| 873 | } |
---|
| 874 | |
---|
| 875 | Element::Element( const std::string& value ) |
---|
| 876 | : NodeImp< TiXmlElement >( new TiXmlElement( value ) ) |
---|
| 877 | { |
---|
| 878 | m_impRC->InitRef(); |
---|
| 879 | } |
---|
| 880 | |
---|
| 881 | Element::Element( const char* value ) |
---|
| 882 | : NodeImp< TiXmlElement >( new TiXmlElement( value ) ) |
---|
| 883 | { |
---|
| 884 | m_impRC->InitRef(); |
---|
| 885 | } |
---|
| 886 | |
---|
| 887 | Element::Element( TiXmlElement* element ) |
---|
| 888 | : NodeImp< TiXmlElement >( element ) |
---|
| 889 | { |
---|
| 890 | } |
---|
| 891 | |
---|
| 892 | Attribute* Element::FirstAttribute( bool throwIfNoAttributes ) const |
---|
| 893 | { |
---|
| 894 | ValidatePointer(); |
---|
| 895 | TiXmlAttribute* attribute = m_tiXmlPointer->FirstAttribute(); |
---|
| 896 | if ( ( 0 == attribute ) && throwIfNoAttributes ) |
---|
| 897 | { |
---|
| 898 | TICPPTHROW( "This Element (" << Value() << ") has no attributes" ) |
---|
| 899 | } |
---|
| 900 | |
---|
| 901 | if ( 0 == attribute ) |
---|
| 902 | { |
---|
| 903 | if( throwIfNoAttributes ) |
---|
| 904 | { |
---|
| 905 | TICPPTHROW( "Element (" << Value() << ") has no attributes" ) |
---|
| 906 | } |
---|
| 907 | else |
---|
| 908 | { |
---|
| 909 | return 0; |
---|
| 910 | } |
---|
| 911 | } |
---|
| 912 | |
---|
| 913 | Attribute* temp = new Attribute( attribute ); |
---|
| 914 | m_spawnedWrappers.push_back( temp ); |
---|
| 915 | |
---|
| 916 | return temp; |
---|
| 917 | } |
---|
| 918 | |
---|
| 919 | Attribute* Element::LastAttribute( bool throwIfNoAttributes ) const |
---|
| 920 | { |
---|
| 921 | ValidatePointer(); |
---|
| 922 | TiXmlAttribute* attribute = m_tiXmlPointer->LastAttribute(); |
---|
| 923 | if ( ( 0 == attribute ) && throwIfNoAttributes ) |
---|
| 924 | { |
---|
| 925 | TICPPTHROW( "This Element (" << Value() << ") has no attributes" ) |
---|
| 926 | } |
---|
| 927 | |
---|
| 928 | if ( 0 == attribute ) |
---|
| 929 | { |
---|
| 930 | if( throwIfNoAttributes ) |
---|
| 931 | { |
---|
| 932 | TICPPTHROW( "Element (" << Value() << ") has no attributes" ) |
---|
| 933 | } |
---|
| 934 | else |
---|
| 935 | { |
---|
| 936 | return 0; |
---|
| 937 | } |
---|
| 938 | } |
---|
| 939 | |
---|
| 940 | Attribute* temp = new Attribute( attribute ); |
---|
| 941 | m_spawnedWrappers.push_back( temp ); |
---|
| 942 | |
---|
| 943 | return temp; |
---|
| 944 | } |
---|
| 945 | |
---|
| 946 | std::string Element::GetAttributeOrDefault( const std::string& name, const std::string& defaultValue ) const |
---|
| 947 | { |
---|
| 948 | std::string value; |
---|
| 949 | if ( !GetAttributeImp( name, &value ) ) |
---|
| 950 | { |
---|
| 951 | return defaultValue; |
---|
| 952 | } |
---|
| 953 | return value; |
---|
| 954 | } |
---|
| 955 | |
---|
| 956 | std::string Element::GetAttribute( const std::string& name ) const |
---|
| 957 | { |
---|
| 958 | return GetAttributeOrDefault( name, std::string() ); |
---|
| 959 | } |
---|
| 960 | |
---|
| 961 | bool Element::GetAttributeImp( const std::string& name, std::string* value ) const |
---|
| 962 | { |
---|
| 963 | ValidatePointer(); |
---|
| 964 | |
---|
| 965 | // Get value from TinyXML, if the attribute exists |
---|
| 966 | const char* retVal = m_tiXmlPointer->Attribute( name.c_str() ); |
---|
| 967 | |
---|
| 968 | // TinyXML returns NULL if the attribute doesn't exist |
---|
| 969 | if ( 0 == retVal ) |
---|
| 970 | { |
---|
| 971 | return false; |
---|
| 972 | } |
---|
| 973 | else |
---|
| 974 | { |
---|
| 975 | *value = retVal; |
---|
| 976 | return true; |
---|
| 977 | } |
---|
| 978 | } |
---|
| 979 | |
---|
| 980 | bool Element::GetTextImp( std::string* value ) const |
---|
| 981 | { |
---|
| 982 | ValidatePointer(); |
---|
| 983 | |
---|
| 984 | // Get value from TinyXML, if the attribute exists |
---|
| 985 | const char* retVal = m_tiXmlPointer->GetText(); |
---|
| 986 | |
---|
| 987 | // TinyXML returns NULL if the attribute doesn't exist |
---|
| 988 | if ( 0 == retVal ) |
---|
| 989 | { |
---|
| 990 | return false; |
---|
| 991 | } |
---|
| 992 | else |
---|
| 993 | { |
---|
| 994 | *value = retVal; |
---|
| 995 | return true; |
---|
| 996 | } |
---|
| 997 | } |
---|
| 998 | |
---|
| 999 | //***************************************************************************** |
---|
| 1000 | |
---|
| 1001 | Declaration::Declaration() |
---|
| 1002 | : NodeImp< TiXmlDeclaration >( new TiXmlDeclaration() ) |
---|
| 1003 | { |
---|
| 1004 | m_impRC->InitRef(); |
---|
| 1005 | } |
---|
| 1006 | |
---|
| 1007 | Declaration::Declaration( TiXmlDeclaration* declaration ) |
---|
| 1008 | : NodeImp< TiXmlDeclaration >( declaration ) |
---|
| 1009 | { |
---|
| 1010 | } |
---|
| 1011 | |
---|
| 1012 | Declaration::Declaration( const std::string& version, const std::string& encoding, const std::string& standalone ) |
---|
| 1013 | : NodeImp< TiXmlDeclaration >( new TiXmlDeclaration( version, encoding, standalone ) ) |
---|
| 1014 | { |
---|
| 1015 | m_impRC->InitRef(); |
---|
| 1016 | } |
---|
| 1017 | |
---|
| 1018 | std::string Declaration::Version() const |
---|
| 1019 | { |
---|
| 1020 | return m_tiXmlPointer->Version(); |
---|
| 1021 | } |
---|
| 1022 | |
---|
| 1023 | std::string Declaration::Encoding() const |
---|
| 1024 | { |
---|
| 1025 | return m_tiXmlPointer->Encoding(); |
---|
| 1026 | } |
---|
| 1027 | |
---|
| 1028 | std::string Declaration::Standalone() const |
---|
| 1029 | { |
---|
| 1030 | return m_tiXmlPointer->Standalone(); |
---|
| 1031 | } |
---|
| 1032 | |
---|
| 1033 | //***************************************************************************** |
---|
| 1034 | |
---|
| 1035 | StylesheetReference::StylesheetReference() |
---|
| 1036 | : NodeImp< TiXmlStylesheetReference >( new TiXmlStylesheetReference() ) |
---|
| 1037 | { |
---|
| 1038 | m_impRC->InitRef(); |
---|
| 1039 | } |
---|
| 1040 | |
---|
| 1041 | StylesheetReference::StylesheetReference( TiXmlStylesheetReference* stylesheetReference ) |
---|
| 1042 | : NodeImp< TiXmlStylesheetReference >( stylesheetReference ) |
---|
| 1043 | { |
---|
| 1044 | } |
---|
| 1045 | |
---|
| 1046 | StylesheetReference::StylesheetReference( const std::string& type, const std::string& href ) |
---|
| 1047 | : NodeImp< TiXmlStylesheetReference >( new TiXmlStylesheetReference( type, href ) ) |
---|
| 1048 | { |
---|
| 1049 | m_impRC->InitRef(); |
---|
| 1050 | } |
---|
| 1051 | |
---|
| 1052 | std::string StylesheetReference::Type() const |
---|
| 1053 | { |
---|
| 1054 | return m_tiXmlPointer->Type(); |
---|
| 1055 | } |
---|
| 1056 | |
---|
| 1057 | std::string StylesheetReference::Href() const |
---|
| 1058 | { |
---|
| 1059 | return m_tiXmlPointer->Href(); |
---|
| 1060 | } |
---|
| 1061 | |
---|
| 1062 | //***************************************************************************** |
---|
| 1063 | |
---|
| 1064 | Exception::Exception(const std::string &details) |
---|
| 1065 | : |
---|
| 1066 | m_details( details ) |
---|
| 1067 | { |
---|
| 1068 | |
---|
| 1069 | } |
---|
| 1070 | |
---|
| 1071 | Exception::~Exception() throw() |
---|
| 1072 | { |
---|
| 1073 | } |
---|
| 1074 | |
---|
| 1075 | const char* Exception::what() const throw() |
---|
| 1076 | { |
---|
| 1077 | return m_details.c_str(); |
---|
| 1078 | } |
---|
| 1079 | |
---|
| 1080 | //***************************************************************************** |
---|
| 1081 | |
---|
| 1082 | TiCppRC::TiCppRC() |
---|
| 1083 | { |
---|
| 1084 | // Spawn reference counter for this object |
---|
| 1085 | m_tiRC = new TiCppRCImp( this ); |
---|
| 1086 | } |
---|
| 1087 | |
---|
| 1088 | TiCppRC::~TiCppRC() |
---|
| 1089 | { |
---|
| 1090 | // Set pointer held by reference counter to NULL |
---|
| 1091 | this->m_tiRC->Nullify(); |
---|
| 1092 | |
---|
| 1093 | // Decrement reference - so reference counter will delete itself if necessary |
---|
| 1094 | this->m_tiRC->DecRef(); |
---|
| 1095 | } |
---|
| 1096 | |
---|
| 1097 | //***************************************************************************** |
---|
| 1098 | |
---|
| 1099 | TiCppRCImp::TiCppRCImp( TiCppRC* tiCppRC ) |
---|
| 1100 | : m_count( 1 ), m_tiCppRC ( tiCppRC ) |
---|
| 1101 | { |
---|
| 1102 | } |
---|
| 1103 | |
---|
| 1104 | void TiCppRCImp::IncRef() |
---|
| 1105 | { |
---|
| 1106 | m_count++; |
---|
| 1107 | } |
---|
| 1108 | |
---|
| 1109 | void TiCppRCImp::DecRef() |
---|
| 1110 | { |
---|
| 1111 | m_count--; |
---|
| 1112 | if ( 0 == m_count ) |
---|
| 1113 | { |
---|
| 1114 | delete m_tiCppRC; |
---|
| 1115 | delete this; |
---|
| 1116 | } |
---|
| 1117 | } |
---|
| 1118 | |
---|
| 1119 | void TiCppRCImp::InitRef() |
---|
| 1120 | { |
---|
| 1121 | m_count = 1; |
---|
| 1122 | } |
---|
| 1123 | |
---|
| 1124 | void TiCppRCImp::Nullify() |
---|
| 1125 | { |
---|
| 1126 | m_tiCppRC = 0; |
---|
| 1127 | } |
---|
| 1128 | |
---|
| 1129 | TiCppRC* TiCppRCImp::Get() |
---|
| 1130 | { |
---|
| 1131 | return m_tiCppRC; |
---|
| 1132 | } |
---|
| 1133 | |
---|
| 1134 | bool TiCppRCImp::IsNull() |
---|
| 1135 | { |
---|
| 1136 | return 0 == m_tiCppRC; |
---|
| 1137 | } |
---|
| 1138 | |
---|
| 1139 | #endif // TIXML_USE_TICPP |
---|