From 950859af5ff133383dcfd3f0fc70907cc94afd15 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Thu, 19 Sep 2013 17:07:14 +0200 Subject: [PATCH] Rewrote macro generated function code to handwritten code This increases the number of Bytes, but it also increases readability, and reduces complexity. It also allows to specialize functions for database engines. --- include/sqlpp11/any.h | 93 +++++++++++++++++++++++++++++++++++++ include/sqlpp11/avg.h | 92 ++++++++++++++++++++++++++++++++++++ include/sqlpp11/concat.h | 6 ++- include/sqlpp11/count.h | 92 ++++++++++++++++++++++++++++++++++++ include/sqlpp11/exists.h | 92 ++++++++++++++++++++++++++++++++++++ include/sqlpp11/functions.h | 58 ++++------------------- include/sqlpp11/like.h | 6 ++- include/sqlpp11/max.h | 92 ++++++++++++++++++++++++++++++++++++ include/sqlpp11/min.h | 92 ++++++++++++++++++++++++++++++++++++ include/sqlpp11/some.h | 93 +++++++++++++++++++++++++++++++++++++ include/sqlpp11/sum.h | 92 ++++++++++++++++++++++++++++++++++++ 11 files changed, 757 insertions(+), 51 deletions(-) create mode 100644 include/sqlpp11/any.h create mode 100644 include/sqlpp11/avg.h create mode 100644 include/sqlpp11/count.h create mode 100644 include/sqlpp11/exists.h create mode 100644 include/sqlpp11/max.h create mode 100644 include/sqlpp11/min.h create mode 100644 include/sqlpp11/some.h create mode 100644 include/sqlpp11/sum.h diff --git a/include/sqlpp11/any.h b/include/sqlpp11/any.h new file mode 100644 index 00000000..3130a69e --- /dev/null +++ b/include/sqlpp11/any.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2013, 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_ANY_H +#define SQLPP_ANY_H + +#include +#include + +namespace sqlpp +{ + namespace detail + { + template + struct any_t: public boolean::template operators> + { + static_assert(is_select_t::value, "any() requires a single column select expression as argument"); + + struct _value_type: public Select::_value_type::_base_value_type + { + using _is_named_expression = tag_yes; + }; + + struct _name_t + { + static constexpr const char* _get_name() { return "ANY"; } + template + struct _member_t + { + T any; + }; + }; + + any_t(Select&& select): + _select(std::move(select)) + {} + + any_t(const Select& select): + _select(select) + {} + + any_t(const any_t&) = default; + any_t(any_t&&) = default; + any_t& operator=(const any_t&) = default; + any_t& operator=(any_t&&) = default; + ~any_t() = default; + + template + void serialize(std::ostream& os, Db& db) const + { + os << "ANY("; + _select.serialize(os, db); + os << ")"; + } + + private: + Select _select; + }; + } + + template + auto any(T&& t) -> typename detail::any_t::type> + { + return { std::forward(t) }; + } + +} + +#endif diff --git a/include/sqlpp11/avg.h b/include/sqlpp11/avg.h new file mode 100644 index 00000000..fea4e42d --- /dev/null +++ b/include/sqlpp11/avg.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2013, 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_AVG_H +#define SQLPP_AVG_H + +#include +#include + +namespace sqlpp +{ + namespace detail + { + template + struct avg_t: public boolean::template operators> + { + static_assert(is_value_t::value, "avg() requires a value expression as argument"); + + struct _value_type: public Expr::_value_type::_base_value_type + { + using _is_named_expression = tag_yes; + }; + + struct _name_t + { + static constexpr const char* _get_name() { return "AVG"; } + template + struct _member_t + { + T avg; + }; + }; + + avg_t(Expr&& expr): + _expr(std::move(expr)) + {} + + avg_t(const Expr& expr): + _expr(expr) + {} + + avg_t(const avg_t&) = default; + avg_t(avg_t&&) = default; + avg_t& operator=(const avg_t&) = default; + avg_t& operator=(avg_t&&) = default; + ~avg_t() = default; + + template + void serialize(std::ostream& os, Db& db) const + { + os << "AVG("; + _expr.serialize(os, db); + os << ")"; + } + + private: + Expr _expr; + }; + } + + template + auto avg(T&& t) -> typename detail::avg_t::type> + { + return { std::forward(t) }; + } + +} + +#endif diff --git a/include/sqlpp11/concat.h b/include/sqlpp11/concat.h index 0070b6dd..c0b0814b 100644 --- a/include/sqlpp11/concat.h +++ b/include/sqlpp11/concat.h @@ -42,7 +42,11 @@ namespace sqlpp using _valid_args = typename detail::make_set_if_not::type; static_assert(_valid_args::size::value == 0, "at least one non-text argument detected in concat()"); - using _value_type = typename First::_value_type::_base_value_type; + struct _value_type: public First::_value_type::_base_value_type + { + using _is_named_expression = tag_yes; + }; + struct _name_t { static constexpr const char* _get_name() { return "CONCAT"; } diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h new file mode 100644 index 00000000..4a3e0774 --- /dev/null +++ b/include/sqlpp11/count.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2013, 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_COUNT_H +#define SQLPP_COUNT_H + +#include +#include + +namespace sqlpp +{ + namespace detail + { + template + struct count_t: public numeric::template operators> + { + static_assert(is_value_t::value, "count() requires a sql value as argument"); + + struct _value_type: public numeric + { + using _is_named_expression = tag_yes; + }; + + struct _name_t + { + static constexpr const char* _get_name() { return "COUNT"; } + template + struct _member_t + { + T count; + }; + }; + + count_t(Expr&& expr): + _expr(std::move(expr)) + {} + + count_t(const Expr& expr): + _expr(expr) + {} + + count_t(const count_t&) = default; + count_t(count_t&&) = default; + count_t& operator=(const count_t&) = default; + count_t& operator=(count_t&&) = default; + ~count_t() = default; + + template + void serialize(std::ostream& os, Db& db) const + { + os << "COUNT("; + _expr.serialize(os, db); + os << ")"; + } + + private: + Expr _expr; + }; + } + + template + auto count(T&& t) -> typename detail::count_t::type> + { + return { std::forward(t) }; + } + +} + +#endif diff --git a/include/sqlpp11/exists.h b/include/sqlpp11/exists.h new file mode 100644 index 00000000..2b04d8d8 --- /dev/null +++ b/include/sqlpp11/exists.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2013, 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_EXISTS_H +#define SQLPP_EXISTS_H + +#include +#include + +namespace sqlpp +{ + namespace detail + { + template + struct exists_t: public boolean::template operators> + { + static_assert(is_select_t::value, "some() requires a single column select expression as argument"); + static_assert(is_value_t