From 151e92a20374d9259d8a0686916293749740ed88 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 17 Jan 2012 16:43:20 +0200 Subject: Rewrite size() function to not rely in DATABSE_* macros in header Those are not defined for some tests (e.g., database-specific tests built with VC++ project). --- libcommon/common/common.cxx | 12 ++++++++++++ libcommon/common/common.hxx | 17 +++-------------- libcommon/common/common.txx | 26 ++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 libcommon/common/common.txx (limited to 'libcommon') diff --git a/libcommon/common/common.cxx b/libcommon/common/common.cxx index 66a629f..8be7631 100644 --- a/libcommon/common/common.cxx +++ b/libcommon/common/common.cxx @@ -141,3 +141,15 @@ create_database (int& argc, return db; } + +bool +size_available () +{ +#if defined(DATABASE_SQLITE) || \ + defined(DATABASE_ORACLE) || \ + defined(DATABASE_MSSQL) + return false; +#else + return true; +#endif +} diff --git a/libcommon/common/common.hxx b/libcommon/common/common.hxx index 2cf2357..da3737a 100644 --- a/libcommon/common/common.hxx +++ b/libcommon/common/common.hxx @@ -12,7 +12,6 @@ #include // odb::database #include -#include #include // Make sure assert() is not disabled. @@ -32,18 +31,8 @@ create_database (int& argc, // template std::size_t -size (odb::result& r) -{ - std::size_t n (0); -#if defined(DATABASE_SQLITE) || \ - defined(DATABASE_ORACLE) || \ - defined(DATABASE_MSSQL) - for (typename odb::result::iterator i (r.begin ()); i != r.end (); ++i) - n++; -#else - n = r.size (); -#endif - return n; -} +size (odb::result&); + +#include #endif // LIBCOMMON_COMMON_COMMON_HXX diff --git a/libcommon/common/common.txx b/libcommon/common/common.txx new file mode 100644 index 0000000..ef1461e --- /dev/null +++ b/libcommon/common/common.txx @@ -0,0 +1,26 @@ +// file : libcommon/common/common.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// We have to use this helper function instead of just checking which +// database is used because the DATABASE_* macro may not be defined +// in a project that includes this header. +// +LIBCOMMON_EXPORT bool +size_available (); + +template +std::size_t +size (odb::result& r) +{ + if (size_available ()) + return r.size (); + else + { + std::size_t n (0); + for (typename odb::result::iterator i (r.begin ()); i != r.end (); ++i) + n++; + return n; + } +} -- cgit v1.1