1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
// Copyright (C) 2020 Mikhail Svetkin <mikhail.svetkin@gmail.com>
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef QHTTPSERVERVIEWTRAITS_IMPL_H
#define QHTTPSERVERVIEWTRAITS_IMPL_H
#include <QtCore/qglobal.h>
#include <QtCore/qmetatype.h>
#include <QtCore/qnamespace.h>
#include <QtCore/qobjectdefs.h>
#include <tuple>
#include <type_traits>
QT_BEGIN_NAMESPACE
namespace QtPrivate {
template<typename ReturnT, typename... Args>
struct FunctionTraitsHelper
{
static constexpr const int ArgumentCount = sizeof ... (Args);
static constexpr const int ArgumentIndexMax = ArgumentCount - 1;
using ReturnType = ReturnT;
template <size_t I>
struct Arg {
using Type = typename std::tuple_element<I, std::tuple<Args...>>::type;
using CleanType = q20::remove_cvref_t<Type>;
static constexpr bool CopyConstructible = std::is_copy_constructible_v<CleanType>;
};
};
template<typename T>
struct FunctionTraitsImpl;
template<typename T>
struct FunctionTraitsImpl : public FunctionTraitsImpl<decltype(&T::operator())>
{
};
template<typename ReturnT, typename... Args>
struct FunctionTraitsImpl<ReturnT (*)(Args...)> : public FunctionTraitsHelper<ReturnT, Args...>
{
};
template<typename ReturnT, typename ClassT, typename... Args>
struct FunctionTraitsImpl<ReturnT (ClassT::*)(Args...)>
: public FunctionTraitsHelper<ReturnT, Args...>
{
};
template<typename ReturnT, typename ClassT, typename... Args>
struct FunctionTraitsImpl<ReturnT (ClassT::*)(Args...) const>
: public FunctionTraitsHelper<ReturnT, Args...>
{
};
template<typename T>
using FunctionTraits = FunctionTraitsImpl<std::decay_t<T>>;
template<typename ... T>
struct CheckAny {
static constexpr bool Value = (T::Value || ...);
static constexpr bool Valid = (T::Valid || ...);
static constexpr bool StaticAssert = (T::StaticAssert || ...);
};
template<typename ViewHandler, bool DisableStaticAssert>
struct ViewTraits {
using FTraits = FunctionTraits<ViewHandler>;
using ArgumentIndexes = typename std::make_index_sequence<FTraits::ArgumentCount>;
template<int I, typename Special>
struct SpecialHelper {
using Arg = typename FTraits::template Arg<I>;
using CleanSpecialT = q20::remove_cvref_t<Special>;
static constexpr bool TypeMatched = std::is_same<typename Arg::CleanType, CleanSpecialT>::value;
static constexpr bool TypeCVRefMatched = std::is_same<typename Arg::Type, Special>::value;
static constexpr bool ValidPosition =
(I == FTraits::ArgumentIndexMax ||
I == FTraits::ArgumentIndexMax - 1);
static constexpr bool ValidAll = TypeCVRefMatched && ValidPosition;
static constexpr bool AssertCondition =
DisableStaticAssert || !TypeMatched || TypeCVRefMatched;
static constexpr bool AssertConditionOrder =
DisableStaticAssert || !TypeMatched || ValidPosition;
static constexpr bool StaticAssert = AssertCondition && AssertConditionOrder;
static_assert(AssertConditionOrder,
"ViewHandler arguments error: "
"QHttpServerRequest or QHttpServerResponder"
" can only be the last argument");
};
template<int I, typename T>
struct Special {
using Helper = SpecialHelper<I, T>;
static constexpr bool Value = Helper::TypeMatched;
static constexpr bool Valid = Helper::ValidAll;
static constexpr bool StaticAssert = Helper::StaticAssert;
static constexpr bool AssertCondition = Helper::AssertCondition;
};
};
} // namespace QtPrivate
QT_END_NAMESPACE
#endif // QHTTPSERVERVIEWTRAITS_IMPL_H
|