From d87a78e24d5988cfa3556707b7beffd1b0c15901 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 11 Sep 2012 13:55:48 +0200 Subject: Add support for mapping std::array to BLOB and char[16] to UUID types --- common/blob/driver.cxx | 6 ++++++ common/blob/test.hxx | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) (limited to 'common') diff --git a/common/blob/driver.cxx b/common/blob/driver.cxx index b280771..ec507ce 100644 --- a/common/blob/driver.cxx +++ b/common/blob/driver.cxx @@ -5,6 +5,8 @@ // Test BLOB mapping. // +#include // HAVE_CXX11 + #include // std::auto_ptr #include #include @@ -47,6 +49,10 @@ main (int argc, char* argv[]) o.vuc.assign (udata, udata + sizeof (data)); memcpy (o.c, data, sizeof (data)); memcpy (o.uc, udata, sizeof (data)); +#ifdef HAVE_CXX11 + memcpy (o.a.data (), data, sizeof (data)); + memcpy (o.ua.data (), udata, sizeof (data)); +#endif o.cont.push_back (1); o.cont.push_back (2); o.cont.push_back (3); diff --git a/common/blob/test.hxx b/common/blob/test.hxx index 9e6434b..5d88d8b 100644 --- a/common/blob/test.hxx +++ b/common/blob/test.hxx @@ -5,17 +5,25 @@ #ifndef TEST_HXX #define TEST_HXX +#include // HAVE_CXX11 + #include #include // std::memcmp +#ifdef HAVE_CXX11 +# include +#endif + #include #ifdef ODB_COMPILER # if defined(ODB_DATABASE_PGSQL) # define BLOB_TYPE "BYTEA" # elif defined(ODB_DATABASE_MSSQL) +//# define BLOB_TYPE "VARBINARY(1024)" # define BLOB_TYPE "VARBINARY(max)" # else +//# define BLOB_TYPE "RAW(1024)" # define BLOB_TYPE "BLOB" # endif #endif @@ -41,7 +49,16 @@ struct object #pragma db type(BLOB_TYPE) unsigned char uc[1024]; - // Make sure we can still use std::vector as a container. +#ifdef HAVE_CXX11 + #pragma db type(BLOB_TYPE) + std::array a; + + #pragma db type(BLOB_TYPE) + std::array ua; +#endif + + // Make sure we can still use std::vector and std::array + // as containers. // std::vector cont; }; @@ -49,13 +66,16 @@ struct object inline bool operator== (const object& x, const object& y) { - return - x.id_ == y.id_ && - x.vc == y.vc && - x.vuc == y.vuc && - std::memcmp (x.c, y.c, sizeof (x.c)) == 0 && - std::memcmp (x.uc, y.uc, sizeof (x.uc)) == 0 && - x.cont == y.cont; + return x.id_ == y.id_ + && x.vc == y.vc + && x.vuc == y.vuc + && std::memcmp (x.c, y.c, sizeof (x.c)) == 0 + && std::memcmp (x.uc, y.uc, sizeof (x.uc)) == 0 +#ifdef HAVE_CXX11 + && x.a == y.a + && x.ua == y.ua +#endif + && x.cont == y.cont; } #endif // TEST_HXX -- cgit v1.1