Blender  V2.93
IO_dupli_persistent_id.hh
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2020 Blender Foundation.
17  * All rights reserved.
18  */
19 #pragma once
20 
21 #include "BKE_duplilist.h"
22 
23 #include "DNA_object_types.h" /* For MAX_DUPLI_RECUR */
24 
25 #include <array>
26 #include <optional>
27 #include <ostream>
28 
29 namespace blender::io {
30 
31 /* Wrapper for DupliObject::persistent_id that can act as a map key. */
32 class PersistentID {
33  protected:
34  constexpr static int array_length_ = MAX_DUPLI_RECUR;
35  typedef std::array<int, array_length_> PIDArray;
37 
38  explicit PersistentID(const PIDArray &persistent_id_values);
39 
40  public:
41  PersistentID();
42  explicit PersistentID(const DupliObject *dupli_ob);
43 
44  /* Return true if the persistent IDs are the same, ignoring the first digit. */
45  bool is_from_same_instancer_as(const PersistentID &other) const;
46 
47  /* Construct the persistent ID of this instance's instancer. */
49 
50  /* Construct a string representation by reversing the persistent ID.
51  * In case of a duplicator that is duplicated itself as well, this
52  * results in strings like:
53  * "3" for the duplicated duplicator, and
54  * "3-0", "3-1", etc. for its duplis. */
55  std::string as_object_name_suffix() const;
56 
57  friend bool operator==(const PersistentID &persistent_id_a, const PersistentID &persistent_id_b);
58  friend bool operator<(const PersistentID &persistent_id_a, const PersistentID &persistent_id_b);
59  friend std::ostream &operator<<(std::ostream &os, const PersistentID &persistent_id);
60 
61  private:
62  void copy_values_from(const PIDArray &persistent_id_values);
63 };
64 
65 } // 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