From f48e807ce5f7072fa6b73848ff29570c270951ca Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 30 Oct 2015 23:24:42 +0100 Subject: [PATCH] Started to use parameter_value_base to simplify parameter_value code --- include/sqlpp11/count.h | 2 +- include/sqlpp11/data_types/boolean.h | 4 +- .../data_types/boolean/parameter_type.h | 66 +------------ include/sqlpp11/data_types/day_point.h | 4 +- include/sqlpp11/data_types/floating_point.h | 4 +- include/sqlpp11/data_types/integral.h | 4 +- .../data_types/integral/parameter_type.h | 65 +------------ .../data_types/integral/wrap_operand.h | 2 +- .../sqlpp11/data_types/parameter_value_base.h | 97 +++++++++++++++++++ include/sqlpp11/data_types/text.h | 4 +- include/sqlpp11/data_types/time_point.h | 4 +- 11 files changed, 121 insertions(+), 135 deletions(-) create mode 100644 include/sqlpp11/data_types/parameter_value_base.h diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index 62e85225..cc33d1b1 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -29,7 +29,7 @@ #include #include -#include +#include namespace sqlpp { diff --git a/include/sqlpp11/data_types/boolean.h b/include/sqlpp11/data_types/boolean.h index d80f9134..dbc2f13a 100644 --- a/include/sqlpp11/data_types/boolean.h +++ b/include/sqlpp11/data_types/boolean.h @@ -28,12 +28,12 @@ #define SQLPP_BOOLEAN_H #include +#include +#include #include #include #include #include -#include -#include #include #endif diff --git a/include/sqlpp11/data_types/boolean/parameter_type.h b/include/sqlpp11/data_types/boolean/parameter_type.h index 33d715a6..2e00b1b3 100644 --- a/include/sqlpp11/data_types/boolean/parameter_type.h +++ b/include/sqlpp11/data_types/boolean/parameter_type.h @@ -28,80 +28,24 @@ #define SQLPP_BOOLEAN_PARAMETER_TYPE_H #include +#include #include -#include -#include #include namespace sqlpp { template <> - struct parameter_value_t + struct parameter_value_t : public base_parameter_value { - using _value_type = boolean; // FIXME - using _cpp_value_type = typename _value_type::_cpp_value_type; - - parameter_value_t() : _value(false), _is_null(true) - { - } - - parameter_value_t(const _cpp_value_type& val) : _value(val), _is_null(false) - { - } - - parameter_value_t& operator=(const _cpp_value_type& val) - { - _value = val; - _is_null = false; - return *this; - } - - parameter_value_t& operator=(const tvin_t>& t) - { - if (t._is_trivial()) - { - _value = false; - _is_null = true; - } - else - { - _value = t._value._t; - _is_null = false; - } - return *this; - } - - parameter_value_t& operator=(const std::nullptr_t&) - { - _value = false; - _is_null = true; - return *this; - } - - bool is_null() const - { - return _is_null; - } - - _cpp_value_type value() const - { - return _value; - } - - operator _cpp_value_type() const - { - return value(); - } + using base = base_parameter_value; + using base::base; + using base::operator=; template void _bind(Target& target, size_t index) const { target._bind_boolean_parameter(index, &_value, _is_null); } - - private: - signed char _value; - bool _is_null; }; } diff --git a/include/sqlpp11/data_types/day_point.h b/include/sqlpp11/data_types/day_point.h index 78f36460..0c6457bd 100644 --- a/include/sqlpp11/data_types/day_point.h +++ b/include/sqlpp11/data_types/day_point.h @@ -28,12 +28,12 @@ #define SQLPP_DAY_POINT_H #include +#include +#include #include #include #include #include -#include -#include #include #endif diff --git a/include/sqlpp11/data_types/floating_point.h b/include/sqlpp11/data_types/floating_point.h index e7c53bba..14731c5e 100644 --- a/include/sqlpp11/data_types/floating_point.h +++ b/include/sqlpp11/data_types/floating_point.h @@ -28,12 +28,12 @@ #define SQLPP_FLOATING_POINT_H #include +#include +#include #include #include #include #include -#include -#include #include #endif diff --git a/include/sqlpp11/data_types/integral.h b/include/sqlpp11/data_types/integral.h index c224f1c0..1aa43498 100644 --- a/include/sqlpp11/data_types/integral.h +++ b/include/sqlpp11/data_types/integral.h @@ -28,12 +28,12 @@ #define SQLPP_INTEGRAL_H #include +#include +#include #include #include #include #include -#include -#include #include #endif diff --git a/include/sqlpp11/data_types/integral/parameter_type.h b/include/sqlpp11/data_types/integral/parameter_type.h index 3d256d45..ba8e1d5d 100644 --- a/include/sqlpp11/data_types/integral/parameter_type.h +++ b/include/sqlpp11/data_types/integral/parameter_type.h @@ -28,79 +28,24 @@ #define SQLPP_INTEGRAL_PARAMETER_TYPE_H #include +#include #include -#include -#include #include namespace sqlpp { template <> - struct parameter_value_t + struct parameter_value_t : public base_parameter_value { - using _value_type = integral; - using _cpp_value_type = typename _value_type::_cpp_value_type; - - parameter_value_t() : _value(0), _is_null(true) - { - } - - explicit parameter_value_t(const _cpp_value_type& val) : _value(val), _is_null(false) - { - } - - parameter_value_t& operator=(const _cpp_value_type& val) - { - _value = val; - _is_null = false; - return *this; - } - - parameter_value_t& operator=(const tvin_t>& t) - { - if (t._is_trivial()) - { - _value = 0; - _is_null = true; - } - else - { - _value = t._value._t; - _is_null = false; - } - return *this; - } - - void set_null() - { - _value = 0; - _is_null = true; - } - - bool is_null() const - { - return _is_null; - } - - const _cpp_value_type& value() const - { - return _value; - } - - operator _cpp_value_type() const - { - return _value; - } + using base = base_parameter_value; + using base::base; + using base::operator=; template void _bind(Target& target, size_t index) const { target._bind_integral_parameter(index, &_value, _is_null); } - - private: - _cpp_value_type _value; - bool _is_null; }; } #endif diff --git a/include/sqlpp11/data_types/integral/wrap_operand.h b/include/sqlpp11/data_types/integral/wrap_operand.h index 9c658bb4..a395b864 100644 --- a/include/sqlpp11/data_types/integral/wrap_operand.h +++ b/include/sqlpp11/data_types/integral/wrap_operand.h @@ -35,7 +35,7 @@ namespace sqlpp struct integral_operand; template - struct wrap_operand::value>::type> + struct wrap_operand::value and not std::is_same::value>::type> { using type = integral_operand; }; diff --git a/include/sqlpp11/data_types/parameter_value_base.h b/include/sqlpp11/data_types/parameter_value_base.h new file mode 100644 index 00000000..2f407498 --- /dev/null +++ b/include/sqlpp11/data_types/parameter_value_base.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2013-2015, 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_PARAMETER_VALUE_BASE_H +#define SQLPP_PARAMETER_VALUE_BASE_H + +#include +#include + +namespace sqlpp +{ + template + struct base_parameter_value + { + using _value_type = DataType; + using _cpp_value_type = typename _value_type::_cpp_value_type; + + base_parameter_value() : _value(0), _is_null(true) + { + } + + explicit base_parameter_value(const _cpp_value_type& val) : _value(val), _is_null(false) + { + } + + base_parameter_value& operator=(const _cpp_value_type& val) + { + _value = val; + _is_null = false; + return *this; + } + + base_parameter_value& operator=(const tvin_t>& t) + { + if (t._is_trivial()) + { + _value = 0; + _is_null = true; + } + else + { + _value = t._value._t; + _is_null = false; + } + return *this; + } + + void set_null() + { + _value = 0; + _is_null = true; + } + + bool is_null() const + { + return _is_null; + } + + const _cpp_value_type& value() const + { + return _value; + } + + operator _cpp_value_type() const + { + return _value; + } + + protected: + _cpp_value_type _value; + bool _is_null; + }; +} +#endif diff --git a/include/sqlpp11/data_types/text.h b/include/sqlpp11/data_types/text.h index dcd08b38..d7099cd4 100644 --- a/include/sqlpp11/data_types/text.h +++ b/include/sqlpp11/data_types/text.h @@ -28,12 +28,12 @@ #define SQLPP_TEXT_H #include +#include +#include #include #include #include #include -#include -#include #include // text specific functions diff --git a/include/sqlpp11/data_types/time_point.h b/include/sqlpp11/data_types/time_point.h index cbf90688..ec982439 100644 --- a/include/sqlpp11/data_types/time_point.h +++ b/include/sqlpp11/data_types/time_point.h @@ -28,12 +28,12 @@ #define SQLPP_TIME_POINT_H #include +#include +#include #include #include #include #include -#include -#include #include #endif