[odb-users] Custom pointer as in pointer-traits.hxx

Boris Kolpackov boris at codesynthesis.com
Wed Sep 16 11:20:18 EDT 2015


Andreas Pasternak MT-Robot AG <a.pasternak at mt-robot.com> writes:

> Now everything works without any problems.

Great, glad to hear that. Just for reference, to add support for a 
custom smart pointer in ODB:

1. You will need to implement a pointer_traits specialization. See
   libodb/odb/pointer-traits.hxx for inspirations.

2a. The easiest way to integrate this traits implementation into
    ODB is to simply add it at the end of the header that defines
    your smart pointer.

2b. If you want to make it a bit less intrusive (i.e., you may
    be using the same smart pointer in other parts of your
    application that have nothing to do with ODB), then you can
    place this traits specialization into a separate file and
    then:

    1) Include it into the ODB compilation with the --odb-epilogue
       option, for example:

       --odb-epilogue '#include "ptr-traits.h"'

    2) Include it into the generated source code with --hxx-prologue:

       --hxx-epilogue '#include "ptr-traits.h"'

    For an example on how to do this, see libodb-boost, specifically,
    the smart-ptr.options file.


> I tried to create a pointer of a db value (an int exactly) and
> not an db object.

You can make that work as well: see wrapper_traits.

Boris



More information about the odb-users mailing list