/// Function name : deleteXMLTreeNode // Description : delete an XMLTreeNode and any children and properties it contains // // XML_TREE_NODE* &pNode : [in] XMLTreeNode to destroy // VOID deleteXMLTreeNode(XML_TREE_NODE* &pNode) { // Delete node text utilSafeDeleteString(pNode->szText); // Delete lists deleteListContents(&pNode->oChildren); // deleteList(pNode->pChildren); deleteListContents(&pNode->oProperties); // deleteList(pNode->pProperties); // Delete calling object utilDeleteObject(pNode); }
// ******************************************************************** // deleteListContents // // Recursively cleans up the memory allocated for each list. // ******************************************************************** void RecursiveDescentParser::deleteListContents( std::list<ListData> *incoming_list) { // while the incoming list is not empty while (!incoming_list->empty()) { // if the front item is a list, recursively delete it // else delete the allocated space for the int if (incoming_list->front().data_type == LIST) { std::list<ListData> *current_list = (std::list<ListData> *)incoming_list->front().data; deleteListContents(current_list); delete current_list; } else { int *current_int = (int *)incoming_list->front().data; delete current_int; } // pop the current item of the current list incoming_list->pop_front(); } }
// ******************************************************************** // ~RecursiveDescentParser // // The destructor for the RecursiveDescentParser class. // ******************************************************************** RecursiveDescentParser::~RecursiveDescentParser() { // recursively cleanup lists deleteListContents(initial_list); // delete list and stack objects delete initial_list; initial_list = NULL; delete list_stack; list_stack = NULL; }