AW: [odb-users] Object Model based on Interfaces
    Lichtenberger, Christian 
    christian.lichtenberger at etm.at
       
    Thu Jun 12 10:23:16 EDT 2014
    
    
  
I think this should be relatively easy to implement in ODB.
All you need is a own object_traits:
template <>
  class WBE_REPOSITORY_EXPORT access::object_traits< ::IDerived > :
    public access::object_traits< ::Derived >
  {
  };
And a cast in the object_traits_impl, which depends on the pointer type
First one I have tried, but second is not possible without modifying generated code.
One open question is how get the odb compiler the necessary information?
#pragma db object
#pragma db interface IDerived
Class Derived : Base, IDerived
{
}
Or
#pragma db interface
Class IDerived
{
}
Christian
-----Ursprüngliche Nachricht-----
Von: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Gesendet: Donnerstag, 12. Juni 2014 12:02
An: Lichtenberger, Christian
Cc: odb-users at codesynthesis.com
Betreff: Re: [odb-users] Object Model based on Interfaces
Hi Christian,
Lichtenberger, Christian <christian.lichtenberger at etm.at> writes:
> #pragma db object polymorphic
> class Base
> {
>   //some base functionality
> }
> 
> class IDerived
> {
>   //define pure virtual functions
> }
> 
> #pragma db object
> class Derived : public Base, public IDerived {
>   //implements virtual functions
> }
> 
> How can I archive that following is possible:
>
> main()
> {
>   QSharedPointer<odb::database> db;
>   IDerived derived = new Derived;
>   db->persist<IDerived>(derived);
> }
To persist via IDerived you would have to make it a persistent object. But ODB does not support multiple inheritance. So the only way is to simplify this somehow into a single inheritance chain (e.g., derive Base from IDerived or the other way around).
Boris
    
    
More information about the odb-users
mailing list