24#ifndef PXR_BASE_TF_PY_RESULT_CONVERSIONS_H
25#define PXR_BASE_TF_PY_RESULT_CONVERSIONS_H
31#include <boost/python/tuple.hpp>
32#include <boost/python/list.hpp>
33#include <boost/python/dict.hpp>
37PXR_NAMESPACE_OPEN_SCOPE
39template <
typename T>
struct Tf_PySequenceToListConverter;
40template <
typename T>
struct Tf_PySequenceToSetConverter;
41template <
typename T>
struct Tf_PyMapToDictionaryConverter;
42template <
typename T>
struct Tf_PySequenceToTupleConverter;
43template <
typename First,
typename Second>
struct Tf_PyPairToTupleConverter;
70 typedef Tf_PySequenceToListConverter<T> type;
99 typedef Tf_PySequenceToSetConverter<T> type;
108 template <
typename T>
110 typedef Tf_PyMapToDictionaryConverter<T> type;
120 template <
typename T>
122 typedef Tf_PySequenceToTupleConverter<T> type;
129 template <
typename T>
131 typedef Tf_PyPairToTupleConverter<
typename T::first_type,
132 typename T::second_type> type;
137struct Tf_PySequenceToListConverter {
138 typedef std::remove_reference_t<T> SeqType;
139 bool convertible()
const {
142 PyObject *operator()(T seq)
const {
143 return boost::python::incref(TfPyCopySequenceToList(seq).ptr());
145 PyTypeObject *get_pytype() {
151struct Tf_PySequenceToSetConverter {
152 typedef std::remove_reference_t<T> SeqType;
153 bool convertible()
const {
156 PyObject *operator()(T seq)
const {
159 PyTypeObject *get_pytype() {
165struct Tf_PyMapToDictionaryConverter {
166 typedef std::remove_reference_t<T> SeqType;
169 bool convertible()
const {
172 PyObject *operator()(T seq)
const {
175 PyTypeObject *get_pytype() {
181struct Tf_PySequenceToTupleConverter {
182 typedef std::remove_reference_t<T> SeqType;
183 bool convertible()
const {
186 PyObject *operator()(T seq)
const {
187 return boost::python::incref(TfPyCopySequenceToTuple(seq).ptr());
189 PyTypeObject *get_pytype() {
190 return &PyTuple_Type;
194template <
typename First,
typename Second>
195struct Tf_PyPairToTupleConverter {
196 typedef std::pair<First, Second> PairType;
197 bool convertible()
const {
200 PyObject *operator()(PairType
const& a)
const {
201 boost::python::tuple result =
202 boost::python::make_tuple(a.first, a.second);
203 return boost::python::incref(result.ptr());
205 PyTypeObject *get_pytype() {
206 return &PyTuple_Type;
210PXR_NAMESPACE_CLOSE_SCOPE
Miscellaneous Utilities for dealing with script.
boost::python::dict TfPyCopyMapToDictionary(Map const &map)
Creates a python dictionary from a std::map.
boost::python::object TfPyCopySequenceToSet(Seq const &seq)
Create a python set from an iterable sequence.
A boost::python result converter generator which converts standard library maps to dictionaries.
A boost::python result converter generator which converts standard library pairs to tuples.
A boost::python result converter generator which converts standard library sequences to lists.
A boost::python result converter generator which converts standard library sequences to sets.
A boost::python result converter generator which converts standard library sequences to tuples.