[PATCH V2] wayland.xml: add "enum", "bitfield" and "is_bitfield" attributes

Bill Spitzak spitzak at gmail.com
Tue Sep 23 11:43:08 PDT 2014


On 09/23/2014 08:17 AM, Nils Chr. Brause wrote:

> Having
> more than the power-of-two values listed isn't a problem in my opinion. I see
> these extra values as some sort of shortcuts for often used OR-combinations.

That is what I was thinking too. A bitfield can be treated identically 
to an enum. I think there may be confusion that the values would be 
specified differently. But they should be specified as the actual 
numeric power of 2 that the resulting integer has, and extra values that 
are not powers of 2 are allowed. This means that a backend that does not 
distinguish enum and bitfield can trivially treat them the same.

Backends that do care will look for the entries that are powers of 2 and 
use them as the bits. Depending on the language they may be able to do 
something with the other values (certainly C++ could handle those 
easily, though it gets tricky if you want to prevent & with these values).

In C++11 this just means adding an inline operator| and operator& to the 
enum in the header file. Pre-C++11 you have to make a fake class which 
is annoying.

If the bitfield is missing the best that can be done is to assume all 
enums are bitfields. This will allow invalid settings that could be 
detected at compile time to be passed to the ones that are not bitfields.

So I certainly see some advantage in this and no harm whatsoever.



More information about the wayland-devel mailing list