[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#682804: ITP: libtenum -- C++ metaprogramming library to make enums a little bit nicer



This is a header only library to wrap C++ enums and automatically
provide some functionality for (de)serialization from text streams. It
also provides some different semantics on the way enumerations can be
combined.
I can give more detail as I'm the author of the library, but I'm not
sure how to summarize this in one line for the bug title.

The most obvious use-case for it is to read and write key combination
to key mapping files. For example "Alt+S" could automatically be
parsed using the "Bit field" concept as the bitwise or combination of
enum values "Alt" and "S".
Some test cases and samples are also available in the source code:
https://github.com/berenm/libtenum/tree/master/test.

Here is an excerpt of the README:

This library introduces three new variation over the enum concept. The
main difference between them is the way these enums are (de)serialized
and the available enum / enum and enum / integer operators when this
is meaningful (only when using C++0x).

- Static enums only allow explicitely defined constants (with
specified or implicit integer values), any other value will result in
a (de)serialization to special value "unknown".

- Dynamic enums allow explicitely defined constants and offsets from
these constants, within a given global range (from the first constant
to the specified upper integer limit).
 Every value whithin the range will be serializable, any other will
result in "unknown". An integer value between two enum constants will
be (de)serialized as the nearest lower enum constant plus an offset.
 For example, if the enum is defined as { value1 = 1, value2 = 5...,
unknown = 10 }, the available range would be from 1 to 9, and the
integer 4 will be serialized as "value1#3" which means (value1 + 3).

- Bit fields only allow combination of explicitely defined constants.
 These will be (de)serialized as a combination of every defined enum
constants, any other value will be (de)serialized as "unknown". This
flavor restricts constants values to bitwise distinct integers, and to
values different from 0 in order to be able to decompose the enum into
the specified enum constants. 0 being the special "unknown" value for
this flavor.
 For example, for an enum defined as { bit1 = 0b001, bit2 = 0b010,
bit3 = 0b100... }, an instance of this enum with an integer value of 3
will be serialized as "bit1+bit2", and "bit1+bit3" will be
deserialized as an enum instance of integer value 5.

I also did a package on mentors.debian.net if anybody is interested in
sponsoring it : http://mentors.debian.net/package/libtenum.

Best,
-- 
Beren Minor


Reply to: