7#ifndef PXR_BASE_TF_PY_RESULT_CONVERSIONS_H
8#define PXR_BASE_TF_PY_RESULT_CONVERSIONS_H
14#include "pxr/external/boost/python/tuple.hpp"
15#include "pxr/external/boost/python/list.hpp"
16#include "pxr/external/boost/python/dict.hpp"
20PXR_NAMESPACE_OPEN_SCOPE
22template <
typename T>
struct Tf_PySequenceToListConverter;
23template <
typename T>
struct Tf_PySequenceToSetConverter;
24template <
typename T>
struct Tf_PyMapToDictionaryConverter;
25template <
typename T>
struct Tf_PySequenceToTupleConverter;
26template <
typename First,
typename Second>
struct Tf_PyPairToTupleConverter;
53 typedef Tf_PySequenceToListConverter<T> type;
82 typedef Tf_PySequenceToSetConverter<T> type;
93 typedef Tf_PyMapToDictionaryConverter<T> type;
103 template <
typename T>
105 typedef Tf_PySequenceToTupleConverter<T> type;
112 template <
typename T>
114 typedef Tf_PyPairToTupleConverter<
typename T::first_type,
115 typename T::second_type> type;
120struct Tf_PySequenceToListConverter {
121 typedef std::remove_reference_t<T> SeqType;
122 bool convertible()
const {
125 PyObject *operator()(T seq)
const {
126 return pxr_boost::python::incref(TfPyCopySequenceToList(seq).ptr());
128 PyTypeObject *get_pytype() {
134struct Tf_PySequenceToSetConverter {
135 typedef std::remove_reference_t<T> SeqType;
136 bool convertible()
const {
139 PyObject *operator()(T seq)
const {
142 PyTypeObject *get_pytype() {
148struct Tf_PyMapToDictionaryConverter {
149 typedef std::remove_reference_t<T> SeqType;
152 bool convertible()
const {
155 PyObject *operator()(T seq)
const {
158 PyTypeObject *get_pytype() {
164struct Tf_PySequenceToTupleConverter {
165 typedef std::remove_reference_t<T> SeqType;
166 bool convertible()
const {
169 PyObject *operator()(T seq)
const {
170 return pxr_boost::python::incref(TfPyCopySequenceToTuple(seq).ptr());
172 PyTypeObject *get_pytype() {
173 return &PyTuple_Type;
177template <
typename First,
typename Second>
178struct Tf_PyPairToTupleConverter {
179 typedef std::pair<First, Second> PairType;
180 bool convertible()
const {
183 PyObject *operator()(PairType
const& a)
const {
184 pxr_boost::python::tuple result =
185 pxr_boost::python::make_tuple(a.first, a.second);
186 return pxr_boost::python::incref(result.ptr());
188 PyTypeObject *get_pytype() {
189 return &PyTuple_Type;
193PXR_NAMESPACE_CLOSE_SCOPE
Miscellaneous Utilities for dealing with script.
pxr_boost::python::object TfPyCopySequenceToSet(Seq const &seq)
Create a python set from an iterable sequence.
pxr_boost::python::dict TfPyCopyMapToDictionary(Map const &map)
Creates a python dictionary from a std::map.
A pxr_boost::python result converter generator which converts standard library maps to dictionaries.
A pxr_boost::python result converter generator which converts standard library pairs to tuples.
A pxr_boost::python result converter generator which converts standard library sequences to lists.
A pxr_boost::python result converter generator which converts standard library sequences to sets.
A pxr_boost::python result converter generator which converts standard library sequences to tuples.