github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/3rd_party/fflib/include/ff/sql/columns.h (about) 1 /*********************************************** 2 The MIT License (MIT) 3 4 Copyright (c) 2012 Athrun Arthur <athrunarthur@gmail.com> 5 6 Permission is hereby granted, free of charge, to any person obtaining a copy 7 of this software and associated documentation files (the "Software"), to deal 8 in the Software without restriction, including without limitation the rights 9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 copies of the Software, and to permit persons to whom the Software is 11 furnished to do so, subject to the following conditions: 12 13 The above copyright notice and this permission notice shall be included in 14 all copies or substantial portions of the Software. 15 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 THE SOFTWARE. 23 *************************************************/ 24 #pragma once 25 #include "ff/sql/common.h" 26 #include "ff/sql/stmt.h" 27 #include "ff/util/type_list.h" 28 29 namespace ff { 30 namespace sql { 31 32 template <typename T> struct column_base { typedef T type; }; 33 template <typename T> struct column : public column_base<T> {}; 34 35 template <typename T> class index : public column_base<T> {}; 36 37 template <typename T> class key : public column_base<T> {}; 38 39 // template <typename TT, typename CT> struct table_column { 40 // typedef TT table_type; 41 // typedef CT column_type; 42 // typedef typename CT::type type; 43 //}; 44 45 template <typename TL> struct get_key_column_type {}; 46 47 template <typename T, typename... TS> 48 struct get_key_column_type<ff::util::type_list<T, TS...>> { 49 typedef typename std::conditional< 50 std::is_base_of<key<typename T::type>, T>::value, T, 51 typename get_key_column_type<ff::util::type_list<TS...>>::type>::type 52 type; 53 }; 54 55 template <> struct get_key_column_type<ff::util::type_list<>> { 56 typedef void type; 57 }; 58 } // namespace sql 59 } // namespace ff 60 61 #define define_column(_name, _type, _dtype, _tname) \ 62 struct _name : public ::ff::sql::_type<_dtype> { \ 63 constexpr static const char *name = _tname; \ 64 static ff::sql::eq_cond_stmt<_name> eq(const _dtype &value) { \ 65 return ff::sql::eq_cond_stmt<_name>(value); \ 66 } \ 67 static ff::sql::ne_cond_stmt<_name> ne(const _dtype &value) { \ 68 return ff::sql::ne_cond_stmt<_name>(value); \ 69 } \ 70 static ff::sql::le_cond_stmt<_name> le(const _dtype &value) { \ 71 return ff::sql::le_cond_stmt<_name>(value); \ 72 } \ 73 static ff::sql::ge_cond_stmt<_name> ge(const _dtype &value) { \ 74 return ff::sql::ge_cond_stmt<_name>(value); \ 75 } \ 76 }; \ 77 namespace ff { \ 78 namespace util { \ 79 namespace internal { \ 80 template <> struct nt_traits<_name> { \ 81 constexpr static const char *name = _tname; \ 82 typedef _dtype type; \ 83 }; \ 84 } \ 85 } \ 86 } 87