[C++-sig] Need help on enum--a concrete example
David Abrahams
dave at boost-consulting.com
Mon Sep 9 05:41:12 CEST 2002
Nevermind all that; I implemented real enum support ;-).
Now given Min's example enum:
enum choice { red, blue };
the construct:
enum_<choice>("choice")
.value("red", red)
.value("blue", blue)
;
can be used to expose it to Python. The new enum type is created in the
current scope(), which is usually the current module.
You can access those values in Python as
>>> extension_module.choice.red
extension_module.choice.red
Remember that you can create a new scope around a class:
scope in_X(class_<X>("X")
.def( ... )
.def( ... )
);
// Expose X::nested as X.nested
enum_<X::nested>("nested")
.value("red", red)
.value("blue", blue)
;
Enjoy!
-----------------------------------------------------------
David Abrahams * Boost Consulting
dave at boost-consulting.com * http://www.boost-consulting.com
----- Original Message -----
From: "David Abrahams" <dave at boost-consulting.com>
To: <c++-sig at python.org>
Cc: "Joel de Guzman" <joel at boost-consulting.com>
Sent: Sunday, September 08, 2002 10:20 AM
Subject: Re: [C++-sig] Need help on enum--a concrete example
> From: "Min Xu" <minxu at sci.ccny.cuny.edu>
>
> <<
> Hi,
>
> Thanks for the quick reply. I compiled the code with your changes. The
> compilation failed.
> >>
>
> Sorry, Min. Please make the following change:
>
> class_<A, A_wrap>("A")
> // .def(init<double,int>()) // ******
> .def_init(args<double, int>())
> .def("get", &A::get)
> .def("get1", &A::get1);
>
> Joel, I think this bug is one of yours; uncomment the indicated line to
> reproduce it.
>
>
> -Dave
>
>
> -----------------------------------------------------------
> David Abrahams * Boost Consulting
> dave at boost-consulting.com * http://www.boost-consulting.com
>
>
>
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
More information about the Cplusplus-sig
mailing list