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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_BASE_TF_PY_ARG_H
25 #define PXR_BASE_TF_PY_ARG_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/tf/api.h"
29 
30 #include <hboost/python/dict.hpp>
31 #include <hboost/python/tuple.hpp>
32 #include <string>
33 #include <vector>
34 
36 
37 /// \class TfPyArg
38 ///
39 /// Class representing a function argument.
40 ///
41 /// This is similar to \c hboost::python::arg, except it's not opaque and
42 /// provides more fields for documentation purposes.
43 class TfPyArg
44 {
45 public:
46  /// Create a TfPyArg representing an argument with the given \p name.
47  /// \p typeDoc and \p defaultValueDoc are optional documentation strings
48  /// describing the expected type and default value of this argument.
50  const std::string& typeDoc = std::string(),
51  const std::string& defaultValueDoc = std::string())
52  : _name(name), _typeDoc(typeDoc), _defaultValueDoc(defaultValueDoc)
53  { }
54 
55  /// Returns argument name.
56  const std::string& GetName() const
57  { return _name; }
58 
59  /// Returns documentation for default value (if any) for this argument.
61  { return _defaultValueDoc; }
62 
63  /// Returns documentation of type of value required by this argument.
64  const std::string& GetTypeDoc() const
65  { return _typeDoc; }
66 
67 private:
68  std::string _name;
69  std::string _typeDoc;
70  std::string _defaultValueDoc;
71 };
72 
73 typedef std::vector<TfPyArg> TfPyArgs;
74 
75 /// Helper function for processing optional arguments given as a tuple of
76 /// positional arguments and a dictionary of keyword arguments.
77 ///
78 /// This function will match the given positional arguments in \p args with
79 /// the ordered list of allowed arguments in \p optionalArgs. Arguments that
80 /// are matched up in this way will be stored as (name, value) pairs and
81 /// merged with \p kwargs in the returned dictionary.
82 ///
83 /// If \p allowExtraArgs is \c false, any unrecognized keyword or positional
84 /// arguments will cause a Python TypeError to be emitted. Otherwise,
85 /// unmatched arguments will be added to the returned tuple or dict.
86 TF_API
87 std::pair<hboost::python::tuple, hboost::python::dict>
89  const hboost::python::tuple& args,
90  const hboost::python::dict& kwargs,
91  const TfPyArgs& expectedArgs,
92  bool allowExtraArgs = false);
93 
94 /// Create a doc string for a function with the given \p functionName,
95 /// \p requiredArguments and \p optionalArguments. An extra \p description
96 /// may also be supplied.
97 TF_API
99  const std::string& functionName,
100  const TfPyArgs& requiredArguments = TfPyArgs(),
101  const TfPyArgs& optionalArguments = TfPyArgs(),
102  const std::string& description = std::string());
103 
105 
106 #endif // PXR_BASE_TF_PY_ARG_H
#define TF_API
Definition: api.h:40
Definition: pyArg.h:43
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
const std::string & GetDefaultValueDoc() const
Returns documentation for default value (if any) for this argument.
Definition: pyArg.h:60
const std::string & GetTypeDoc() const
Returns documentation of type of value required by this argument.
Definition: pyArg.h:64
TF_API std::pair< hboost::python::tuple, hboost::python::dict > TfPyProcessOptionalArgs(const hboost::python::tuple &args, const hboost::python::dict &kwargs, const TfPyArgs &expectedArgs, bool allowExtraArgs=false)
std::vector< TfPyArg > TfPyArgs
Definition: pyArg.h:73
GLuint const GLchar * name
Definition: glcorearb.h:786
const std::string & GetName() const
Returns argument name.
Definition: pyArg.h:56
TfPyArg(const std::string &name, const std::string &typeDoc=std::string(), const std::string &defaultValueDoc=std::string())
Definition: pyArg.h:49
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
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:91
**If you just want to fire and args
Definition: thread.h:609