[Bf-blender-cvs] [61d0f778109] master: Cleanup: Better follow class layout style guide in asset headers

Julian Eisel noreply at git.blender.org
Fri Nov 18 12:46:02 CET 2022


Commit: 61d0f778109c95fecd8883fd43059d27357a0dd6
Author: Julian Eisel
Date:   Fri Nov 18 12:34:47 2022 +0100
Branches: master
https://developer.blender.org/rB61d0f778109c95fecd8883fd43059d27357a0dd6

Cleanup: Better follow class layout style guide in asset headers

Move "using" declarations and member variables to the top of the class.
See https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Class_Layout.

Changes access specifiers of some variables from public/protected to
private, there was no point in not having them private.

===================================================================

M	source/blender/asset_system/AS_asset_catalog.hh
M	source/blender/asset_system/AS_asset_catalog_path.hh
M	source/blender/asset_system/AS_asset_catalog_tree.hh
M	source/blender/asset_system/AS_asset_library.hh
M	source/blender/asset_system/AS_asset_representation.hh
M	source/blender/asset_system/intern/asset_library.cc
M	source/blender/asset_system/intern/asset_library_service.hh

===================================================================

diff --git a/source/blender/asset_system/AS_asset_catalog.hh b/source/blender/asset_system/AS_asset_catalog.hh
index 5cf7c0e3188..d11717736af 100644
--- a/source/blender/asset_system/AS_asset_catalog.hh
+++ b/source/blender/asset_system/AS_asset_catalog.hh
@@ -38,6 +38,13 @@ using OwningAssetCatalogMap = Map<CatalogID, std::unique_ptr<AssetCatalog>>;
 /* Manages the asset catalogs of a single asset library (i.e. of catalogs defined in a single
  * directory hierarchy). */
 class AssetCatalogService {
+  std::unique_ptr<AssetCatalogCollection> catalog_collection_;
+  std::unique_ptr<AssetCatalogTree> catalog_tree_;
+  CatalogFilePath asset_library_root_;
+
+  Vector<std::unique_ptr<AssetCatalogCollection>> undo_snapshots_;
+  Vector<std::unique_ptr<AssetCatalogCollection>> redo_snapshots_;
+
  public:
   static const CatalogFilePath DEFAULT_CATALOG_FILENAME;
 
@@ -164,13 +171,6 @@ class AssetCatalogService {
   bool is_redo_possbile() const;
 
  protected:
-  std::unique_ptr<AssetCatalogCollection> catalog_collection_;
-  std::unique_ptr<AssetCatalogTree> catalog_tree_;
-  CatalogFilePath asset_library_root_;
-
-  Vector<std::unique_ptr<AssetCatalogCollection>> undo_snapshots_;
-  Vector<std::unique_ptr<AssetCatalogCollection>> redo_snapshots_;
-
   void load_directory_recursive(const CatalogFilePath &directory_path);
   void load_single_file(const CatalogFilePath &catalog_definition_file_path);
 
@@ -246,15 +246,6 @@ class AssetCatalogService {
  * struct.
  */
 class AssetCatalogCollection {
-  friend AssetCatalogService;
-
- public:
-  AssetCatalogCollection() = default;
-  AssetCatalogCollection(const AssetCatalogCollection &other) = delete;
-  AssetCatalogCollection(AssetCatalogCollection &&other) noexcept = default;
-
-  std::unique_ptr<AssetCatalogCollection> deep_copy() const;
-
  protected:
   /** All catalogs known, except the known-but-deleted ones. */
   OwningAssetCatalogMap catalogs_;
@@ -271,6 +262,16 @@ class AssetCatalogCollection {
   /** Whether any of the catalogs have unsaved changes. */
   bool has_unsaved_changes_ = false;
 
+  friend AssetCatalogService;
+
+ public:
+  AssetCatalogCollection() = default;
+  AssetCatalogCollection(const AssetCatalogCollection &other) = delete;
+  AssetCatalogCollection(AssetCatalogCollection &&other) noexcept = default;
+
+  std::unique_ptr<AssetCatalogCollection> deep_copy() const;
+
+ protected:
   static OwningAssetCatalogMap copy_catalog_map(const OwningAssetCatalogMap &orig);
 };
 
@@ -278,6 +279,11 @@ class AssetCatalogCollection {
  * 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. */
 class AssetCatalogDefinitionFile {
+ protected:
+  /* Catalogs stored in this file. They are mapped by ID to make it possible to query whether a
+   * catalog is already known, without having to find the corresponding `AssetCatalog*`. */
+  Map<CatalogID, AssetCatalog *> catalogs_;
+
  public:
   /* For now this is the only version of the catalog definition files that is supported.
    * Later versioning code may be added to handle older files. */
@@ -290,6 +296,7 @@ class AssetCatalogDefinitionFile {
 
   CatalogFilePath file_path;
 
+ public:
   AssetCatalogDefinitionFile() = default;
 
   /**
@@ -323,10 +330,6 @@ class AssetCatalogDefinitionFile {
       const OwningAssetCatalogMap &catalogs, const OwningAssetCatalogMap &deleted_catalogs) const;
 
  protected:
-  /* Catalogs stored in this file. They are mapped by ID to make it possible to query whether a
-   * catalog is already known, without having to find the corresponding `AssetCatalog*`. */
-  Map<CatalogID, AssetCatalog *> catalogs_;
-
   bool parse_version_line(StringRef line);
   std::unique_ptr<AssetCatalog> parse_catalog_line(StringRef line);
 
@@ -342,9 +345,6 @@ class AssetCatalogDefinitionFile {
  * catalog hierarchy. */
 class AssetCatalog {
  public:
-  AssetCatalog() = default;
-  AssetCatalog(CatalogID catalog_id, const AssetCatalogPath &path, const std::string &simple_name);
-
   CatalogID catalog_id;
   AssetCatalogPath path;
   /**
@@ -376,6 +376,10 @@ class AssetCatalog {
     bool has_unsaved_changes = false;
   } flags;
 
+ public:
+  AssetCatalog() = default;
+  AssetCatalog(CatalogID catalog_id, const AssetCatalogPath &path, const std::string &simple_name);
+
   /**
    * Create a new Catalog with the given path, auto-generating a sensible catalog simple-name.
    *
@@ -420,6 +424,11 @@ using MutableAssetCatalogOrderedSet = std::set<AssetCatalog *, AssetCatalogLessT
  * \see AssetCatalogService::create_catalog_filter()
  */
 class AssetCatalogFilter {
+  const Set<CatalogID> matching_catalog_ids;
+  const Set<CatalogID> known_catalog_ids;
+
+  friend AssetCatalogService;
+
  public:
   bool contains(CatalogID asset_catalog_id) const;
 
@@ -427,10 +436,6 @@ class AssetCatalogFilter {
   bool is_known(CatalogID asset_catalog_id) const;
 
  protected:
-  friend AssetCatalogService;
-  const Set<CatalogID> matching_catalog_ids;
-  const Set<CatalogID> known_catalog_ids;
-
   explicit AssetCatalogFilter(Set<CatalogID> &&matching_catalog_ids,
                               Set<CatalogID> &&known_catalog_ids);
 };
diff --git a/source/blender/asset_system/AS_asset_catalog_path.hh b/source/blender/asset_system/AS_asset_catalog_path.hh
index 0ac50ab00c9..22b5ca63efa 100644
--- a/source/blender/asset_system/AS_asset_catalog_path.hh
+++ b/source/blender/asset_system/AS_asset_catalog_path.hh
@@ -34,7 +34,6 @@ namespace blender::asset_system {
 class AssetCatalogPath {
   friend std::ostream &operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append);
 
- private:
   /**
    * The path itself, such as "Agents/Secret/327".
    */
diff --git a/source/blender/asset_system/AS_asset_catalog_tree.hh b/source/blender/asset_system/AS_asset_catalog_tree.hh
index 3dcfa000634..8a2608842cc 100644
--- a/source/blender/asset_system/AS_asset_catalog_tree.hh
+++ b/source/blender/asset_system/AS_asset_catalog_tree.hh
@@ -22,14 +22,30 @@ 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 &)>;
 
+ private:
+  /** 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;
+
+  friend class AssetCatalogTree;
+
+ public:
   AssetCatalogTreeItem(StringRef name,
                        CatalogID catalog_id,
                        StringRef simple_name,
@@ -49,21 +65,6 @@ class AssetCatalogTreeItem {
    * 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);
 };
@@ -72,6 +73,9 @@ class AssetCatalogTree {
   using ChildMap = AssetCatalogTreeItem::ChildMap;
   using ItemIterFn = AssetCatalogTreeItem::ItemIterFn;
 
+  /** Child tree items, ordered by their names. */
+  ChildMap root_items_;
+
  public:
   /** Ensure an item representing \a path is in the tree, adding it if necessary. */
   void insert_item(const AssetCatalog &catalog);
@@ -85,10 +89,6 @@ class AssetCatalogTree {
 
   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/AS_asset_library.hh b/source/blender/asset_system/AS_asset_library.hh
index 97db15dd640..47a45b7056f 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -33,13 +33,32 @@ class AssetStorage;
  * The asset library contains catalogs and storage for asset representations. It could be extended
  * to also include asset indexes and more.
  */
-struct AssetLibrary {
+class AssetLibrary {
+  bCallbackFuncStore on_save_callback_store_{};
+
+  /** Storage for assets (better said their representations) that are considered to be part of this
+   * library. Assets are not automatically loaded into this when loading an asset library. Assets
+   * have to be loaded externally and added to this storage via #add_external_asset() or
+   * #add_local_id_asset(). So this really is arbitrary storage as far as #AssetLibrary is
+   * concerned (allowing the API user to manage partial library storage and partial loading, so
+   * only relevant parts of a library are kept in memory).
+   *
+   * For now, multiple parts of Blender just keep adding their own assets to this storage. E.g.
+   * multiple asset browsers might load multiple representations for the same asset into this.
+   * Currently there is just no way to properly identify assets, or keep track of which assets are
+   * already in memory and which not. Neither do we keep track of how many parts of Blender are
+   * using an asset or an asset library, which is needed to know when assets ca

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list