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