[odb-users] composite value type

MM finjulhich at gmail.com
Tue Jun 3 04:44:57 EDT 2014


On 2 June 2014 16:19, Boris Kolpackov <boris at codesynthesis.com> wrote:

> Hi,
>
> MM <finjulhich at gmail.com> writes:
>
> > I can come up with some encoding from these date_time types to
> std::string,
> > to store and load, which i can then store to db.
>
> It doesn't have to be a string. You could encode it as a number of
> columns that capture the state using convenient data types, etc. In
> other words, think of a struct that would capture the state of your
> tuple using basic types like strings, integers, date-time types
> from the Boost profile, etc.
>
> > I was hoping the date_time profile included a direct representation of
> this.
>
> Even if it did, it wouldn't help you much since in your case you have
> pointers of an abstract year_based_generator that point to the concrete
> generator implementations with their own states.
>
> In fact, who manages the lifetime of these generators? If there is
> some fixed "registry" of them, then maybe you could store a "key"
> to this registry instead of the state and type of the generator.
>
> Boris
>

Trying here according to your response yesterday:

class period_s_hours {
public:
  const year_based_generator& from() const;

  const year_based_generator& to() const;

  const time_period* tperiods() const;
  void tperiods(const time_period[]);

private:
  std::shared_ptr<year_based_generator> from_;
  std::shared_ptr<year_based_generator> to_;
  std::array<time_period,5>                      tperiods_;
  /// start/end times for Mon..Fri
};


1) period_s_hours is the element type of std::vector that is a member of
another class.

I understand I am not allowed to have containers of containers, which would
be the case here.
In fact, I don't want the tperiods_ member to be treated as a container by
odb, but it's probably cleaner to have it map to 5 columns.

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


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

Thanks,


More information about the odb-users mailing list