HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pyArg.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_TF_PY_ARG_H
8 #define PXR_BASE_TF_PY_ARG_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/base/tf/api.h"
12 
13 #include "pxr/external/boost/python/dict.hpp"
14 #include "pxr/external/boost/python/tuple.hpp"
15 #include <string>
16 #include <vector>
17 
19 
20 /// \class TfPyArg
21 ///
22 /// Class representing a function argument.
23 ///
24 /// This is similar to \c pxr_boost::python::arg, except it's not opaque and
25 /// provides more fields for documentation purposes.
26 class TfPyArg
27 {
28 public:
29  /// Create a TfPyArg representing an argument with the given \p name.
30  /// \p typeDoc and \p defaultValueDoc are optional documentation strings
31  /// describing the expected type and default value of this argument.
32  TfPyArg(const std::string& name,
33  const std::string& typeDoc = std::string(),
34  const std::string& defaultValueDoc = std::string())
35  : _name(name), _typeDoc(typeDoc), _defaultValueDoc(defaultValueDoc)
36  { }
37 
38  /// Returns argument name.
39  const std::string& GetName() const
40  { return _name; }
41 
42  /// Returns documentation for default value (if any) for this argument.
43  const std::string& GetDefaultValueDoc() const
44  { return _defaultValueDoc; }
45 
46  /// Returns documentation of type of value required by this argument.
47  const std::string& GetTypeDoc() const
48  { return _typeDoc; }
49 
50 private:
51  std::string _name;
52  std::string _typeDoc;
53  std::string _defaultValueDoc;
54 };
55 
56 typedef std::vector<TfPyArg> TfPyArgs;
57 
58 /// Helper function for processing optional arguments given as a tuple of
59 /// positional arguments and a dictionary of keyword arguments.
60 ///
61 /// This function will match the given positional arguments in \p args with
62 /// the ordered list of allowed arguments in \p optionalArgs. Arguments that
63 /// are matched up in this way will be stored as (name, value) pairs and
64 /// merged with \p kwargs in the returned dictionary.
65 ///
66 /// If \p allowExtraArgs is \c false, any unrecognized keyword or positional
67 /// arguments will cause a Python TypeError to be emitted. Otherwise,
68 /// unmatched arguments will be added to the returned tuple or dict.
69 TF_API
70 std::pair<pxr_boost::python::tuple, pxr_boost::python::dict>
72  const pxr_boost::python::tuple& args,
73  const pxr_boost::python::dict& kwargs,
74  const TfPyArgs& expectedArgs,
75  bool allowExtraArgs = false);
76 
77 /// Create a doc string for a function with the given \p functionName,
78 /// \p requiredArguments and \p optionalArguments. An extra \p description
79 /// may also be supplied.
80 TF_API
81 std::string TfPyCreateFunctionDocString(
82  const std::string& functionName,
83  const TfPyArgs& requiredArguments = TfPyArgs(),
84  const TfPyArgs& optionalArguments = TfPyArgs(),
85  const std::string& description = std::string());
86 
88 
89 #endif // PXR_BASE_TF_PY_ARG_H
#define TF_API
Definition: api.h:23
Definition: pyArg.h:26
const std::string & GetDefaultValueDoc() const
Returns documentation for default value (if any) for this argument.
Definition: pyArg.h:43
const std::string & GetTypeDoc() const
Returns documentation of type of value required by this argument.
Definition: pyArg.h:47
std::vector< TfPyArg > TfPyArgs
Definition: pyArg.h:56
TF_API std::pair< pxr_boost::python::tuple, pxr_boost::python::dict > TfPyProcessOptionalArgs(const pxr_boost::python::tuple &args, const pxr_boost::python::dict &kwargs, const TfPyArgs &expectedArgs, bool allowExtraArgs=false)
GLuint const GLchar * name
Definition: glcorearb.h:786
const std::string & GetName() const
Returns argument name.
Definition: pyArg.h:39
TfPyArg(const std::string &name, const std::string &typeDoc=std::string(), const std::string &defaultValueDoc=std::string())
Definition: pyArg.h:32
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
TF_API std::string TfPyCreateFunctionDocString(const std::string &functionName, const TfPyArgs &requiredArguments=TfPyArgs(), const TfPyArgs &optionalArguments=TfPyArgs(), const std::string &description=std::string())
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
**If you just want to fire and args
Definition: thread.h:618