Blender V5.3
AS_asset_catalog_tree.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
16
17#pragma once
18
19#include <map>
20#include <optional>
21
22#include "AS_asset_catalog.hh"
23
24namespace blender::asset_system {
25
30 public:
35 using ChildMap = std::map<std::string, AssetCatalogTreeItem>;
37
38 private:
40 ChildMap children_;
43 CatalogID catalog_id_;
45 std::string simple_name_;
47 bool has_unsaved_changes_ = false;
48
53 const AssetCatalogTreeItem *parent_ = nullptr;
54
55 friend class AssetCatalogTree;
56
57 public:
59 CatalogID catalog_id,
60 StringRef simple_name,
61 const AssetCatalogTreeItem *parent = nullptr);
62
65 StringRefNull get_name() const;
66 bool has_unsaved_changes() const;
72 int count_parents() const;
73 bool has_children() const;
74
79 void foreach_child(ItemIterFn callback) const;
80 void foreach_item(ItemIterFn callback) const;
81
82 private:
83 static void foreach_item_recursive(const ChildMap &children_, ItemIterFn callback);
84};
85
87 using ChildMap = AssetCatalogTreeItem::ChildMap;
88 using ItemIterFn = AssetCatalogTreeItem::ItemIterFn;
89
91 ChildMap root_items_;
92
93 public:
103 void insert_item(const AssetCatalog &catalog,
104 std::optional<StringRef> skip_prefix = std::nullopt);
105
106 void foreach_item(ItemIterFn callback) const;
111 void foreach_root_item(ItemIterFn callback) const;
112
113 bool is_empty() const;
114
115 const AssetCatalogTreeItem *find_item(const AssetCatalogPath &path) const;
116 const AssetCatalogTreeItem *find_root_item(const AssetCatalogPath &path) const;
117};
118
119} // namespace blender::asset_system
void foreach_child(ItemIterFn callback) const
AssetCatalogTreeItem(StringRef name, CatalogID catalog_id, StringRef simple_name, const AssetCatalogTreeItem *parent=nullptr)
FunctionRef< void(const AssetCatalogTreeItem &)> ItemIterFn
std::map< std::string, AssetCatalogTreeItem > ChildMap
void foreach_item(ItemIterFn callback) const
void insert_item(const AssetCatalog &catalog, std::optional< StringRef > skip_prefix=std::nullopt)
void foreach_root_item(ItemIterFn callback) const
const AssetCatalogTreeItem * find_item(const AssetCatalogPath &path) const
void foreach_item(ItemIterFn callback) const
const AssetCatalogTreeItem * find_root_item(const AssetCatalogPath &path) const