Code

was trying to have my cake and eat it too, memory-management-wise ... for
authormental <mental@users.sourceforge.net>
Sun, 1 Jul 2007 20:08:45 +0000 (20:08 +0000)
committermental <mental@users.sourceforge.net>
Sun, 1 Jul 2007 20:08:45 +0000 (20:08 +0000)
now, manual management for Subtree

src/xml/subtree.cpp
src/xml/subtree.h

index 7c549e7d738e297d982fdd59b70c6f9035672740..f19bf055afb401db67e85d3248ec6888f4037cae 100644 (file)
@@ -32,25 +32,16 @@ void recursively(void (Node::*m)(NodeObserver &observer),
 
 }
 
-Subtree::Subtree(Node &root) : _root(&root) {
-    recursively(&Node::addObserver, *_root, *this);
+Subtree::Subtree(Node &root) : _root(root) {
+    recursively(&Node::addObserver, _root, *this);
 }
 
 Subtree::~Subtree() {
-    finish();
-}
-
-void Subtree::finish() {
-    if (_root) {
-        recursively(&Node::removeObserver, *_root, *this);
-        _root = NULL;
-    }
+    recursively(&Node::removeObserver, _root, *this);
 }
 
 void Subtree::synthesizeEvents(NodeObserver &observer) {
-    if (_root) {
-        recursively(&Node::synthesizeEvents, *_root, *this);
-    }
+    recursively(&Node::synthesizeEvents, _root, *this);
 }
 
 void Subtree::addObserver(NodeObserver &observer) {
index 73a6485d1eb641f20de7707bb558e31ed4119e8b..a70598fca6cc07343920c29a8da1c3774133614f 100644 (file)
 
 #include "xml/node-observer.h"
 #include "xml/composite-node-observer.h"
+#include "gc-finalized.h"
 
 namespace Inkscape {
 namespace XML {
 
 class Node;
 
-class Subtree : public Inkscape::GC::Anchored,
-                public Inkscape::GC::Managed<>,
+class Subtree : public GC::Managed<GC::SCANNED, GC::MANUAL>,
                 private NodeObserver
 {
 public:
     Subtree(Node &root);
     ~Subtree();
 
-    void finish();
-
     void synthesizeEvents(NodeObserver &observer);
     void addObserver(NodeObserver &observer);
     void removeObserver(NodeObserver &observer);
@@ -53,7 +51,7 @@ private:
                                 Util::ptr_shared<char> old_value,
                                 Util::ptr_shared<char> new_value);
 
-    Node *_root;
+    Node &_root;
     CompositeNodeObserver _observers;
 };