[odb-users] containers of containers

Jeroen N. Witmond jnw at xs4all.nl
Thu Aug 18 14:40:44 EDT 2016


On 2016-08-18 19:50, Andrew Cunningham wrote:
>> 
>> You can actually map std::array<float, 3> as a composite value type 
>> and it
>> can be used "as if" it was a container. For example:
>> 
>> 
>> 
>> #include <array>
>> 
>> #include <vector>
>> 
>> 
>> 
>> using float3 = std::array<float, 3>;
>> 
>> 
>> 
>> #pragma db value(float3) transient
>> 
>> #pragma db member(float3::e1) virtual(float) get(this[0]) set(this[0])
>> #pragma db member(float3::e2) virtual(float) get(this[1]) set(this[1])
>> #pragma db member(float3::e3) virtual(float) get(this[2]) set(this[2])
>> 
>> 
>> 
>> #pragma db object
>> 
>> struct object
>> 
>> {
>> 
>>   #pragma db id
>> 
>>   int id;
>> 
>> 
>> 
>>   std::vector<float3> vf3;
>> 
>> };
>> 
>> 
>> 
>> Note how with this approach you can easily customize column name/type, 
>> use
>> members in queries, etc.
>> 
> 
> OK, i see how that can work... I think....could get painful for larger
> array sizes.

You could write a simple program (or even a shell script) to generate 
all "#pragma db member" statements required ...



More information about the odb-users mailing list