HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PY_Kwargs.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  */
7 
8 #ifndef PY_Kwargs_H
9 #define PY_Kwargs_H
10 
11 #include "PY_API.h"
12 #include "PY_Result.h"
13 
14 #include <UT/UT_StringHolder.h>
15 #include <UT/UT_WorkBuffer.h>
16 
17 class PY_PyObject;
18 
20 {
21  public:
23 
24  // Keyword argument builder
25  // ------------------------
26  // The builder is used for adding entries to a json dictionary. It
27  // then generates a string representation of the dictionary usable
28  // in a python script.
29  struct PY_API Expr
30  {
31  Expr() = default;
32 
33  Expr(UT_StringRef const& val) : myStr(val)
34  {
35  }
36 
37  const char* c_str() const
38  {
39  return myStr.c_str();
40  }
41 
43  };
44 
45  PY_Kwargs( UT_StringRef const & fmt = "{'args':{%s}}");
46  ~PY_Kwargs() = default;
47 
48  PY_Kwargs(PY_Kwargs && other);
49  PY_Kwargs(PY_Kwargs const& other) = default;
50 
51  void add(char const * key, PY_Kwargs const & value);
52 
53  // Add a string entry to the dictionary.
54  // Note: single quote is specified by default to format the
55  // value. Fouble quotes are used for enclosing strings
56  // containing single quotes.
57  //
58  // yes: add('key', "'single_quote_string'", true);
59  // out: "{'key' : "'single_quote_string'"}
60  //
61  // no: add('key', "'single_quote_string'", false);
62  // out: "{'key' : ''single_quote_string''}
63  // this string will cause a syntax error in python
64  void add(char const * key, char const * value, bool use_double_quote=false);
65  void addUIEvent(char const * key, int64 value);
66  void add(char const * key, Expr const & value);
67  void add(char const * key, UT_Vector3 const & value);
68  void add(char const * key, UT_Vector3D const & value);
69  void add(char const * key, UT_Vector4 const & value);
70  void add(char const * key, UT_Vector4D const & value);
71  void add(char const * key, int value);
72  void add(char const * key, int64 value);
73  void add(char const * key, float value);
74  void add(char const * key, fpreal64 value);
75  void addBool(char const * key, int value);
76 
77  // Add a formatted expression entry that takes an int64 value as argument.
78  // e.g. "hou.GeometryDrawable(%s)".
79  // addExpr doesn't do any validation on the value argument.
80  void addExpr(char const * key, char const * expr, int64 value);
81 
82  // adds a hou.GeometrySelection entry. sinfo_address is a
83  // pointer to a OP3D_ScriptSelectStateInfoPtr instance
84  void addGeometrySelection(char const * key, int64 sinfo_address);
85 
86  // adds a hou.ui.nodes() entry. nodelist_address is a pointer
87  // to a OP_NodeList instance.
88  void addNodeList(char const * key, int64 nodelist_address);
89 
90  // Adds HOM dynamic objects entry. sinfo_address is a pointer
91  // to a OP3D_ScriptSelectStateInfoPtr instance
92  void addDynDetails(char const * key, int64 sinfo_address);
93  void addDynPoints(char const * key, int64 sinfo_address);
94  void addDynPolygons(char const * key, int64 sinfo_address);
95 
96  void addPYObject(const char* key, void* value);
97  void addPYObject(const char* key, PY_PyObject const* value);
98 
99  // append the content of an existing PY_Kwargs to this one
100  void append(PY_Kwargs const & other);
101 
102  // Evaluate a specific dictionary entry
103  PY_Result evaluate(const char* key, PY_Result::Type desired_result_type) const;
104 
105  PyObjectMap const & pyObjectMap() const;
106  PyObjectMap & pyObjectMap();
107 
108  operator UT_StringHolder () const
109  {
110  return value();
111  }
112 
114  {
116  value.sprintf( myOutputFormat.c_str(), myStr.c_str() );
117 
118  return UT_StringHolder(std::move(value));
119  }
120 
121  void setOutputFormat(UT_StringRef const & out_format);
122 
123  // Reset the Kwargs content with a kwargs value string
124  // representation.
125  void reset(UT_StringHolder const& kwargs_value);
126 
127  protected:
128  UT_StringHolder format(char const * value_fmt);
129  UT_StringHolder make(char const * fmt, char const * key, char const * val);
130 
133  size_t myCount;
135 };
136 
137 #endif // PY_Kwargs_H
Expr(UT_StringRef const &val)
Definition: PY_Kwargs.h:33
UT_StringHolder value() const
Definition: PY_Kwargs.h:113
GLsizei const GLfloat * value
Definition: glcorearb.h:824
size_t myCount
Definition: PY_Kwargs.h:133
UT_StringHolder myStr
Definition: PY_Kwargs.h:131
double fpreal64
Definition: SYS_Types.h:201
GLboolean reset
Definition: glad.h:5138
const char * c_str() const
Definition: PY_Kwargs.h:37
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
PY_PyObject
#define PY_API
Definition: PY_API.h:10
long long int64
Definition: SYS_Types.h:116
UT_StringHolder myOutputFormat
Definition: PY_Kwargs.h:132
int sprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
GLuint GLfloat * val
Definition: glcorearb.h:1608
UT_StringHolder myStr
Definition: PY_Kwargs.h:42
Definition: core.h:1131
ImageBuf OIIO_API add(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
PyObjectMap myPyObjectMap
Definition: PY_Kwargs.h:134