OmniSciDB  c07336695a
SQLTypeUtilities.h
Go to the documentation of this file.
1 #ifndef SQLTYPEUTILITIES_H
2 #define SQLTYPEUTILITIES_H
3 
4 template <SQLTypes... TYPE_SET>
6  public:
7  OnTypesetMember() = delete;
8 
9  template <typename SQL_INFO_TYPE>
10  OnTypesetMember(SQL_INFO_TYPE const& s)
11  : resolved_(internalResolveType<SQL_INFO_TYPE, TYPE_SET...>(s)) {}
12 
13  template <typename SQL_INFO_TYPE, typename FUNCTOR_TYPE>
14  OnTypesetMember(SQL_INFO_TYPE const& s, FUNCTOR_TYPE f)
15  : resolved_(internalResolveType<SQL_INFO_TYPE, TYPE_SET...>(s)) {
16  if (resolved_) {
17  f();
18  }
19  }
20 
21  template <typename SQL_INFO_TYPE,
22  typename SUCCESS_FUNCTOR_TYPE,
23  typename FAILURE_FUNCTOR_TYPE>
24  OnTypesetMember(SQL_INFO_TYPE const& s,
25  SUCCESS_FUNCTOR_TYPE success,
26  FAILURE_FUNCTOR_TYPE failure)
27  : resolved_(internalResolveType<SQL_INFO_TYPE, TYPE_SET...>(s)) {
28  resolved_ ? success() : failure();
29  }
30 
31  template <typename SQL_INFO_TYPE, typename FUNCTOR_TYPE>
32  bool operator()(SQL_INFO_TYPE const& s, FUNCTOR_TYPE failure) const {
33  bool resolved = internalResolveType<TYPE_SET...>(s);
34  if (resolved) {
35  failure();
36  }
37  return resolved;
38  }
39 
40  template <typename SQL_INFO_TYPE,
41  typename SUCCESS_FUNCTOR_TYPE,
42  typename FAILURE_FUNCTOR_TYPE>
43  bool operator()(SQL_INFO_TYPE const& s,
44  SUCCESS_FUNCTOR_TYPE success,
45  FAILURE_FUNCTOR_TYPE failure) const {
46  bool resolved = internalResolveType<SQL_INFO_TYPE, TYPE_SET...>(s);
47  resolved ? success() : failure();
48  return resolved;
49  }
50 
51  operator bool() const { return resolved_; }
52 
53  private:
54  template <typename SQL_INFO_TYPE, SQLTypes TYPE>
55  bool internalResolveType(SQL_INFO_TYPE const& s) const {
56  if (s.get_type() == TYPE) {
57  return true;
58  }
59  return false;
60  }
61 
62  template <typename SQL_INFO_TYPE,
63  SQLTypes TYPE,
64  SQLTypes SECOND_TYPE,
65  SQLTypes... REMAINING_TYPES>
66  bool internalResolveType(SQL_INFO_TYPE const& s) const {
67  if (s.get_type() == TYPE) {
68  return true;
69  }
70  return internalResolveType<SQL_INFO_TYPE, SECOND_TYPE, REMAINING_TYPES...>(s);
71  }
72 
73  bool const resolved_ = false;
74 };
75 
76 template <SQLTypes... TYPE_SET, typename SQL_INFO_TYPE>
77 bool is_member_of_typeset(SQL_INFO_TYPE const& s) {
78  return OnTypesetMember<TYPE_SET...>(s);
79 }
80 
81 template <SQLTypes... TYPE_SET, typename SUCCESS_FUNCTOR_TYPE, typename SQL_INFO_TYPE>
82 bool on_member_of_typeset(SQL_INFO_TYPE const& s, SUCCESS_FUNCTOR_TYPE success) {
83  return OnTypesetMember<TYPE_SET...>(s, success);
84 }
85 
86 template <SQLTypes... TYPE_SET,
87  typename SUCCESS_FUNCTOR_TYPE,
88  typename FAILURE_FUNCTOR_TYPE,
89  typename SQL_INFO_TYPE>
90 bool on_member_of_typeset(SQL_INFO_TYPE const& s,
91  SUCCESS_FUNCTOR_TYPE success,
92  FAILURE_FUNCTOR_TYPE failure) {
93  return OnTypesetMember<TYPE_SET...>(s, success, failure);
94 }
95 
96 #endif
OnTypesetMember()=delete
SQLTypes
Definition: sqltypes.h:40
bool on_member_of_typeset(SQL_INFO_TYPE const &s, SUCCESS_FUNCTOR_TYPE success)
bool is_member_of_typeset(SQL_INFO_TYPE const &s)
OnTypesetMember(SQL_INFO_TYPE const &s, SUCCESS_FUNCTOR_TYPE success, FAILURE_FUNCTOR_TYPE failure)
bool internalResolveType(SQL_INFO_TYPE const &s) const
bool operator()(SQL_INFO_TYPE const &s, FUNCTOR_TYPE failure) const
bool const resolved_
bool operator()(SQL_INFO_TYPE const &s, SUCCESS_FUNCTOR_TYPE success, FAILURE_FUNCTOR_TYPE failure) const
OnTypesetMember(SQL_INFO_TYPE const &s)
OnTypesetMember(SQL_INFO_TYPE const &s, FUNCTOR_TYPE f)
bool internalResolveType(SQL_INFO_TYPE const &s) const