Blender  V3.3
object_identifier.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2019 Blender Foundation. All rights reserved. */
4 
5 #include "BKE_duplilist.h"
6 
7 extern "C" {
8 #include <climits> /* For INT_MAX. */
9 }
10 #include <cstring>
11 #include <sstream>
12 
13 namespace blender::io {
14 
16  Object *duplicated_by,
17  const PersistentID &persistent_id)
18  : object(object), duplicated_by(duplicated_by), persistent_id(persistent_id)
19 {
20 }
21 
23 {
24  return ObjectIdentifier(object, nullptr, PersistentID());
25 }
26 
28 {
29  if (context == nullptr) {
30  return for_graph_root();
31  }
32  if (context->duplicator != nullptr) {
33  return ObjectIdentifier(context->object, context->duplicator, context->persistent_id);
34  }
35  return for_real_object(context->object);
36 }
37 
39  Object *duplicated_by)
40 {
41  return ObjectIdentifier(dupli_object->ob, duplicated_by, PersistentID(dupli_object));
42 }
43 
45 {
46  return ObjectIdentifier(nullptr, nullptr, PersistentID());
47 }
48 
50 {
51  return object == nullptr;
52 }
53 
54 bool operator<(const ObjectIdentifier &obj_ident_a, const ObjectIdentifier &obj_ident_b)
55 {
56  if (obj_ident_a.object != obj_ident_b.object) {
57  return obj_ident_a.object < obj_ident_b.object;
58  }
59 
60  if (obj_ident_a.duplicated_by != obj_ident_b.duplicated_by) {
61  return obj_ident_a.duplicated_by < obj_ident_b.duplicated_by;
62  }
63 
64  if (obj_ident_a.duplicated_by == nullptr) {
65  /* Both are real objects, no need to check the persistent ID. */
66  return false;
67  }
68 
69  /* Same object, both are duplicated, use the persistent IDs to determine order. */
70  return obj_ident_a.persistent_id < obj_ident_b.persistent_id;
71 }
72 
73 bool operator==(const ObjectIdentifier &obj_ident_a, const ObjectIdentifier &obj_ident_b)
74 {
75  if (obj_ident_a.object != obj_ident_b.object) {
76  return false;
77  }
78  if (obj_ident_a.duplicated_by != obj_ident_b.duplicated_by) {
79  return false;
80  }
81  if (obj_ident_a.duplicated_by == nullptr) {
82  return true;
83  }
84 
85  /* Same object, both are duplicated, use the persistent IDs to determine equality. */
86  return obj_ident_a.persistent_id == obj_ident_b.persistent_id;
87 }
88 
89 } // namespace blender::io
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)
bool operator==(const PersistentID &persistent_id_a, const PersistentID &persistent_id_b)
struct Object * ob
Definition: BKE_duplilist.h:34