[odb-users] Enum encapsulation + getters / setters + query

Boris Kolpackov boris at codesynthesis.com
Tue Feb 9 09:00:57 EST 2016


Hi Andreas,

Andreas Pasternak <a.pasternak at mt-robot.com> writes:

> typedef safe_enum<SomeEnum_impl> Some_Enum;
> Some_Enum  event_type;
> 
> #pragma db value(Some_Enum) definition
> #pragma db member(Some_Enum::val) get(underlying) set(set)
> 
> /../odb_query.h:370:23: error: no match for ‘operator==’ [...]

You have mapped it as a composite type and ODB doesn't support
comparing composite types to anything but themselves in queries
(which is what you normally want).

This mapping is also conceptually not quite correct (Some_Enum
"is a" SomeEnum_impl, not "has a" SomeEnum_impl).

In the upcoming version this will be pretty easy to implement
using the type mapping pragma:

#pragma db map type(Some_Enum) as(SomeEnum_impl)  \
    to((?).underlying ()) from(Some_Enum (?))

In the current version the only way to achieve the same is either
by using virtual data members (but then you will have to repeat
the same thing for each data member) or by providing a value_traits
specialization. Neither option is particularly appealing, so maybe
a pre-release is the answer? I can package one if you would like.

Boris



More information about the odb-users mailing list