[C++-sig] how do i wrap enums defined in a struct/class

David Abrahams dave at boost-consulting.com
Thu Jan 9 19:01:49 CET 2003


"horace\(seednet\)" <horace_hdsl at seed.net.tw> writes:

>     Could anybody be so kind to tell me how to wrap this code snippet (or where can I find the example) by Boost.Python :
> // 
> struct NeedToBeWrapped
> {
>     enum color     { eRed        =  0,
>                              eGreen      =  1,
>                              eBlue        =  2
>     };
>     enum ErrorStatus       { eES1       =  0,
>                                         eES2        =  1,
>                                          eES3       =  2
>     };
> ...
> };

{
    scope in_class(  // establish new scope for definitions
       class_<NeedToBeWrapped>("NeedToBeWrapped")
    );

    enum_< NeedToBeWrapped::color >("color")
        .value("eRed", NeedToBeWrapped::eRed)
        .value("eGreen", NeedToBeWrapped::eGreen)
        .value("eBlue", NeedToBeWrapped::eBlue)
        ;

    // similarly for ErrorStatus
}

HTH,
-- 
                       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