-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.hpp
121 lines (105 loc) · 4.14 KB
/
common.hpp
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
119
120
121
/* This file is part of the the dci project. Copyright (C) 2013-2023 vopl, shtoba.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public
License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */
#pragma once
#include <array>
#include <tuple>
#include <QMetaType>
#include <dci/utils/ct.hpp>
#include <dci/sbs/signal.hpp>
#include <dci/idl/introspection.hpp>
#include <dci/cmt/future.hpp>
namespace dci::qml::qmeta
{
using namespace utils::ct;
using namespace idl::introspection;
}
namespace dci::qml::qmeta
{
template<std::size_t size>
struct Name
{
static constexpr std::size_t _size = size;
char _buf[_size + 1];
constexpr Name(const Name<size>& n)
{
for(std::size_t i = 0; i <= _size; ++i) _buf[i] = n._buf[i];
}
constexpr Name(const char* s)
{
for(std::size_t i = 0; i <= _size; ++i) _buf[i] = s[i];
}
constexpr Name(std::array<char, size+1> s)
{
for(std::size_t i = 0; i <= _size; ++i) _buf[i] = s[i];
}
};
template<std::size_t size> Name(const Name<size>&) -> Name<size>;
template<std::size_t N> Name(char const (&)[N]) -> Name<N - 1>;
template<std::size_t N> Name(std::array<char, N>) -> Name<N - 1>;
/////////0/////////1/////////2/////////3/////////4/////////5/////////6/////////7
template <class C, class=void>
struct CallableSignature
{
static constexpr bool _valid = false;
using Return = void;
using ParamList = TList<>;
};
template <class R, class... Params>
struct CallableSignature<R(*)(Params...)>
{
static constexpr bool _valid = true;
using Return = R;
using ParamList = TList<Params...>;
};
template <class C, class R, class... Params>
struct CallableSignature<R(C::*)(Params...)>
{
static constexpr bool _valid = true;
using Return = R;
using ParamList = TList<Params...>;
};
template <class C, class R, class... Params>
struct CallableSignature<R(C::*)(Params...) const>
{
static constexpr bool _valid = true;
using Return = R;
using ParamList = TList<Params...>;
};
template <class C>
struct CallableSignature<C, std::void_t<decltype(&C::operator())>>
: CallableSignature<decltype(&C::operator())>
{
};
/////////0/////////1/////////2/////////3/////////4/////////5/////////6/////////7
template <class C>
requires (CallableSignature<C>::ParamList::_size == 1)
bool registerConvertorIfMissing(C&& convertor)
{
using Signature = CallableSignature<std::decay_t<C>>;
using From = typename std::decay_t<typename Signature::ParamList::template Get<0>>;
using To = typename std::decay_t<typename Signature::Return>;
if(!QMetaType::hasRegisteredConverterFunction<From, To>())
{
return QMetaType::registerConverter<From, To>(std::forward<C>(convertor));
}
return false;
}
/////////0/////////1/////////2/////////3/////////4/////////5/////////6/////////7
template <class MV>
requires (CallableSignature<MV>::ParamList::_size == 1)
bool registerMutableViewIfMissing(MV&& mutableView)
{
using Signature = CallableSignature<std::decay_t<MV>>;
using From = typename std::decay_t<typename Signature::ParamList::template Get<0>>;
using To = typename std::decay_t<typename Signature::Return>;
if(!QMetaType::hasRegisteredMutableViewFunction<From, To>())
{
return QMetaType::registerMutableView<From, To>(std::forward<MV>(mutableView));
}
return false;
}
}