/* * common.h * * Created on: 15 Apr 2016 * Author: hbruintjes */ #pragma once #include #include #include #include namespace py = pybind11; #if PY_MAJOR_VERSION >= 3 #define PY_DIV "__truediv__" #define PY_RDIV "__rtruediv__" #else #define PY_DIV "__div__" #define PY_RDIV "__rdiv__" #endif PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); namespace pybind11 { namespace detail { /** * Dummy type caster for handle, so functions can return pybind11 handles directly */ /*template <> class type_caster { public: bool load(handle src, bool) { value = handle(src).inc_ref(); return true; } static handle cast(handle src, return_value_policy policy, handle parent) { switch(policy) { case return_value_policy::automatic: case return_value_policy::copy: case return_value_policy::take_ownership: return handle(src); case return_value_policy::reference: return handle(src).inc_ref(); case return_value_policy::reference_internal: parent.inc_ref(); return handle(src); } return handle(src); } PYBIND11_TYPE_CASTER(handle, _("handle")); };*/ /* template struct tuple_caster { typedef TupleType type; template using type_conv = type_caster::type>; bool load(handle src, bool convert) { pybind11::tuple tup(src, true); if (!tup.check()) return false; return loadItem<0, Keys...>(tup, convert); } static handle cast(const type &src, return_value_policy policy, handle parent) { pybind11::tuple tup(sizeof...(Keys)); if (!castItem<0, Keys...>(tup, src, policy, parent)) { return handle(); } return tup.release(); } private: template bool loadItem(pybind11::tuple& tup, bool convert) { type_conv conv; if (!conv.load(tup[N], convert)) return false; std::get(value) = static_cast(conv); return loadItem(tup, convert); } template bool loadItem(pybind11::tuple& tup, bool convert) { type_conv conv; if (!conv.load(tup[N], convert)) return false; std::get(value) = static_cast(conv); return true; } template static bool castItem(pybind11::tuple& tup, const type &src, return_value_policy policy, handle parent) { auto obj = type_conv::cast(std::get(src), policy, parent); object value_ = object(obj, false); if (!obj) { return false; } return castItem(tup, src, policy, parent); } template static bool castItem(pybind11::tuple& tu, const type &src, return_value_policy policy, handle parent) { auto obj = type_conv::cast(std::get(src), policy, parent); object value_ = object(obj, false); if (!obj) { return false; } return true; } }; template struct type_caster> : tuple_caster, Types...> { }; template struct type_caster> : tuple_caster, Type1, Type2> { }; */ } }