AW: [odb-users] reuse inheritance with templated base class

Marcel Nehring mne at qosmotec.com
Wed Jul 30 05:57:13 EDT 2014


Hi Boris,

I understand that proper support of persistent class templates can get complex, but yes I guess what you proposed should work for me. Thanks.

Regards,
Marcel

-----Ursprüngliche Nachricht-----
Von: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Gesendet: Mittwoch, 30. Juli 2014 11:10
An: Marcel Nehring
Cc: odb-users at codesynthesis.com
Betreff: Re: [odb-users] reuse inheritance with templated base class

Hi Marcel,

Marcel Nehring <mne at qosmotec.com> writes:

> uhm, that is quite a limitation. I did not expect that. The example I 
> provided was only a short, self-contained, compilable example to 
> demonstrate the error I am getting. In fact my code *does* contain 
> persistent classes where the persistent data depends on the template 
> argument.

Implementing proper persistent class templates support is a whole different level of complexity. In fact, I am not sure this is even possible (or makes sense) since a persistent class operates on a concrete table that has concrete columns with concrete types.
If the column (member) type is a template argument, we cannot generate statements (which are just static strings) nor code that uses them.

What we could probably do is support persistent class template instantiations. We already do something similar for composite values (copying an example from the manual):

template <typename T>
struct point
{
  T x;
  T y;
  T z;
};

typedef point<int> int_point;
#pragma db value(int_point)

#pragma db object
class object
{
  ...

  int_point center_;
};

Note that the template itself is not a composite value (in ODB sense).
It is the instantiation that is the value. We could do the same for
objects:

class Derived;
typedef Base<Derived> DerivedBase;
#pragma db object(DerivedBase) optimistic

#pragma db object
class Derived : public DerivedBase
{
  ...
};

Not particularly pretty. The way we handle this for composite values right now, you would also have to specify the object id pragma, etc., for each instantiation:

#pragma db object(DerivedBase) optimistic #pragma db object(DerivedBase) id(DerivedBase::m_id) #pragma db object(DerivedBase) version(DerivedBase::m_version)

But we will probably be able to fix this so that you don't have to (i.e., we will "apply" pragmas that were specified for the template to each instantiation).

Would something like this work for you?

Boris



More information about the odb-users mailing list