Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2137


Ignore:
Timestamp:
Nov 4, 2008, 10:05:43 PM (15 years ago)
Author:
rgrieder
Message:

Updated tinycpp to it's trunk revision 98.
Note that our own changes are lost for now. Going to merge them in right after.
Added readme.txt with license and changes.txt.

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_TICPP
    2 
    31/*
    42http://code.google.com/p/ticpp/
     
    2321*/
    2422
    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 
    3223#ifdef TIXML_USE_TICPP
    3324
     
    164155
    165156        Attribute* temp = new Attribute( attribute );
    166         m_spawnedWrappers.push_back( temp );
     157        attribute->m_spawnedWrappers.push_back( temp );
    167158
    168159        return temp;
     
    186177
    187178        Attribute* temp = new Attribute( attribute );
    188         m_spawnedWrappers.push_back( temp );
     179        attribute->m_spawnedWrappers.push_back( temp );
    189180
    190181        return temp;
     
    262253        if ( rememberSpawnedWrapper )
    263254        {
    264                 m_spawnedWrappers.push_back( temp );
     255                tiXmlNode->m_spawnedWrappers.push_back( temp );
    265256        }
    266257        return temp;
     
    386377        }
    387378
     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
     388Node* 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
     406Node* 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
    388413        // Increment reference count when adding to the tree
    389414        addThis.m_impRC->IncRef();
    390415
    391         TiXmlNode* pointer = GetTiXmlPointer()->InsertEndChild( *addThis.GetTiXmlPointer() );
     416        TiXmlNode* pointer = GetTiXmlPointer()->InsertBeforeChild( beforeThis->GetTiXmlPointer(), *addThis.GetTiXmlPointer() );
    392417        if ( 0 == pointer )
    393418        {
     
    398423}
    399424
    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 )
     425Node* Node::InsertAfterChild( Node* afterThis, Node& addThis )
    419426{
    420427        if ( addThis.Type() == TiXmlNode::DOCUMENT )
     
    426433        addThis.m_impRC->IncRef();
    427434
    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 
    447435        TiXmlNode* pointer = GetTiXmlPointer()->InsertAfterChild( afterThis->GetTiXmlPointer(), *addThis.GetTiXmlPointer() );
    448436        if ( 0 == pointer )
     
    576564
    577565        Element* temp = new Element( sibling );
    578         m_spawnedWrappers.push_back( temp );
     566        sibling->m_spawnedWrappers.push_back( temp );
    579567
    580568        return temp;
     
    616604
    617605        Element* temp = new Element( element );
    618         m_spawnedWrappers.push_back( temp );
     606        element->m_spawnedWrappers.push_back( temp );
    619607
    620608        return temp;
     
    641629        }
    642630        Document* temp = new Document( doc );
    643         m_spawnedWrappers.push_back( temp );
     631        doc->m_spawnedWrappers.push_back( temp );
    644632
    645633        return temp;
     
    659647        }
    660648        Document* temp = new Document( doc );
    661         m_spawnedWrappers.push_back( temp );
     649        doc->m_spawnedWrappers.push_back( temp );
    662650
    663651        return temp;
     
    672660        }
    673661        Element* temp = new Element( doc );
    674         m_spawnedWrappers.push_back( temp );
     662        doc->m_spawnedWrappers.push_back( temp );
    675663
    676664        return temp;
     
    685673        }
    686674        Comment* temp = new Comment( doc );
    687         m_spawnedWrappers.push_back( temp );
     675        doc->m_spawnedWrappers.push_back( temp );
    688676
    689677        return temp;
     
    698686        }
    699687        Text* temp = new Text( doc );
    700         m_spawnedWrappers.push_back( temp );
     688        doc->m_spawnedWrappers.push_back( temp );
    701689
    702690        return temp;
     
    711699        }
    712700        Declaration* temp = new Declaration( doc );
    713         m_spawnedWrappers.push_back( temp );
     701        doc->m_spawnedWrappers.push_back( temp );
    714702
    715703        return temp;
     
    724712        }
    725713        StylesheetReference* temp = new StylesheetReference( doc );
    726         m_spawnedWrappers.push_back( temp );
     714        doc->m_spawnedWrappers.push_back( temp );
    727715
    728716        return temp;
     
    860848        if( throwIfParseError && m_tiXmlPointer->Error() )
    861849        {
    862                 TICPPTHROW( "Error parsing xml: " << m_tiXmlPointer->ErrorDesc()
    863             << " In row " << m_tiXmlPointer->ErrorRow() << ", column " << m_tiXmlPointer->ErrorCol() << ".");
     850                TICPPTHROW( "Error parsing xml." );
    864851        }
    865852}
     
    912899
    913900        Attribute* temp = new Attribute( attribute );
    914         m_spawnedWrappers.push_back( temp );
     901        attribute->m_spawnedWrappers.push_back( temp );
    915902
    916903        return temp;
     
    939926
    940927        Attribute* temp = new Attribute( attribute );
    941         m_spawnedWrappers.push_back( temp );
     928        attribute->m_spawnedWrappers.push_back( temp );
    942929
    943930        return temp;
     
    957944{
    958945        return GetAttributeOrDefault( name, std::string() );
     946}
     947
     948bool Element::HasAttribute( const std::string& name ) const
     949{
     950        ValidatePointer();
     951        return ( 0 != m_tiXmlPointer->Attribute( name.c_str() ) );
     952}
     953
     954void Element::RemoveAttribute( const std::string& name )
     955{
     956        ValidatePointer();
     957        m_tiXmlPointer->RemoveAttribute( name.c_str() );
    959958}
    960959
     
    10861085}
    10871086
     1087void 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               
    10881097TiCppRC::~TiCppRC()
    1089 {
     1098{       
     1099        DeleteSpawnedWrappers();
     1100       
    10901101        // Set pointer held by reference counter to NULL
    10911102        this->m_tiRC->Nullify();
  • code/branches/buildsystem/src/tinyxml/ticpp.h

    r1639 r2137  
    1 #define TIXML_USE_TICPP
    2 
    31/*
    42http://code.google.com/p/ticpp/
     
    3028@date           04/11/2006
    3129
    32 @version  0.04b by nico@orxonox.net: gcc-4.3 compilation hotfixes
    3330@version        0.04a by edam@waxworlds.org: based Exception based on std::exception; added stream
    3431                                        << and >> support; added Document::Parse(); bug fix; improved THROW() macro.
     
    9491                file = file.substr( file.find_last_of( "\\/" ) + 1 );                           \
    9592                full_message << message << " <" << file << "@" << __LINE__ << ">";      \
     93                full_message << BuildDetailedErrorString();                                                     \
    9694                throw Exception( full_message.str() );                                                          \
    9795        }
     
    221219
    222220                /**
     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                /**
    223263                Destructor
    224264                */
    225265                virtual ~Base()
    226266                {
    227                         DeleteSpawnedWrappers();
    228267                }
    229268
     
    231270                mutable TiCppRCImp* m_impRC;    /**< Holds status of internal TiXmlPointer - use this to determine if object has been deleted already */
    232271
    233                 mutable std::vector< Base* > m_spawnedWrappers; /**< Remember all wrappers that we've created with 'new' - ( e.g. NodeFactory, FirstChildElement, etc. )*/
    234 
    235272                /**
    236273                @internal
     
    250287                                TICPPTHROW( "Internal TiXml Pointer is NULL" );
    251288                        }
    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                }               
    267290
    268291                /**
     
    875898                bool NoChildren() const;
    876899
     900                #ifndef TICPP_NO_RTTI
    877901                /**
    878902                Pointer conversion ( NOT OBJECT CONVERSION ) - replaces TiXmlNode::ToElement, TiXmlNode::ToDocument, TiXmlNode::ToComment, etc.
     
    895919                        return pointer;
    896920                }
     921                #endif
    897922
    898923                /**
     
    10851110
    10861111                /// 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 )
    10891114                {
    10901115                }
     
    11031128                {
    11041129                        m_p = it.m_p;
     1130                        m_value = it.m_value;
    11051131                        return *this;
    11061132                }
     
    11211147
    11221148                /** 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;
    11261154                }
    11271155
     
    11341162
    11351163                /** 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;
    11391169                }
    11401170
    11411171                /** 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;
    11451183                }
    11461184
     
    11481186                bool operator!=( const Iterator& it ) const
    11491187                {
    1150                         return m_p != it.m_p;
     1188                        return operator!=( it.m_p );
    11511189                }
    11521190
     
    11541192                bool operator==( T* p ) const
    11551193                {
    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;
    11571203                }
    11581204
     
    11601206                bool operator==( const Iterator& it ) const
    11611207                {
    1162                         return m_p == it.m_p;
     1208                        return operator==( it.m_p );
    11631209                }
    11641210
     
    12181264                        if ( 0 == tiXmlPointer )
    12191265                        {
    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
    12211271                        }
    12221272                        SetTiXmlPointer( tiXmlPointer );
     
    12311281                virtual void operator=( const NodeImp<T>& copy )
    12321282                {
    1233                         DeleteSpawnedWrappers();
    1234 
    12351283                        // Dropping the reference to the old object
    12361284                        this->m_impRC->DecRef();
     
    12651313                virtual ~NodeImp()
    12661314                {
    1267                         // The spawnedWrappers need to be deleted before m_tiXmlPointer
    1268                         DeleteSpawnedWrappers();
    12691315                        m_impRC->DecRef();
    12701316                }
     
    16831729
    16841730                /**
     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                /**
    16851762                Gets an attribute of @a name from an element.
    16861763                Uses FromString to convert the string to the type of choice.
     
    17251802                std::string GetAttribute( const std::string& name ) const;
    17261803
     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
    17271819        private:
    17281820
  • code/branches/buildsystem/src/tinyxml/ticpprc.h

    r1505 r2137  
    1 #define TIXML_USE_TICPP
    2 
    31/*
    42http://code.google.com/p/ticpp/
     
    2826#define TICPPRC_INCLUDED
    2927
     28#include <vector>
    3029
    3130// Forward declare ticpp::Node, so it can be made a friend of TiCppRC
     
    6463        */
    6564        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();
    6672};
    6773
  • code/branches/buildsystem/src/tinyxml/tinyxml.h

    r1505 r2137  
    1 #define TIXML_USE_TICPP
    2 
    31/*
    42www.sourceforge.net/projects/tinyxml
Note: See TracChangeset for help on using the changeset viewer.