From 828106acbdacbbadcee1f2f58b03ea095fc0fc9c Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 30 Jul 2014 17:56:33 +0200 Subject: [PATCH] Moved shared result field code into separate file --- include/sqlpp11/boolean.h | 41 +---------- include/sqlpp11/floating_point.h | 41 +---------- include/sqlpp11/integral.h | 41 +---------- include/sqlpp11/result_field_methods.h | 97 ++++++++++++++++++++++++++ include/sqlpp11/text.h | 41 +---------- include/sqlpp11/type_traits.h | 3 + 6 files changed, 108 insertions(+), 156 deletions(-) create mode 100644 include/sqlpp11/result_field_methods.h diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index 1ae482ac..d37b7546 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -32,6 +32,7 @@ #include #include #include +#include namespace sqlpp { @@ -97,46 +98,8 @@ namespace sqlpp }; template - struct _result_field_t; - - // I am SO waiting for concepts lite! - template - struct field_methods_t + struct _result_field_t: public result_field_methods_t<_result_field_t> { - static constexpr bool _null_is_trivial = true; - operator _cpp_value_type() const { return static_cast(*this).value(); } - }; - - template - struct field_methods_t< - _result_field_t, - typename std::enable_if::value - and column_spec_can_be_null_t::value - and not null_is_trivial_value_t::value>::type> - { - static constexpr bool _null_is_trivial = false; - }; - - template - struct _result_field_t: public field_methods_t<_result_field_t> - { - using _field_methods_t = field_methods_t<_result_field_t>; - - using _traits = make_traits>; - - struct _recursive_traits - { - using _parameters = std::tuple<>; - using _provided_tables = detail::type_set<>; - using _provided_outer_tables = detail::type_set<>; - using _required_tables = detail::type_set<>; - using _extra_tables = detail::type_set<>; - using _can_be_null = column_spec_can_be_null_t; - }; - _result_field_t(): _is_valid(false), _is_null(true), diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h index 0feb7f7e..a9decec7 100644 --- a/include/sqlpp11/floating_point.h +++ b/include/sqlpp11/floating_point.h @@ -31,6 +31,7 @@ #include #include #include +#include namespace sqlpp { @@ -96,46 +97,8 @@ namespace sqlpp }; template - struct _result_field_t; - - // I am SO waiting for concepts lite! - template - struct field_methods_t + struct _result_field_t: public result_field_methods_t<_result_field_t> { - static constexpr bool _null_is_trivial = true; - operator _cpp_value_type() const { return static_cast(*this).value(); } - }; - - template - struct field_methods_t< - _result_field_t, - typename std::enable_if::value - and column_spec_can_be_null_t::value - and not null_is_trivial_value_t::value>::type> - { - static constexpr bool _null_is_trivial = false; - }; - - template - struct _result_field_t: public field_methods_t<_result_field_t> - { - using _field_methods_t = field_methods_t<_result_field_t>; - - using _traits = make_traits>; - - struct _recursive_traits - { - using _parameters = std::tuple<>; - using _provided_tables = detail::type_set<>; - using _provided_outer_tables = detail::type_set<>; - using _required_tables = detail::type_set<>; - using _extra_tables = detail::type_set<>; - using _can_be_null = column_spec_can_be_null_t; - }; - _result_field_t(): _is_valid(false), _is_null(true), diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index f100e81b..f99d772c 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace sqlpp { @@ -97,46 +98,8 @@ namespace sqlpp }; template - struct _result_field_t; - - // I am SO waiting for concepts lite! - template - struct field_methods_t + struct _result_field_t: public result_field_methods_t<_result_field_t> { - static constexpr bool _null_is_trivial = true; - operator _cpp_value_type() const { return static_cast(*this).value(); } - }; - - template - struct field_methods_t< - _result_field_t, - typename std::enable_if::value - and column_spec_can_be_null_t::value - and not null_is_trivial_value_t::value>::type> - { - static constexpr bool _null_is_trivial = false; - }; - - template - struct _result_field_t: public field_methods_t<_result_field_t> - { - using _field_methods_t = field_methods_t<_result_field_t>; - - using _traits = make_traits>; - - struct _recursive_traits - { - using _parameters = std::tuple<>; - using _provided_tables = detail::type_set<>; - using _provided_outer_tables = detail::type_set<>; - using _required_tables = detail::type_set<>; - using _extra_tables = detail::type_set<>; - using _can_be_null = column_spec_can_be_null_t; - }; - _result_field_t(): _is_valid(false), _is_null(true), diff --git a/include/sqlpp11/result_field_methods.h b/include/sqlpp11/result_field_methods.h new file mode 100644 index 00000000..c561a0d2 --- /dev/null +++ b/include/sqlpp11/result_field_methods.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2013-2014, Roland Bock + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SQLPP_RESULT_FIELD_METHODS_H +#define SQLPP_RESULT_FIELD_METHODS_H + +#include + +namespace sqlpp +{ + namespace detail + { + template + struct get_field_spec_impl + { + static_assert(wrong_t::value, "Invalid argument for get_field_spec"); + }; + + template class Field, typename Db, typename FieldSpec> + struct get_field_spec_impl> + { + using type = FieldSpec; + }; + + template + using get_field_spec_t = typename get_field_spec_impl::type; + } + + template + struct result_field_methods_base_t + { + using _field_spec_t = detail::get_field_spec_t; + static constexpr bool _null_is_trivial = true; + operator cpp_value_type_of<_field_spec_t>() const { return static_cast(*this).value(); } + }; + + template class Field, typename Db, typename FieldSpec> + struct result_field_methods_base_t< + Field, + typename std::enable_if::value + and column_spec_can_be_null_t::value + and not null_is_trivial_value_t::value>::type> + { + using _field_spec_t = FieldSpec; + static constexpr bool _null_is_trivial = false; + }; + + template + struct result_field_methods_t: public result_field_methods_base_t + { + using _base_t = result_field_methods_base_t; + using _field_spec_t = typename _base_t::_field_spec_t; + + using _traits = make_traits, + tag::is_result_field, + tag::is_expression, + tag_if>; + + struct _recursive_traits + { + using _parameters = std::tuple<>; + using _provided_tables = detail::type_set<>; + using _provided_outer_tables = detail::type_set<>; + using _required_tables = detail::type_set<>; + using _extra_tables = detail::type_set<>; + using _can_be_null = column_spec_can_be_null_t<_field_spec_t>; + }; + + using _name_t = typename _field_spec_t::_name_t; + + }; + +} +#endif diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index d1ba51e2..1a264676 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -32,6 +32,7 @@ #include #include #include +#include namespace sqlpp { @@ -96,46 +97,8 @@ namespace sqlpp }; template - struct _result_field_t; - - // I am SO waiting for concepts lite! - template - struct field_methods_t + struct _result_field_t: public result_field_methods_t<_result_field_t> { - static constexpr bool _null_is_trivial = true; - operator _cpp_value_type() const { return static_cast(*this).value(); } - }; - - template - struct field_methods_t< - _result_field_t, - typename std::enable_if::value - and column_spec_can_be_null_t::value - and not null_is_trivial_value_t::value>::type> - { - static constexpr bool _null_is_trivial = false; - }; - - template - struct _result_field_t: public field_methods_t<_result_field_t> - { - using _field_methods_t = field_methods_t<_result_field_t>; - - using _traits = make_traits>; - - struct _recursive_traits - { - using _parameters = std::tuple<>; - using _provided_tables = detail::type_set<>; - using _provided_outer_tables = detail::type_set<>; - using _required_tables = detail::type_set<>; - using _extra_tables = detail::type_set<>; - using _can_be_null = column_spec_can_be_null_t; - }; - _result_field_t(): _is_valid(false), _value_ptr(nullptr), diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 79e3f22a..f12f1785 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -192,6 +192,9 @@ namespace sqlpp template using value_type_of = typename detail::value_type_of_impl::type; + template + using cpp_value_type_of = typename value_type_of::_cpp_value_type; + template using required_tables_of = typename detail::required_table_of_impl::type;