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