11#ifndef OPENVDB_TREE_NODEUNION_HAS_BEEN_INCLUDED
12#define OPENVDB_TREE_NODEUNION_HAS_BEEN_INCLUDED
14#include <openvdb/version.h>
24#if OPENVDB_ABI_VERSION_NUMBER >= 8
32template<
typename ValueT,
typename ChildT,
typename Enable =
void>
45 const ValueT&
getValue()
const {
return mValue; }
47 void setValue(
const ValueT& val) { mValue = val; }
56 "Unexpected instantiation of NodeUnion");
61template<
typename ValueT,
typename ChildT>
63 typename
std::enable_if<std::is_trivially_copyable<ValueT>::value>::type>
66 union { ChildT*
mChild; ValueT mValue; };
74 const ValueT&
getValue()
const {
return mValue; }
76 void setValue(
const ValueT& val) { mValue = val; }
82template<
typename T>
struct CopyTraits;
87template<
typename ValueT,
typename ChildT,
typename Enable =
void>
95 NodeUnion(): mChild(nullptr), mValue() {}
97 ChildT* getChild()
const {
return mChild; }
98 void setChild(ChildT*
child) { mChild =
child; }
100 const ValueT& getValue()
const {
return mValue; }
101 ValueT& getValue() {
return mValue; }
102 void setValue(
const ValueT& val) { mValue = val; }
107template<
typename ValueT,
typename ChildT>
108class NodeUnion<ValueT, ChildT, typename
std::enable_if<std::is_pod<ValueT>::value>::type>
111 union { ChildT* mChild; ValueT mValue; };
114 NodeUnion(): mChild(nullptr) {}
116 ChildT* getChild()
const {
return mChild; }
117 void setChild(ChildT*
child) { mChild =
child; }
119 const ValueT& getValue()
const {
return mValue; }
120 ValueT& getValue() {
return mValue; }
121 void setValue(
const ValueT& val) { mValue = val; }
127template<
typename ValueT,
typename ChildT>
128class NodeUnion<ValueT, ChildT, typename
std::enable_if<CopyTraits<ValueT>::IsCopyable>::type>
131 union { ChildT* mChild; ValueT mValue; };
134 NodeUnion(): mChild(nullptr) {}
135 NodeUnion(
const NodeUnion& other): mChild(nullptr)
136 { std::memcpy(
static_cast<void*
>(
this), &other,
sizeof(*
this)); }
137 NodeUnion& operator=(
const NodeUnion& rhs)
138 { std::memcpy(
static_cast<void*
>(
this), &rhs,
sizeof(*
this));
return *
this; }
140 ChildT* getChild()
const {
return mChild; }
141 void setChild(ChildT*
child) { mChild =
child; }
143 const ValueT& getValue()
const {
return mValue; }
144 ValueT& getValue() {
return mValue; }
145 void setValue(
const ValueT& val) { mValue = val; }
155template<
typename T>
struct CopyTraits {
static const bool IsCopyable =
false; };
156template<
typename T>
struct CopyTraits<math::Vec2<T>> {
static const bool IsCopyable =
true; };
157template<
typename T>
struct CopyTraits<math::Vec3<T>> {
static const bool IsCopyable =
true; };
158template<
typename T>
struct CopyTraits<math::Vec4<T>> {
static const bool IsCopyable =
true; };
159template<>
struct CopyTraits<math::Coord> {
static const bool IsCopyable =
true; };
ValueT value
Definition: GridBuilder.h:1287
ChildT * child
Definition: GridBuilder.h:1286
void setChild(ChildT *child)
Definition: NodeUnion.h:72
ValueT & getValue()
Definition: NodeUnion.h:75
const ValueT & getValue() const
Definition: NodeUnion.h:74
ChildT * getChild() const
Definition: NodeUnion.h:71
NodeUnion()
Definition: NodeUnion.h:69
void setValue(const ValueT &val)
Definition: NodeUnion.h:76
ChildT * mChild
Definition: NodeUnion.h:66
Default implementation of a NodeUnion that stores the child pointer and the value separately (i....
Definition: NodeUnion.h:34
void setChild(ChildT *child)
Definition: NodeUnion.h:43
ValueT & getValue()
Definition: NodeUnion.h:46
const ValueT & getValue() const
Definition: NodeUnion.h:45
ChildT * getChild() const
Definition: NodeUnion.h:42
NodeUnion()
Definition: NodeUnion.h:40
void setValue(const ValueT &val)
Definition: NodeUnion.h:47
Definition: Exceptions.h:13
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202