HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_AttributePyObject.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_PY_OBJECT_H__
10 #define __PDG_ATTRIBUTE_PY_OBJECT_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_AttributeData.h"
15 
16 #include <UT/UT_StringMap.h>
17 
18 class PDG_AttributeQuery;
19 class PY_PyObject;
20 class UT_JSONValue;
21 class UT_JSONWriter;
22 class UT_OptionsHolder;
23 class UT_StringHolder;
24 
25 /**
26  * Attribute that contains a single PY_PyObject*, mostly opaque in C++ code but
27  * accessible from the Python API.
28  */
30 {
31 public:
33 
34  using Data = PY_PyObject*;
37 
38 public:
40  explicit PDG_AttributePyObject(PY_PyObject* object);
41  ~PDG_AttributePyObject() override;
42 
43  int64 getMemoryUsage(bool inclusive) const override;
45  UT_WorkBuffer& errors) const override;
46  PDG_AttributeData* clone() const override;
47 
48  bool saveData(UT_JSONWriter& writer) const override;
49  void saveData(
50  const UT_StringHolder& key,
51  UT_OptionsHolder& dict) const override;
52 
53  bool loadData(const UT_JSONValue& value) override;
54  bool loadData(
55  const UT_StringHolder& key,
56  const UT_OptionsHolder& dict) override;
57 
58  bool compare(
59  const PDG_AttributeData* other
60  ) const override;
62  PDG_AttributeMergeOp merge_op,
63  int stride) override;
64 
66  fpreal& value,
68  int component) const;
70  fpreal& value,
71  const UT_StringHolder& str,
72  int component) const;
73 
77  int component) const;
80  const UT_StringHolder& str,
81  int component) const;
82 
83  PY_PyObject* query(const UT_StringHolder& str) const;
84 
85  bool setObjectFromString(const UT_StringHolder& repr);
86 
87  PY_PyObject* object() const;
88  void setObject(PY_PyObject* object);
89 
90  inline bool hasData() const
91  {
92  return (myObject != nullptr);
93  }
94 
95  inline int size() const
96  {
97  return 1;
98  }
99 
100  inline bool valid(int component) const
101  {
102  return (component == 0);
103  }
104 
105  inline bool value(PY_PyObject*& object, int component) const
106  {
107  if (component != 0)
108  return false;
109 
110  object = myObject;
111  return true;
112  }
113 
114  inline void setValue(PY_PyObject* object, int index)
115  {
116  setObject(object);
117  }
118 
119  bool repr(UT_WorkBuffer& str) const;
120  bool repr(UT_StringHolder& str) const;
121  bool str(UT_StringHolder& str) const;
122 
123  inline void swap(PDG_AttributePyObject* other)
124  {
125  std::swap(myObject, other->myObject);
126  }
127 
128  void copy(const PDG_AttributePyObject* other);
129 
130 private:
131  void serializationRepr(
132  UT_StringHolder& object_repr) const;
133  PY_PyObject* queryInternal(
134  const PDG_AttributeQuery& query,
135  int component) const;
136  static PY_PyObject* getItem(PY_PyObject* source,
137  const UT_StringHolder& key);
138  static PY_PyObject* getItem(PY_PyObject* source, int key);
139 
140  static PDG_AttributeCast
141  castValue(fpreal& value, PY_PyObject* object);
142  static PDG_AttributeCast
143  castValue(UT_WorkBuffer& value,
144  PY_PyObject* object);
145 private:
146  PY_PyObject* myObject;
147 };
148 
149 #endif
GLenum query
Definition: glad.h:2772
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:1639
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
virtual bool compare(const PDG_AttributeData *) const =0
Compares this data object with another data object.
#define PDG_API
Definition: PDG_API.h:23
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
void setValue(PY_PyObject *object, int index)
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.
PDG_AttributeCast
Enumeration of attribute cast results.
PY_PyObject
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
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.
PDG_AttributeMergeOp
Enumeration of different ways that attributes can be combined.
virtual bool hash(SYS_HashType &hash_value, 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.
fpreal64 fpreal
Definition: SYS_Types.h:277
GLuint index
Definition: glcorearb.h:786
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
A single, opaque PyObject.
PDG_AttributeMergeError
Enumerations of errors that can occur when merging attributes.
Definition: core.h:1131
void swap(PDG_AttributePyObject *other)
bool value(PY_PyObject *&object, int component) const
size_t hash_value(const CH_ChannelRef &ref)
virtual PDG_AttributeData * clone() const =0
Deep copies this attribute.