Changeset 7221 in orxonox.OLD for trunk/src/lib/parser/tinyxml
- Timestamp:
- Mar 15, 2006, 3:10:45 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/parser/tinyxml/tinyxml.h
r5819 r7221 26 26 #ifndef TINYXML_INCLUDED 27 27 #define TINYXML_INCLUDED 28 29 #define TIXML_USE_STL 28 30 29 31 #ifdef _MSC_VER … … 81 83 #define TIXML_SNSCANF snscanf 82 84 #endif 83 #endif 85 #endif 84 86 85 87 class TiXmlDocument; … … 96 98 const int TIXML_PATCH_VERSION = 2; 97 99 98 /* Internal structure for tracking location of items 100 /* Internal structure for tracking location of items 99 101 in the XML file. 100 102 */ … … 110 112 111 113 // Only used by Attribute::Query functions 112 enum 113 { 114 enum 115 { 114 116 TIXML_SUCCESS, 115 117 TIXML_NO_ATTRIBUTE, … … 162 164 /** All TinyXml classes can print themselves to a filestream. 163 165 This is a formatted print, and will insert tabs and newlines. 164 166 165 167 (For an unformatted stream, use the << operator.) 166 168 */ … … 206 208 static const int utf8ByteTable[256]; 207 209 208 virtual const char* Parse( const char* p, 209 TiXmlParsingData* data, 210 virtual const char* Parse( const char* p, 211 TiXmlParsingData* data, 210 212 TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; 211 213 … … 245 247 246 248 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding ); 247 inline static bool IsWhiteSpace( char c ) 248 { 249 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); 249 inline static bool IsWhiteSpace( char c ) 250 { 251 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); 250 252 } 251 253 … … 334 336 /// Field containing a generic user pointer 335 337 void* userData; 336 338 337 339 // None of these methods are reliable for any language except English. 338 340 // Good for approximation, not great for accuracy. … … 386 388 387 389 public: 388 #ifdef TIXML_USE_STL 390 #ifdef TIXML_USE_STL 389 391 390 392 /** An input stream operator, for every class. Tolerant of newlines and … … 400 402 a node to a stream is very well defined. You'll get a nice stream 401 403 of output, without any extra whitespace or newlines. 402 404 403 405 But reading is not as well defined. (As it always is.) If you create 404 406 a TiXmlElement (for example) and read that from an input stream, … … 408 410 A TiXmlDocument will read nodes until it reads a root element, and 409 411 all the children of that root element. 410 */ 412 */ 411 413 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base); 412 414 … … 470 472 #ifdef TIXML_USE_STL 471 473 /// STL std::string form. 472 void SetValue( const std::string& _value ) 473 { 474 void SetValue( const std::string& _value ) 475 { 474 476 StringToBuffer buf( _value ); 475 SetValue( buf.buffer ? buf.buffer : "" ); 476 } 477 SetValue( buf.buffer ? buf.buffer : "" ); 478 } 477 479 #endif 478 480 … … 492 494 TiXmlNode* LastChild() { return lastChild; } 493 495 const TiXmlNode* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children. 494 TiXmlNode* LastChild( const char * value ); 496 TiXmlNode* LastChild( const char * value ); 495 497 496 498 #ifdef TIXML_USE_STL … … 649 651 650 652 /** Create an exact duplicate of this node and return it. The memory must be deleted 651 by the caller. 653 by the caller. 652 654 */ 653 655 virtual TiXmlNode* Clone() const = 0; … … 731 733 /** QueryIntValue examines the value string. It is an alternative to the 732 734 IntValue() method with richer error checking. 733 If the value is an integer, it is stored in 'value' and 735 If the value is an integer, it is stored in 'value' and 734 736 the call returns TIXML_SUCCESS. If it is not 735 737 an integer, it returns TIXML_WRONG_TYPE. … … 750 752 #ifdef TIXML_USE_STL 751 753 /// STL std::string form. 752 void SetName( const std::string& _name ) 753 { 754 void SetName( const std::string& _name ) 755 { 754 756 StringToBuffer buf( _name ); 755 SetName ( buf.buffer ? buf.buffer : "error" ); 756 } 757 /// STL std::string form. 758 void SetValue( const std::string& _value ) 759 { 757 SetName ( buf.buffer ? buf.buffer : "error" ); 758 } 759 /// STL std::string form. 760 void SetValue( const std::string& _value ) 761 { 760 762 StringToBuffer buf( _value ); 761 SetValue( buf.buffer ? buf.buffer : "error" ); 763 SetValue( buf.buffer ? buf.buffer : "error" ); 762 764 } 763 765 #endif … … 801 803 /* A class used to manage a group of attributes. 802 804 It is only used internally, both by the ELEMENT and the DECLARATION. 803 805 804 806 The set can be changed transparent to the Element and Declaration 805 807 classes that use it, but NOT transparent to the Attribute … … 882 884 /** QueryIntAttribute examines the attribute - it is an alternative to the 883 885 Attribute() method with richer error checking. 884 If the attribute is an integer, it is stored in 'value' and 886 If the attribute is an integer, it is stored in 'value' and 885 887 the call returns TIXML_SUCCESS. If it is not 886 888 an integer, it returns TIXML_WRONG_TYPE. If the attribute 887 889 does not exist, then TIXML_NO_ATTRIBUTE is returned. 888 */ 890 */ 889 891 int QueryIntAttribute( const char* name, int* _value ) const; 890 892 /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). … … 913 915 914 916 /// STL std::string form. 915 void SetAttribute( const std::string& name, const std::string& _value ) 916 { 917 void SetAttribute( const std::string& name, const std::string& _value ) 918 { 917 919 StringToBuffer n( name ); 918 920 StringToBuffer v( _value ); 919 921 if ( n.buffer && v.buffer ) 920 SetAttribute (n.buffer, v.buffer ); 921 } 922 SetAttribute (n.buffer, v.buffer ); 923 } 922 924 ///< STL std::string form. 923 void SetAttribute( const std::string& name, int _value ) 924 { 925 void SetAttribute( const std::string& name, int _value ) 926 { 925 927 StringToBuffer n( name ); 926 928 if ( n.buffer ) 927 SetAttribute (n.buffer, _value); 928 } 929 SetAttribute (n.buffer, _value); 930 } 929 931 #endif 930 932 … … 954 956 and concise, GetText() is limited compared to getting the TiXmlText child 955 957 and accessing it directly. 956 958 957 959 If the first child of 'this' is a TiXmlText, the GetText() 958 960 returns the character string of the Text node, else null is returned. … … 964 966 @endverbatim 965 967 966 'str' will be a pointer to "This is text". 967 968 'str' will be a pointer to "This is text". 969 968 970 Note that this function can be misleading. If the element foo was created from 969 971 this XML: 970 972 @verbatim 971 <foo><b>This is text</b></foo> 973 <foo><b>This is text</b></foo> 972 974 @endverbatim 973 975 … … 975 977 another element. From this XML: 976 978 @verbatim 977 <foo>This is <b>text</b></foo> 979 <foo>This is <b>text</b></foo> 978 980 @endverbatim 979 981 GetText() will return "This is ". 980 982 981 WARNING: GetText() accesses a child node - don't become confused with the 982 similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are 983 WARNING: GetText() accesses a child node - don't become confused with the 984 similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are 983 985 safe type casts on the referenced node. 984 986 */ … … 1054 1056 1055 1057 1056 /** XML text. A text node can have 2 ways to output the next. "normal" output 1058 /** XML text. A text node can have 2 ways to output the next. "normal" output 1057 1059 and CDATA. It will default to the mode it was parsed from the XML file and 1058 you generally want to leave it alone, but you can change the output mode with 1060 you generally want to leave it alone, but you can change the output mode with 1059 1061 SetCDATA() and query it with CDATA(). 1060 1062 */ … … 1063 1065 friend class TiXmlElement; 1064 1066 public: 1065 /** Constructor for text element. By default, it is treated as 1067 /** Constructor for text element. By default, it is treated as 1066 1068 normal, encoded text. If you want it be output as a CDATA text 1067 1069 element, set the parameter _cdata to 'true' … … 1279 1281 - The ErrorDesc() method will return the name of the error. (very useful) 1280 1282 - The ErrorRow() and ErrorCol() will return the location of the error (if known) 1281 */ 1283 */ 1282 1284 bool Error() const { return error; } 1283 1285 … … 1290 1292 int ErrorId() const { return errorId; } 1291 1293 1292 /** Returns the location (if known) of the error. The first column is column 1, 1294 /** Returns the location (if known) of the error. The first column is column 1, 1293 1295 and the first row is row 1. A value of 0 means the row and column wasn't applicable 1294 1296 (memory errors, for example, have no row/column) or the parser lost the error. (An … … 1303 1305 to report the correct values for row and column. It does not change the output 1304 1306 or input in any way. 1305 1307 1306 1308 By calling this method, with a tab size 1307 1309 greater than 0, the row and column of each node and attribute is stored … … 1331 1333 state is automatically cleared if you Parse a new XML block. 1332 1334 */ 1333 void ClearError() { error = false; 1334 errorId = 0; 1335 errorDesc = ""; 1336 errorLocation.row = errorLocation.col = 0; 1337 //errorLocation.last = 0; 1335 void ClearError() { error = false; 1336 errorId = 0; 1337 errorDesc = ""; 1338 errorLocation.row = errorLocation.col = 0; 1339 //errorLocation.last = 0; 1338 1340 } 1339 1341 … … 1381 1383 @endverbatim 1382 1384 1383 Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very 1385 Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very 1384 1386 easy to write a *lot* of code that looks like: 1385 1387 … … 1401 1403 1402 1404 And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity 1403 of such code. A TiXmlHandle checks for null pointers so it is perfectly safe 1405 of such code. A TiXmlHandle checks for null pointers so it is perfectly safe 1404 1406 and correct to use: 1405 1407 … … 1422 1424 1423 1425 @verbatim 1424 int i=0; 1426 int i=0; 1425 1427 while ( true ) 1426 1428 { … … 1433 1435 @endverbatim 1434 1436 1435 It seems reasonable, but it is in fact two embedded while loops. The Child method is 1436 a linear walk to find the element, so this code would iterate much more than it needs 1437 It seems reasonable, but it is in fact two embedded while loops. The Child method is 1438 a linear walk to find the element, so this code would iterate much more than it needs 1437 1439 to. Instead, prefer: 1438 1440 … … 1464 1466 TiXmlHandle FirstChildElement( const char * value ) const; 1465 1467 1466 /** Return a handle to the "index" child with the given name. 1468 /** Return a handle to the "index" child with the given name. 1467 1469 The first child is 0, the second 1, etc. 1468 1470 */ 1469 1471 TiXmlHandle Child( const char* value, int index ) const; 1470 /** Return a handle to the "index" child. 1472 /** Return a handle to the "index" child. 1471 1473 The first child is 0, the second 1, etc. 1472 1474 */ 1473 1475 TiXmlHandle Child( int index ) const; 1474 /** Return a handle to the "index" child element with the given name. 1476 /** Return a handle to the "index" child element with the given name. 1475 1477 The first child element is 0, the second 1, etc. Note that only TiXmlElements 1476 1478 are indexed: other types are not counted. 1477 1479 */ 1478 1480 TiXmlHandle ChildElement( const char* value, int index ) const; 1479 /** Return a handle to the "index" child element. 1481 /** Return a handle to the "index" child element. 1480 1482 The first child element is 0, the second 1, etc. Note that only TiXmlElements 1481 1483 are indexed: other types are not counted. … … 1492 1494 1493 1495 /// Return the handle as a TiXmlNode. This may return null. 1494 TiXmlNode* Node() const { return node; } 1496 TiXmlNode* Node() const { return node; } 1495 1497 /// Return the handle as a TiXmlElement. This may return null. 1496 1498 TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
Note: See TracChangeset
for help on using the changeset viewer.