Blender V5.0
asset_catalog_collection.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
12
13namespace blender::asset_system {
14
16{
17 return catalogs_.is_empty() && deleted_catalogs_.is_empty();
18}
19
20std::unique_ptr<AssetCatalogCollection> AssetCatalogCollection::deep_copy() const
21{
22 auto copy = std::make_unique<AssetCatalogCollection>();
23
24 copy->has_unsaved_changes_ = this->has_unsaved_changes_;
25 copy->catalogs_ = copy_catalog_map(this->catalogs_);
26 copy->deleted_catalogs_ = copy_catalog_map(this->deleted_catalogs_);
27
29 copy->catalog_definition_file_ = catalog_definition_file_->copy_and_remap(
30 copy->catalogs_, copy->deleted_catalogs_);
31 }
32
33 return copy;
34}
35
37 const OwningAssetCatalogMap &source,
40{
41 for (const auto &orig_catalog_uptr : source.values()) {
42 if (dest.contains(orig_catalog_uptr->catalog_id)) {
43 if (on_duplicate_items) {
44 on_duplicate_items(*dest.lookup(orig_catalog_uptr->catalog_id), *orig_catalog_uptr);
45 }
46 continue;
47 }
48
49 auto copy_catalog_uptr = std::make_unique<AssetCatalog>(*orig_catalog_uptr);
50 dest.add_new(copy_catalog_uptr->catalog_id, std::move(copy_catalog_uptr));
51 }
52}
53
60
62{
65 orig, copy, /*on_duplicate_items=*/[](const AssetCatalog &, const AssetCatalog &) {
66 /* `copy` was empty before. If this happens it means there was a duplicate in the `orig`
67 * catalog map which should've been caught already. */
69 });
70 return copy;
71}
72
73} // namespace blender::asset_system
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
ValueIterator values() const &
Definition BLI_map.hh:884
const Value & lookup(const Key &key) const
Definition BLI_map.hh:545
void add_new(const Key &key, const Value &value)
Definition BLI_map.hh:265
bool contains(const Key &key) const
Definition BLI_map.hh:353
void add_catalogs_from_existing(const AssetCatalogCollection &other, OnDuplicateCatalogIdFn on_duplicate_items)
FunctionRef< void(const AssetCatalog &existing, const AssetCatalog &to_be_ignored)> OnDuplicateCatalogIdFn
std::unique_ptr< AssetCatalogDefinitionFile > catalog_definition_file_
std::unique_ptr< AssetCatalogCollection > deep_copy() const
static OwningAssetCatalogMap copy_catalog_map(const OwningAssetCatalogMap &orig)
static void copy_catalog_map_into_existing(const OwningAssetCatalogMap &source, OwningAssetCatalogMap &dest, AssetCatalogCollection::OnDuplicateCatalogIdFn on_duplicate_items)
Map< CatalogID, std::unique_ptr< AssetCatalog > > OwningAssetCatalogMap
static void copy(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node)