[C++-sig] Re: Wrapping #define's and anonymous enum's
David Abrahams
dave at boost-consulting.com
Thu Dec 12 22:15:56 CET 2002
"Mike Rovner" <mike at bindkey.com> writes:
> "William Trenker" <wtrenker at hotmail.com> wrote in message
> news:F62JMYRF7luM8gbvdBR000026c2 at hotmail.com...
>> Many C/C++ libraries contain one or more .h/.hpp files that define various
>> constants used by that library's API.
>>
>> What is the prescribed method for wrapping #defines that are used to
>> represent constants?
>>
>> Also, how do I wrap anonymous enums?
>>
>> For example, I have a project with an Constants.h file containing:
>>
>> #define MSG_A 23
>> #define MSG_B 25
>> enum {Red, White, Blue = 40 };
>>
>> What would the boost wrapper code for the above look like?
>>
>
> #include <boost/python.hpp>
>
> BOOST_PYTHON_MODULE(my_module)
> {
> scope().attr("MSG_A") = 23;
> scope().attr("MSG_B") = 25;
> scope().attr("Red") = 0;
> ...
> }
>
> But you really DON'T WANT to do this.
> Think twice about your code.
Why not, Mike?
FYI, there's also:
enum_<my_enum>("my_enum")
.value("Red", Red)
.value("White", White)
.value("Blue", Blue)
;
But of course, you have to have a name for the enum type to do that.
--
David Abrahams
dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution
More information about the Cplusplus-sig
mailing list