[odb-users] Problem using <complex>

Andrew Cunningham odb at a-cunningham.com
Fri May 5 16:20:36 EDT 2023


Never mind, I figured it out.
The "transient" keyword is required - it tells ODB to ignore the data
fields of the object. Obvious when you think about it!

#pragma db value(FComplex) definition transient
#pragma db member(FComplex::real)   virtual(float) get(real) set(real)
  column("re")
#pragma db member(FComplex::imag)   virtual(float) get(imag) set(imag)
column("im")

On Fri, May 5, 2023 at 8:51 AM Andrew Cunningham <odb at a-cunningham.com> wrote:
>
> Hi Boris,
> Just following up on this issue.
>
> Let's assume I have upgraded ODB and no longer hit the compile errors
> and don't need the workaround.
>
> Then I must admit I am struggling with the correct #pragma db pattern
> to persist a 'complex' value.
>
> We do not know the names of the private data members of 'complex' so
> can only use the public member functions which are standardized across
> all implementations.
>
> I have tried the following, but I am flailing around and getting nowhere.
>
> using FComplex=std::complex<float>;
>
> #ifdef ODB_COMPILER
> #pragma db value(FComplex) definition
> #pragma db member(FComplex::real)   virtual(float) get(real) \
>              set(real)   column("re")
> #pragma db member(FComplex::imag)   virtual(float) get(imag) \
>              set(imag) column("im")
> #endif
>
>
> Andrew
>
> On Fri, May 5, 2023 at 3:50 AM Boris Kolpackov <boris at codesynthesis.com> wrote:
> >
> > Andrew Cunningham <odb at a-cunningham.com> writes:
> >
> > > Whenever I include <complex> in a header file to  be processed by ODB
> > > I get many of the following types of errors. I will be making the
> > > complex data member persistent.
> > >
> > > [...]
> > >
> > > I have been unable to come up with a workaround so far.
> >
> > If upgrading to a later version of ODB is not an option here, I would
> > probably resort to emulating std::complex during the ODB compilation.
> > Something along these lines:
> >
> > #ifndef ODB_COMPILER
> > #  include <complex>
> > #else
> > namespace std
> > {
> >   template <typename T>
> >   class complex
> >   {
> >     T re_;
> >     T im_;
> >
> >   public:
> >     using value_type = T;
> >
> >     complex(T re = T(), T im = T()): re_ (re), im_ (im) {}
> >
> >     complex(const complex&) = default;
> >     complex& operator=(const complex&) = default;
> >
> >     T real() const {return re_;}
> >     void real(T re) {re_ = re;}
> >     T imag() const {return im_;}
> >     void imag(T im) {im_ = im;};
> >   };
> > }
> > #endif
> >
> > You may also need to #ifdef-out any inline code that requires a proper
> > definition std::complex based on the ODB_COMPILER macro.



More information about the odb-users mailing list