[odb-users] private data members, accessors, and transient

MM finjulhich at gmail.com
Fri May 30 13:47:29 EDT 2014


but what about if C doesn't contain just m1 and m2 accessors, but also m3
and m4 which I don't want odb to store?


On 30 May 2014 16:56, MM <finjulhich at gmail.com> wrote:

> i see, indeed the solution is simple:-) thanks
>
>
> On 30 May 2014 16:38, Boris Kolpackov <boris at codesynthesis.com> wrote:
>
>> Hi,
>>
>> MM <finjulhich at gmail.com> writes:
>>
>> > class C {
>> >  ... m1() const;
>> >   void m1(...);  /// with the right signatures
>> >
>> >  ... m2() const;
>> >   void m2(...);  /// with the right signatures
>> > private:
>> >   ...
>> > };
>> >
>> > // non instrusive
>> > #pragma db value(C) definition transient
>> > #pragma db member(C::m1)
>> > #pragma db member(C::m2)
>> >
>> > This will make all the internal data members transient, but will store
>> m1
>> > and m2 in the database when C is persisted?
>>
>> No, if you mark an object of composite value transient, then this is
>> equivalent to marking all real (that is, no-virtual) data members as
>> transient. And none of them will be stored in the database. Only
>> virtual data members will be stored. This feature is primarily useful
>> for supporting things like the pimpl idiom (see the 'pimpl' example
>> in the odb-examples package).
>>
>> You seem to be over-thinking things. In your case, normally, all you
>> need to do is this:
>>
>> #pragma db value(C)
>>
>> The ODB compiler will then discover and use the m1() and m2() accessors
>> and modifiers to store the data members.
>>
>> Boris
>>
>
>


More information about the odb-users mailing list