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