aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/lazy-ptr/driver.cxx51
-rw-r--r--common/lazy-ptr/test.hxx137
-rw-r--r--common/relationship/driver.cxx14
-rw-r--r--common/relationship/test.hxx39
4 files changed, 156 insertions, 85 deletions
diff --git a/common/lazy-ptr/driver.cxx b/common/lazy-ptr/driver.cxx
index 3e031d3..2e2f140 100644
--- a/common/lazy-ptr/driver.cxx
+++ b/common/lazy-ptr/driver.cxx
@@ -21,18 +21,21 @@
using namespace std;
using namespace odb::core;
-auto_ptr<obj2>
-create (unsigned int id)
+namespace test2
{
- auto_ptr<obj2> r (new obj2 (id));
- return r;
-}
+ obj_ptr
+ create (unsigned int id)
+ {
+ obj_ptr r (new obj (id));
+ return r;
+ }
-lazy_auto_ptr<obj2>
-create (database& db, unsigned int id)
-{
- lazy_auto_ptr<obj2> r (db, id);
- return r;
+ lazy_obj_ptr
+ create (database& db, unsigned int id)
+ {
+ lazy_obj_ptr r (db, id);
+ return r;
+ }
}
int
@@ -45,8 +48,7 @@ main (int argc, char* argv[])
// Raw.
//
{
- typedef cont1 cont;
- typedef obj1 obj;
+ using namespace test1;
// persist
//
@@ -141,28 +143,31 @@ main (int argc, char* argv[])
}
}
- // Auto pointer.
+ // std::auto_ptr/std::unique_ptr
//
{
- typedef cont2 cont;
- typedef obj2 obj;
+ using namespace test2;
// persist
//
{
- auto_ptr<obj> o1 (new obj (1));
+ obj_ptr o1 (new obj (1));
transaction t (db->begin ());
db->persist (*o1);
t.commit ();
}
- auto_ptr<cont> c1 (new cont (1));
- auto_ptr<cont> c2 (new cont (2));
+ cont_ptr c1 (new cont (1));
+ cont_ptr c2 (new cont (2));
- lazy_auto_ptr<obj> lo1 = create (*db, 1);
+ lazy_obj_ptr lo1 = create (*db, 1);
lo1 = create (*db, 1);
+#ifdef HAVE_CXX11
+ c1->o = std::move (lo1);
+#else
c1->o = lo1;
+#endif
c2->o = create (2);
{
@@ -181,7 +186,7 @@ main (int argc, char* argv[])
{
session s;
transaction t (db->begin ());
- auto_ptr<cont> c (db->load<cont> (1));
+ cont_ptr c (db->load<cont> (1));
obj* o (db->load<obj> (1));
// Not loaded.
@@ -202,7 +207,7 @@ main (int argc, char* argv[])
// Load.
//
cont* cl (o->c.load ());
- const auto_ptr<obj>& ol (c->o.load ());
+ const obj_ptr& ol (c->o.load ());
assert (cl == c.get ());
assert (ol.get () == o);
@@ -215,7 +220,7 @@ main (int argc, char* argv[])
{
// No session.
transaction t (db->begin ());
- auto_ptr<cont> c (db->load<cont> (1));
+ cont_ptr c (db->load<cont> (1));
assert (!c->o.loaded ());
c->o.load ();
@@ -233,7 +238,7 @@ main (int argc, char* argv[])
//
#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
{
- using namespace shared;
+ using namespace test3;
// persist
//
diff --git a/common/lazy-ptr/test.hxx b/common/lazy-ptr/test.hxx
index 0adddf8..2813c50 100644
--- a/common/lazy-ptr/test.hxx
+++ b/common/lazy-ptr/test.hxx
@@ -21,87 +21,106 @@
// Raw pointer.
//
-using odb::lazy_ptr;
-class obj1;
-
-#pragma db object
-class cont1
+#pragma db namespace table("t1_")
+namespace test1
{
-public:
- cont1 () {}
- cont1 (unsigned long i): id (i) {}
- ~cont1 ();
+ using odb::lazy_ptr;
+ class obj;
- #pragma db id
- unsigned long id;
+ #pragma db object
+ class cont
+ {
+ public:
+ cont () {}
+ cont (unsigned long i): id (i) {}
+ ~cont ();
- typedef std::vector<lazy_ptr<obj1> > obj_list;
+ #pragma db id
+ unsigned long id;
- #pragma db value_not_null
- obj_list o;
-};
+ typedef std::vector<lazy_ptr<obj> > obj_list;
-#pragma db object
-class obj1
-{
-public:
- obj1 () {}
- obj1 (unsigned long i): id (i) {}
+ #pragma db value_not_null
+ obj_list o;
+ };
- #pragma db id
- unsigned long id;
+ #pragma db object
+ class obj
+ {
+ public:
+ obj () {}
+ obj (unsigned long i): id (i) {}
+
+ #pragma db id
+ unsigned long id;
- #pragma db inverse(o) not_null
- lazy_ptr<cont1> c; // weak
-};
+ #pragma db inverse(o) not_null
+ lazy_ptr<cont> c; // weak
+ };
-inline cont1::
-~cont1 ()
-{
- for (obj_list::iterator i (o.begin ()); i != o.end (); ++i)
- if (obj1* p = i->get ())
- delete p;
+ inline cont::
+ ~cont ()
+ {
+ for (obj_list::iterator i (o.begin ()); i != o.end (); ++i)
+ if (obj* p = i->get ())
+ delete p;
+ }
}
-// Auto pointer.
+// std::auto_ptr/std::unique_ptr
//
-using std::auto_ptr;
-using odb::lazy_auto_ptr;
+#pragma db namespace table("t2_")
+namespace test2
+{
+ using odb::lazy_ptr;
-class obj2;
+ class obj;
+ class cont;
-#pragma db object
-class cont2
-{
-public:
- cont2 () {}
- cont2 (unsigned long i): id (i) {}
+#ifdef HAVE_CXX11
+ typedef std::unique_ptr<obj> obj_ptr;
+ typedef std::unique_ptr<cont> cont_ptr;
+ typedef odb::lazy_unique_ptr<obj> lazy_obj_ptr;
+#else
+ typedef std::auto_ptr<obj> obj_ptr;
+ typedef std::auto_ptr<cont> cont_ptr;
+ typedef odb::lazy_auto_ptr<obj> lazy_obj_ptr;
+#endif
- #pragma db id
- unsigned long id;
+ #pragma db object
+ class cont
+ {
+ public:
+ cont () {}
+ cont (unsigned long i): id (i) {}
- #pragma db not_null
- lazy_auto_ptr<obj2> o;
-};
+ #pragma db id
+ unsigned long id;
-#pragma db object
-class obj2
-{
-public:
- obj2 () {}
- obj2 (unsigned long i): id (i) {}
+ #pragma db not_null
+ lazy_obj_ptr o;
+ };
+
+ #pragma db object
+ class obj
+ {
+ public:
+ obj () {}
+ obj (unsigned long i): id (i) {}
- #pragma db id
- unsigned long id;
+ #pragma db id
+ unsigned long id;
- #pragma db inverse(o) not_null
- lazy_ptr<cont2> c; // weak
-};
+ #pragma db inverse(o) not_null
+ lazy_ptr<cont> c; // weak
+ };
+}
// shared_ptr
//
#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
-namespace shared
+#pragma db namespace table("t3_")
+namespace test3
{
#ifdef HAVE_CXX11
using std::shared_ptr;
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<obj2>)
+struct obj2;
+
+#ifdef HAVE_CXX11
+typedef std::unique_ptr<obj2> obj2_ptr;
+#else
+typedef std::auto_ptr<obj2> 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_ptr> 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<obj2> 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 &&