From 1e1a40eb86919a19b0c6738741be50ec084be596 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 18 Apr 2011 18:45:35 +0200 Subject: Get rid of image type argument in value_traits --- odb/mysql/query.hxx | 50 +++++++++------------ odb/mysql/traits.hxx | 121 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 118 insertions(+), 53 deletions(-) diff --git a/odb/mysql/query.hxx b/odb/mysql/query.hxx index d58fb30..f4845cf 100644 --- a/odb/mysql/query.hxx +++ b/odb/mysql/query.hxx @@ -1030,7 +1030,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1063,7 +1063,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1098,7 +1098,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1131,8 +1131,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image ( - image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1167,7 +1166,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1200,7 +1199,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1235,7 +1234,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1268,8 +1267,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image ( - image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1304,7 +1302,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1339,7 +1337,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1375,8 +1373,7 @@ namespace odb { bool dummy; std::size_t size, cap (buffer_.capacity ()); - value_traits::set_image ( - buffer_, size, dummy, v); + value_traits::set_image (buffer_, size, dummy, v); size_ = static_cast (size); return cap != buffer_.capacity (); } @@ -1413,7 +1410,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1447,7 +1444,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1481,7 +1478,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1515,8 +1512,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image ( - image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1551,7 +1547,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits::set_image (image_, dummy, v); + value_traits::set_image (image_, dummy, v); } private: @@ -1587,8 +1583,7 @@ namespace odb { bool dummy; std::size_t size, cap (buffer_.capacity ()); - value_traits::set_image ( - buffer_, size, dummy, v); + value_traits::set_image (buffer_, size, dummy, v); size_ = static_cast (size); return cap != buffer_.capacity (); } @@ -1627,8 +1622,7 @@ namespace odb { bool dummy; std::size_t size, cap (buffer_.capacity ()); - value_traits::set_image ( - buffer_, size, dummy, v); + value_traits::set_image (buffer_, size, dummy, v); size_ = static_cast (size); return cap != buffer_.capacity (); } @@ -1668,7 +1662,7 @@ namespace odb { bool dummy; std::size_t size; - value_traits::set_image ( + value_traits::set_image ( buffer_, sizeof (buffer_), size, dummy, v); size_ = static_cast (size); } @@ -1709,8 +1703,7 @@ namespace odb { bool dummy; std::size_t size, cap (buffer_.capacity ()); - value_traits::set_image ( - buffer_, size, dummy, v); + value_traits::set_image (buffer_, size, dummy, v); size_ = static_cast (size); return cap != buffer_.capacity (); } @@ -1749,8 +1742,7 @@ namespace odb { bool dummy; std::size_t size, cap (buffer_.capacity ()); - value_traits::set_image ( - buffer_, size, dummy, v); + value_traits::set_image (buffer_, size, dummy, v); size_ = static_cast (size); return cap != buffer_.capacity (); } diff --git a/odb/mysql/traits.hxx b/odb/mysql/traits.hxx index 63673ff..5418fa1 100644 --- a/odb/mysql/traits.hxx +++ b/odb/mysql/traits.hxx @@ -54,26 +54,99 @@ namespace odb }; // + // image_traits + // + + template + struct image_traits; + + template <> + struct image_traits {typedef signed char image_type;}; + + template <> + struct image_traits {typedef unsigned char image_type;}; + + template <> + struct image_traits {typedef short image_type;}; + + template <> + struct image_traits {typedef unsigned short image_type;}; + + template <> + struct image_traits {typedef int image_type;}; + + template <> + struct image_traits {typedef unsigned int image_type;}; + + template <> + struct image_traits {typedef long long image_type;}; + + template <> + struct image_traits {typedef unsigned long long image_type;}; + + template <> + struct image_traits {typedef float image_type;}; + + template <> + struct image_traits {typedef double image_type;}; + + template <> + struct image_traits {typedef details::buffer image_type;}; + + template <> + struct image_traits {typedef MYSQL_TIME image_type;}; + + template <> + struct image_traits {typedef MYSQL_TIME image_type;}; + + template <> + struct image_traits {typedef MYSQL_TIME image_type;}; + + template <> + struct image_traits {typedef MYSQL_TIME image_type;}; + + template <> + struct image_traits {typedef short image_type;}; + + template <> + struct image_traits {typedef details::buffer image_type;}; + + template <> + struct image_traits {typedef details::buffer image_type;}; + + template <> + struct image_traits {typedef unsigned char* image_type;}; + + // Note: default mapping is to integer. Alternative mapping is to + // string. + // + template <> + struct image_traits {typedef unsigned short image_type;}; + + template <> + struct image_traits {typedef details::buffer image_type;}; + + // // value_traits // - template + template struct default_value_traits; - template - class value_traits: public default_value_traits + template + class value_traits: public default_value_traits { }; - template + template struct default_value_traits { typedef T value_type; typedef T query_type; - typedef I image_type; + typedef typename image_traits::image_type image_type; static void - set_value (T& v, I i, bool is_null) + set_value (T& v, const image_type& i, bool is_null) { if (!is_null) v = T (i); @@ -82,10 +155,10 @@ namespace odb } static void - set_image (I& i, bool& is_null, T v) + set_image (image_type& i, bool& is_null, T v) { is_null = false; - i = I (v); + i = image_type (v); } }; @@ -118,26 +191,26 @@ namespace odb }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - std::string, details::buffer, id_string>: string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits: + string_value_traits { }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - std::string, details::buffer, id_decimal>: string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits: + string_value_traits { }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - std::string, details::buffer, id_enum>: string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits: + string_value_traits { }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - std::string, details::buffer, id_set>: string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits: + string_value_traits { }; @@ -162,26 +235,26 @@ namespace odb }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - const char*, details::buffer, id_string>: c_string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits: + c_string_value_traits { }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - const char*, details::buffer, id_decimal>: c_string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits: + c_string_value_traits { }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - const char*, details::buffer, id_enum>: c_string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits: + c_string_value_traits { }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - const char*, details::buffer, id_set>: c_string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits: + c_string_value_traits { }; -- cgit v1.1