Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-10-23 09:37:20


Another thing I still need to get into the documentation.

To handle this case, you need to decide how you want the enum to show up in
Python (since Python doesn't have enums). If you are satisfied with a Python
int as a way to get your enum value, you can write a simple from_python()
function in namespace py::

#ifndef PY_NO_INLINE_FRIENDS_IN_NAMESPACE
namespace py {
#endif

mynamespace::SomeMeasure from_python(PyObject* x,
     py::Type<mynamespace::SomeMeasure>)
{
    return static_cast<mynamespace::SomeMeasure>(
      from_python(x, py::Type<unsigned long>()));
}

#ifndef PY_NO_INLINE_FRIENDS_IN_NAMESPACE
}
#endif

You may also want to add a bunch of lines like this to your module
initialization:
 mymodule.add(PyInt_FromLong(case1), "case1");
 mymodule.add(PyInt_FromLong(case2), "case2");
...

-Dave
----- Original Message -----
From: "Anton Gluck" <gluc_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Sunday, October 22, 2000 11:48 PM
Subject: [boost] py_cpp: enumerations

> Hi,
>
> This time I'm trying to expose a method that uses an enumeration as an
> argument to Python.
>
> This is the method I'm trying to wrap:
>
> void SomeClass::SetSomeMeasure(SomeMeasure s) {
> measure = s;
> }
>
> SomeMeasure is defined in the corresponding header file as:
>
> enum SomeMeasure {
> case1 = 1,
> case2
> };
>
> The wrapper code is:
>
> SomeClass_class.def(SomeClass::SetSomeMeasure,"SetSomeMeasure");
>
> The error I get is:
>
> d:\py_cpp/caller.h(275) : error C2665: 'from_python' : none of the 86
> overloads can convert parameter 2 from type 'struct py::Type<enum
> SomeClass::SomeMeasure>'
>
> As usual, I'd appreciate any help.
>
> Toni
>
>
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk