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  void setDataType(DataType data_type,
56  bool initialize=false);
57 
58  void setFloatValue(fpreal float_value);
59  void setIntValue(exint int_value);
60  void setBoolValue(bool bool_value);
61  void setStringValue(const char* str_value);
62  void setPythonObjectValue(PY_PyObject* py_value);
63 
64  void setValue(const PDGT_Value& value);
65  void setValue(fpreal float_value);
66  void setValue(exint int_value);
67  void setValue(int int_value);
68  void setValue(bool bool_value);
69  void setValue(const char* str_value);
70  void setValue(PY_PyObject* py_object);
71 
72  void loadValue(
73  const UT_JSONValue& json_value,
74  DataType data_type);
75 
76  bool valid() const;
77  DataType dataType() const;
78 
79  fpreal floatValue() const;
80  exint intValue() const;
81  bool boolValue() const;
82  const UT_StringHolder& stringValue() const;
83  PY_PyObject* pyObjectValue() const;
84 
85  void value(fpreal& value) const;
86  void value(exint& value) const;
87  void value(int& value) const;
88  void value(bool& value) const;
89  void value(UT_StringHolder& value) const;
90 
91  UT_StringHolder valueAsString(bool quoted=true) const;
92  void valueAsString(UT_WorkBuffer& buffer,
93  bool quoted=true) const;
94  void valueToJSON(UT_JSONWriter& writer) const;
95 
96  static void fromJSONArray(
97  Array& value_array,
98  const UT_JSONValueArray& json_array,
99  DataType data_type);
100 
101 private:
102  void freePyObject();
103  void replacePyObject(PY_PyObject* other);
104 
105 private:
106  union PODData
107  {
108  fpreal myFloatValue;
109  exint myIntValue;
110  PY_PyObject* myPyObjectValue;
111  };
112 
113  UT_StringHolder myStringValue;
114  PODData myData;
115  DataType myDataType;
116 };
117 
118 namespace UT
119 {
120  template <typename T>
121  struct DefaultClearer;
122 
123  template <>
125  {
126  static void clear(PDGT_Value& value)
128  static bool isClear(const PDGT_Value& value)
129  { return value.valid(); }
130  static void clearConstruct(PDGT_Value *p)
131  { new ((void *)p) PDGT_Value(); }
132  static const bool clearNeedsDestruction = false;
133  };
134 }
135 
136 #endif /* __PDGT_VALUE_H__ */
#define PDGT_API
Definition: PDGT_API.h:23
Definition: ImfArray.h:47
static void clearConstruct(PDGT_Value *p)
Definition: PDGT_Value.h:130
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
bool valid() const
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
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
static bool isClear(const PDGT_Value &value)
Definition: PDGT_Value.h:128
Definition: core.h:1131
type
Definition: core.h:1059
HUSD_API const char * dataType()
static void clear(PDGT_Value &value)
Definition: PDGT_Value.h:126