00001 /****************************************************************************** 00002 * SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3 * 00003 * (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS * 00004 * * 00005 * This library is free software; you can redistribute it and/or modify it * 00006 * under the terms of the GNU Lesser General Public License as published by * 00007 * the Free Software Foundation; either version 2.1 of the License, or (at * 00008 * your option) any later version. * 00009 * * 00010 * This library is distributed in the hope that it will be useful, but WITHOUT * 00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * 00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * 00013 * for more details. * 00014 * * 00015 * You should have received a copy of the GNU Lesser General Public License * 00016 * along with this library; if not, write to the Free Software Foundation, * 00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 00018 ******************************************************************************* 00019 * SOFA :: Modules * 00020 * * 00021 * Authors: The SOFA Team and external contributors (see Authors.txt) * 00022 * * 00023 * Contact information: contact@sofa-framework.org * 00024 ******************************************************************************/ 00025 #include <sofa/simulation/tree/DeleteVisitor.h> 00026 #include <sofa/simulation/common/Node.h> 00027 00028 namespace sofa 00029 { 00030 00031 namespace simulation 00032 { 00033 00034 namespace tree 00035 { 00036 00037 simulation::Visitor::Result CleanupVisitor::processNodeTopDown(GNode* node) 00038 { 00039 // some object will modify the graph during cleanup (removing other nodes or objects) 00040 // so we cannot assume that the list of object will stay constant 00041 00042 std::set<sofa::core::objectmodel::BaseObject*> done; // list of objects we already processed 00043 bool stop = false; 00044 while (!stop) 00045 { 00046 stop = true; 00047 for (GNode::ObjectIterator it = node->object.begin(); it != node->object.end(); ++it) 00048 if (done.insert(*it).second) 00049 { 00050 (*it)->cleanup(); 00051 stop = false; 00052 break; // we have to restart as objects could have been removed anywhere 00053 } 00054 } 00055 return RESULT_CONTINUE; 00056 } 00057 00058 void CleanupVisitor::processNodeBottomUp(GNode* /*node*/) 00059 { 00060 } 00061 00062 simulation::Visitor::Result DeleteVisitor::processNodeTopDown(GNode* /*node*/) 00063 { 00064 return RESULT_CONTINUE; 00065 } 00066 00067 void DeleteVisitor::processNodeBottomUp(GNode* node) 00068 { 00069 while (!node->child.empty()) 00070 { 00071 GNode* child = *node->child.begin(); 00072 node->removeChild(child); 00073 delete child; 00074 } 00075 while (!node->object.empty()) 00076 { 00077 core::objectmodel::BaseObject* object = *node->object.begin(); 00078 node->simulation::Node::removeObject(object); 00079 delete object; 00080 } 00081 } 00082 00083 } // namespace tree 00084 00085 } // namespace simulation 00086 00087 } // namespace sofa 00088
1.5.7.1