Depsgraph: Add utility function to unlink relation from graph
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 20 Dec 2017 15:15:55 +0000 (16:15 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 20 Dec 2017 15:15:55 +0000 (16:15 +0100)
source/blender/depsgraph/intern/depsgraph.cc
source/blender/depsgraph/intern/depsgraph.h

index 2ab6320f14f52938f6a8276ba9c2f274f578b3cb..9a3b1788aa11ce69ba929d0131876bccad225c36 100644 (file)
@@ -51,6 +51,7 @@ extern "C" {
 #include "RNA_access.h"
 }
 
+#include <algorithm>
 #include <cstring>
 
 #include "DEG_depsgraph.h"
@@ -68,6 +69,14 @@ static DEG_EditorUpdateIDCb deg_editor_update_id_cb = NULL;
 static DEG_EditorUpdateSceneCb deg_editor_update_scene_cb = NULL;
 static DEG_EditorUpdateScenePreCb deg_editor_update_scene_pre_cb = NULL;
 
+/* TODO(sergey): Find a better place for this. */
+template <typename T>
+static void remove_from_vector(vector<T> *vector, const T& value)
+{
+       vector->erase(std::remove(vector->begin(), vector->end(), value),
+                     vector->end());
+}
+
 Depsgraph::Depsgraph()
   : time_source(NULL),
     need_update(false),
@@ -391,7 +400,15 @@ DepsRelation::DepsRelation(DepsNode *from,
 DepsRelation::~DepsRelation()
 {
        /* Sanity check. */
-       BLI_assert(this->from && this->to);
+       BLI_assert(from != NULL && to != NULL);
+}
+
+void DepsRelation::unlink()
+{
+       /* Sanity check. */
+       BLI_assert(from != NULL && to != NULL);
+       remove_from_vector(&from->outlinks, this);
+       remove_from_vector(&to->inlinks, this);
 }
 
 /* Low level tagging -------------------------------------- */
index be20b20a2ac7254817e62025a90642b3f56dea4f..ce56d67b6de8ecfe6be93d17638bbf194155114e 100644 (file)
@@ -84,6 +84,8 @@ struct DepsRelation {
                     const char *description);
 
        ~DepsRelation();
+
+       void unlink();
 };
 
 /* ********* */