diff --git a/py.h b/py.h index 3818e73a..4f6c1b7d 100644 --- a/py.h +++ b/py.h @@ -17,7 +17,35 @@ # include "errors.h" # include +PY_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround + +// This can be instantiated on an enum to provide the to_python/from_python +// conversions, provided the values can fit in a long. +template +class py_enum_as_int_converters +{ + friend EnumType from_python(PyObject* x, py::Type) + { + return static_cast( + from_python(x, py::Type())); + } + + friend EnumType from_python(PyObject* x, py::Type) + { + return static_cast( + from_python(x, py::Type())); + } + + friend PyObject* to_python(EnumType x) + { + return to_python(static_cast(x)); + } +}; +PY_END_CONVERSION_NAMESPACE + namespace py { +template class enum_as_int_converters + : public PY_CONVERSION::py_enum_as_int_converters {}; template class WrappedPointer; @@ -42,10 +70,9 @@ inline void xdecref(T* p) xdecref_impl(reinterpret_cast(p_base)); } -#ifdef PY_NO_INLINE_FRIENDS_IN_NAMESPACE -} -#endif +} // namespace py +PY_BEGIN_CONVERSION_NAMESPACE // // Converters // @@ -293,19 +320,6 @@ inline unsigned long from_python(PyObject* p, py::Type) } -#ifdef PY_NO_INLINE_FRIENDS_IN_NAMESPACE -namespace py { -namespace converters { // bringing these into namespace py tended to confuse gcc; -using ::to_python; // they are in namespace py::converters for use by clients -using ::from_python; -} -#else -namespace converters { -using ::py::to_python; -using ::py::from_python; -} -#endif +PY_END_CONVERSION_NAMESPACE -} // namespace py - -#endif +#endif // METHOD_DWA122899_H_