From fc3fb39c90ab7fe5fccbe3f3bc0eb2645157bb96 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 13 Dec 2023 21:57:53 +0300 Subject: Switch to build2 --- common/bulk/driver.cxx | 88 +++++++++++++++++--------------------------------- 1 file changed, 29 insertions(+), 59 deletions(-) (limited to 'common/bulk/driver.cxx') diff --git a/common/bulk/driver.cxx b/common/bulk/driver.cxx index 2214bfd..23b49ad 100644 --- a/common/bulk/driver.cxx +++ b/common/bulk/driver.cxx @@ -4,9 +4,8 @@ // Test bulk database operations. // -#include // std::auto_ptr +#include // std::unique_ptr #include -#include #include #include @@ -15,12 +14,15 @@ #include -#include // HAVE_CXX11, DATABASE_* -#include +#include // DATABASE_* +#include #include "test.hxx" #include "test-odb.hxx" +#undef NDEBUG +#include + using namespace std; using namespace odb::core; @@ -41,7 +43,7 @@ struct element_traits { typedef T type; typedef T* pointer; - typedef std::auto_ptr auto_ptr; + typedef std::unique_ptr unique_ptr; static T& ref (T& x) {return x;} static T* ptr (T* p) {return p;} @@ -52,43 +54,30 @@ struct element_traits { typedef T type; typedef T* pointer; - typedef std::auto_ptr auto_ptr; + typedef std::unique_ptr unique_ptr; static T& ref (T* p) {return *p;} static T* ptr (T* p) {return p;} }; template -struct element_traits > -{ - typedef T type; - typedef std::auto_ptr pointer; - typedef std::auto_ptr auto_ptr; - - static T& ref (const auto_ptr& p) {return *p;} - static T* ptr (const auto_ptr& p) {return p.get ();} -}; - -#ifdef HAVE_CXX11 -template -struct element_traits> +struct element_traits > { typedef T type; typedef std::unique_ptr pointer; - typedef std::unique_ptr auto_ptr; + typedef std::unique_ptr unique_ptr; - static T& ref (const unique_ptr& p) {return *p;} - static T* ptr (const unique_ptr& p) {return p.get ();} + static T& ref (const unique_ptr& p) {return *p;} + static T* ptr (const unique_ptr& p) {return p.get ();} }; -#endif template void -persist (const auto_ptr& db, I b, I e, bool cont = true) +persist (const unique_ptr& db, I b, I e, bool cont = true) { typedef element_traits traits; typedef typename traits::type type; - typedef typename traits::auto_ptr auto_ptr; + typedef typename traits::unique_ptr unique_ptr; { transaction t (db->begin ()); @@ -104,7 +93,7 @@ persist (const auto_ptr& db, I b, I e, bool cont = true) for (I i (b); i != e; ++i) { type& x (traits::ref (*i)); - auto_ptr p (db->load (x.id)); + unique_ptr p (db->load (x.id)); assert (p->n == x.n && p->s == x.s); } @@ -114,7 +103,7 @@ persist (const auto_ptr& db, I b, I e, bool cont = true) template void -try_persist (const auto_ptr& db, I b, I e, bool cont = true) +try_persist (const unique_ptr& db, I b, I e, bool cont = true) { try { @@ -129,12 +118,12 @@ try_persist (const auto_ptr& db, I b, I e, bool cont = true) template void -update (const auto_ptr& db, I b, I e, +update (const unique_ptr& db, I b, I e, bool modify = true, bool cont = true) { typedef element_traits traits; typedef typename traits::type type; - typedef typename traits::auto_ptr auto_ptr; + typedef typename traits::unique_ptr unique_ptr; if (modify) { @@ -160,7 +149,7 @@ update (const auto_ptr& db, I b, I e, for (I i (b); i != e; ++i) { type& x (traits::ref (*i)); - auto_ptr p (db->load (x.id)); + unique_ptr p (db->load (x.id)); assert (p->n == x.n && p->s == x.s); } @@ -170,7 +159,7 @@ update (const auto_ptr& db, I b, I e, template void -try_update (const auto_ptr& db, I b, I e, bool cont = true) +try_update (const unique_ptr& db, I b, I e, bool cont = true) { try { @@ -185,7 +174,7 @@ try_update (const auto_ptr& db, I b, I e, bool cont = true) template void -erase (const auto_ptr& db, I b, I e) +erase (const unique_ptr& db, I b, I e) { typedef element_traits traits; typedef typename traits::type type; @@ -214,7 +203,7 @@ erase (const auto_ptr& db, I b, I e) template void -erase_id (const auto_ptr& db, I b, I e, bool cont = true) +erase_id (const unique_ptr& db, I b, I e, bool cont = true) { typedef element_traits traits; typedef T type; @@ -239,7 +228,7 @@ erase_id (const auto_ptr& db, I b, I e, bool cont = true) template void -try_erase (const auto_ptr& db, const A& a, bool cont = true) +try_erase (const unique_ptr& db, const A& a, bool cont = true) { try { @@ -255,7 +244,7 @@ try_erase (const auto_ptr& db, const A& a, bool cont = true) template void -test (const auto_ptr& db, I b, I e) +test (const unique_ptr& db, I b, I e) { persist (db, b, e); update (db, b, e); @@ -286,11 +275,12 @@ main (int argc, char* argv[]) { try { - auto_ptr db (create_database (argc, argv)); + unique_ptr db (create_database (argc, argv)); -// @@ TODO: bulk operations in PostgreSQL are only available with libpq >= 14. -// -#if defined(DATABASE_ORACLE) || defined(DATABASE_MSSQL) || defined(DATABASE_PGSQL) +#if !defined(MULTI_DATABASE) && \ + (defined(DATABASE_ORACLE) || \ + defined(DATABASE_MSSQL) || \ + defined(DATABASE_PGSQL)) // Test database class API with various forms of containers // and elements (test #6 is a copy). @@ -328,21 +318,12 @@ main (int argc, char* argv[]) test (db, v.begin (), v.end ()); } -#ifdef HAVE_CXX11 { vector> v; v.push_back (unique_ptr (new unique_object (1, "a"))); v.push_back (unique_ptr (new unique_object (2, "b"))); test (db, v.begin (), v.end ()); } -#else - { - auto_ptr a[2]; - a[0].reset (new auto_object (1, "a")); - a[1].reset (new auto_object (2, "b")); - test (db, a, a + sizeof (a) / sizeof (a[0])); - } -#endif { vector v; @@ -425,7 +406,6 @@ main (int argc, char* argv[]) test (db, v.begin (), v.end ()); } -#ifdef HAVE_CXX11 { typedef unique_ptr unique_ptr; @@ -434,7 +414,6 @@ main (int argc, char* argv[]) v.push_back (unique_ptr (new unique_object ("2", 2, "b"))); test (db, v.begin (), v.end ()); } -#endif // Test const objects. // @@ -990,21 +969,12 @@ main (int argc, char* argv[]) test (db, v.begin (), v.end ()); } -#ifdef HAVE_CXX11 { vector> v; v.push_back (unique_ptr (new unique_object (1, "a"))); v.push_back (unique_ptr (new unique_object (2, "b"))); test (db, v.begin (), v.end ()); } -#else - { - auto_ptr a[2]; - a[0].reset (new auto_object (1, "a")); - a[1].reset (new auto_object (2, "b")); - test (db, a, a + sizeof (a) / sizeof (a[0])); - } -#endif { vector v; -- cgit v1.1