Krita Source Code Documentation
Loading...
Searching...
No Matches
KisOptionTuple.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#ifndef KISOPTIONTUPLE_H
7#define KISOPTIONTUPLE_H
8
9#include <KisMpl.h>
10#include <boost/operators.hpp>
11#include <boost/tti/has_static_member_data.hpp>
12
13namespace detail {
14
15BOOST_TTI_HAS_STATIC_MEMBER_DATA(supports_prefix)
16
17
21template <typename T, bool has_member = has_static_member_data_supports_prefix<T, const bool>::value>
23
24template <typename T>
25struct supports_prefix<T, false>
26 : std::bool_constant<false>
27{
28};
29
30template <typename T>
31struct supports_prefix<T, true>
32 : std::bool_constant<T::supports_prefix>
33{
34};
35
39template <typename... T>
41{
42 static constexpr bool value = (supports_prefix<T>::value && ...);
43};
44
48template <typename... T>
50{
51 static constexpr bool value = (!supports_prefix<T>::value && ...);
52};
53
54template <bool allSupportPrefix, bool noneSupportPrefix, typename... Data>
56{
57 static_assert (allSupportPrefix || noneSupportPrefix,
58 "Either **all** or **none** arguments of KisOptionTuple should define 'supports_prefix'");
59};
60
64template <typename FirstData, typename... RestData>
65struct KisOptionTupleImpl<true, false, FirstData, RestData...>
66 : public FirstData,
67 public RestData...,
68 public boost::equality_comparable<KisOptionTupleImpl<true, false, FirstData, RestData...>>
69{
70 template <typename... T>
71 KisOptionTupleImpl(const QString &prefix, T... args)
72 : FirstData(prefix, std::forward<decltype(args)>(args)...),
73 RestData(prefix)...
74 {
75 }
76
79 {
80
81 return ((static_cast<const FirstData&>(lhs) == static_cast<const FirstData&>(rhs)) && ... &&
82 (static_cast<const RestData&>(lhs) == static_cast<const RestData&>(rhs)));
83 }
84
85 bool read(const KisPropertiesConfiguration *setting)
86 {
87 return (static_cast<FirstData&>(*this).read(setting) && ... &&
88 static_cast<RestData&>(*this).read(setting));
89 }
90
91 void write(KisPropertiesConfiguration *setting) const
92 {
93 (static_cast<const FirstData&>(*this).write(setting) , ... ,
94 static_cast<const RestData&>(*this).write(setting));
95 }
96
97};
98
102template <typename... Data>
103struct KisOptionTupleImpl<false, true, Data...>
104 : public Data...,
105 public boost::equality_comparable<KisOptionTupleImpl<false, true, Data...>>
106{
107 template <typename... T>
109 : kismpl::first_type_t<Data...>(std::forward<decltype(args)>(args)...)
110 {
111 }
112
115 {
116
117 return ((static_cast<const Data&>(lhs) == static_cast<const Data&>(rhs)) && ... );
118 }
119
120 bool read(const KisPropertiesConfiguration *setting)
121 {
122 return (static_cast<Data&>(*this).read(setting) && ... );
123 }
124
126 {
127 (static_cast<const Data&>(*this).write(setting) , ... );
128 }
129};
130
131} // namespace detail
132
173template <typename... Data>
177 Data...>;
178
179#endif // KISOPTIONTUPLE_H
float value(const T *src, size_t ch)
friend bool operator==(const KisOptionTupleImpl< false, true, Data... > &lhs, const KisOptionTupleImpl< false, true, Data... > &rhs)
void write(KisPropertiesConfiguration *setting) const
bool read(const KisPropertiesConfiguration *setting)
friend bool operator==(const KisOptionTupleImpl< true, false, FirstData, RestData... > &lhs, const KisOptionTupleImpl< true, false, FirstData, RestData... > &rhs)
bool read(const KisPropertiesConfiguration *setting)
void write(KisPropertiesConfiguration *setting) const
static constexpr bool value
static constexpr bool value