Page 1 of 1

How to persist collections of class data members?

PostPosted: Tue Jul 17, 2012 8:31 pm
by marat
How do I persist datamembers that are defined as collections?

For example, if a data member is an STL vector of ints, what needs to be done to map it appropriately in
QxOrm and the Database? Does it need serialization? What should the type of the field be in the database?

Code: Select all
class ExpTable
{
public:

   std::vector<int> intVec_;

   virtual ~ExpTable() {;}
};

Code: Select all
namespace qx {
template <> void register_class(QxClass<ExpTable>& t)
{
   t.data(&ExpTable::intVec, "intColl');
}


Thanks.

Re: How to persist collections of class data members?

PostPosted: Wed Jul 18, 2012 8:16 am
by QxOrm admin
Hi,

How do I persist datamembers that are defined as collections?
For example, if a data member is an STL vector of ints, what needs to be done to map it appropriately in
QxOrm and the Database? Does it need serialization? What should the type of the field be in the database?

For std::vector<int>, there is nothing to do, it will be saved into database in XML format automatically.
There is a Q&R in the FAQ about it : http://www.qxorm.com/qxorm_en/faq.html#faq_180

Re: How to persist collections of class data members?

PostPosted: Wed Jul 18, 2012 3:18 pm
by marat
QxOrm admin wrote:Hi,

How do I persist datamembers that are defined as collections?
For example, if a data member is an STL vector of ints, what needs to be done to map it appropriately in
QxOrm and the Database? Does it need serialization? What should the type of the field be in the database?

For std::vector<int>, there is nothing to do, it will be saved into database in XML format automatically.
There is a Q&R in the FAQ about it : http://www.qxorm.com/qxorm_en/faq.html#faq_180


Thanks that works. On a related topic, how do I persist a user defined class (my own) to be persisted via default XML format into a text column?

Code: Select all
Ex:
class UserDefined
{
public:
    UserDefined();
    char* toString();
private:
    int x, y;
};

Re: How to persist collections of class data members?

PostPosted: Wed Jul 18, 2012 7:16 pm
by QxOrm admin
How do I persist a user defined class (my own) to be persisted via default XML format into a text column ?

If you register your UserDefined class and all its properties into QxOrm context, you have nothing to do => it will be serialized automatically in XML format (default behaviour).
If you don't want to register your own class into QxOrm context, you have to write the boost serialization functions, it's explained in the FAQ here (search ExtObject3D class) : http://www.qxorm.com/qxorm_en/faq.html#faq_180