Changeset 2137
- Timestamp:
- Nov 4, 2008, 10:05:43 PM (16 years ago)
- Location:
- code/branches/buildsystem/src/tinyxml
- Files:
-
- 3 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/buildsystem/src/tinyxml/ticpp.cc
r1625 r2137 1 #define TIXML_USE_TICPP2 3 1 /* 4 2 http://code.google.com/p/ticpp/ … … 23 21 */ 24 22 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 Grieder30 */31 32 23 #ifdef TIXML_USE_TICPP 33 24 … … 164 155 165 156 Attribute* temp = new Attribute( attribute ); 166 m_spawnedWrappers.push_back( temp );157 attribute->m_spawnedWrappers.push_back( temp ); 167 158 168 159 return temp; … … 186 177 187 178 Attribute* temp = new Attribute( attribute ); 188 m_spawnedWrappers.push_back( temp );179 attribute->m_spawnedWrappers.push_back( temp ); 189 180 190 181 return temp; … … 262 253 if ( rememberSpawnedWrapper ) 263 254 { 264 m_spawnedWrappers.push_back( temp );255 tiXmlNode->m_spawnedWrappers.push_back( temp ); 265 256 } 266 257 return temp; … … 386 377 } 387 378 379 TiXmlNode* pointer = GetTiXmlPointer()->InsertEndChild( *addThis.GetTiXmlPointer() ); 380 if ( 0 == pointer ) 381 { 382 TICPPTHROW( "Node can't be inserted" ); 383 } 384 385 return NodeFactory( pointer ); 386 } 387 388 Node* Node::LinkEndChild( Node* childNode ) 389 { 390 if ( childNode->Type() == TiXmlNode::DOCUMENT ) 391 { 392 TICPPTHROW( "Node is a Document and can't be linked" ); 393 } 394 395 // Increment reference count when adding to the tree 396 childNode->m_impRC->IncRef(); 397 398 if ( 0 == GetTiXmlPointer()->LinkEndChild( childNode->GetTiXmlPointer() ) ) 399 { 400 TICPPTHROW( "Node can't be linked" ); 401 } 402 403 return childNode; 404 } 405 406 Node* Node::InsertBeforeChild( Node* beforeThis, Node& addThis ) 407 { 408 if ( addThis.Type() == TiXmlNode::DOCUMENT ) 409 { 410 TICPPTHROW( "Node is a Document and can't be inserted" ); 411 } 412 388 413 // Increment reference count when adding to the tree 389 414 addThis.m_impRC->IncRef(); 390 415 391 TiXmlNode* pointer = GetTiXmlPointer()->Insert EndChild(*addThis.GetTiXmlPointer() );416 TiXmlNode* pointer = GetTiXmlPointer()->InsertBeforeChild( beforeThis->GetTiXmlPointer(), *addThis.GetTiXmlPointer() ); 392 417 if ( 0 == pointer ) 393 418 { … … 398 423 } 399 424 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 ) 425 Node* Node::InsertAfterChild( Node* afterThis, Node& addThis ) 419 426 { 420 427 if ( addThis.Type() == TiXmlNode::DOCUMENT ) … … 426 433 addThis.m_impRC->IncRef(); 427 434 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 tree445 addThis.m_impRC->IncRef();446 447 435 TiXmlNode* pointer = GetTiXmlPointer()->InsertAfterChild( afterThis->GetTiXmlPointer(), *addThis.GetTiXmlPointer() ); 448 436 if ( 0 == pointer ) … … 576 564 577 565 Element* temp = new Element( sibling ); 578 m_spawnedWrappers.push_back( temp );566 sibling->m_spawnedWrappers.push_back( temp ); 579 567 580 568 return temp; … … 616 604 617 605 Element* temp = new Element( element ); 618 m_spawnedWrappers.push_back( temp );606 element->m_spawnedWrappers.push_back( temp ); 619 607 620 608 return temp; … … 641 629 } 642 630 Document* temp = new Document( doc ); 643 m_spawnedWrappers.push_back( temp );631 doc->m_spawnedWrappers.push_back( temp ); 644 632 645 633 return temp; … … 659 647 } 660 648 Document* temp = new Document( doc ); 661 m_spawnedWrappers.push_back( temp );649 doc->m_spawnedWrappers.push_back( temp ); 662 650 663 651 return temp; … … 672 660 } 673 661 Element* temp = new Element( doc ); 674 m_spawnedWrappers.push_back( temp );662 doc->m_spawnedWrappers.push_back( temp ); 675 663 676 664 return temp; … … 685 673 } 686 674 Comment* temp = new Comment( doc ); 687 m_spawnedWrappers.push_back( temp );675 doc->m_spawnedWrappers.push_back( temp ); 688 676 689 677 return temp; … … 698 686 } 699 687 Text* temp = new Text( doc ); 700 m_spawnedWrappers.push_back( temp );688 doc->m_spawnedWrappers.push_back( temp ); 701 689 702 690 return temp; … … 711 699 } 712 700 Declaration* temp = new Declaration( doc ); 713 m_spawnedWrappers.push_back( temp );701 doc->m_spawnedWrappers.push_back( temp ); 714 702 715 703 return temp; … … 724 712 } 725 713 StylesheetReference* temp = new StylesheetReference( doc ); 726 m_spawnedWrappers.push_back( temp );714 doc->m_spawnedWrappers.push_back( temp ); 727 715 728 716 return temp; … … 860 848 if( throwIfParseError && m_tiXmlPointer->Error() ) 861 849 { 862 TICPPTHROW( "Error parsing xml: " << m_tiXmlPointer->ErrorDesc() 863 << " In row " << m_tiXmlPointer->ErrorRow() << ", column " << m_tiXmlPointer->ErrorCol() << "."); 850 TICPPTHROW( "Error parsing xml." ); 864 851 } 865 852 } … … 912 899 913 900 Attribute* temp = new Attribute( attribute ); 914 m_spawnedWrappers.push_back( temp );901 attribute->m_spawnedWrappers.push_back( temp ); 915 902 916 903 return temp; … … 939 926 940 927 Attribute* temp = new Attribute( attribute ); 941 m_spawnedWrappers.push_back( temp );928 attribute->m_spawnedWrappers.push_back( temp ); 942 929 943 930 return temp; … … 957 944 { 958 945 return GetAttributeOrDefault( name, std::string() ); 946 } 947 948 bool Element::HasAttribute( const std::string& name ) const 949 { 950 ValidatePointer(); 951 return ( 0 != m_tiXmlPointer->Attribute( name.c_str() ) ); 952 } 953 954 void Element::RemoveAttribute( const std::string& name ) 955 { 956 ValidatePointer(); 957 m_tiXmlPointer->RemoveAttribute( name.c_str() ); 959 958 } 960 959 … … 1086 1085 } 1087 1086 1087 void TiCppRC::DeleteSpawnedWrappers() 1088 { 1089 std::vector< Base* >::reverse_iterator wrapper; 1090 for ( wrapper = m_spawnedWrappers.rbegin(); wrapper != m_spawnedWrappers.rend(); ++wrapper ) 1091 { 1092 delete *wrapper; 1093 } 1094 m_spawnedWrappers.clear(); 1095 } 1096 1088 1097 TiCppRC::~TiCppRC() 1089 { 1098 { 1099 DeleteSpawnedWrappers(); 1100 1090 1101 // Set pointer held by reference counter to NULL 1091 1102 this->m_tiRC->Nullify(); -
code/branches/buildsystem/src/tinyxml/ticpp.h
r1639 r2137 1 #define TIXML_USE_TICPP2 3 1 /* 4 2 http://code.google.com/p/ticpp/ … … 30 28 @date 04/11/2006 31 29 32 @version 0.04b by nico@orxonox.net: gcc-4.3 compilation hotfixes33 30 @version 0.04a by edam@waxworlds.org: based Exception based on std::exception; added stream 34 31 << and >> support; added Document::Parse(); bug fix; improved THROW() macro. … … 94 91 file = file.substr( file.find_last_of( "\\/" ) + 1 ); \ 95 92 full_message << message << " <" << file << "@" << __LINE__ << ">"; \ 93 full_message << BuildDetailedErrorString(); \ 96 94 throw Exception( full_message.str() ); \ 97 95 } … … 221 219 222 220 /** 221 Compare internal TiXml pointers to determine is both are wrappers around the same node 222 */ 223 bool operator == ( const Base& rhs ) const 224 { 225 return ( GetBasePointer() == rhs.GetBasePointer() ); 226 } 227 228 /** 229 Compare internal TiXml pointers to determine is both are wrappers around the same node 230 */ 231 bool operator != ( const Base& rhs ) const 232 { 233 return ( GetBasePointer() != rhs.GetBasePointer() ); 234 } 235 236 /** 237 Builds detailed error string using TiXmlDocument::Error() and others 238 */ 239 std::string BuildDetailedErrorString() const 240 { 241 std::ostringstream full_message; 242 #ifndef TICPP_NO_RTTI 243 TiXmlNode* node = dynamic_cast< TiXmlNode* >( GetBasePointer() ); 244 if ( node != 0 ) 245 { 246 TiXmlDocument* doc = node->GetDocument(); 247 if ( doc != 0 ) 248 { 249 if ( doc->Error() ) 250 { 251 full_message << "\nDescription: " << doc->ErrorDesc() 252 << "\nFile: " << (strlen( doc->Value() ) > 0 ? doc->Value() : "<unnamed-file>") 253 << "\nLine: " << doc->ErrorRow() 254 << "\nColumn: " << doc->ErrorCol(); 255 } 256 } 257 } 258 #endif 259 return full_message.str(); 260 } 261 262 /** 223 263 Destructor 224 264 */ 225 265 virtual ~Base() 226 266 { 227 DeleteSpawnedWrappers();228 267 } 229 268 … … 231 270 mutable TiCppRCImp* m_impRC; /**< Holds status of internal TiXmlPointer - use this to determine if object has been deleted already */ 232 271 233 mutable std::vector< Base* > m_spawnedWrappers; /**< Remember all wrappers that we've created with 'new' - ( e.g. NodeFactory, FirstChildElement, etc. )*/234 235 272 /** 236 273 @internal … … 250 287 TICPPTHROW( "Internal TiXml Pointer is NULL" ); 251 288 } 252 } 253 254 /** 255 @internal 256 Delete all container objects we've spawned with 'new'. 257 */ 258 void DeleteSpawnedWrappers() 259 { 260 std::vector< Base* >::reverse_iterator wrapper; 261 for ( wrapper = m_spawnedWrappers.rbegin(); wrapper != m_spawnedWrappers.rend(); ++wrapper ) 262 { 263 delete *wrapper; 264 } 265 m_spawnedWrappers.clear(); 266 } 289 } 267 290 268 291 /** … … 875 898 bool NoChildren() const; 876 899 900 #ifndef TICPP_NO_RTTI 877 901 /** 878 902 Pointer conversion ( NOT OBJECT CONVERSION ) - replaces TiXmlNode::ToElement, TiXmlNode::ToDocument, TiXmlNode::ToComment, etc. … … 895 919 return pointer; 896 920 } 921 #endif 897 922 898 923 /** … … 1085 1110 1086 1111 /// Constructor 1087 Iterator( const Iterator& it , const std::string& value = "")1088 : m_p( it.m_p ), m_value( value )1112 Iterator( const Iterator& it ) 1113 : m_p( it.m_p ), m_value( it.m_value ) 1089 1114 { 1090 1115 } … … 1103 1128 { 1104 1129 m_p = it.m_p; 1130 m_value = it.m_value; 1105 1131 return *this; 1106 1132 } … … 1121 1147 1122 1148 /** Sets internal pointer to the Next Sibling, or Iterator::END, if there are no more siblings */ 1123 Iterator& operator++(int) 1124 { 1125 return this->operator ++(); 1149 Iterator operator++(int) 1150 { 1151 Iterator tmp(*this); 1152 ++(*this); 1153 return tmp; 1126 1154 } 1127 1155 … … 1134 1162 1135 1163 /** Sets internal pointer to the Previous Sibling, or Iterator::END, if there are no prior siblings */ 1136 Iterator& operator--(int) 1137 { 1138 return this->operator --(); 1164 Iterator operator--(int) 1165 { 1166 Iterator tmp(*this); 1167 --(*this); 1168 return tmp; 1139 1169 } 1140 1170 1141 1171 /** Compares internal pointer */ 1142 bool operator!=( T* p ) const 1143 { 1144 return m_p != p; 1172 bool operator!=( const T* p ) const 1173 { 1174 if ( m_p == p ) 1175 { 1176 return false; 1177 } 1178 if ( 0 == m_p || 0 == p ) 1179 { 1180 return true; 1181 } 1182 return *m_p != *p; 1145 1183 } 1146 1184 … … 1148 1186 bool operator!=( const Iterator& it ) const 1149 1187 { 1150 return m_p != it.m_p;1188 return operator!=( it.m_p ); 1151 1189 } 1152 1190 … … 1154 1192 bool operator==( T* p ) const 1155 1193 { 1156 return m_p == p; 1194 if ( m_p == p ) 1195 { 1196 return true; 1197 } 1198 if ( 0 == m_p || 0 == p ) 1199 { 1200 return false; 1201 } 1202 return *m_p == *p; 1157 1203 } 1158 1204 … … 1160 1206 bool operator==( const Iterator& it ) const 1161 1207 { 1162 return m_p == it.m_p;1208 return operator==( it.m_p ); 1163 1209 } 1164 1210 … … 1218 1264 if ( 0 == tiXmlPointer ) 1219 1265 { 1220 TICPPTHROW( "Can not create a " << typeid( T ).name() ); 1266 #ifdef TICPP_NO_RTTI 1267 TICPPTHROW( "Can not create TinyXML objext" ); 1268 #else 1269 TICPPTHROW( "Can not create a " << typeid( T ).name() ); 1270 #endif 1221 1271 } 1222 1272 SetTiXmlPointer( tiXmlPointer ); … … 1231 1281 virtual void operator=( const NodeImp<T>& copy ) 1232 1282 { 1233 DeleteSpawnedWrappers();1234 1235 1283 // Dropping the reference to the old object 1236 1284 this->m_impRC->DecRef(); … … 1265 1313 virtual ~NodeImp() 1266 1314 { 1267 // The spawnedWrappers need to be deleted before m_tiXmlPointer1268 DeleteSpawnedWrappers();1269 1315 m_impRC->DecRef(); 1270 1316 } … … 1683 1729 1684 1730 /** 1731 Returns an attribute of @a name from an element. 1732 Uses FromString to convert the string to the type of choice. 1733 1734 @param name The name of the attribute you are querying. 1735 @param throwIfNotFound [DEF] If true, will throw an exception if the attribute doesn't exist 1736 @throws Exception When the attribute doesn't exist and throwIfNotFound is true 1737 @see GetAttributeOrDefault 1738 */ 1739 template < class T > 1740 T GetAttribute( const std::string& name, bool throwIfNotFound = true ) const 1741 { 1742 // Get the attribute's value as a std::string 1743 std::string temp; 1744 T value; 1745 if ( !GetAttributeImp( name, &temp ) ) 1746 { 1747 if ( throwIfNotFound ) 1748 { 1749 TICPPTHROW( "Attribute does not exist" ); 1750 } 1751 } 1752 else 1753 { 1754 // Stream the value from the string to T 1755 FromString( temp, &value ); 1756 } 1757 1758 return value; 1759 } 1760 1761 /** 1685 1762 Gets an attribute of @a name from an element. 1686 1763 Uses FromString to convert the string to the type of choice. … … 1725 1802 std::string GetAttribute( const std::string& name ) const; 1726 1803 1804 /** 1805 Returns true, if attribute exists 1806 1807 @param name The name of the attribute you are checking. 1808 @return Existence of attribute 1809 */ 1810 bool HasAttribute( const std::string& name ) const; 1811 1812 /** 1813 Removes attribute from element. 1814 1815 @param name The name of the attribute to remove. 1816 */ 1817 void RemoveAttribute( const std::string& name ); 1818 1727 1819 private: 1728 1820 -
code/branches/buildsystem/src/tinyxml/ticpprc.h
r1505 r2137 1 #define TIXML_USE_TICPP2 3 1 /* 4 2 http://code.google.com/p/ticpp/ … … 28 26 #define TICPPRC_INCLUDED 29 27 28 #include <vector> 30 29 31 30 // Forward declare ticpp::Node, so it can be made a friend of TiCppRC … … 64 63 */ 65 64 virtual ~TiCppRC(); 65 66 std::vector< ticpp::Base* > m_spawnedWrappers; /**< Remember all wrappers that we've created with 'new' - ( e.g. NodeFactory, FirstChildElement, etc. )*/ 67 68 /** 69 Delete all container objects we've spawned with 'new'. 70 */ 71 void DeleteSpawnedWrappers(); 66 72 }; 67 73 -
code/branches/buildsystem/src/tinyxml/tinyxml.h
r1505 r2137 1 #define TIXML_USE_TICPP2 3 1 /* 4 2 www.sourceforge.net/projects/tinyxml
Note: See TracChangeset
for help on using the changeset viewer.