Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2022-01-14 20:35:14 +0300
committerJulian Eisel <julian@blender.org>2022-01-14 21:26:04 +0300
commitca9a749b21e6048845ca1401ba73c023dda68340 (patch)
treee61087aeb24201ef0be74d0a4854ab7972ffe6db /source/blender/editors/space_outliner
parente9a43a3b6060b57b75e42f27c288608352f000ea (diff)
Cleanup: Use smart pointers for Outliner tree display and element types
Smart pointers should be the default choice for C++ owning pointers, since they let you manage memory using RAII. Also moved type factory methods into static class functions.
Diffstat (limited to 'source/blender/editors/space_outliner')
-rw-r--r--source/blender/editors/space_outliner/outliner_intern.hh6
-rw-r--r--source/blender/editors/space_outliner/outliner_tree.cc9
-rw-r--r--source/blender/editors/space_outliner/space_outliner.cc2
-rw-r--r--source/blender/editors/space_outliner/tree/tree_display.cc35
-rw-r--r--source/blender/editors/space_outliner/tree/tree_display.hh7
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element.cc35
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element.hh7
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element_id.cc8
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element_id.hh2
9 files changed, 46 insertions, 65 deletions
diff --git a/source/blender/editors/space_outliner/outliner_intern.hh b/source/blender/editors/space_outliner/outliner_intern.hh
index 880d0bd7fb1..bc6eedb7620 100644
--- a/source/blender/editors/space_outliner/outliner_intern.hh
+++ b/source/blender/editors/space_outliner/outliner_intern.hh
@@ -23,6 +23,8 @@
#pragma once
+#include <memory>
+
#include "RNA_types.h"
#ifdef __cplusplus
@@ -55,7 +57,7 @@ class AbstractTreeElement;
struct SpaceOutliner_Runtime {
/** Object to create and manage the tree for a specific display type (View Layers, Scenes,
* Blender File, etc.). */
- blender::ed::outliner::AbstractTreeDisplay *tree_display;
+ std::unique_ptr<blender::ed::outliner::AbstractTreeDisplay> tree_display;
/** Pointers to tree-store elements, grouped by `(id, type, nr)`
* in hash-table for faster searching. */
@@ -91,7 +93,7 @@ typedef struct TreeElement {
* #TreeElement. Step by step, data should be moved to it and operations based on the type should
* become virtual methods of the class hierarchy.
*/
- blender::ed::outliner::AbstractTreeElement *type;
+ std::unique_ptr<blender::ed::outliner::AbstractTreeElement> type;
ListBase subtree;
int xs, ys; /* Do selection. */
diff --git a/source/blender/editors/space_outliner/outliner_tree.cc b/source/blender/editors/space_outliner/outliner_tree.cc
index 477ed88cb87..5f378a02052 100644
--- a/source/blender/editors/space_outliner/outliner_tree.cc
+++ b/source/blender/editors/space_outliner/outliner_tree.cc
@@ -217,7 +217,7 @@ void outliner_free_tree_element(TreeElement *element, ListBase *parent_subtree)
if (element->flag & TE_FREE_NAME) {
MEM_freeN((void *)element->name);
}
- outliner_tree_element_type_free(&element->type);
+ element->type = nullptr;
MEM_freeN(element);
}
@@ -862,7 +862,7 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
/* New C++ based type handle. Only some support this, eventually this should replace
* `TreeElement` entirely. */
- te->type = outliner_tree_element_type_create(type, *te, idv);
+ te->type = AbstractTreeElement::createFromType(type, *te, idv);
if (te->type) {
/* Element types ported to the new design are expected to have their name set at this point! */
BLI_assert(te->name != nullptr);
@@ -1880,10 +1880,9 @@ void outliner_build_tree(Main *mainvar,
outliner_free_tree(&space_outliner->tree);
outliner_storage_cleanup(space_outliner);
- outliner_tree_display_destroy(&space_outliner->runtime->tree_display);
- space_outliner->runtime->tree_display = outliner_tree_display_create(space_outliner->outlinevis,
- space_outliner);
+ space_outliner->runtime->tree_display = AbstractTreeDisplay::createFromDisplayMode(
+ space_outliner->outlinevis, *space_outliner);
/* All tree displays should be created as sub-classes of AbstractTreeDisplay. */
BLI_assert(space_outliner->runtime->tree_display != nullptr);
diff --git a/source/blender/editors/space_outliner/space_outliner.cc b/source/blender/editors/space_outliner/space_outliner.cc
index a7f5a0b906d..a8068bc9b71 100644
--- a/source/blender/editors/space_outliner/space_outliner.cc
+++ b/source/blender/editors/space_outliner/space_outliner.cc
@@ -367,7 +367,7 @@ static void outliner_free(SpaceLink *sl)
}
if (space_outliner->runtime) {
- outliner_tree_display_destroy(&space_outliner->runtime->tree_display);
+ space_outliner->runtime->tree_display = nullptr;
if (space_outliner->runtime->treehash) {
BKE_outliner_treehash_free(space_outliner->runtime->treehash);
}
diff --git a/source/blender/editors/space_outliner/tree/tree_display.cc b/source/blender/editors/space_outliner/tree/tree_display.cc
index 25345bc493d..d2b6fff6996 100644
--- a/source/blender/editors/space_outliner/tree/tree_display.cc
+++ b/source/blender/editors/space_outliner/tree/tree_display.cc
@@ -27,45 +27,28 @@ using namespace blender::ed::outliner;
namespace blender::ed::outliner {
-AbstractTreeDisplay *outliner_tree_display_create(int /*eSpaceOutliner_Mode*/ mode,
- SpaceOutliner *space_outliner)
+std::unique_ptr<AbstractTreeDisplay> AbstractTreeDisplay::createFromDisplayMode(
+ int /*eSpaceOutliner_Mode*/ mode, SpaceOutliner &space_outliner)
{
- AbstractTreeDisplay *tree_display = nullptr;
-
switch ((eSpaceOutliner_Mode)mode) {
case SO_SCENES:
- tree_display = new TreeDisplayScenes(*space_outliner);
- break;
+ return std::make_unique<TreeDisplayScenes>(space_outliner);
case SO_LIBRARIES:
- tree_display = new TreeDisplayLibraries(*space_outliner);
- break;
+ return std::make_unique<TreeDisplayLibraries>(space_outliner);
case SO_SEQUENCE:
- tree_display = new TreeDisplaySequencer(*space_outliner);
- break;
+ return std::make_unique<TreeDisplaySequencer>(space_outliner);
case SO_DATA_API:
- tree_display = new TreeDisplayDataAPI(*space_outliner);
- break;
+ return std::make_unique<TreeDisplayDataAPI>(space_outliner);
case SO_ID_ORPHANS:
- tree_display = new TreeDisplayIDOrphans(*space_outliner);
- break;
+ return std::make_unique<TreeDisplayIDOrphans>(space_outliner);
case SO_OVERRIDES_LIBRARY:
- tree_display = new TreeDisplayOverrideLibrary(*space_outliner);
- break;
+ return std::make_unique<TreeDisplayOverrideLibrary>(space_outliner);
case SO_VIEW_LAYER:
/* FIXME(Julian): this should not be the default! Return nullptr and handle that as valid
* case. */
default:
- tree_display = new TreeDisplayViewLayer(*space_outliner);
- break;
+ return std::make_unique<TreeDisplayViewLayer>(space_outliner);
}
-
- return tree_display;
-}
-
-void outliner_tree_display_destroy(AbstractTreeDisplay **tree_display)
-{
- delete *tree_display;
- *tree_display = nullptr;
}
bool AbstractTreeDisplay::hasWarnings() const
diff --git a/source/blender/editors/space_outliner/tree/tree_display.hh b/source/blender/editors/space_outliner/tree/tree_display.hh
index d6085770965..c14a5f133cf 100644
--- a/source/blender/editors/space_outliner/tree/tree_display.hh
+++ b/source/blender/editors/space_outliner/tree/tree_display.hh
@@ -73,6 +73,9 @@ class AbstractTreeDisplay {
}
virtual ~AbstractTreeDisplay() = default;
+ static std::unique_ptr<AbstractTreeDisplay> createFromDisplayMode(
+ int /*eSpaceOutliner_Mode*/ mode, SpaceOutliner &space_outliner);
+
/**
* Build a tree for this display mode with the Blender context data given in \a source_data and
* the view settings in \a space_outliner.
@@ -89,10 +92,6 @@ class AbstractTreeDisplay {
SpaceOutliner &space_outliner_;
};
-AbstractTreeDisplay *outliner_tree_display_create(int /*eSpaceOutliner_Mode*/ mode,
- SpaceOutliner *space_outliner);
-void outliner_tree_display_destroy(AbstractTreeDisplay **tree_display);
-
/* -------------------------------------------------------------------- */
/* View Layer Tree-Display */
diff --git a/source/blender/editors/space_outliner/tree/tree_element.cc b/source/blender/editors/space_outliner/tree/tree_element.cc
index 5b9a75208f7..7afbe6efb6b 100644
--- a/source/blender/editors/space_outliner/tree/tree_element.cc
+++ b/source/blender/editors/space_outliner/tree/tree_element.cc
@@ -41,7 +41,9 @@
namespace blender::ed::outliner {
-AbstractTreeElement *outliner_tree_element_type_create(int type, TreeElement &legacy_te, void *idv)
+std::unique_ptr<AbstractTreeElement> AbstractTreeElement::createFromType(const int type,
+ TreeElement &legacy_te,
+ void *idv)
{
ID &id = *static_cast<ID *>(idv);
@@ -61,28 +63,29 @@ AbstractTreeElement *outliner_tree_element_type_create(int type, TreeElement &le
case TSE_SOME_ID:
return TreeElementID::createFromID(legacy_te, id);
case TSE_ANIM_DATA:
- return new TreeElementAnimData(legacy_te, *reinterpret_cast<IdAdtTemplate &>(id).adt);
+ return std::make_unique<TreeElementAnimData>(legacy_te,
+ *reinterpret_cast<IdAdtTemplate &>(id).adt);
case TSE_DRIVER_BASE:
- return new TreeElementDriverBase(legacy_te, *static_cast<AnimData *>(idv));
+ return std::make_unique<TreeElementDriverBase>(legacy_te, *static_cast<AnimData *>(idv));
case TSE_NLA:
- return new TreeElementNLA(legacy_te, *static_cast<AnimData *>(idv));
+ return std::make_unique<TreeElementNLA>(legacy_te, *static_cast<AnimData *>(idv));
case TSE_NLA_TRACK:
- return new TreeElementNLATrack(legacy_te, *static_cast<NlaTrack *>(idv));
+ return std::make_unique<TreeElementNLATrack>(legacy_te, *static_cast<NlaTrack *>(idv));
case TSE_NLA_ACTION:
- return new TreeElementNLAAction(legacy_te, *static_cast<bAction *>(idv));
+ return std::make_unique<TreeElementNLAAction>(legacy_te, *static_cast<bAction *>(idv));
case TSE_GP_LAYER:
- return new TreeElementGPencilLayer(legacy_te, *static_cast<bGPDlayer *>(idv));
+ return std::make_unique<TreeElementGPencilLayer>(legacy_te, *static_cast<bGPDlayer *>(idv));
case TSE_R_LAYER_BASE:
- return new TreeElementViewLayerBase(legacy_te, *static_cast<Scene *>(idv));
+ return std::make_unique<TreeElementViewLayerBase>(legacy_te, *static_cast<Scene *>(idv));
case TSE_SCENE_COLLECTION_BASE:
- return new TreeElementCollectionBase(legacy_te, *static_cast<Scene *>(idv));
+ return std::make_unique<TreeElementCollectionBase>(legacy_te, *static_cast<Scene *>(idv));
case TSE_SCENE_OBJECTS_BASE:
- return new TreeElementSceneObjectsBase(legacy_te, *static_cast<Scene *>(idv));
+ return std::make_unique<TreeElementSceneObjectsBase>(legacy_te, *static_cast<Scene *>(idv));
case TSE_LIBRARY_OVERRIDE_BASE:
- return new TreeElementOverridesBase(legacy_te, id);
+ return std::make_unique<TreeElementOverridesBase>(legacy_te, id);
case TSE_LIBRARY_OVERRIDE:
- return new TreeElementOverridesProperty(legacy_te,
- *static_cast<TreeElementOverridesData *>(idv));
+ return std::make_unique<TreeElementOverridesProperty>(
+ legacy_te, *static_cast<TreeElementOverridesData *>(idv));
default:
break;
}
@@ -90,12 +93,6 @@ AbstractTreeElement *outliner_tree_element_type_create(int type, TreeElement &le
return nullptr;
}
-void outliner_tree_element_type_free(AbstractTreeElement **tree_element)
-{
- delete *tree_element;
- *tree_element = nullptr;
-}
-
void tree_element_expand(const AbstractTreeElement &tree_element, SpaceOutliner &space_outliner)
{
/* Most types can just expand. IDs optionally expand (hence the poll) and do additional, common
diff --git a/source/blender/editors/space_outliner/tree/tree_element.hh b/source/blender/editors/space_outliner/tree/tree_element.hh
index 35d007a96b4..ac8c923fb60 100644
--- a/source/blender/editors/space_outliner/tree/tree_element.hh
+++ b/source/blender/editors/space_outliner/tree/tree_element.hh
@@ -43,6 +43,10 @@ class AbstractTreeElement {
public:
virtual ~AbstractTreeElement() = default;
+ static std::unique_ptr<AbstractTreeElement> createFromType(int type,
+ TreeElement &legacy_te,
+ void *idv);
+
/**
* Check if the type is expandable in current context.
*/
@@ -63,7 +67,6 @@ class AbstractTreeElement {
return true;
}
- friend void outliner_tree_element_type_free(AbstractTreeElement **tree_element);
friend void tree_element_expand(const AbstractTreeElement &tree_element,
SpaceOutliner &space_outliner);
@@ -96,8 +99,6 @@ struct TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
short index);
void tree_element_expand(const AbstractTreeElement &tree_element, SpaceOutliner &space_outliner);
-AbstractTreeElement *outliner_tree_element_type_create(int type, TreeElement &legacy_te, void *idv);
-void outliner_tree_element_type_free(AbstractTreeElement **tree_element);
/**
* Get actual warning data of a tree element, if any.
diff --git a/source/blender/editors/space_outliner/tree/tree_element_id.cc b/source/blender/editors/space_outliner/tree/tree_element_id.cc
index f94e7a5b194..afbbd171cf4 100644
--- a/source/blender/editors/space_outliner/tree/tree_element_id.cc
+++ b/source/blender/editors/space_outliner/tree/tree_element_id.cc
@@ -39,13 +39,13 @@
namespace blender::ed::outliner {
-TreeElementID *TreeElementID::createFromID(TreeElement &legacy_te, ID &id)
+std::unique_ptr<TreeElementID> TreeElementID::createFromID(TreeElement &legacy_te, ID &id)
{
switch (ID_Type type = GS(id.name); type) {
case ID_LI:
- return new TreeElementIDLibrary(legacy_te, (Library &)id);
+ return std::make_unique<TreeElementIDLibrary>(legacy_te, (Library &)id);
case ID_SCE:
- return new TreeElementIDScene(legacy_te, (Scene &)id);
+ return std::make_unique<TreeElementIDScene>(legacy_te, (Scene &)id);
case ID_OB:
case ID_ME:
case ID_CU:
@@ -83,7 +83,7 @@ TreeElementID *TreeElementID::createFromID(TreeElement &legacy_te, ID &id)
case ID_PAL:
case ID_PC:
case ID_CF:
- return new TreeElementID(legacy_te, id);
+ return std::make_unique<TreeElementID>(legacy_te, id);
/* Deprecated */
case ID_IP:
BLI_assert_msg(0, "Outliner trying to build tree-element for deprecated ID type");
diff --git a/source/blender/editors/space_outliner/tree/tree_element_id.hh b/source/blender/editors/space_outliner/tree/tree_element_id.hh
index 12527992e8a..9b5b955be0b 100644
--- a/source/blender/editors/space_outliner/tree/tree_element_id.hh
+++ b/source/blender/editors/space_outliner/tree/tree_element_id.hh
@@ -36,7 +36,7 @@ class TreeElementID : public AbstractTreeElement {
public:
TreeElementID(TreeElement &legacy_te, ID &id);
- static TreeElementID *createFromID(TreeElement &legacy_te, ID &id);
+ static std::unique_ptr<TreeElementID> createFromID(TreeElement &legacy_te, ID &id);
void postExpand(SpaceOutliner &) const override;
bool expandPoll(const SpaceOutliner &) const override;