[odb-users] Containers of containers

Boris Kolpackov boris at codesynthesis.com
Thu Aug 18 11:43:17 EDT 2016


Hi Andrew,

> I would like that the ODB compiler detect this issue and fail with an
> error. At the moment, the compiler runs without error and generates
> 'working' ODB code.

I've implemented this diagnostics. Will send you a binary shortly.


> On a related issue, I also would like the ODB compiler to be enhanced to
> deal with fixed sized arrays of 'simple' data types (other than char) not
> as containers - put them in the object as members/columns.
> 
> For example
> 
> float xyz_[3];
> or
> std::array<float,3> xyz_;

This sounds simple on the surface but it is a can of worms. Just to start,
what should be the names of those members? What if they conflict with
existing members? What if you want to customize their types or column
names? Should we invent special syntax for such members, e.g.:

#pragma db member(xyz_[0]) type("DECIMAL") column("xyz_first")

If we support simple types, why not composite? And object pointers?
Inverse? What about using those members in queries, should we support
that?

So I don't think we will implement this any time soon.


> At the moment, this type of member data has to be spelled out as, say,
> float x_;
> float y_;
> float z_;
> 
> if you ever intend the owning class to be used in a container.

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.

Boris



More information about the odb-users mailing list