4

Is way to move odb (c++ orm like framework) pragmas outside class header? For example I define class basic_object (abstract) with id only:

class basic_object  {
   int _id;
public:
    int get_id() const;
    void set_id(int _id);
};

And then create pragmas for that class in another file

#pragma db object(basic_object) abstract
#pragma db member(basic_object::_id) get(get_id) set(set_id) id auto
Dcow
  • 1,413
  • 1
  • 19
  • 42

1 Answers1

1

Yes, you can, it's called named pragmas.

In your other file you would have to write

#pragma db object(basic_object)
#pragma db member(basic_object::_id) id

Then you have to tell the odb compiler where to look for. You can either do this by adding

#ifdef ODB_COMPILER
#include "other_file.hxx"
#endif

to your original file OR by using

--odb-epilogue '#include "other_file.hxx"'

as parameter to the odb compiler.


But there is one problem in the example class basic_object you had given: Your data field _id is private. You can fix this by

declaring it public

or

by adding the odb access class as a friend in your class with:

private:
friend class odb::access; 
Superlokkus
  • 4,731
  • 1
  • 25
  • 57
  • thanks for answering! For now I already solve problem, but forgot add own solution to topic( In addition to yours answer, I wanna say that not necessarily to make `_id` public or add friend class. Newest versions of ODB Compiler is able to parse/use yours public getters and setters if they fit in common style, or you can add own regex to find their – Dcow Dec 29 '15 at 13:11
  • @Dcow Nice to know thanks (I guess they said this on the mailing list? Didn't read it in the manual) – Superlokkus Dec 29 '15 at 13:18