Blender  V3.3
IO_dupli_persistent_id.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 #pragma once
4 
5 #include "BKE_duplilist.h"
6 
7 #include "DNA_object_types.h" /* For MAX_DUPLI_RECUR */
8 
9 #include <array>
10 #include <optional>
11 #include <ostream>
12 
13 namespace blender::io {
14 
15 /* Wrapper for DupliObject::persistent_id that can act as a map key. */
16 class PersistentID {
17  protected:
18  constexpr static int array_length_ = MAX_DUPLI_RECUR;
19  typedef std::array<int, array_length_> PIDArray;
21 
22  explicit PersistentID(const PIDArray &persistent_id_values);
23 
24  public:
25  PersistentID();
26  explicit PersistentID(const DupliObject *dupli_ob);
27 
28  /* Return true if the persistent IDs are the same, ignoring the first digit. */
29  bool is_from_same_instancer_as(const PersistentID &other) const;
30 
31  /* Construct the persistent ID of this instance's instancer. */
33 
34  /* Construct a string representation by reversing the persistent ID.
35  * In case of a duplicator that is duplicated itself as well, this
36  * results in strings like:
37  * "3" for the duplicated duplicator, and
38  * "3-0", "3-1", etc. for its duplis. */
39  std::string as_object_name_suffix() const;
40 
41  friend bool operator==(const PersistentID &persistent_id_a, const PersistentID &persistent_id_b);
42  friend bool operator<(const PersistentID &persistent_id_a, const PersistentID &persistent_id_b);
43  friend std::ostream &operator<<(std::ostream &os, const PersistentID &persistent_id);
44 
45  private:
46  void copy_values_from(const PIDArray &persistent_id_values);
47 };
48 
49 } // namespace blender::io
Object is a sort of wrapper for general info.
#define MAX_DUPLI_RECUR
friend bool operator==(const PersistentID &persistent_id_a, const PersistentID &persistent_id_b)
friend bool operator<(const PersistentID &persistent_id_a, const PersistentID &persistent_id_b)
friend std::ostream & operator<<(std::ostream &os, const PersistentID &persistent_id)
PersistentID instancer_pid() const
std::string as_object_name_suffix() const
constexpr static int array_length_
bool is_from_same_instancer_as(const PersistentID &other) const
std::array< int, array_length_ > PIDArray