diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-02-28 12:46:48 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-02-28 12:46:48 +0200 |
commit | 439bc0ff201f38025d224ce421c86ca44f3dc063 (patch) | |
tree | 71d9f025b3ee1dc1a49f83584c2e21a88cc048cd /common/relationship-query | |
parent | 564700ab7c96b671b0c08a37e9a0e50f4b2fc176 (diff) |
Test std::shared_ptr in C++11 mode and std::tr1::shared_ptr in C++98 mode
Diffstat (limited to 'common/relationship-query')
-rw-r--r-- | common/relationship-query/driver.cxx | 9 | ||||
-rw-r--r-- | common/relationship-query/test.hxx | 43 |
2 files changed, 29 insertions, 23 deletions
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 |