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 PY_PyObject;
19 
20 class UT_JSONValue;
21 class UT_JSONWriter;
22 class UT_StringHolder;
23 
24 /**
25  * Attribute that contains a single PY_PyObject*, mostly opaque in C++ code but
26  * accessible from the Python API.
27  */
29 {
30 public:
32 
33  using Data = PY_PyObject*;
36 
37 public:
39  explicit PDG_AttributePyObject(PY_PyObject* object);
40  ~PDG_AttributePyObject() override;
41 
42  int64 getMemoryUsage(bool inclusive) const override;
44  UT_WorkBuffer& errors) const override;
45  PDG_AttributeData* clone() const override;
46  bool saveData(UT_JSONWriter& writer) const override;
47  bool loadData(const UT_JSONValue& value) override;
48  bool compare(
49  const PDG_AttributeData* other
50  ) const override;
52  PDG_AttributeMergeOp merge_op,
53  int stride) override;
54 
56  const UT_StringHolder& str,
57  int component) const;
59  const UT_StringHolder& str,
60  int component) const;
61  PY_PyObject* query(const UT_StringHolder& str) const;
62  bool setObjectFromString(const UT_StringHolder& repr);
63 
64  PY_PyObject* object() const;
65  void setObject(PY_PyObject* object);
66 
67  inline bool hasData() const
68  {
69  return (myObject != nullptr);
70  }
71 
72  inline int size() const
73  {
74  return 1;
75  }
76 
77  inline bool valid(int component) const
78  {
79  return (component == 0);
80  }
81 
82  inline bool value(PY_PyObject*& object, int component) const
83  {
84  if (component != 0)
85  return false;
86 
87  object = myObject;
88  return true;
89  }
90 
91  inline void setValue(PY_PyObject* object, int index)
92  {
93  setObject(object);
94  }
95 
96  bool repr(UT_WorkBuffer& str) const;
97  bool repr(UT_StringHolder& str) const;
98  bool str(UT_StringHolder& str) const;
99 
100  inline void swap(PDG_AttributePyObject* other)
101  {
102  std::swap(myObject, other->myObject);
103  }
104 
105  void copy(const PDG_AttributePyObject* other);
106 
107 private:
108  PY_PyObject* queryInternal(const UT_StringHolder& str,
109  int component) const;
110  static PY_PyObject* getItem(PY_PyObject* source,
111  const UT_StringHolder& key);
112  static PY_PyObject* getItem(PY_PyObject* source, int key);
113 
114  static PDG_AttributeCast
115  castValue(fpreal& value, PY_PyObject* object);
116  static PDG_AttributeCast
117  castValue(UT_WorkBuffer& value,
118  PY_PyObject* object);
119 private:
120  PY_PyObject* myObject;
121 };
122 
123 #endif
GLenum query
Definition: glad.h:2772
A single, opaque PyObject.
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:1631
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_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.
PDG_AttributeType
Enumeration of possible attribute types.
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
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.