[odb-users] raw pointer to application's global array

MM finjulhich at gmail.com
Thu May 29 06:28:13 EDT 2014


On 28 May 2014 14:45, Boris Kolpackov <boris at codesynthesis.com> wrote:

> Hi,
>
> > Loading would load the row from the table and somehow make the pointer
> > point to right element of the static global array.
> > Storing would store the persistent object in the table.
> >
> > I assume the pointee (string) could be stored in the table but i'm
> > not sure how to implement that?
>
> The best way to handle such cases (i.e., storing something other that
> the value of the data member) is to use virtual data members (see
> Section 14.4.13, "virtual" in the ODB manual). With the virtual data
> member you can specify your own accessors/modifiers that will do
> the translation that you want. For example:
>
> #pragma db object
> class object
> {
>   ...
>
>   #pragma db transient
>   std::string* foo_;
>
>   #pragma db member(foo) virtual(std::string) get(*this.foo_) set(set_foo)
>
>   void set_foo (const std::string& str)
>   {
>     // Find str in the array and set foo_ to point to that element.
>   }
> };
>
>
> Boris
>
This is very very good. I'll go with this solution. Thanks Boris for great
explanations.

object actually has a couple of other members, 1 of which is
std::string code

The combination (foo_, code) is the unique identifier.

Is it possible, non-intrusively, to have a auto-generated id?

MM


More information about the odb-users mailing list