Discussion:
[odb-users] custom containers or not: boost::multi_array
MM
2018-06-26 17:45:13 UTC
Permalink
Hello


class EL {
std::uint32_t id_;
std::vector<date> dates_;
boost::multi_array<entry, 2> entries_;
};
/// dates_.size() == number or rows of entries_
/// number of cols of entries_ = N
/// entry is a struct that maps to a composite value type

My object target tables look like:

table "EL"
id
-------------
.
.
.


table "EL_rows"
ELid date entrycols
--------------------------------------
1 d1 entry11
1 d1 entry12
...
1 d1 entry1N

1 d2 entry21
1 d2 entry22
...
1 d2 entry2N

...

1 dM entryM1
1 dM entryM2
...
1 dM entryMN
...
and so on for ELid 2 ....

If the class EL is constrainted in its definition, is the way to use a
custom container as explained in chapter 5.5?

The relationship that the row entries_[x] corresponds the date dates_[x]
would have to be implemented somehow.

I'm at a loss as how to implement this really?
MM
2018-06-28 20:43:36 UTC
Permalink
Post by MM
Hello
class EL {
std::uint32_t id_;
std::vector<date> dates_;
boost::multi_array<entry, 2> entries_;
};
/// dates_.size() == number or rows of entries_
/// number of cols of entries_ = N
/// entry is a struct that maps to a composite value type
table "EL"
id
-------------
.
.
.
table "EL_rows"
ELid date entrycols
--------------------------------------
1 d1 entry11
1 d1 entry12
...
1 d1 entry1N
1 d2 entry21
1 d2 entry22
...
1 d2 entry2N
...
1 dM entryM1
1 dM entryM2
...
1 dM entryMN
...
and so on for ELid 2 ....
If the class EL is constrainted in its definition, is the way to use a
custom container as explained in chapter 5.5?
The relationship that the row entries_[x] corresponds the date dates_[x]
would have to be implemented somehow.
I'm at a loss as how to implement this really?
This use case boils down to just 2 dimensions for multi_array.
If the multi_array container has N rows and M columns, and all the cells
are of the same simple value type, is it possible to store as M*N rows in a
SQL table?
Is it possible to load M*N rows back into it?

To use the container_traits, I suppose this would be a ordered container.
The Index type would be a pair of integers for both dimensions?
The value_type would be "entry"

rds,
MM
2018-07-03 19:55:07 UTC
Permalink
Is it possible to implement persistence and loading for a
boost::multi_array using the custom container method in the manual?
Help is appreciated,
MM
Boris Kolpackov
2018-07-04 14:41:36 UTC
Permalink
Post by MM
Is it possible to implement persistence and loading for a
boost::multi_array using the custom container method in the manual?
You could try to store it as a map kind with a composite key with
members for all the indexes. I think it should work though I haven't
tried it myself.
MM
2018-07-05 08:22:55 UTC
Permalink
Post by Boris Kolpackov
Post by MM
Is it possible to implement persistence and loading for a
boost::multi_array using the custom container method in the manual?
You could try to store it as a map kind with a composite key with
members for all the indexes. I think it should work though I haven't
tried it myself.
"Map container" in the odb sense doesn't guarantee ordering which is fine
for this boost::multi_array case.
But I suspect that odb understands when it sees a std::map that it is a
"map container".
You are saying that I should create a new header for boost multi_array
similar to odb/std_map-traits.hxx where I provide a partial template
specialization for the primary template odb::access::container_traits ?

Did I understand that correctly?

Thanks
MM

Loading...