HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_AttributeGeometry.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  */
8 
9 #ifndef __PDG_ATTRIBUTE_Geometry_H__
10 #define __PDG_ATTRIBUTE_Geometry_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_ApplicationShim.h"
15 #include "PDG_AttributeData.h"
16 
17 #include <UT/UT_UniquePtr.h>
18 #include <type_traits>
19 
20 class UT_JSONValue;
21 class UT_JSONWriter;
22 class UT_OptionsHolder;
23 class UT_StringHolder;
24 
25 /**
26  * Attribute that contains a single PDG_AttributeShim::Geometry* for storing
27  * geometry on a work item.
28  */
30 {
31 public:
32  static constexpr PDG_AttributeType TypeEnum = PDG_AttributeType::eGeometry;
33 
35  using Data = Geometry*;
37 
39 
40 public:
42  ~PDG_AttributeGeometry() override;
43 
44  int64 getMemoryUsage(bool inclusive) const override;
45  bool hash(
47  exint index,
48  UT_WorkBuffer& errors) const override;
49  PDG_AttributeData* clone() const override;
50 
51  bool saveData(UT_JSONWriter& writer) const override;
52  void saveData(
53  const UT_StringHolder& key,
54  UT_OptionsHolder& dict) const override;
55 
56  bool loadData(const UT_JSONValue& value) override;
57  bool loadData(
58  const UT_StringHolder& key,
59  const UT_OptionsHolder& dict) override;
60 
61  bool compare(
62  const PDG_AttributeData* other
63  ) const override;
65  PDG_AttributeMergeOp merge_op,
66  int stride) override;
67 
68  const Geometry* geometry() const;
69  Geometry* geometry();
70 
71  template <typename T>
72  const T* geometryT() const
73  {
74  return dynamic_cast<const T*>(geometry());
75  }
76 
77  template <typename T>
79  {
80  return dynamic_cast<T*>(geometry());
81  }
82 
83  bool desc(UT_StringHolder& str) const;
84 
85  inline bool hasData() const
86  {
87  return (myGeometry.get() != nullptr);
88  }
89 
90  inline int size() const
91  {
92  return 1;
93  }
94 
95  inline bool valid(int component) const
96  {
97  return (component == 0);
98  }
99 
100  inline bool value(Data& geometry, int component) const
101  {
102  if (component != 0)
103  return false;
104 
105  geometry = myGeometry.get();
106  return true;
107  }
108 
109  template <typename T>
110  inline T* createGeometry()
111  {
112  myGeometry = UTmakeUnique<T>();
113  return static_cast<T*>(myGeometry.get());
114  }
115 
116  inline void swap(PDG_AttributeGeometry* other)
117  {
118  std::swap(myGeometry, other->myGeometry);
119  }
120 
121  void copy(
122  const PDG_AttributeGeometry* other,
123  PDG_AttributeCopyOp copy_op);
124 
125 private:
126  UT_UniquePtr<Geometry> myGeometry;
127 };
128 
129 #endif
const T * geometryT() const
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
Definition: UT_ArraySet.h:1699
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
GLsizei const GLfloat * value
Definition: glcorearb.h:824
virtual bool compare(const PDG_AttributeData *) const =0
Compares this data object with another data object.
#define PDG_API
Definition: PDG_API.h:23
int64 exint
Definition: SYS_Types.h:125
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
bool valid(int component) const
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
A single PDG_ApplicationShim::Geometry instance.
virtual bool loadData(const UT_JSONValue &)=0
Loads data from a JSON value.
virtual PDG_AttributeMergeError merge(PDG_AttributeMergeOp merge_op, int stride)=0
Applies a merge op to the data in this attribute.
ApexGeometry Geometry
Definition: APEX_Include.h:69
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
virtual bool saveData(UT_JSONWriter &) const =0
Serializes the data to a JSON writer.
long long int64
Definition: SYS_Types.h:116
PDG_AttributeType
Enumeration of possible attribute types.
void swap(PDG_AttributeGeometry *other)
PDG_AttributeMergeOp
Enumeration of different ways that attributes can be combined.
bool value(Data &geometry, int component) const
virtual bool hash(SYS_HashType &hash_value, exint index, UT_WorkBuffer &errors) const =0
Return a hash value derived from the attribute data.
virtual int64 getMemoryUsage(bool inclusive) const =0
Returns the memory usage of the attribute and its data.
GLuint index
Definition: glcorearb.h:786
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
PDG_AttributeMergeError
Enumerations of errors that can occur when merging attributes.
size_t hash_value(const CH_ChannelRef &ref)
virtual PDG_AttributeData * clone() const =0
Deep copies this attribute.
PDG_AttributeCopyOp
Enumeration of attribute copy operations.