[odb-users] containers of containers

Andrew Cunningham odb at a-cunningham.com
Thu Aug 18 15:27:44 EDT 2016


I see how that is a workaround, but I would like ODB to do that work for me
:)

I still think maybe a "#pragma db array" or similar would be very useful,
despite Boris's misgivings. It could be restricted to "simple SQL types" -
int,float, double with some default naming convention for the columns.
Forgetting about issues with containers of containers for the moment,
currently using a std::array<float, 3> "as is" in any object is very
inefficient in time and space vs, say, float x,y,z;.
The ODB compiler generates another table to store the array data, along
with associated "SELECT" when loading the parent object.


On Thu, Aug 18, 2016 at 11:40 AM, Jeroen N. Witmond <jnw at xs4all.nl> wrote:

> 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