From 83550874e5e879f5e213522dbbe645e9137be8b9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 28 Aug 2011 11:39:17 +0200 Subject: Add wrapper support for containers --- common/wrapper/driver.cxx | 38 +++++++++++++++++++++++++++++++++----- common/wrapper/test.hxx | 31 +++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/common/wrapper/driver.cxx b/common/wrapper/driver.cxx index 32ac412..af6a3d1 100644 --- a/common/wrapper/driver.cxx +++ b/common/wrapper/driver.cxx @@ -31,9 +31,6 @@ main (int argc, char* argv[]) // // Simple values. // - - // - // unsigned long id; { object o; @@ -50,8 +47,6 @@ main (int argc, char* argv[]) t.commit (); } - // - // { transaction t (db->begin ()); auto_ptr o (db->load (id)); @@ -101,6 +96,39 @@ main (int argc, char* argv[]) assert (*o->c2 == *co.c2); } } + + // + // Containers. + // + { + cont_object co; + + co.vi.reset (new vector); + co.vi->push_back (1); + co.vi->push_back (2); + co.vi->push_back (3); + + co.c.num = 123; + co.c.strs.reset (new vector); + co.c.strs->push_back ("1"); + co.c.strs->push_back ("2"); + co.c.strs->push_back ("3"); + + { + transaction t (db->begin ()); + id = db->persist (co); + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr o (db->load (id)); + t.commit (); + + assert (*o->vi == *co.vi); + assert (o->c == co.c); + } + } } catch (const odb::exception& e) { diff --git a/common/wrapper/test.hxx b/common/wrapper/test.hxx index b28d7a0..6a1e0a9 100644 --- a/common/wrapper/test.hxx +++ b/common/wrapper/test.hxx @@ -69,7 +69,7 @@ struct comp1 }; inline bool -operator== (const comp1& x, const comp1 y) +operator== (const comp1& x, const comp1& y) { return x.str == y.str && x.num == y.num; } @@ -88,7 +88,7 @@ struct comp2 }; inline bool -operator== (const comp2& x, const comp2 y) +operator== (const comp2& x, const comp2& y) { return x.str == y.str && x.num == y.num && x.strs == y.strs; } @@ -122,4 +122,31 @@ struct comp_object2 std::auto_ptr c3; }; +// +// Containers. +// + +#pragma db value +struct cont_comp +{ + int num; + std::auto_ptr > strs; +}; + +inline bool +operator== (const cont_comp& x, const cont_comp& y) +{ + return x.num == y.num && *x.strs == *y.strs; +} + +#pragma db object +struct cont_object +{ + #pragma db id auto + unsigned long id_; + + std::auto_ptr > vi; // Wrapped container. + cont_comp c; // Wrapped container in comp value. +}; + #endif // TEST_HXX -- cgit v1.1