Re: [pygccxml-development] Order of enum values
Brought to you by:
mbaas,
roman_yakovenko
|
From: Roman Y. <rom...@gm...> - 2006-07-06 17:52:13
|
On 7/6/06, Matthias Baas <ba...@ir...> wrote:
> - A comment in the source code says that the value part is stored as an
> int but obviously it's a unicode string containing an int. Is this a
> bug?
Yes, It could be fixed in scanner_t class.
> Could the value actually also be something else than an int?
I am not sure. May be it possible to create an enum, with some expression as
value. And may be in this case gccxml will dump it as a string. I don't know.
So, small investigation is needed. If it could be expression, then
'int' in comment
should be replaced to 'string'
> - Are those integer values ever used?
They don't.
> The generated code looks like this:
>
> bp::enum_<MColor::MColorType>("MColorType")
> .value("kCMY", MColor::kCMY)
> .value("kHSV", MColor::kHSV)
> .value("kRGB", MColor::kRGB)
> .value("kCMYK", MColor::kCMYK)
> .export_values()
> ;
>
> Now what I'd like to have is a scheme that always produces the same
> order. There are several options how this could be implemented:
Me too.
> - Store the values inside a list instead of a dict. The items can be
> either just the enum names or tuples (name, value) if the value is still
> required somewhen.
You loose a convenience of dictionary: value = x[name].
> - The code creator could sort the enum names according to their value
> and then use this order to write them out.
>
>
> To me the first option seems to be the right one as an enum actually
> *is* an ordered construct.
If gccxml reports enums, using the order from source file, you can
replace dict with
a list, otherwise any order you define will surprise a user.
> But I don't know the entire pyplusplus code,
> so maybe there are cases where a value has to be looked up quickly which
> justifies using a dict.
There is no such place.
> So, Roman, which approach would you prefer? (I might have a go at fixing
> it myself then)
I prefer to make a change in pygccxml, but I am not sure, that it will
be enough.
Please take a look on decl_wrappers.enumeration_t. It also defines few
containers,
may be you will have to change those containers too. Please take a look also
on code_creators.enum_t and code_creators.unnamed_enum_t. They generate
the code, I think you will have to fix them too :-(.
Please, implement what ever you think is right and I try to help you as much
as I can.
Thanks
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
|