24 #ifndef PXR_BASE_VT_VALUE_FROM_PYTHON_H
25 #define PXR_BASE_VT_VALUE_FROM_PYTHON_H
50 return !_GetInstance()._lvalueExtractors.empty() &&
51 !_GetInstance()._rvalueExtractors.empty();
59 TF_FATAL_ERROR(
"Tried to register a VtValue from python conversion "
60 "but python is not initialized!");
62 _GetInstance()._RegisterLValue(_Extractor::MakeLValue<T>());
64 _GetInstance()._RegisterRValue(_Extractor::MakeRValue<T>());
83 using _ExtractFunc =
VtValue (*)(PyObject *);
89 static VtValue _ExtractLValue(PyObject *);
95 static VtValue _ExtractRValue(PyObject *);
100 static _Extractor MakeLValue() {
101 return _Extractor(&_ExtractLValue<T>);
105 static _Extractor MakeRValue() {
106 return _Extractor(&_ExtractRValue<T>);
110 return _extract(obj);
114 explicit _Extractor(_ExtractFunc
extract) : _extract(extract) {}
116 _ExtractFunc _extract;
123 VT_API void _RegisterLValue(_Extractor
const &e);
124 VT_API void _RegisterRValue(_Extractor
const &e);
126 std::vector<_Extractor> _lvalueExtractors;
127 std::vector<_Extractor> _rvalueExtractors;
130 _LValueExtractorCache _lvalueExtractorCache;
137 VtValue Vt_ValueFromPythonRegistry::
138 _Extractor::_ExtractLValue(PyObject *obj) {
139 hboost::python::extract<T &>
x(obj);
146 VtValue Vt_ValueFromPythonRegistry::
147 _Extractor::_ExtractRValue(PyObject *obj) {
148 hboost::python::extract<T>
x(obj);
156 Vt_ValueFromPythonRegistry::Register<T>(
true);
161 Vt_ValueFromPythonRegistry::Register<T>(
false);
166 #endif // PXR_BASE_VT_VALUE_FROM_PYTHON_H
TF_API bool TfPyIsInitialized()
Returns true if python is initialized.
static VT_API VtValue Invoke(PyObject *obj)
OIIO_FORCEINLINE bool extract(const vbool4 &a)
static void Register(bool registerRvalue)
Vt_ValueFromPythonRegistry & operator=(Vt_ValueFromPythonRegistry const &)=delete
VT_API_TEMPLATE_CLASS(TfSingleton< Vt_ValueFromPythonRegistry >)
static bool HasConversions()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
void VtValueFromPythonLValue()
#define PXR_NAMESPACE_CLOSE_SCOPE