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  Package
32 };
33 
34 // Registration status
35 enum class RegisterStatus : short
36 {
37  Invalid = 0,
38  Registered,
39  Waiting
40 };
41 
42 // Enum used to report registration/unregistration status
43 enum class Status : unsigned
44 {
46  InUse,
47  NoError,
48  NoFactory,
54  Success,
58 };
59 
61 {
62  // Callback event types. This enum is used for mapping user callbacks to
63  // various viewer state and handle operations
64  enum class Type : short
65  {
66  None = 0,
67  OnEnter,
68  OnExit,
70  OnRegister,
71  OnReload,
72  OnResume,
75  OnGenerate,
78  OnPreEnter,
79  OnActivate,
81  OnLoad,
82  OnUnload
83  };
84 
85  enum class DeliveryMode : unsigned
86  {
87  Immediate = 0,
88  Queue
89  };
90 
91  struct Data
92  {
93  struct Elem
94  {
96 
97  Elem() : myExprFlag(false), myDoubleQuoteFormat(false)
98  {
99  }
100 
101  Elem(char const * key, Value const & value, bool expr, bool double_quote)
102  {
103  myKey = key;
104  myValue = value;
105  myExprFlag = expr;
106  myDoubleQuoteFormat = double_quote;
107  }
108 
109  ~Elem() = default;
110 
115  };
116 
118 
119  Data() : myDeliveryMode(EventMessage::DeliveryMode::Queue)
120  {
121  }
122 
123  ~Data() = default;
124 
125  void add(char const * key, Elem::Value const & value)
126  {
127  myDataArray.append(Elem(key,value,false,false));
128  }
129 
130  void add(char const * key, char const * value, bool double_quote)
131  {
132  UT_String value_str(value);
133  value_str.substitute("\\","\\\\");
134  value_str.substitute("\n","\\n");
135  value_str.substitute("\"","\\\"");
136  value_str.substitute("\'","\\\'");
137 
138  myDataArray.append(Elem(key,Elem::Value(value_str.c_str()),false,double_quote));
139  }
140 
141  void addExpr(char const * key, char const * value)
142  {
143  myDataArray.append(Elem(key,Elem::Value(value),true,false));
144  }
145 
146  void addStateType( char const * value, bool double_quote=false)
147  {
148  add("state_type", value, double_quote);
149  }
150 
151  void addStateLabel( char const * value, bool double_quote=false)
152  {
153  add("state_label", value, double_quote);
154  }
155 
156  void addHandleType( char const * value, bool double_quote=false)
157  {
158  add("handle_type", value, double_quote);
159  }
160 
161  void addHandleLabel( char const * value, bool double_quote=false)
162  {
163  add("handle_label", value, double_quote);
164  }
165 
166  void addPackageName( char const * value, bool double_quote=false)
167  {
168  add("package_name", value, double_quote);
169  }
170 
171  void addPackageFilepath( char const * value, bool double_quote=false)
172  {
173  add("package_filepath", value, double_quote);
174  }
175 
176  void addMessage( char const * value, bool double_quote=false)
177  {
178  add("event_message", value, double_quote);
179  addExpr("event_message_type","hou.severityType.Message");
180  }
181 
182  void addImportantMessage( char const * value, bool double_quote=false)
183  {
184  add("event_message", value, double_quote);
185  addExpr("event_message_type","hou.severityType.ImportantMessage");
186  }
187 
188  void addWarning( char const * value, bool double_quote=false)
189  {
190  add("event_message", value, double_quote);
191  addExpr("event_message_type","hou.severityType.Warning");
192  }
193 
194  void addError( char const * value, bool double_quote=false)
195  {
196  add("event_message", value, double_quote);
197  addExpr("event_message_type","hou.severityType.Error");
198  }
199 
200  void addFatal( char const * value, bool double_quote=false )
201  {
202  add("event_message", value, double_quote);
203  addExpr("event_message_type","hou.severityType.Fatal");
204  }
205 
207  {
208  myDeliveryMode = mode;
209  }
210 
212  {
213  return myDeliveryMode;
214  }
215 
216  Array const & values() const
217  {
218  return myDataArray;
219  }
220 
221  private:
222  Array myDataArray;
223  EventMessage::DeliveryMode myDeliveryMode;
224  };
225 
227  : myType(type)
228  , myKwargs("{}")
229  {
230  }
231 
233  : myType(Type::None)
234  , myKwargs("{}")
235  {
236  }
237  ~EventMessage() = default;
238 
241 };
242 
243 // Convert any to requested type
244 template <typename T> T
246 {
247  if (typeid(int) == any.type())
248  {
249  return static_cast<T>(hboost::any_cast<int>(any));
250  }
251  else if (typeid(double) == any.type())
252  {
253  return static_cast<T>(hboost::any_cast<double>(any));
254  }
255  else if (typeid(bool) == any.type())
256  {
257  return static_cast<T>(hboost::any_cast<bool>(any));
258  }
259  return T(0);
260 }
261 
262 template <> inline std::string
264 {
265  if (typeid(std::string) == any.type())
266  {
267  return hboost::any_cast<std::string>(any);
268  }
269  else if (typeid(int) == any.type())
270  {
271  return std::to_string(hboost::any_cast<int>(any));
272  }
273  else if (typeid(double) == any.type())
274  {
275  return std::to_string(hboost::any_cast<double>(any));
276  }
277  else if (typeid(bool) == any.type())
278  {
279  return std::to_string(hboost::any_cast<bool>(any));
280  }
281  return std::string();
282 }
283 
284 template <> inline int
286 {
287  if (typeid(int) == any.type())
288  {
289  return hboost::any_cast<int>(any);
290  }
291  else if (typeid(bool) == any.type())
292  {
293  return (int)hboost::any_cast<bool>(any);
294  }
295  return 0;
296 }
297 
298 } // PI_PythonResource
299 
300 
301 #endif // PI_PythonResourceTypes_H
void addStateLabel(char const *value, bool double_quote=false)
Definition: ImfArray.h:47
auto to_string(const T &value) -> std::string
Definition: format.h:2597
void add(char const *key, Elem::Value const &value)
int substitute(const char *find, const char *replacement, int count=-1)
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
GLsizei const GLfloat * value
Definition: glcorearb.h:824
Elem(char const *key, Value const &value, bool expr, bool double_quote)
const char * c_str() const
Definition: UT_String.h:508
bool any(const vbool4 &v)
Definition: simd.h:3468
void setDeliveryMode(EventMessage::DeliveryMode mode)
void addMessage(char const *value, bool double_quote=false)
void addImportantMessage(char const *value, bool double_quote=false)
void addWarning(char const *value, bool double_quote=false)
void addFatal(char const *value, bool double_quote=false)
exint append()
Definition: UT_Array.h:142
void addHandleType(char const *value, bool double_quote=false)
GLenum mode
Definition: glcorearb.h:99
void addError(char const *value, bool double_quote=false)
void addPackageName(char const *value, bool double_quote=false)
T anyToType(hboost::any const &any)
void addStateType(char const *value, bool double_quote=false)
void add(char const *key, char const *value, bool double_quote)
Definition: core.h:1131
void addExpr(char const *key, char const *value)
type
Definition: core.h:1059
void addPackageFilepath(char const *value, bool double_quote=false)
void addHandleLabel(char const *value, bool double_quote=false)