[odb-users] Re: shared_ptr<int> as object data member

Boris Kolpackov boris at codesynthesis.com
Wed Mar 18 09:12:03 EDT 2015


Hi,

In the future please don't ask a question by replying to the
digest (or by replying to any other unrelated post, for that
matter). Instead, start a new thread with a descriptive
subject, as discussed in the posting guidelines:

http://codesynthesis.com/support/posting-guidelines.xhtml


天空同学 <tiankongcc1991 at qq.com> writes:

> I defined a class Employee with a member boost::shared_ptr<int>,
> then the odb tell me a error in generate the xx-odb.hxx file:
> "unable to map c++ type ::boost::shared_ptr<int> ..."

There are too many "semantics" that one can prescribe to this
construct for ODB to make any specific assumption. For example,
when loading the value from the database, and the pointer is
not NULL, should we assign to the existing value (and thus
modify it for every other shared_ptr that points to it) or
should we allocate a new value?

You can, however, use the virtual data member feature (Section
14.4.13, "virtual") to implement the logic that you want. For
example, below is one way to do it. Here we assume the pointer
cannot be NULL when we get the value and we always allocate
a new value when we set it.

#pragma db object
class object
{
  #pragma db transient
  boost::shared_ptr<int> i_;

  #pragma db member(i) virtual(int)  \
    get(*this.i_)                    \
    set(this.i_.reset (new int (?)))
};

Boris



More information about the odb-users mailing list