[odb-users] value classes in views

Boris Kolpackov boris at codesynthesis.com
Fri Sep 19 07:18:23 EDT 2014


Hi Quentin,

Quentin Deldycke <quentindeldycke at gmail.com> writes:

> #pragma db value
> class A
> {
> //some int / string and stuff...
> }
> 
> #pragma db object
> class B
> {
>  //some int / string and stuff...
> }
> 
> #pragma db object
> class C
> {
>   A   classA;
>   shared_ptr<B>  classB;
> }
> 
> I want to build a view, equivalent to object C (i displayed only usefull
> data)
> 
> My view is built like this:
> 
> #pragma db view object(C) object(B = classB: A::classB)
> class view_C
> {
>  A classA;
>  B classB;
> }

You cannot (yet) use an object (B) as data member in view. This is what
we call an "object-loading view" and is still on the TODO list. What
you can do is something like this:

#pragma db object
class B
{

  #pragma db value
  struct Data
  {
    //some int / string and stuff...
  } data_;
}

#pragma db view object(C) object(B = classB: C::classB)
class view_C
{
  A classA;

  #pragma db column(classB::data_)
  B::Data classB;
};

Or, if you really, absolutely must have 'B classB', then you can do this:

#pragma db object
class B
{

  #pragma db value
  struct Data
  {
    //some int / string and stuff...
  } data_;

  const Data& getData () const {return data_;} 
  void setData (const Data& d) {data_ = d;}
};


#pragma db view object(C) object(B = classB: C::classB)
class view_C
{
  A classA;

  #pragma db transient
  B classB;

  #pragma db member(classBData) virtual(B::Data) column(classB::data_) \
    get(this.getData ()) set (this.setData((?)))
};

Boris



More information about the odb-users mailing list