From d706ea36e08230eb21996562e4e129495d871239 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 29 Feb 2012 10:57:43 +0200 Subject: Support for C++11 std::unique_ptr as object pointer This includes the odb::lazy_unique_ptr implementation. --- common/relationship/driver.cxx | 14 ++++++++++++++ common/relationship/test.hxx | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-) (limited to 'common/relationship') diff --git a/common/relationship/driver.cxx b/common/relationship/driver.cxx index 20e0f0c..c6f4b01 100644 --- a/common/relationship/driver.cxx +++ b/common/relationship/driver.cxx @@ -30,6 +30,13 @@ main (int argc, char* argv[]) aggr a ("aggr"); a.o1 = new obj1 ("o1", "obj1"); a.o2.reset (new obj2 ("obj2")); + +#ifdef HAVE_CXX11 + a.v2.push_back (obj2_ptr (new obj2 ("v1 obj2 1"))); + a.v2.push_back (0); + a.v2.push_back (obj2_ptr (new obj2 ("v1 obj2 2"))); +#endif + #if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY) a.o3.reset (new obj3 ("obj3")); @@ -60,6 +67,13 @@ main (int argc, char* argv[]) transaction t (db->begin ()); db->persist (a.o1); db->persist (a.o2); + +#ifdef HAVE_CXX11 + for (obj2_vec::iterator i (a.v2.begin ()); i != a.v2.end (); ++i) + if (*i) + db->persist (*i); +#endif + #if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY) db->persist (a.o3); diff --git a/common/relationship/test.hxx b/common/relationship/test.hxx index 8b40dba..e66e72c 100644 --- a/common/relationship/test.hxx +++ b/common/relationship/test.hxx @@ -118,9 +118,17 @@ operator== (const obj1_map& x, const obj1_map& y) return true; } -// auto_ptr +// auto_ptr/unique_ptr // -#pragma db object pointer(std::auto_ptr) +struct obj2; + +#ifdef HAVE_CXX11 +typedef std::unique_ptr obj2_ptr; +#else +typedef std::auto_ptr obj2_ptr; +#endif + +#pragma db object pointer(obj2_ptr) struct obj2 { obj2 () {} @@ -138,6 +146,23 @@ operator== (const obj2& x, const obj2& y) return x.id == y.id && x.str == y.str; } +#ifdef HAVE_CXX11 +typedef std::vector obj2_vec; + +inline bool +operator== (const obj2_vec& x, const obj2_vec& y) +{ + if (x.size () != y.size ()) + return false; + + for (obj2_vec::size_type i (0); i < x.size (); ++i) + if (!(x[i] ? (y[i] && *x[i] == *y[i]) : !y[i])) + return false; + + return true; +} +#endif + // shared_ptr // #if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY) @@ -215,7 +240,12 @@ struct aggr unsigned long id; obj1* o1; - std::auto_ptr o2; + + obj2_ptr o2; // std::auto_ptr or std::unique_ptr +#ifdef HAVE_CXX11 + obj2_vec v2; +#endif + #if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY) obj3_ptr o3; comp c; @@ -240,6 +270,9 @@ operator== (const aggr& x, const aggr& y) x.id == y.id && (x.o1 ? (y.o1 && *x.o1 == *y.o1) : !y.o1) && (x.o2.get () ? (y.o2.get () && *x.o2 == *y.o2) : !y.o2.get ()) && +#ifdef HAVE_CXX11 + x.v2 == y.v2 && +#endif #if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY) (x.o3.get () ? (y.o3.get () && *x.o3 == *y.o3) : !y.o3.get ()) && x.c == y.c && -- cgit v1.1