[odb-users] reuse inheritance with templated base class

Boris Kolpackov boris at codesynthesis.com
Thu Aug 21 03:49:28 EDT 2014


Hi Marcel,

[I've CC'ed odb-users since others may find this information useful.]

Marcel Nehring <mne at qosmotec.com> writes:

> But I have indeed discovered a few other issues/questions this morning.
> 
> 1) Trying to compile the generated ODB code gives me a C2380 error with
> Visual Studio. To me it looks like that this might be because I have a value
> type declared that has a member called value. If I then define a class that
> has a member of type of this value type that is also named value, then the
> resulting struct in the ODB code is called value_type_ and inside this
> struct there is a typedef that is also called value_type_.

Uh, you are really pushing ODB, I like that ;-). I've fixed this, let me
know if you would like the updated ODB compiler binary.


> 2) Is it somehow possible to store different classes in the same
> database table? For example for a certain template class I would 
> like to store all of its instantiations in a single table.

Yes, you can map multiple classes to the same table:

#pragma db object table("foo")
class foo
{
  ...
};

#pragma db object table("foo")
class bar
{
  ...
};

ODB just assumes you know what you are doing ;-).


> I would  be able to figure out the correct template instantiation that
> is needed when reading the row from the database by one of the columns
> value.

Just to clarify, "you" here is literally "you", not ODB. You will need
to somehow figure out the correct class to use before, say, calling
load(). You could, for example, use a view to first load the column
value and then based on that, load the correct object.

You might also want to take a look at object sections (Chapter 9). They
allow you to partition a class into multiple separately loadable,
updatable, etc., groups of data members. Maybe this is what you are
looking for.

Also polymorphism might be related (Section 8.2).


> 3) I cannot specify different output directories for the different
> types (*.hxx, *.sql, etc.) of generated files, can I?

No, but you can always move the files where you need to afterwards
with a few shell commands.


> 4) I cannot specify different include prefixes for my own header files
> and odb's header files, can I? For example that it results in #include
> "inc/MyClass.h" and #include "gen/odb/MyClass-odb.h". At the moment I
> do this by using the include-regex option.

--include-regex is the way to do it. There is no special mechanism to
separate headers into "your own" and "odb's".

Boris



More information about the odb-users mailing list