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

Nikolay Mladenov nickm at sitius.com
Mon Dec 3 20:01:42 CET 2007


May be you should post some more code ...

Did you try 
class_<...>(...)
	. def_readonly(...) 
	;
? (or may be add_property )

HTH,

Nikolay Mladenov


Matthew Scouten wrote:
> 
> 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?
> 
>     ---------------------------------------------------------------
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig




More information about the Cplusplus-sig mailing list