7 #ifndef PXR_BASE_VT_VALUE_FROM_PYTHON_H
8 #define PXR_BASE_VT_VALUE_FROM_PYTHON_H
33 return !_GetInstance()._lvalueExtractors.empty() &&
34 !_GetInstance()._rvalueExtractors.empty();
42 TF_FATAL_ERROR(
"Tried to register a VtValue from python conversion "
43 "but python is not initialized!");
45 _GetInstance()._RegisterLValue(_Extractor::MakeLValue<T>());
47 _GetInstance()._RegisterRValue(_Extractor::MakeRValue<T>());
66 using _ExtractFunc =
VtValue (*)(PyObject *);
72 static VtValue _ExtractLValue(PyObject *);
78 static VtValue _ExtractRValue(PyObject *);
83 static _Extractor MakeLValue() {
84 return _Extractor(&_ExtractLValue<T>);
88 static _Extractor MakeRValue() {
89 return _Extractor(&_ExtractRValue<T>);
97 explicit _Extractor(_ExtractFunc
extract) : _extract(extract) {}
99 _ExtractFunc _extract;
106 VT_API void _RegisterLValue(_Extractor
const &e);
107 VT_API void _RegisterRValue(_Extractor
const &e);
109 std::vector<_Extractor> _lvalueExtractors;
110 std::vector<_Extractor> _rvalueExtractors;
113 _LValueExtractorCache _lvalueExtractorCache;
120 VtValue Vt_ValueFromPythonRegistry::
121 _Extractor::_ExtractLValue(PyObject *obj) {
122 pxr_boost::python::extract<T &>
x(obj);
129 VtValue Vt_ValueFromPythonRegistry::
130 _Extractor::_ExtractRValue(PyObject *obj) {
131 pxr_boost::python::extract<T>
x(obj);
139 Vt_ValueFromPythonRegistry::Register<T>(
true);
144 Vt_ValueFromPythonRegistry::Register<T>(
false);
149 #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