drogon
C++14/17-based HTTP application framework
Loading...
Searching...
No Matches
FunctionTraits.h
1
14
15#pragma once
16#include <exception>
17#include <string>
18#include <tuple>
19#include <type_traits>
20
21namespace drogon
22{
23namespace orm
24{
25class Result;
27
28namespace internal
29{
30template <typename>
31struct FunctionTraits;
32
33template <>
34struct FunctionTraits<void (*)()>
35{
36 using result_type = void;
37 template <std::size_t Index>
38 using argument = void;
39 static const std::size_t arity = 0;
40
41 static const bool isSqlCallback = false;
42 static const bool isExceptCallback = false;
43};
44
45// functor,lambda
46template <typename Function>
48 : public FunctionTraits<
49 decltype(&std::remove_reference<Function>::type::operator())>
50{
51};
52
53template <typename ClassType, typename ReturnType, typename... Arguments>
54struct FunctionTraits<ReturnType (ClassType::*)(Arguments...) const>
55 : FunctionTraits<ReturnType (*)(Arguments...)>
56{
57};
58
59template <typename ClassType, typename ReturnType, typename... Arguments>
60struct FunctionTraits<ReturnType (ClassType::*)(Arguments...)>
61 : FunctionTraits<ReturnType (*)(Arguments...)>
62{
63};
64
65template <>
66struct FunctionTraits<void (*)(const Result &)>
67 : public FunctionTraits<void (*)()>
68{
69 static const bool isSqlCallback = true;
70 static const bool isStepResultCallback = false;
71 static const bool isExceptCallback = false;
72};
73
74template <>
75struct FunctionTraits<void (*)(const DrogonDbException &)>
76 : public FunctionTraits<void (*)()>
77{
78 static const bool isExceptCallback = true;
79 static const bool isSqlCallback = false;
80 static const bool isStepResultCallback = false;
81 static const bool isPtr = false;
82};
83
84template <>
85struct FunctionTraits<void (*)(const std::exception_ptr &)>
86 : public FunctionTraits<void (*)()>
87{
88 static const bool isExceptCallback = true;
89 static const bool isSqlCallback = false;
90 static const bool isStepResultCallback = false;
91 static const bool isPtr = true;
92};
93
94template <typename ReturnType, typename... Arguments>
95struct FunctionTraits<ReturnType (*)(bool, Arguments...)>
96 : FunctionTraits<ReturnType (*)(Arguments...)>
97{
98 static const bool isSqlCallback = true;
99 static const bool isStepResultCallback = true;
100};
101
102template <typename ReturnType, typename... Arguments>
103struct FunctionTraits<ReturnType (*)(Arguments...)>
104{
105 using result_type = ReturnType;
106
107 template <std::size_t Index>
108 using argument =
109 typename std::tuple_element<Index, std::tuple<Arguments...>>::type;
110
111 static const std::size_t arity = sizeof...(Arguments);
112
113 static const bool isSqlCallback = true;
114 static const bool isStepResultCallback = true;
115 static const bool isExceptCallback = false;
116 static const bool isPtr = false;
117};
118} // namespace internal
119} // namespace orm
120} // namespace drogon
Mixin base class to identify drogon-db-specific exception types.
Definition Exception.h:51
Result set containing data returned by a query or command.
Definition Result.h:58
Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn'...
Definition Attribute.h:23
Definition FunctionTraits.h:50