HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDGT_Value.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 __PDGT_VALUE_H__
10 #define __PDGT_VALUE_H__
11 
12 #include "PDGT_API.h"
13 
14 #include <UT/UT_ArrayStringMap.h>
15 #include <UT/UT_StringHolder.h>
16 
17 class PY_PyObject;
18 class UT_JSONValue;
19 class UT_JSONValueArray;
20 class UT_JSONWriter;
21 class UT_WorkBuffer;
22 
24 {
25 public:
28 
29  enum DataType
30  {
35  eInvalid
36  };
37 
38  static UT_StringHolder getDataTypeAsString(DataType type);
39 
40 public:
41  PDGT_Value();
42  PDGT_Value(const PDGT_Value& other);
43 
44  PDGT_Value(fpreal float_value);
45  PDGT_Value(exint int_value);
46  PDGT_Value(bool bool_value);
47  PDGT_Value(int int_value);
48  PDGT_Value(const char* str_value);
49  PDGT_Value(PY_PyObject* py_value);
50 
51  ~PDGT_Value();
52 
53  PDGT_Value& operator=(const PDGT_Value& other);
54 
55  bool operator==(const PDGT_Value& other) const;
56  bool operator!=(const PDGT_Value& other) const;
57 
58  void setDataType(DataType data_type,
59  bool initialize=false);
60 
61  void setFloatValue(fpreal float_value);
62  void setIntValue(exint int_value);
63  void setBoolValue(bool bool_value);
64  void setStringValue(const char* str_value);
65  void setPythonObjectValue(PY_PyObject* py_value);
66 
67  void setValue(const PDGT_Value& value);
68  void setValue(fpreal float_value);
69  void setValue(exint int_value);
70  void setValue(int int_value);
71  void setValue(bool bool_value);
72  void setValue(const char* str_value);
73  void setValue(PY_PyObject* py_object);
74 
75  void loadValue(
76  const UT_JSONValue& json_value,
77  DataType data_type);
78 
79  bool valid() const;
80  DataType dataType() const;
81 
82  fpreal floatValue() const;
83  exint intValue() const;
84  bool boolValue() const;
85  const UT_StringHolder& stringValue() const;
86  PY_PyObject* pyObjectValue() const;
87 
88  void value(fpreal& value) const;
89  void value(exint& value) const;
90  void value(int& value) const;
91  void value(bool& value) const;
92  void value(UT_StringHolder& value) const;
93 
94  UT_StringHolder valueAsString(bool quoted=true) const;
95  void valueAsString(UT_WorkBuffer& buffer,
96  bool quoted=true) const;
97  void valueToJSON(UT_JSONWriter& writer) const;
98 
99  static void fromJSONArray(
100  Array& value_array,
101  const UT_JSONValueArray& json_array,
102  DataType data_type);
103 
104 private:
105  void freePyObject();
106  void replacePyObject(PY_PyObject* other);
107 
108 private:
109  union PODData
110  {
111  fpreal myFloatValue;
112  exint myIntValue;
113  PY_PyObject* myPyObjectValue;
114  };
115 
116  UT_StringHolder myStringValue;
117  PODData myData;
118  DataType myDataType;
119 };
120 
121 namespace UT
122 {
123  template <typename T>
124  struct DefaultClearer;
125 
126  template <>
128  {
129  static void clear(PDGT_Value& value)
131  static bool isClear(const PDGT_Value& value)
132  { return value.valid(); }
133  static void clearConstruct(PDGT_Value *p)
134  { new ((void *)p) PDGT_Value(); }
135  static const bool clearNeedsDestruction = false;
136  };
137 }
138 
139 #endif /* __PDGT_VALUE_H__ */
#define PDGT_API
Definition: PDGT_API.h:23
Definition: ImfArray.h:45
static void clearConstruct(PDGT_Value *p)
Definition: PDGT_Value.h:133
GLsizei const GLfloat * value
Definition: glcorearb.h:824
UT_JSONValueArray stores a list of UT_JSONValue objects.
int64 exint
Definition: SYS_Types.h:125
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
__hostdev__ void setValue(uint32_t offset, bool v)
Definition: NanoVDB.h:5750
bool valid() const
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
Definition: core.h:760
PY_PyObject
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
void setDataType(DataType data_type, bool initialize=false)
fpreal64 fpreal
Definition: SYS_Types.h:277
LeafData & operator=(const LeafData &)=delete
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
static bool isClear(const PDGT_Value &value)
Definition: PDGT_Value.h:131
Definition: core.h:1131
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
type
Definition: core.h:1059
HUSD_API const char * dataType()
static void clear(PDGT_Value &value)
Definition: PDGT_Value.h:129