[Bf-blender-cvs] [a8ee305c7ab] temp-asset-browser-catalogs-ui: Merge branch 'temp-asset-browser-catalogs' into temp-asset-browser-catalogs-ui

Julian Eisel noreply at git.blender.org
Tue Sep 7 15:21:23 CEST 2021


Commit: a8ee305c7ab425f57ed7df005f4322a8b9357425
Author: Julian Eisel
Date:   Mon Sep 6 18:30:37 2021 +0200
Branches: temp-asset-browser-catalogs-ui
https://developer.blender.org/rBa8ee305c7ab425f57ed7df005f4322a8b9357425

Merge branch 'temp-asset-browser-catalogs' into temp-asset-browser-catalogs-ui

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



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

diff --cc source/blender/blenkernel/BKE_asset_catalog.hh
index 3b9c9263b08,2eafc177494..5986f4cae2e
--- a/source/blender/blenkernel/BKE_asset_catalog.hh
+++ b/source/blender/blenkernel/BKE_asset_catalog.hh
@@@ -108,11 -107,9 +108,10 @@@ class AssetCatalogService 
  
  class AssetCatalogTreeItem {
    friend class AssetCatalogService;
 +  friend class AssetCatalogTree;
  
   public:
-   /* TODO change name to ChildMap! */
-   using ChildSet = std::map<std::string, AssetCatalogTreeItem>;
+   using ChildMap = std::map<std::string, AssetCatalogTreeItem>;
    using ItemIterFn = FunctionRef<void(const AssetCatalogTreeItem &)>;
  
    AssetCatalogTreeItem(StringRef name, const AssetCatalogTreeItem *parent = nullptr);
@@@ -123,9 -119,8 +122,9 @@@
     * catalog path of its parent and a separator. */
    CatalogPath catalog_path() const;
    int count_parents() const;
 +  bool has_children() const;
  
-   static void foreach_item_recursive(const ChildSet &children_, const ItemIterFn callback);
+   static void foreach_item_recursive(const ChildMap &children_, const ItemIterFn callback);
  
   protected:
    /** Child tree items, ordered by their names. */
@@@ -145,46 -140,13 +144,46 @@@
   */
  class AssetCatalogTree {
    friend class AssetCatalogService;
-   using ChildSet = AssetCatalogTreeItem::ChildSet;
++  using ChildMap = AssetCatalogTreeItem::ChildMap;
  
   public:
 +  /** Ensure an item representing \a path is in the tree, adding it if necessary. */
 +  void insert_item(StringRef catalog_path_str);
 +
 +  AssetCatalogTreeItemIterator children();
    void foreach_item(const AssetCatalogTreeItem::ItemIterFn callback) const;
  
   protected:
    /** Child tree items, ordered by their names. */
-   ChildSet children_;
 -  AssetCatalogTreeItem::ChildMap children_;
++  ChildMap children_;
 +};
 +
- /* TODO mostly boilerplate code. Is that worth it? Could alternatively expose the ChildSet
++/* TODO mostly boilerplate code. Is that worth it? Could alternatively expose the ChildMap
 + * directly, and let users iterate over the map and its (key, value) pairs directly. */
 +class AssetCatalogTreeItemIterator
 +    : public std::iterator<std::forward_iterator_tag, AssetCatalogTreeItem> {
 +  /** #AssetCatalogTreeItemIterator is just a wrapper around the child-maps iterator. That is so we
 +   * can iterate over the values only of the map's (key, value) pairs. */
-   using WrappedIterator = AssetCatalogTreeItem::ChildSet::iterator;
++  using WrappedIterator = AssetCatalogTreeItem::ChildMap::iterator;
 +
 +  WrappedIterator wrapped_iterator_;
 +  WrappedIterator wrapped_end_iterator_;
 +
 + public:
 +  AssetCatalogTreeItemIterator(WrappedIterator wrapped_iterator,
 +                               WrappedIterator wrapped_end_iterator);
 +
 +  AssetCatalogTreeItemIterator begin() const;
 +  AssetCatalogTreeItemIterator end() const;
 +
 +  AssetCatalogTreeItem &operator*() const;
 +  AssetCatalogTreeItem *operator->() const;
 +
 +  AssetCatalogTreeItemIterator &operator++();
 +  AssetCatalogTreeItemIterator operator++(int);
 +
 +  friend bool operator==(AssetCatalogTreeItemIterator a, AssetCatalogTreeItemIterator b);
 +  friend bool operator!=(AssetCatalogTreeItemIterator a, AssetCatalogTreeItemIterator b);
  };
  
  /** Keeps track of which catalogs are defined in a certain file on disk.
diff --cc source/blender/blenkernel/intern/asset_catalog.cc
index 758be9c28e5,21dd3cc438c..bcc2d5f75d9
--- a/source/blender/blenkernel/intern/asset_catalog.cc
+++ b/source/blender/blenkernel/intern/asset_catalog.cc
@@@ -281,91 -292,6 +281,91 @@@ int AssetCatalogTreeItem::count_parents
    return i;
  }
  
 +bool AssetCatalogTreeItem::has_children() const
 +{
 +  return !children_.empty();
 +}
 +
 +/* ---------------------------------------------------------------------- */
 +
 +AssetCatalogTreeItemIterator::AssetCatalogTreeItemIterator(WrappedIterator wrapped_iterator,
 +                                                           WrappedIterator wrapped_end_iterator)
 +    : wrapped_iterator_(wrapped_iterator), wrapped_end_iterator_(wrapped_end_iterator)
 +{
 +}
 +
 +AssetCatalogTreeItemIterator AssetCatalogTreeItemIterator::begin() const
 +{
 +  return *this;
 +}
 +
 +AssetCatalogTreeItemIterator AssetCatalogTreeItemIterator::end() const
 +{
 +  return AssetCatalogTreeItemIterator(wrapped_end_iterator_, wrapped_end_iterator_);
 +}
 +
 +AssetCatalogTreeItem &AssetCatalogTreeItemIterator::operator*() const
 +{
 +  return wrapped_iterator_->second;
 +}
 +AssetCatalogTreeItem *AssetCatalogTreeItemIterator::operator->() const
 +{
 +  return &wrapped_iterator_->second;
 +}
 +
 +AssetCatalogTreeItemIterator &AssetCatalogTreeItemIterator::operator++()
 +{
 +  ++wrapped_iterator_;
 +  return *this;
 +}
 +AssetCatalogTreeItemIterator AssetCatalogTreeItemIterator::operator++(int)
 +{
 +  AssetCatalogTreeItemIterator copy(*this);
 +  ++wrapped_iterator_;
 +  return copy;
 +}
 +
 +bool operator==(AssetCatalogTreeItemIterator a, AssetCatalogTreeItemIterator b)
 +{
 +  return a.wrapped_iterator_ == b.wrapped_iterator_;
 +}
 +bool operator!=(AssetCatalogTreeItemIterator a, AssetCatalogTreeItemIterator b)
 +{
 +  return a.wrapped_iterator_ != b.wrapped_iterator_;
 +}
 +
 +/* ---------------------------------------------------------------------- */
 +
 +void AssetCatalogTree::insert_item(StringRef catalog_path_str)
 +{
 +  /* #fs::path adds useful behavior to the path. Remember that on Windows it uses "\" as
 +   * separator! For catalogs it should always be "/". Use #fs::path::generic_string if needed. */
 +  fs::path catalog_path = std::string_view(catalog_path_str);
 +
 +  const AssetCatalogTreeItem *parent = nullptr;
-   AssetCatalogTreeItem::ChildSet *insert_to_set = &children_;
++  AssetCatalogTreeItem::ChildMap *insert_to_map = &children_;
 +
 +  BLI_assert_msg(catalog_path.is_relative() && !catalog_path.has_root_path(),
 +                 "Malformed catalog path: Path should be a relative path, with no root-name or "
 +                 "root-directory as defined by std::filesystem::path.");
 +  for (const fs::path &component : catalog_path) {
 +    std::string component_name = component.string();
 +
 +    /* Insert new tree element - if no matching one is there yet! */
-     auto [item, was_inserted] = insert_to_set->emplace(
++    auto [item, was_inserted] = insert_to_map->emplace(
 +        component_name, AssetCatalogTreeItem(component_name, parent));
 +
 +    /* Walk further into the path (no matter if a new item was created or not). */
 +    parent = &item->second;
-     insert_to_set = &item->second.children_;
++    insert_to_map = &item->second.children_;
 +  }
 +}
 +
 +AssetCatalogTreeItemIterator AssetCatalogTree::children()
 +{
 +  return AssetCatalogTreeItemIterator(children_.begin(), children_.end());
 +}
 +
  void AssetCatalogTree::foreach_item(const AssetCatalogTreeItem::ItemIterFn callback) const
  {
    AssetCatalogTreeItem::foreach_item_recursive(children_, callback);



More information about the Bf-blender-cvs mailing list