CARVIEW |
Select Language
HTTP/2 200
date: Fri, 18 Jul 2025 05:48:13 GMT
server: Apache/2.4.41 (Ubuntu)
vary: Cookie,User-Agent,Accept-Encoding
set-cookie: MOIN_SESSION_443_ROOT_moin=819b842be073cb91b8e846a42fdf9c878a88946d; Expires=Fri, 18-Jul-2025 06:48:00 GMT; Max-Age=3600; Secure; Path=/
content-encoding: gzip
content-type: text/html; charset=utf-8
x-clacks-overhead: GNU Terry Pratchett
strict-transport-security: max-age=315360000; includeSubDomains; preload
boost.python/WrappingEnums - Python Wiki
For example, let's define an object in module namespace to represent enum:
#include <boost/python.hpp> using namespace boost::python; enum color { red = 1, green = 2, blue = 4 }; color identity_(color x) { return x; } BOOST_PYTHON_MODULE(enum_ext) { enum_<color>("color") .value("red", red) .value("green", green) .value("blue", blue) ; def("identity", identity_); }
The usage is follows:
>>> from enum_ext import * >>> identity(color.red) enum_ext.color.red >>> identity(color.green) enum_ext.color.green >>> identity(color.blue) enum_ext.color.blue >>> identity(color(1)) enum_ext.color.red >>> identity(color(2)) enum_ext.color.green >>> identity(color(3)) enum_ext.color(3) >>> identity(color(4)) enum_ext.color.blue >>> try: identity(1) ... except TypeError: pass ... else: print 'expected a TypeError'
boost.python/WrappingEnums (last edited 2008-11-15 14:01:18 by localhost)
Unable to edit the page? See the FrontPage for instructions.