[Bf-blender-cvs] [7c0cecfd009] master: Asset system: Move catalog tree code to own files
Julian Eisel
noreply at git.blender.org
Fri Nov 18 12:46:01 CET 2022
Commit: 7c0cecfd00978e5d55dfcc30644d5963709e0e89
Author: Julian Eisel
Date: Fri Nov 18 11:46:12 2022 +0100
Branches: master
https://developer.blender.org/rB7c0cecfd00978e5d55dfcc30644d5963709e0e89
Asset system: Move catalog tree code to own files
The catalog code is already quite complex, I rather keep the tree stuff
separate in a more focused unit.
===================================================================
M source/blender/asset_system/AS_asset_catalog.hh
A source/blender/asset_system/AS_asset_catalog_tree.hh
M source/blender/asset_system/CMakeLists.txt
M source/blender/asset_system/intern/asset_catalog.cc
A source/blender/asset_system/intern/asset_catalog_tree.cc
M source/blender/asset_system/intern/asset_library.cc
M source/blender/asset_system/tests/asset_catalog_test.cc
M source/blender/editors/space_file/asset_catalog_tree_view.cc
M source/blender/editors/space_node/add_menu_assets.cc
===================================================================
diff --git a/source/blender/asset_system/AS_asset_catalog.hh b/source/blender/asset_system/AS_asset_catalog.hh
index 8160676603d..71d53f25261 100644
--- a/source/blender/asset_system/AS_asset_catalog.hh
+++ b/source/blender/asset_system/AS_asset_catalog.hh
@@ -165,7 +165,7 @@ class AssetCatalogService {
protected:
std::unique_ptr<AssetCatalogCollection> catalog_collection_;
- std::unique_ptr<AssetCatalogTree> catalog_tree_ = std::make_unique<AssetCatalogTree>();
+ std::unique_ptr<AssetCatalogTree> catalog_tree_;
CatalogFilePath asset_library_root_;
Vector<std::unique_ptr<AssetCatalogCollection>> undo_snapshots_;
@@ -274,88 +274,6 @@ class AssetCatalogCollection {
static OwningAssetCatalogMap copy_catalog_map(const OwningAssetCatalogMap &orig);
};
-/**
- * Representation of a catalog path in the #AssetCatalogTree.
- */
-class AssetCatalogTreeItem {
- friend class AssetCatalogTree;
-
- public:
- /** Container for child items. Uses a #std::map to keep items ordered by their name (i.e. their
- * last catalog component). */
- using ChildMap = std::map<std::string, AssetCatalogTreeItem>;
- using ItemIterFn = FunctionRef<void(AssetCatalogTreeItem &)>;
-
- AssetCatalogTreeItem(StringRef name,
- CatalogID catalog_id,
- StringRef simple_name,
- const AssetCatalogTreeItem *parent = nullptr);
-
- CatalogID get_catalog_id() const;
- StringRefNull get_simple_name() const;
- StringRefNull get_name() const;
- bool has_unsaved_changes() const;
- /** Return the full catalog path, defined as the name of this catalog prefixed by the full
- * catalog path of its parent and a separator. */
- AssetCatalogPath catalog_path() const;
- int count_parents() const;
- bool has_children() const;
-
- /** Iterate over children calling \a callback for each of them, but do not recurse into their
- * children. */
- void foreach_child(ItemIterFn callback);
-
- protected:
- /** Child tree items, ordered by their names. */
- ChildMap children_;
- /** The user visible name of this component. */
- CatalogPathComponent name_;
- CatalogID catalog_id_;
- /** Copy of #AssetCatalog::simple_name. */
- std::string simple_name_;
- /** Copy of #AssetCatalog::flags.has_unsaved_changes. */
- bool has_unsaved_changes_ = false;
-
- /** Pointer back to the parent item. Used to reconstruct the hierarchy from an item (e.g. to
- * build a path). */
- const AssetCatalogTreeItem *parent_ = nullptr;
-
- private:
- static void foreach_item_recursive(ChildMap &children_, ItemIterFn callback);
-};
-
-/**
- * A representation of the catalog paths as tree structure. Each component of the catalog tree is
- * represented by an #AssetCatalogTreeItem. The last path component of an item is used as its name,
- * which may also be shown to the user.
- * An item can not have multiple children with the same name. That means the name uniquely
- * identifies an item within its parent.
- *
- * There is no single root tree element, the #AssetCatalogTree instance itself represents the root.
- */
-class AssetCatalogTree {
- using ChildMap = AssetCatalogTreeItem::ChildMap;
- using ItemIterFn = AssetCatalogTreeItem::ItemIterFn;
-
- public:
- /** Ensure an item representing \a path is in the tree, adding it if necessary. */
- void insert_item(const AssetCatalog &catalog);
-
- void foreach_item(ItemIterFn callback);
- /** Iterate over root items calling \a callback for each of them, but do not recurse into their
- * children. */
- void foreach_root_item(ItemIterFn callback);
-
- bool is_empty() const;
-
- AssetCatalogTreeItem *find_item(const AssetCatalogPath &path);
- AssetCatalogTreeItem *find_root_item(const AssetCatalogPath &path);
-
- protected:
- /** Child tree items, ordered by their names. */
- ChildMap root_items_;
-};
-
/** Keeps track of which catalogs are defined in a certain file on disk.
* Only contains non-owning pointers to the #AssetCatalog instances, so ensure the lifetime of this
* class is shorter than that of the #`AssetCatalog`s themselves. */
diff --git a/source/blender/asset_system/AS_asset_catalog_tree.hh b/source/blender/asset_system/AS_asset_catalog_tree.hh
new file mode 100644
index 00000000000..3dcfa000634
--- /dev/null
+++ b/source/blender/asset_system/AS_asset_catalog_tree.hh
@@ -0,0 +1,94 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup asset_system
+ *
+ * A representation of the catalog paths as tree structure. Each component of the catalog tree is
+ * represented by an #AssetCatalogTreeItem. The last path component of an item is used as its name,
+ * which may also be shown to the user.
+ * An item can not have multiple children with the same name. That means the name uniquely
+ * identifies an item within its parent.
+ *
+ * There is no single root tree element, the #AssetCatalogTree instance itself represents the root.
+ */
+
+#pragma once
+
+#include "AS_asset_catalog.hh"
+
+namespace blender::asset_system {
+
+/**
+ * Representation of a catalog path in the #AssetCatalogTree.
+ */
+class AssetCatalogTreeItem {
+ friend class AssetCatalogTree;
+
+ public:
+ /** Container for child items. Uses a #std::map to keep items ordered by their name (i.e. their
+ * last catalog component). */
+ using ChildMap = std::map<std::string, AssetCatalogTreeItem>;
+ using ItemIterFn = FunctionRef<void(AssetCatalogTreeItem &)>;
+
+ AssetCatalogTreeItem(StringRef name,
+ CatalogID catalog_id,
+ StringRef simple_name,
+ const AssetCatalogTreeItem *parent = nullptr);
+
+ CatalogID get_catalog_id() const;
+ StringRefNull get_simple_name() const;
+ StringRefNull get_name() const;
+ bool has_unsaved_changes() const;
+ /** Return the full catalog path, defined as the name of this catalog prefixed by the full
+ * catalog path of its parent and a separator. */
+ AssetCatalogPath catalog_path() const;
+ int count_parents() const;
+ bool has_children() const;
+
+ /** Iterate over children calling \a callback for each of them, but do not recurse into their
+ * children. */
+ void foreach_child(ItemIterFn callback);
+
+ protected:
+ /** Child tree items, ordered by their names. */
+ ChildMap children_;
+ /** The user visible name of this component. */
+ CatalogPathComponent name_;
+ CatalogID catalog_id_;
+ /** Copy of #AssetCatalog::simple_name. */
+ std::string simple_name_;
+ /** Copy of #AssetCatalog::flags.has_unsaved_changes. */
+ bool has_unsaved_changes_ = false;
+
+ /** Pointer back to the parent item. Used to reconstruct the hierarchy from an item (e.g. to
+ * build a path). */
+ const AssetCatalogTreeItem *parent_ = nullptr;
+
+ private:
+ static void foreach_item_recursive(ChildMap &children_, ItemIterFn callback);
+};
+
+class AssetCatalogTree {
+ using ChildMap = AssetCatalogTreeItem::ChildMap;
+ using ItemIterFn = AssetCatalogTreeItem::ItemIterFn;
+
+ public:
+ /** Ensure an item representing \a path is in the tree, adding it if necessary. */
+ void insert_item(const AssetCatalog &catalog);
+
+ void foreach_item(ItemIterFn callback);
+ /** Iterate over root items calling \a callback for each of them, but do not recurse into their
+ * children. */
+ void foreach_root_item(ItemIterFn callback);
+
+ bool is_empty() const;
+
+ AssetCatalogTreeItem *find_item(const AssetCatalogPath &path);
+ AssetCatalogTreeItem *find_root_item(const AssetCatalogPath &path);
+
+ protected:
+ /** Child tree items, ordered by their names. */
+ ChildMap root_items_;
+};
+
+} // namespace blender::asset_system
diff --git a/source/blender/asset_system/CMakeLists.txt b/source/blender/asset_system/CMakeLists.txt
index 05f03c2bfc5..d00c3c72e3b 100644
--- a/source/blender/asset_system/CMakeLists.txt
+++ b/source/blender/asset_system/CMakeLists.txt
@@ -16,6 +16,7 @@ set(INC_SYS
set(SRC
intern/asset_catalog.cc
intern/asset_catalog_path.cc
+ intern/asset_catalog_tree.cc
intern/asset_library.cc
intern/asset_library_service.cc
intern/asset_representation.cc
@@ -23,6 +24,7 @@ set(SRC
AS_asset_catalog.hh
AS_asset_catalog_path.hh
+ AS_asset_catalog_tree.hh
AS_asset_library.hh
AS_asset_representation.hh
intern/asset_library_service.hh
diff --git a/source/blender/asset_system/intern/asset_catalog.cc b/source/blender/asset_system/intern/asset_catalog.cc
index e7790236583..67663503213 100644
--- a/source/blender/asset_system/intern/asset_catalog.cc
+++ b/source/blender/asset_system/intern/asset_catalog.cc
@@ -8,6 +8,7 @@
#include <set>
#include "AS_asset_catalog.hh"
+#include "AS_asset_catalog_tree.hh"
#include "AS_asset_library.h"
#include "AS_asset_library.hh"
@@ -38,14 +39,15 @@ const std::string AssetCatalogDefinitionFile::HEADER =
"# Other lines are of the format \"UUID:catalog/path/for/assets:simple catalog name\"\n";
AssetCatalogService::AssetCatalogService()
- : catalog_collection_(std::make_unique<AssetCatalogCollection>())
+ : catalog_collection_(std::make_unique<AssetCatalogCollection>()),
+ catalog_tree_(std::make_unique<AssetCatalogTree>())
{
}
AssetCatalogService::AssetCatalogService(const CatalogFilePath &asset_library_root)
- : catalog_collection_(std::make_unique<AssetCatalogCollection>()),
- asset_library_root_(asset_library_root)
+ : AssetCatalogService()
{
+ asset_library_root_ = asset_library_root;
}
void AssetCatalogService::tag_has_unsaved_changes(AssetCatalog *edited_catalog)
@@ -670,162 +672,6 @@ OwningAssetCatalogMap AssetCatalogCollection::copy_catalog_map(const OwningAsset
/* ---------------------------------------------------------------------- */
-AssetCatalogTreeItem::AssetCatalogTreeItem(StringRef name,
- CatalogID catalog_id,
- StringRef simple_name,
- const AssetCatalogTreeItem *parent)
- : name_(name), catalog_id_(catalog_id), simple_name_(simple_name), parent_(parent)
-{
-}
-
-CatalogID AssetCatalogTreeItem::get_catalog_id() const
-{
- return catalog_id_;
-}
-
-StringRefNull AssetCatalogTreeItem::get_name() const
-{
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list