00001 #include "MemReleaserRootVisitor.h" 00002 #include "Scene.h" 00003 #include "X3DAbstractNode.h" 00004 00005 #include <iostream> 00006 00007 using namespace X3DTK; 00008 using namespace std; 00009 00010 MemReleaserRootVisitor::MemReleaserRootVisitor() 00011 : RootVisitor() 00012 { 00013 // Enter functions. 00014 defineNewEnterFunction<MemReleaserRootVisitor, X3DAbstractNode>(&MemReleaserRootVisitor::enterX3DAbstractNode); 00015 00016 // Walk on functions. 00017 defineNewWalkOnFunction<MemReleaserRootVisitor, X3DAbstractNode>(&MemReleaserRootVisitor::walkOnX3DAbstractNode); 00018 00019 // Leave functions. 00020 defineNewLeaveFunction<MemReleaserRootVisitor, X3DAbstractNode>(&MemReleaserRootVisitor::leaveX3DAbstractNode); 00021 00022 // GlobalVariables assignation. 00023 globalVariables = GVManager::getInstanceOf<MemReleaserGlobalVariables>(); 00024 } 00025 00026 MemReleaserRootVisitor::~MemReleaserRootVisitor() 00027 { 00028 } 00029 00030 void MemReleaserRootVisitor::enterX3DAbstractNode(X3DAbstractNode *N) const 00031 { 00032 /* cout << "Node " << (void *)N << " of typeName " << N->getTypeName() << " belongs to Scenes:" << endl; 00033 cout << " "; 00034 MFScene list = N->getSceneList(); 00035 for (MFScene::const_iterator it = list.begin(); it != list.end(); ++it) 00036 cout << (void *)(*it) << ", "; 00037 cout << endl;*/ 00038 00039 // if here, then the parent has to be deleted. 00040 SFNode P = globalVariables->getParent(); 00041 if (P != 0) 00042 { 00043 P->removeChild(N); 00044 } 00045 00046 if (N->getParentList().size() == 0) 00047 globalVariables->setDelete(true); 00048 else 00049 globalVariables->setDelete(false); 00050 00051 globalVariables->pushParent(N); 00052 } 00053 00054 bool MemReleaserRootVisitor::walkOnX3DAbstractNode(X3DAbstractNode *N, SFNode child) const 00055 { 00056 return globalVariables->getDelete(); 00057 } 00058 00059 void MemReleaserRootVisitor::leaveX3DAbstractNode(X3DAbstractNode *N) const 00060 { 00061 globalVariables->popParent(); 00062 00063 if (globalVariables->getDelete()) 00064 { 00065 //cout << "deletes " << N->getTypeName() << endl; 00066 delete N; 00067 //cout << "deleted" << endl; 00068 } 00069 else 00070 globalVariables->setDelete(true); 00071 } 00072