aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-02-28 12:46:48 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-02-28 12:46:48 +0200
commit439bc0ff201f38025d224ce421c86ca44f3dc063 (patch)
tree71d9f025b3ee1dc1a49f83584c2e21a88cc048cd /common
parent564700ab7c96b671b0c08a37e9a0e50f4b2fc176 (diff)
Test std::shared_ptr in C++11 mode and std::tr1::shared_ptr in C++98 mode
Diffstat (limited to 'common')
-rw-r--r--common/inverse/driver.cxx44
-rw-r--r--common/inverse/test.hxx395
-rw-r--r--common/lazy-ptr/driver.cxx44
-rw-r--r--common/lazy-ptr/test.hxx20
-rw-r--r--common/relationship-query/driver.cxx9
-rw-r--r--common/relationship-query/test.hxx43
-rw-r--r--common/relationship/driver.cxx6
-rw-r--r--common/relationship/test.hxx17
8 files changed, 327 insertions, 251 deletions
diff --git a/common/inverse/driver.cxx b/common/inverse/driver.cxx
index c2cc98a..cf66276 100644
--- a/common/inverse/driver.cxx
+++ b/common/inverse/driver.cxx
@@ -28,9 +28,11 @@ main (int argc, char* argv[])
{
auto_ptr<database> db (create_database (argc, argv));
- // Raw pointer version.
+ // Test raw pointers.
//
{
+ using namespace test1;
+
obj1_ptr o1_1 (new obj1);
obj1_ptr o1_2 (new obj1);
obj2_ptr o2 (new obj2);
@@ -208,18 +210,20 @@ main (int argc, char* argv[])
delete o1_2;
}
- // TR1 pointer version.
+ // Test shared_ptr/weak_ptr.
//
-#ifdef HAVE_TR1_MEMORY
+#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
{
- tr1_obj1_ptr o1_1 (new tr1_obj1);
- tr1_obj1_ptr o1_2 (new tr1_obj1);
- tr1_obj2_ptr o2 (new tr1_obj2);
- tr1_obj3_ptr o3_1 (new tr1_obj3);
- tr1_obj3_ptr o3_2 (new tr1_obj3);
- tr1_obj4_ptr o4 (new tr1_obj4);
- tr1_obj5_ptr o5_1 (new tr1_obj5);
- tr1_obj5_ptr o5_2 (new tr1_obj5);
+ using namespace test2;
+
+ obj1_ptr o1_1 (new obj1);
+ obj1_ptr o1_2 (new obj1);
+ obj2_ptr o2 (new obj2);
+ obj3_ptr o3_1 (new obj3);
+ obj3_ptr o3_2 (new obj3);
+ obj4_ptr o4 (new obj4);
+ obj5_ptr o5_1 (new obj5);
+ obj5_ptr o5_2 (new obj5);
o1_1->id = "obj1 1";
o1_1->o2 = o2;
@@ -230,7 +234,7 @@ main (int argc, char* argv[])
o1_1->o5.push_back (o5_2);
o1_2->id = "obj1 2";
- o1_2->o2 = tr1_obj2_ptr ();
+ o1_2->o2 = obj2_ptr ();
o1_2->o3.clear ();
o1_2->o4 = o4;
o1_2->o5.push_back (o5_1);
@@ -279,12 +283,12 @@ main (int argc, char* argv[])
{
session s;
transaction t (db->begin ());
- tr1_obj2_ptr x2 (db->load<tr1_obj2> (o2->id));
- tr1_obj3_ptr x3_1 (db->load<tr1_obj3> (o3_1->id));
- tr1_obj3_ptr x3_2 (db->load<tr1_obj3> (o3_2->id));
- tr1_obj4_ptr x4 (db->load<tr1_obj4> (o4->id));
- tr1_obj5_ptr x5_1 (db->load<tr1_obj5> (o5_1->id));
- tr1_obj5_ptr x5_2 (db->load<tr1_obj5> (o5_2->id));
+ obj2_ptr x2 (db->load<obj2> (o2->id));
+ obj3_ptr x3_1 (db->load<obj3> (o3_1->id));
+ obj3_ptr x3_2 (db->load<obj3> (o3_2->id));
+ obj4_ptr x4 (db->load<obj4> (o4->id));
+ obj5_ptr x5_1 (db->load<obj5> (o5_1->id));
+ obj5_ptr x5_2 (db->load<obj5> (o5_2->id));
t.commit ();
assert (x2->str == o2->str);
@@ -301,7 +305,7 @@ main (int argc, char* argv[])
{
assert (x4->str == o4->str);
- tr1_obj1_ptr t1 (x4->o1[0].lock ()), t2 (x4->o1[1].lock ());
+ obj1_ptr t1 (x4->o1[0].lock ()), t2 (x4->o1[1].lock ());
assert (t1->id == o1_1->id || t2->id == o1_1->id);
assert (t1->id == o1_2->id || t2->id == o1_2->id);
@@ -311,7 +315,7 @@ main (int argc, char* argv[])
assert (x5_1->str == o5_1->str);
assert (x5_2->str == o5_2->str);
- tr1_obj1_ptr t1 (x5_1->o1[0].lock ()), t2 (x5_1->o1[1].lock ()),
+ obj1_ptr t1 (x5_1->o1[0].lock ()), t2 (x5_1->o1[1].lock ()),
t3 (x5_2->o1[0].lock ());
assert (t1->id == o1_1->id || t2->id == o1_1->id);
diff --git a/common/inverse/test.hxx b/common/inverse/test.hxx
index fe47eb8..83b6a3c 100644
--- a/common/inverse/test.hxx
+++ b/common/inverse/test.hxx
@@ -5,7 +5,7 @@
#ifndef TEST_HXX
#define TEST_HXX
-#include <common/config.hxx> // HAVE_TR1_MEMORY
+#include <common/config.hxx> // HAVE_CXX11, HAVE_TR1_MEMORY
#include <set>
#include <vector>
@@ -14,203 +14,222 @@
#include <odb/core.hxx>
-#ifdef HAVE_TR1_MEMORY
+#if !defined(HAVE_CXX11) && defined(HAVE_TR1_MEMORY)
# include <odb/tr1/memory.hxx>
#endif
-struct obj1;
-struct obj2;
-struct obj3;
-struct obj4;
-struct obj5;
-
-typedef obj1* obj1_ptr;
-typedef obj2* obj2_ptr;
-typedef obj3* obj3_ptr;
-typedef obj4* obj4_ptr;
-typedef obj5* obj5_ptr;
-
-typedef std::set<obj1_ptr> obj1_ptr_set;
-typedef std::set<obj3_ptr> obj3_ptr_set;
-typedef std::set<obj5_ptr> obj5_ptr_set;
-
-#pragma db object
-struct obj1
-{
- obj1 (): o2 (0), o4 (0) {}
- ~obj1 ();
-
- #pragma db id
- std::string id;
-
- obj2_ptr o2;
-
- #pragma db id_column("obj1_id") value_column("obj3_id")
- obj3_ptr_set o3;
-
- obj4_ptr o4;
-
- obj5_ptr_set o5;
-};
-
-#pragma db object
-struct obj2
-{
- #pragma db id auto
- int id;
-
- // one-to-one
- //
- #pragma db inverse(o2)
- obj1_ptr o1;
-
- std::string str;
-};
-
-#pragma db object
-struct obj3
-{
- std::string str;
-
- // one(i)-to-many
- //
- #pragma db inverse (o3)
- obj1_ptr o1;
-
- #pragma db id auto
- int id;
-};
-
-#pragma db object
-struct obj4
-{
- #pragma db id auto
- int id;
-
- std::string str;
-
- // many(i)-to-one
- //
- #pragma db inverse (o4)
- obj1_ptr_set o1;
-};
-
-#pragma db object
-struct obj5
-{
- #pragma db id auto
- int id;
-
- std::string str;
-
- // many(i)-to-many
- //
- #pragma db inverse (o5)
- obj1_ptr_set o1;
-};
-
-inline obj1::
-~obj1 ()
+// Test raw pointers.
+//
+#pragma db namespace table("t1_")
+namespace test1
{
- delete o2;
- for (obj3_ptr_set::iterator i (o3.begin ()); i != o3.end (); ++i)
- delete *i;
- delete o4;
- for (obj5_ptr_set::iterator i (o5.begin ()); i != o5.end (); ++i)
- delete *i;
+ struct obj1;
+ struct obj2;
+ struct obj3;
+ struct obj4;
+ struct obj5;
+
+ typedef obj1* obj1_ptr;
+ typedef obj2* obj2_ptr;
+ typedef obj3* obj3_ptr;
+ typedef obj4* obj4_ptr;
+ typedef obj5* obj5_ptr;
+
+ typedef std::set<obj1_ptr> obj1_ptr_set;
+ typedef std::set<obj3_ptr> obj3_ptr_set;
+ typedef std::set<obj5_ptr> obj5_ptr_set;
+
+ #pragma db object
+ struct obj1
+ {
+ obj1 (): o2 (0), o4 (0) {}
+ ~obj1 ();
+
+ #pragma db id
+ std::string id;
+
+ obj2_ptr o2;
+
+ #pragma db id_column("obj1_id") value_column("obj3_id")
+ obj3_ptr_set o3;
+
+ obj4_ptr o4;
+
+ obj5_ptr_set o5;
+ };
+
+ #pragma db object
+ struct obj2
+ {
+ #pragma db id auto
+ int id;
+
+ // one-to-one
+ //
+ #pragma db inverse(o2)
+ obj1_ptr o1;
+
+ std::string str;
+ };
+
+ #pragma db object
+ struct obj3
+ {
+ std::string str;
+
+ // one(i)-to-many
+ //
+ #pragma db inverse (o3)
+ obj1_ptr o1;
+
+ #pragma db id auto
+ int id;
+ };
+
+ #pragma db object
+ struct obj4
+ {
+ #pragma db id auto
+ int id;
+
+ std::string str;
+
+ // many(i)-to-one
+ //
+ #pragma db inverse (o4)
+ obj1_ptr_set o1;
+ };
+
+ #pragma db object
+ struct obj5
+ {
+ #pragma db id auto
+ int id;
+
+ std::string str;
+
+ // many(i)-to-many
+ //
+ #pragma db inverse (o5)
+ obj1_ptr_set o1;
+ };
+
+ inline obj1::
+ ~obj1 ()
+ {
+ delete o2;
+ for (obj3_ptr_set::iterator i (o3.begin ()); i != o3.end (); ++i)
+ delete *i;
+ delete o4;
+ for (obj5_ptr_set::iterator i (o5.begin ()); i != o5.end (); ++i)
+ delete *i;
+ }
}
-// TR1 version
+// Test shared_ptr/weak_ptr.
//
-#ifdef HAVE_TR1_MEMORY
-struct tr1_obj1;
-struct tr1_obj2;
-struct tr1_obj3;
-struct tr1_obj4;
-struct tr1_obj5;
-
-typedef std::tr1::shared_ptr<tr1_obj1> tr1_obj1_ptr;
-typedef std::tr1::shared_ptr<tr1_obj2> tr1_obj2_ptr;
-typedef std::tr1::shared_ptr<tr1_obj3> tr1_obj3_ptr;
-typedef std::tr1::shared_ptr<tr1_obj4> tr1_obj4_ptr;
-typedef std::tr1::shared_ptr<tr1_obj5> tr1_obj5_ptr;
-
-typedef std::tr1::weak_ptr<tr1_obj1> tr1_obj1_wptr;
-
-typedef std::vector<tr1_obj1_wptr> tr1_obj1_wptr_vec;
-typedef std::vector<tr1_obj3_ptr> tr1_obj3_ptr_vec;
-typedef std::vector<tr1_obj5_ptr> tr1_obj5_ptr_vec;
-
-#pragma db object pointer(tr1_obj1_ptr)
-struct tr1_obj1
-{
- #pragma db id
- std::string id;
-
- tr1_obj2_ptr o2;
-
- #pragma db id_column("tr1_obj1_id") value_column("tr1_obj3_id")
- tr1_obj3_ptr_vec o3;
-
- tr1_obj4_ptr o4;
- tr1_obj5_ptr_vec o5;
-};
-
-#pragma db object pointer(tr1_obj2_ptr)
-struct tr1_obj2
-{
- #pragma db id auto
- int id;
-
- std::string str;
-
- // one(i)-to-one
- //
- #pragma db inverse(o2)
- tr1_obj1_wptr o1;
-};
+#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
-#pragma db object pointer(tr1_obj3_ptr)
-struct tr1_obj3
+#pragma db namespace table("t2_")
+namespace test2
{
- #pragma db id auto
- int id;
-
- std::string str;
-
- // one(i)-to-many
- //
- #pragma db inverse (o3)
- tr1_obj1_wptr o1;
-};
-
-#pragma db object pointer(tr1_obj4_ptr)
-struct tr1_obj4
-{
- #pragma db id auto
- int id;
-
- std::string str;
-
- // many(i)-to-one
- //
- #pragma db inverse (o4)
- tr1_obj1_wptr_vec o1;
-};
-
-#pragma db object pointer(tr1_obj5_ptr)
-struct tr1_obj5
-{
- #pragma db id auto
- int id;
-
- std::string str;
+#ifdef HAVE_CXX11
+ using std::shared_ptr;
+ using std::weak_ptr;
+#else
+ using std::tr1::shared_ptr;
+ using std::tr1::weak_ptr;
+#endif
- // many(i)-to-many
- //
- #pragma db inverse (o5)
- tr1_obj1_wptr_vec o1;
-};
+ struct obj1;
+ struct obj2;
+ struct obj3;
+ struct obj4;
+ struct obj5;
+
+ typedef shared_ptr<obj1> obj1_ptr;
+ typedef shared_ptr<obj2> obj2_ptr;
+ typedef shared_ptr<obj3> obj3_ptr;
+ typedef shared_ptr<obj4> obj4_ptr;
+ typedef shared_ptr<obj5> obj5_ptr;
+
+ typedef weak_ptr<obj1> obj1_wptr;
+
+ typedef std::vector<obj1_wptr> obj1_wptr_vec;
+ typedef std::vector<obj3_ptr> obj3_ptr_vec;
+ typedef std::vector<obj5_ptr> obj5_ptr_vec;
+
+ #pragma db object pointer(obj1_ptr)
+ struct obj1
+ {
+ #pragma db id
+ std::string id;
+
+ obj2_ptr o2;
+
+ #pragma db id_column("obj1_id") value_column("obj3_id")
+ obj3_ptr_vec o3;
+
+ obj4_ptr o4;
+ obj5_ptr_vec o5;
+ };
+
+ #pragma db object pointer(obj2_ptr)
+ struct obj2
+ {
+ #pragma db id auto
+ int id;
+
+ std::string str;
+
+ // one(i)-to-one
+ //
+ #pragma db inverse(o2)
+ obj1_wptr o1;
+ };
+
+ #pragma db object pointer(obj3_ptr)
+ struct obj3
+ {
+ #pragma db id auto
+ int id;
+
+ std::string str;
+
+ // one(i)-to-many
+ //
+ #pragma db inverse (o3)
+ obj1_wptr o1;
+ };
+
+ #pragma db object pointer(obj4_ptr)
+ struct obj4
+ {
+ #pragma db id auto
+ int id;
+
+ std::string str;
+
+ // many(i)-to-one
+ //
+ #pragma db inverse (o4)
+ obj1_wptr_vec o1;
+ };
+
+ #pragma db object pointer(obj5_ptr)
+ struct obj5
+ {
+ #pragma db id auto
+ int id;
+
+ std::string str;
+
+ // many(i)-to-many
+ //
+ #pragma db inverse (o5)
+ obj1_wptr_vec o1;
+ };
+}
#endif
#endif // TEST_HXX
diff --git a/common/lazy-ptr/driver.cxx b/common/lazy-ptr/driver.cxx
index 8065e2c..3e031d3 100644
--- a/common/lazy-ptr/driver.cxx
+++ b/common/lazy-ptr/driver.cxx
@@ -6,6 +6,7 @@
//
#include <memory> // std::auto_ptr
+#include <utility> // std::move
#include <cassert>
#include <iostream>
@@ -113,8 +114,13 @@ main (int argc, char* argv[])
// Correct object ids.
//
+#ifdef HAVE_CXX11
+ assert (c->o[0].object_id () == o->id);
+ assert (o->c.object_id () == c->id);
+#else
assert (c->o[0].object_id<obj> () == o->id);
assert (o->c.object_id<cont> () == c->id);
+#endif
// Load.
//
@@ -185,8 +191,13 @@ main (int argc, char* argv[])
// Correct object ids.
//
+#ifdef HAVE_CXX11
+ assert (c->o.object_id () == o->id);
+ assert (o->c.object_id () == c->id);
+#else
assert (c->o.object_id<obj> () == o->id);
assert (o->c.object_id<cont> () == c->id);
+#endif
// Load.
//
@@ -218,12 +229,11 @@ main (int argc, char* argv[])
}
}
- // TR1.
+ // Shared pointer from C++11 or TR1.
//
-#ifdef HAVE_TR1_MEMORY
+#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
{
- using namespace ::tr1;
- using std::tr1::shared_ptr;
+ using namespace shared;
// persist
//
@@ -258,6 +268,22 @@ main (int argc, char* argv[])
assert (lc1 == lazy_shared_ptr<cont> (*db, c1));
assert (lc1 != lazy_shared_ptr<cont> (*db, c2));
+ // Test move constructors.
+ //
+#ifdef HAVE_CXX11
+ {
+ lazy_shared_ptr<cont> tmp (*db, 1);
+ lazy_shared_ptr<cont> l (std::move (tmp));
+ assert (lc1 == l);
+ }
+
+ {
+ shared_ptr<cont> tmp (c1);
+ lazy_shared_ptr<cont> l (*db, std::move (tmp));
+ assert (lc1 == l);
+ }
+#endif
+
{
transaction t (db->begin ());
@@ -289,8 +315,13 @@ main (int argc, char* argv[])
// Correct object ids.
//
+#ifdef HAVE_CXX11
+ assert (c->o[0].object_id () == o->id);
+ assert (o->c.object_id () == c->id);
+#else
assert (c->o[0].object_id<obj> () == o->id);
assert (o->c.object_id<cont> () == c->id);
+#endif
// Load.
//
@@ -315,7 +346,12 @@ main (int argc, char* argv[])
assert (!c->o[1].loaded ());
lazy_shared_ptr<obj> l (c->o[1].lock ());
assert (!l.loaded ());
+
+#ifdef HAVE_CXX11
+ assert (l.object_id () == c->o[1].object_id ());
+#else
assert (l.object_id<obj> () == c->o[1].object_id<obj> ());
+#endif
// Reload.
//
diff --git a/common/lazy-ptr/test.hxx b/common/lazy-ptr/test.hxx
index f9362f8..0adddf8 100644
--- a/common/lazy-ptr/test.hxx
+++ b/common/lazy-ptr/test.hxx
@@ -5,7 +5,7 @@
#ifndef TEST_HXX
#define TEST_HXX
-#include <common/config.hxx> // HAVE_TR1_MEMORY
+#include <common/config.hxx> // HAVE_CXX11, HAVE_TR1_MEMORY
#include <vector>
#include <string>
@@ -14,7 +14,7 @@
#include <odb/core.hxx>
#include <odb/lazy-ptr.hxx>
-#ifdef HAVE_TR1_MEMORY
+#if !defined(HAVE_CXX11) && defined(HAVE_TR1_MEMORY)
# include <odb/tr1/memory.hxx>
# include <odb/tr1/lazy-ptr.hxx>
#endif
@@ -59,8 +59,8 @@ inline cont1::
~cont1 ()
{
for (obj_list::iterator i (o.begin ()); i != o.end (); ++i)
- if (i->loaded ())
- delete i->get ();
+ if (obj1* p = i->get ())
+ delete p;
}
// Auto pointer.
@@ -98,14 +98,20 @@ public:
lazy_ptr<cont2> c; // weak
};
-// TR1.
+// shared_ptr
//
-#ifdef HAVE_TR1_MEMORY
-namespace tr1
+#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
+namespace shared
{
+#ifdef HAVE_CXX11
+ using std::shared_ptr;
+ using odb::lazy_shared_ptr;
+ using odb::lazy_weak_ptr;
+#else
using std::tr1::shared_ptr;
using odb::tr1::lazy_shared_ptr;
using odb::tr1::lazy_weak_ptr;
+#endif
class obj;
diff --git a/common/relationship-query/driver.cxx b/common/relationship-query/driver.cxx
index 56d1f14..58bbef5 100644
--- a/common/relationship-query/driver.cxx
+++ b/common/relationship-query/driver.cxx
@@ -13,7 +13,7 @@
#include <odb/database.hxx>
#include <odb/transaction.hxx>
-#include <common/config.hxx> // HAVE_TR1_MEMORY
+#include <common/config.hxx> // HAVE_CXX11, HAVE_TR1_MEMORY
#include <common/common.hxx>
#include "test.hxx"
@@ -29,9 +29,7 @@ main (int argc, char* argv[])
{
auto_ptr<database> db (create_database (argc, argv));
-#ifdef HAVE_TR1_MEMORY
-
- using std::tr1::shared_ptr;
+#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
//
//
@@ -164,7 +162,8 @@ main (int argc, char* argv[])
t.commit ();
}
-#endif
+#endif // HAVE_CXX11 || HAVE_TR1_MEMORY
+
}
catch (const odb::exception& e)
{
diff --git a/common/relationship-query/test.hxx b/common/relationship-query/test.hxx
index 5168ac4..c2e167c 100644
--- a/common/relationship-query/test.hxx
+++ b/common/relationship-query/test.hxx
@@ -5,21 +5,28 @@
#ifndef TEST_HXX
#define TEST_HXX
-#include <common/config.hxx> // HAVE_TR1_MEMORY
+#include <common/config.hxx> // HAVE_CXX11, HAVE_TR1_MEMORY
-#ifdef HAVE_TR1_MEMORY
+#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
#include <string>
#include <odb/core.hxx>
-#include <odb/tr1/memory.hxx>
+
+#ifdef HAVE_CXX11
+# include <memory>
+using std::shared_ptr;
+#else
+# include <odb/tr1/memory.hxx>
+using std::tr1::shared_ptr;
+#endif
struct country;
#pragma db value
struct residence_info
{
- residence_info (bool p, std::tr1::shared_ptr<country> l)
+ residence_info (bool p, shared_ptr<country> l)
: permanent (p), location (l)
{
}
@@ -31,19 +38,19 @@ struct residence_info
bool permanent;
#pragma db not_null
- std::tr1::shared_ptr<country> location;
+ shared_ptr<country> location;
};
-#pragma db object pointer(std::tr1::shared_ptr)
+#pragma db object pointer(shared_ptr)
struct person
{
person (unsigned long i,
const std::string& fn,
const std::string& ln,
unsigned short a,
- std::tr1::shared_ptr<country> r,
+ shared_ptr<country> r,
bool p,
- std::tr1::shared_ptr<country> n)
+ shared_ptr<country> n)
: id (i),
first_name (fn),
last_name (ln),
@@ -71,24 +78,24 @@ struct person
residence_info residence;
#pragma db not_null
- std::tr1::shared_ptr<country> nationality;
+ shared_ptr<country> nationality;
- std::tr1::shared_ptr<person> husband; // Self-join.
+ shared_ptr<person> husband; // Self-join.
};
struct employer;
-#pragma db object pointer(std::tr1::shared_ptr)
+#pragma db object pointer(shared_ptr)
struct employee: person
{
employee (unsigned long i,
const std::string& fn,
const std::string& ln,
unsigned short a,
- std::tr1::shared_ptr<country> r,
+ shared_ptr<country> r,
bool p,
- std::tr1::shared_ptr<country> n,
- std::tr1::shared_ptr<employer> e)
+ shared_ptr<country> n,
+ shared_ptr<employer> e)
: person (i, fn, ln, a, r, p, n),
employed_by (e)
{
@@ -98,10 +105,10 @@ struct employee: person
{
}
- std::tr1::shared_ptr<employer> employed_by;
+ shared_ptr<employer> employed_by;
};
-#pragma db object pointer(std::tr1::shared_ptr)
+#pragma db object pointer(shared_ptr)
struct employer
{
employer (const std::string& n)
@@ -117,7 +124,7 @@ struct employer
std::string name;
};
-#pragma db object pointer(std::tr1::shared_ptr)
+#pragma db object pointer(shared_ptr)
struct country
{
country (const std::string& c, std::string const& n)
@@ -135,5 +142,5 @@ struct country
std::string name;
};
-#endif // HAVE_TR1_MEMORY
+#endif // HAVE_CXX11 || HAVE_TR1_MEMORY
#endif // TEST_HXX
diff --git a/common/relationship/driver.cxx b/common/relationship/driver.cxx
index 879b123..20e0f0c 100644
--- a/common/relationship/driver.cxx
+++ b/common/relationship/driver.cxx
@@ -30,7 +30,7 @@ main (int argc, char* argv[])
aggr a ("aggr");
a.o1 = new obj1 ("o1", "obj1");
a.o2.reset (new obj2 ("obj2"));
-#ifdef HAVE_TR1_MEMORY
+#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
a.o3.reset (new obj3 ("obj3"));
a.c.num = 123;
@@ -60,7 +60,7 @@ main (int argc, char* argv[])
transaction t (db->begin ());
db->persist (a.o1);
db->persist (a.o2);
-#ifdef HAVE_TR1_MEMORY
+#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
db->persist (a.o3);
db->persist (a.c.o3);
@@ -117,7 +117,7 @@ main (int argc, char* argv[])
delete a.o1;
a.o1 = 0;
a.o2.reset ();
-#ifdef HAVE_TR1_MEMORY
+#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
a.o3.reset ();
#endif
diff --git a/common/relationship/test.hxx b/common/relationship/test.hxx
index bd18747..8b40dba 100644
--- a/common/relationship/test.hxx
+++ b/common/relationship/test.hxx
@@ -5,7 +5,7 @@
#ifndef TEST_HXX
#define TEST_HXX
-#include <common/config.hxx> // HAVE_TR1_MEMORY
+#include <common/config.hxx> // HAVE_CXX11, HAVE_TR1_MEMORY
#include <set>
#include <map>
@@ -15,7 +15,7 @@
#include <odb/core.hxx>
-#ifdef HAVE_TR1_MEMORY
+#if !defined(HAVE_CXX11) && defined(HAVE_TR1_MEMORY)
# include <odb/tr1/memory.hxx>
#endif
@@ -138,11 +138,16 @@ operator== (const obj2& x, const obj2& y)
return x.id == y.id && x.str == y.str;
}
-// tr1::shared_ptr
+// shared_ptr
//
-#ifdef HAVE_TR1_MEMORY
+#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
struct obj3;
+
+#ifdef HAVE_CXX11
+typedef std::shared_ptr<obj3> obj3_ptr;
+#else
typedef std::tr1::shared_ptr<obj3> obj3_ptr;
+#endif
#pragma db object pointer(obj3_ptr)
struct obj3
@@ -211,7 +216,7 @@ struct aggr
obj1* o1;
std::auto_ptr<obj2> o2;
-#ifdef HAVE_TR1_MEMORY
+#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
obj3_ptr o3;
comp c;
comp_vec cv;
@@ -235,7 +240,7 @@ 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_TR1_MEMORY
+#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 &&
x.cv == y.cv &&