[odb-users] reuse inheritance with templated base class
Boris Kolpackov
boris at codesynthesis.com
Thu Jul 31 05:48:14 EDT 2014
Hi Marcel,
Ok, I have the first part of this functionality implemented. I uncovered
one interesting issues in that it is now hard to distinguish (at the API
level) whether something like P<T> is a smart pointer or a persistent
class. So in case of a persistent class template instantiation, one
may have to specify the object type explicitly, as in:
db.persist<object> (o);
Rather than:
db.persist (o);
This is not a major issue and won't affect your use-case since you
don't actually persist instantiations but only use them as (abstract)
bases. Still, this is the kind of complications that I am cautious of.
As a result, I would like to get some experience using this feature
before I go ahead and implement the second part of what we talked
about (applying pragmas specified for class templates to their
instantiations). In fact, chances are good that this won't even
be necessary because of this possible arrangement:
#pragma db object abstract
struct base_data
{
#pragma db id auto
unsigned long id;
#pragma db version
unsigned long version;
};
template <typename T>
struct base: public base_data
{
T x;
};
typedef base<std::string> base_derived;
#pragma db object(base_derived) abstract
#pragma db object
struct derived: public base_derived
{
int n;
};
It has the added benefit of minimizing the generated code size since
all the base instantiations will reuse the code generated for base_data
for data member that do not depend on template arguments.
I have the above code working in a test. Will this setup work for your
application? If so, would you like me to build you a pre-release binary
so that you can give it a try (let me know which platform)?
Boris
More information about the odb-users
mailing list