Blender V4.3
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
10
12
13namespace blender::asset_system {
14
15std::unique_ptr<AssetCatalogCollection> AssetCatalogCollection::deep_copy() const
16{
17 auto copy = std::make_unique<AssetCatalogCollection>();
18
19 copy->has_unsaved_changes_ = this->has_unsaved_changes_;
20 copy->catalogs_ = this->copy_catalog_map(this->catalogs_);
21 copy->deleted_catalogs_ = this->copy_catalog_map(this->deleted_catalogs_);
22
24 copy->catalog_definition_file_ = catalog_definition_file_->copy_and_remap(
25 copy->catalogs_, copy->deleted_catalogs_);
26 }
27
28 return copy;
29}
30
32 const OwningAssetCatalogMap &source,
35{
36 for (const auto &orig_catalog_uptr : source.values()) {
37 if (dest.contains(orig_catalog_uptr->catalog_id)) {
38 if (on_duplicate_items) {
39 on_duplicate_items(*dest.lookup(orig_catalog_uptr->catalog_id), *orig_catalog_uptr);
40 }
41 continue;
42 }
43
44 auto copy_catalog_uptr = std::make_unique<AssetCatalog>(*orig_catalog_uptr);
45 dest.add_new(copy_catalog_uptr->catalog_id, std::move(copy_catalog_uptr));
46 }
47}
48
55
57{
60 orig, copy, /*on_duplicate_items=*/[](const AssetCatalog &, const AssetCatalog &) {
61 /* `copy` was empty before. If this happens it means there was a duplicate in the `orig`
62 * catalog map which should've been caught already. */
64 });
65 return copy;
66}
67
68} // namespace blender::asset_system
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
const Value & lookup(const Key &key) const
Definition BLI_map.hh:506
ValueIterator values() const
Definition BLI_map.hh:846
void add_new(const Key &key, const Value &value)
Definition BLI_map.hh:241
bool contains(const Key &key) const
Definition BLI_map.hh:329
void add_catalogs_from_existing(const AssetCatalogCollection &other, OnDuplicateCatalogIdFn on_duplicate_items)
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)
static void copy(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node)