HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PI_PythonResourceTypes.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  * NAME:
7  *
8  * COMMENTS:
9  *
10  * Various enums and types, etc... related to viewer states and
11  * viewer handles.
12  */
13 
14 #ifndef PI_PythonResourceTypes_H
15 #define PI_PythonResourceTypes_H
16 
17 #include "PI_API.h"
18 #include <UT/UT_PackageUtils.h>
19 
20 namespace PI_PythonResource
21 {
22 
24 
25 // Resource type
26 enum class ResourceType : short
27 {
28  NoType = 0,
31 };
32 
33 // Registration status
34 enum class RegisterStatus : short
35 {
36  Invalid = 0,
37  Registered,
38  Waiting
39 };
40 
41 // Enum used to report registration/unregistration status
42 enum class Status : unsigned
43 {
45  InUse,
46  NoError,
47  NoFactory,
53  Success,
57 };
58 
60 {
61  // Callback event types. This enum is used for mapping user callbacks to
62  // various viewer state and handle operations
63  enum class Type : short
64  {
65  None = 0,
66  OnEnter,
67  OnExit,
69  OnRegister,
70  OnReload,
71  OnResume,
74  OnGenerate,
77  OnPreEnter,
78  OnActivate,
80  };
81 
82  enum class DeliveryMode : unsigned
83  {
84  Immediate = 0,
85  Queue
86  };
87 
88  struct Data
89  {
90  struct Elem
91  {
93 
94  Elem() : myExprFlag(false), myDoubleQuoteFormat(false)
95  {
96  }
97 
98  Elem(char const * key, Value const & value, bool expr, bool double_quote)
99  {
100  myKey = key;
101  myValue = value;
102  myExprFlag = expr;
103  myDoubleQuoteFormat = double_quote;
104  }
105 
106  ~Elem() = default;
107 
112  };
113 
115 
116  Data() : myDeliveryMode(EventMessage::DeliveryMode::Queue)
117  {
118  }
119 
120  ~Data() = default;
121 
122  void add(char const * key, Elem::Value const & value)
123  {
124  myDataArray.append(Elem(key,value,false,false));
125  }
126 
127  void add(char const * key, char const * value, bool double_quote)
128  {
129  myDataArray.append(Elem(key,Elem::Value(value),false,double_quote));
130  }
131 
132  void addExpr(char const * key, char const * value)
133  {
134  myDataArray.append(Elem(key,Elem::Value(value),true,false));
135  }
136 
137  void addStateType( char const * value )
138  {
139  add("state_type", value, false);
140  }
141 
142  void addStateLabel( char const * value )
143  {
144  add("state_label", value, false);
145  }
146 
147  void addHandleType( char const * value )
148  {
149  add("handle_type", value, false);
150  }
151 
152  void addHandleLabel( char const * value )
153  {
154  add("handle_label", value, false);
155  }
156 
157  void addMessage( char const * value )
158  {
159  add("event_message", value, true);
160  addExpr("event_message_type","hou.severityType.Message");
161  }
162 
163  void addWarning( char const * value )
164  {
165  add("event_message", value, true);
166  addExpr("event_message_type","hou.severityType.Warning");
167  }
168 
169  void addError( char const * value )
170  {
171  add("event_message", value, true);
172  addExpr("event_message_type","hou.severityType.Error");
173  }
174 
176  {
177  myDeliveryMode = mode;
178  }
179 
181  {
182  return myDeliveryMode;
183  }
184 
185  Array const & values() const
186  {
187  return myDataArray;
188  }
189 
190  private:
191  Array myDataArray;
192  EventMessage::DeliveryMode myDeliveryMode;
193  };
194 
196  : myType(type)
197  , myKwargs("{}")
198  {
199  }
200 
202  : myType(Type::None)
203  , myKwargs("{}")
204  {
205  }
206  ~EventMessage() = default;
207 
210 };
211 
212 // Convert any to requested type
213 template <typename T> T
215 {
216  if (typeid(int) == any.type())
217  {
218  return static_cast<T>(hboost::any_cast<int>(any));
219  }
220  else if (typeid(double) == any.type())
221  {
222  return static_cast<T>(hboost::any_cast<double>(any));
223  }
224  else if (typeid(bool) == any.type())
225  {
226  return static_cast<T>(hboost::any_cast<bool>(any));
227  }
228  return T(0);
229 }
230 
231 template <> inline std::string
233 {
234  if (typeid(std::string) == any.type())
235  {
236  return hboost::any_cast<std::string>(any);
237  }
238  else if (typeid(int) == any.type())
239  {
240  return std::to_string(hboost::any_cast<int>(any));
241  }
242  else if (typeid(double) == any.type())
243  {
244  return std::to_string(hboost::any_cast<double>(any));
245  }
246  else if (typeid(bool) == any.type())
247  {
248  return std::to_string(hboost::any_cast<bool>(any));
249  }
250  return std::string();
251 }
252 
253 template <> inline int
255 {
256  if (typeid(int) == any.type())
257  {
258  return hboost::any_cast<int>(any);
259  }
260  else if (typeid(bool) == any.type())
261  {
262  return (int)hboost::any_cast<bool>(any);
263  }
264  return 0;
265 }
266 
267 } // PI_PythonResource
268 
269 
270 #endif // PI_PythonResourceTypes_H
Definition: ImfArray.h:77
void add(char const *key, Elem::Value const &value)
GLenum mode
Definition: glew.h:2163
Elem(char const *key, Value const &value, bool expr, bool double_quote)
bool any(const vbool4 &v)
Definition: simd.h:3372
void setDeliveryMode(EventMessage::DeliveryMode mode)
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
exint append()
Definition: UT_Array.h:95
GLsizei const GLchar *const * string
Definition: glew.h:1844
std::string to_string(const T &value)
Definition: format.h:3363
T anyToType(hboost::any const &any)
void add(char const *key, char const *value, bool double_quote)
void addExpr(char const *key, char const *value)
GLsizei const GLfloat * value
Definition: glew.h:1849