[C++-sig] Wrapping an enum like class that is not an enum

Matthew Scouten matthew.scouten at gmail.com
Fri Nov 30 22:25:41 CET 2007


I (a BP newbie) could use some advice on how th wrap something odd.

The library I am using has something called an AEnum. It is a type of enum
like class. It is guaranteed to behave exactly like an enum, except that it
has some extra properties. There is an int, a string and a symbol associated
with each value.

In spite of that, the sizeof(AEnum_blah) == sizeof(int) , Guaranteed
an AEnum is castable to and from an int
and the bits of the AEnum are identical to the bits of the int it casts to.

I can't wrap it as a class because it is generated by crazy macros and
meta-template programming (And besides, I don't understand it...)

So, I thought, If this thing is Guaranteed to be just like an enum in
everyway that matters, why not pretend that it IS an enum and wrap it like
one? So I used the "enum_<>()"

Well that works just great when passing to or returning from functions.
Except, if it is the member of a class...

>>> from MantiCore import *
>>> o = Order()
>>> o.order_status
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot create weak reference to 'MantiCore.AEnum_OrderStatusCodes'
object

I can get around this by exporting it as a property of the class rather than
a data member, but there are a lot of them.
So, Anyone have a better way to do this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20071130/0a7c94af/attachment.htm>


More information about the Cplusplus-sig mailing list