Utilize parameter_value_base for the remaining data types

This commit is contained in:
rbock
2015-10-30 23:48:07 +01:00
parent f48e807ce5
commit de1e8f27a4
5 changed files with 23 additions and 238 deletions
@@ -28,6 +28,7 @@
#define SQLPP_DAY_POINT_PARAMETER_TYPE_H
#include <sqlpp11/data_types/parameter_value.h>
#include <sqlpp11/data_types/parameter_value_base.h>
#include <sqlpp11/data_types/day_point/data_type.h>
#include <sqlpp11/data_types/day_point/wrap_operand.h>
#include <sqlpp11/data_types/day_point/operand.h>
@@ -36,71 +37,17 @@
namespace sqlpp
{
template <>
struct parameter_value_t<day_point>
struct parameter_value_t<day_point> : public base_parameter_value<day_point>
{
using _value_type = day_point;
using _cpp_value_type = typename _value_type::_cpp_value_type;
parameter_value_t() : _value{}, _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<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = _cpp_value_type{};
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
void set_null()
{
_value = _cpp_value_type{};
_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<day_point>;
using base::base;
using base::operator=;
template <typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_date_parameter(index, &_value, _is_null);
}
private:
_cpp_value_type _value;
bool _is_null;
};
}
#endif
@@ -28,6 +28,7 @@
#define SQLPP_FLOATING_POINT_PARAMETER_TYPE_H
#include <sqlpp11/data_types/parameter_value.h>
#include <sqlpp11/data_types/parameter_value_base.h>
#include <sqlpp11/data_types/floating_point/data_type.h>
#include <sqlpp11/data_types/floating_point/wrap_operand.h>
#include <sqlpp11/data_types/floating_point/operand.h>
@@ -36,72 +37,17 @@
namespace sqlpp
{
template <>
struct parameter_value_t<floating_point>
struct parameter_value_t<floating_point> : public base_parameter_value<floating_point>
{
using _value_type = floating_point;
using _cpp_value_type = typename _value_type::_cpp_value_type;
parameter_value_t() : _value(0), _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<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = 0;
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
parameter_value_t& operator=(const std::nullptr_t&)
{
_value = 0;
_is_null = true;
return *this;
}
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<floating_point>;
using base::base;
using base::operator=;
template <typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_floating_point_parameter(index, &_value, _is_null);
}
private:
_cpp_value_type _value;
bool _is_null;
};
}
#endif
@@ -38,7 +38,7 @@ namespace sqlpp
using _value_type = DataType;
using _cpp_value_type = typename _value_type::_cpp_value_type;
base_parameter_value() : _value(0), _is_null(true)
base_parameter_value() : _value{}, _is_null{true}
{
}
@@ -57,7 +57,7 @@ namespace sqlpp
{
if (t._is_trivial())
{
_value = 0;
_value = {};
_is_null = true;
}
else
@@ -70,7 +70,7 @@ namespace sqlpp
void set_null()
{
_value = 0;
_value = {};
_is_null = true;
}
@@ -28,6 +28,7 @@
#define SQLPP_TEXT_PARAMETER_TYPE_H
#include <sqlpp11/data_types/parameter_value.h>
#include <sqlpp11/data_types/parameter_value_base.h>
#include <sqlpp11/data_types/text/data_type.h>
#include <sqlpp11/data_types/text/wrap_operand.h>
#include <sqlpp11/data_types/text/operand.h>
@@ -36,72 +37,17 @@
namespace sqlpp
{
template <>
struct parameter_value_t<text>
struct parameter_value_t<text> : public base_parameter_value<text>
{
using _value_type = text;
using _cpp_value_type = typename _value_type::_cpp_value_type;
parameter_value_t() : _value(""), _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<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = "";
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
parameter_value_t& operator=(const std::nullptr_t&)
{
_value = "";
_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<text>;
using base::base;
using base::operator=;
template <typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_text_parameter(index, &_value, _is_null);
}
private:
_cpp_value_type _value;
bool _is_null;
};
}
#endif
@@ -28,6 +28,7 @@
#define SQLPP_TIME_POINT_PARAMETER_TYPE_H
#include <sqlpp11/data_types/parameter_value.h>
#include <sqlpp11/data_types/parameter_value_base.h>
#include <sqlpp11/data_types/time_point/data_type.h>
#include <sqlpp11/data_types/time_point/wrap_operand.h>
#include <sqlpp11/data_types/time_point/operand.h>
@@ -35,73 +36,18 @@
namespace sqlpp
{
// time_point parameter value
template <>
struct parameter_value_t<time_point>
struct parameter_value_t<time_point> : public base_parameter_value<time_point>
{
using _value_type = time_point;
using _cpp_value_type = typename _value_type::_cpp_value_type;
parameter_value_t() : _value{}, _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<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = _cpp_value_type{};
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
void set_null()
{
_value = _cpp_value_type{};
_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<time_point>;
using base::base;
using base::operator=;
template <typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_date_time_parameter(index, &_value, _is_null);
}
private:
_cpp_value_type _value;
bool _is_null;
};
}
#endif