Blender  V3.3
DNA_defs.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
9 #pragma once
10 
11 /* makesdna ignores */
12 #ifdef DNA_DEPRECATED_ALLOW
13 /* allow use of deprecated items */
14 # define DNA_DEPRECATED
15 #else
16 # ifndef DNA_DEPRECATED
17 # ifdef __GNUC__
18 # define DNA_DEPRECATED __attribute__((deprecated))
19 # else
20 /* TODO: MSVC & others. */
21 # define DNA_DEPRECATED
22 # endif
23 # endif
24 #endif
25 
26 #ifdef __GNUC__
27 # define DNA_PRIVATE_ATTR __attribute__((deprecated))
28 #else
29 # define DNA_PRIVATE_ATTR
30 #endif
31 
32 /* poison pragma */
33 #ifdef DNA_DEPRECATED_ALLOW
34 # define DNA_DEPRECATED_GCC_POISON 0
35 #else
36 /* enable the pragma if we can */
37 # ifdef __GNUC__
38 # define DNA_DEPRECATED_GCC_POISON 1
39 # else
40 # define DNA_DEPRECATED_GCC_POISON 0
41 # endif
42 #endif
43 
44 /* hrmf, we need a better include then this */
45 #include "../blenlib/BLI_sys_types.h" /* needed for int64_t only! */
46 
47 /* non-id name variables should use this length */
48 #define MAX_NAME 64
49 
50 /* #DNA_DEFINE_CXX_METHODS is used to define C++ methods which are needed for proper/safe resource
51  * management, making unsafe (from an ownership perspective: i.e. pointers which sometimes needs to
52  * be set to nullptr on copy, sometimes needs to be dupalloc-ed) operations explicit, and taking
53  * care of compiler specific warnings when dealing with members marked with DNA_DEPRECATED.
54  *
55  * The `class_name` argument is to match the structure name the macro is used from.
56  *
57  * Typical usage example:
58  *
59  * typedef struct Object {
60  * DNA_DEFINE_CXX_METHODS(Object)
61  * } Object;
62  */
63 #ifndef __cplusplus
64 # define DNA_DEFINE_CXX_METHODS(class_name)
65 #else
66 
67 /* Forward-declared here since there is no simple header file to be pulled for this functionality.
68  * Avoids pulling `string.h` from this header to get access to #memcpy. */
69 extern "C" void _DNA_internal_memcpy(void *dst, const void *src, size_t size);
70 extern "C" void _DNA_internal_memzero(void *dst, size_t size);
71 
72 namespace blender::dna::internal {
73 
74 template<class T> class ShallowDataConstRef {
75  public:
76  constexpr explicit ShallowDataConstRef(const T &ref) : ref_(ref)
77  {
78  }
79 
80  inline const T *get_pointer() const
81  {
82  return &ref_;
83  }
84 
85  private:
86  const T &ref_;
87 };
88 
89 class ShallowZeroInitializeTag {
90 };
91 
92 } // namespace blender::dna::internal
93 
94 # define DNA_DEFINE_CXX_METHODS(class_name) \
95  class_name() = default; \
96  ~class_name() = default; \
97  /* Delete copy and assignment, which are not safe for resource ownership. */ \
98  class_name(const class_name &other) = delete; \
99  class_name(class_name &&other) noexcept = delete; \
100  class_name &operator=(const class_name &other) = delete; \
101  class_name &operator=(class_name &&other) = delete; \
102  /* Support for shallow copy. */ \
103  /* NOTE: Calling the default constructor works-around deprecated warning generated by GCC. */ \
104  class_name(const blender::dna::internal::ShallowDataConstRef<class_name> ref) : class_name() \
105  { \
106  _DNA_internal_memcpy(this, ref.get_pointer(), sizeof(class_name)); \
107  } \
108  class_name &operator=(const blender::dna::internal::ShallowDataConstRef<class_name> ref) \
109  { \
110  if (this != ref.get_pointer()) { \
111  _DNA_internal_memcpy(this, ref.get_pointer(), sizeof(class_name)); \
112  } \
113  return *this; \
114  } \
115  /* Create object which memory is filled with zeros. */ \
116  class_name(const blender::dna::internal::ShallowZeroInitializeTag /*tag*/) : class_name() \
117  { \
118  _DNA_internal_memzero(this, sizeof(class_name)); \
119  } \
120  class_name &operator=(const blender::dna::internal::ShallowZeroInitializeTag /*tag*/) \
121  { \
122  _DNA_internal_memzero(this, sizeof(class_name)); \
123  return *this; \
124  }
125 
126 namespace blender::dna {
127 
128 /* Creates shallow copy of the given object.
129  * The entire object is copied as-is using memory copy.
130  *
131  * Typical usage:
132  * Object temp_object = blender::dna::shallow_copy(*input_object);
133  *
134  * From the implementation detail go via copy constructor/assign operator defined in the structure.
135  */
136 template<class T>
137 [[nodiscard]] inline internal::ShallowDataConstRef<T> shallow_copy(const T &other)
138 {
139  return internal::ShallowDataConstRef(other);
140 }
141 
142 /* DNA object initializer which leads to an object which underlying memory is filled with zeroes.
143  */
144 [[nodiscard]] inline internal::ShallowZeroInitializeTag shallow_zero_initialize()
145 {
146  return internal::ShallowZeroInitializeTag();
147 }
148 
149 } // namespace blender::dna
150 
151 #endif
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SyclQueue void void * src
void _DNA_internal_memzero(void *dst, size_t size)
Definition: dna_utils.c:323
void _DNA_internal_memcpy(void *dst, const void *src, size_t size)
Definition: dna_utils.c:317
#define T