Blender V5.0
object_identifier.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
5
6#include "BLI_assert.h"
7
8#include "BKE_duplilist.hh"
9
10namespace blender::io {
11
16{
17 /* Class invariants:
18 * If duplicated_by is null, persistent_id must be default.
19 * If duplicated_by is not null, persistent_id must not be default. */
22}
23
28
30{
31 if (context == nullptr) {
32 return for_graph_root();
33 }
34 if (context->duplicator != nullptr) {
35 return ObjectIdentifier(context->object, context->duplicator, context->persistent_id);
36 }
37 return for_real_object(context->object);
38}
39
45
50
52{
53 return object == nullptr;
54}
55
56bool operator==(const ObjectIdentifier &obj_ident_a, const ObjectIdentifier &obj_ident_b)
57{
58 if (obj_ident_a.object != obj_ident_b.object) {
59 return false;
60 }
61 if (obj_ident_a.duplicated_by != obj_ident_b.duplicated_by) {
62 return false;
63 }
64
65 /* Return early if we know the expensive persistent_id check won't be necessary. */
66 if (obj_ident_a.duplicated_by == nullptr) {
67 return true;
68 }
69
70 /* Same object, both are duplicated, use the persistent IDs to determine equality. */
71 return obj_ident_a.persistent_id == obj_ident_b.persistent_id;
72}
73
74} // namespace blender::io
#define BLI_assert(a)
Definition BLI_assert.h:46
static ObjectIdentifier for_graph_root()
static ObjectIdentifier for_duplicated_object(const DupliObject *dupli_object, Object *duplicated_by)
static ObjectIdentifier for_real_object(Object *object)
static ObjectIdentifier for_hierarchy_context(const HierarchyContext *context)
ObjectIdentifier(Object *object, Object *duplicated_by, const PersistentID &persistent_id)
bool operator==(const PersistentID &persistent_id_a, const PersistentID &persistent_id_b)