[C++-sig] How to wrap class enums

Liam Herron herron at ELLINGTON.com
Mon Mar 10 16:42:12 CET 2014


Here is an example:

// c++ code

class A
{
public:
    enum ATypes
    {
        ONE,
        TWO,
        THREE
    };
};


//  boost python code


object obj_A =

class_<A>
   ("A", "A simple A object", init<>() )
   ;

{
   scope in_A(obj_A);
   enum_<A:ATypes>
      ("ATypes")
      .value("ONE", A::ONE)
      .value("TWO", A::TWO)
      .value("THREE", A::THREE)
      ;
}


Hope that helps.

Liam



From: Cplusplus-sig [mailto:cplusplus-sig-bounces+herron=ellington.com at python.org] On Behalf Of Deepankar Sharma
Sent: Saturday, March 08, 2014 3:18 PM
To: cplusplus-sig at python.org
Subject: [C++-sig] How to wrap class enums

Any pointers on how to expose class enums to Python? Given the following enum what would the boost code to expose it to python look like? The page at http://www.boost.org/doc/libs/1_55_0/libs/python/doc/v2/enum.html only lists examples of old style enums.


enum class t_functions
{
            ADD, SUB, MUL, DIV
};

=============================================================================================
Email transmissions can not be guaranteed to be secure or error-free, as information 
could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain 
viruses.  The sender therefore does not accept liability for any errors or omissions in 
the contents of this message which arise as a result of email transmission.  In addition,
the information contained in this email message is intended only for use of the 
individual or entity named above.  If the reader of this message is not the intended
recipient, or the employee or agent responsible to deliver it to the intended recipient,
you are hereby notified that any dissemination, distribution,or copying of this communication,
disclosure of the parties to it, or any action taken or omitted to be taken in reliance on it,
is strictly prohibited, and may be unlawful.  If you are not the intended recipient please
delete this email message. 
==============================================================================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20140310/7ac93a76/attachment.html>


More information about the Cplusplus-sig mailing list