Menu

Is there an operation to destroy a document?

2005-11-03
2013-05-20
  • flamingheart

    flamingheart - 2005-11-03

    because all the nodes are allocated using new operator.
    is there an operation to delete a document node and all its child nodes?

     
    • Ellers

      Ellers - 2005-11-03

      search for 'delete' ;)

      When anything deriving from TiXmlNode goes out of scope (if on the stack) or is deleted (if on the heap) then the destructor destroys all children:

      TiXmlNode::~TiXmlNode()
      {
          TiXmlNode* node = firstChild;
          TiXmlNode* temp = 0;

          while ( node )
          {
              temp = node;
              node = node->next;
              delete temp;
          }   
      }

      But you can erase everything without waiting for end-of-life with:

      void TiXmlNode::Clear()
      {
          TiXmlNode* node = firstChild;
          TiXmlNode* temp = 0;

          while ( node )
          {
              temp = node;
              node = node->next;
              delete temp;
          }   

          firstChild = 0;
          lastChild = 0;
      }

      Hey Lee - what do you think about changing it so the destructor just calls Clear(), to avoid the code duplication ?

      Ellers

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.