[odb-users] composite value type

Boris Kolpackov boris at codesynthesis.com
Tue Jun 3 08:10:45 EDT 2014


Hi,

MM <finjulhich at gmail.com> writes:

> Can I keep it as the std::array<...,5> and have get/set so that odb
> loads/stores that from 5 columns? I assume I need a separate struct of 5
> members that is directly convertible by odb?
> Or perhaps 5 virtual members of type time_period (i have valuetyped
> time_period) with get/set

Yes, I would go for virtual members. It should be as simple as:

#pragma db member(p0) virtual (...) access (tperiods_[0])
#pragma db member(p1) virtual (...) access (tperiods_[1])
...

> 2) For year_based_generator, if I think of a struct S that captures with
> basic types, a virtual member of type S would then be used in
> period_s_hours with get/set to translate from the S type to
> year_based_generator

You could make the year_based_generator an object and then store
it as a polymorphic object hierarchy. But to me this feels like
an overkill and doesn't really fit in well (e.g., what would the
object id be? maybe a year?). So, yes, I would probably just
encode the type and state using some simple struct and then
store that in the database, using a virtual data member with
custom accessor/modifier to seamlesly translate between this
database representation and the actual type.

Boris



More information about the odb-users mailing list