KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
node_operators.h
Go to the documentation of this file.
1/*
2 This file is part of KDBindings.
3
4 SPDX-FileCopyrightText: 2021-2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: Sean Harmer <sean.harmer@kdab.com>
6
7 SPDX-License-Identifier: MIT
8
9 Contact KDAB at <info@kdab.com> for commercial licensing options.
10*/
11
12#pragma once
13
14#include <kdbindings/node.h>
16
17namespace KDBindings {
18
19// Helper macro to declare free standing unary operators for Property and Node
20
21#define KDBINDINGS_DEFINE_UNARY_OP(OP) \
22 template<typename... T> \
23 inline auto operator OP(Property<T...> &arg) noexcept(noexcept(OP arg.get())) \
24 ->Private::Node<std::decay_t<decltype(OP arg.get())>> \
25 { \
26 return Private::makeNode([](auto &&v) { return (OP v); }, arg); \
27 } \
28 \
29 template<typename T> \
30 inline auto operator OP(Private::Node<T> &&arg) noexcept(noexcept(OP arg.evaluate())) \
31 ->Private::Node<std::decay_t<decltype(OP arg.evaluate())>> \
32 { \
33 return Private::makeNode([](auto &&v) { return (OP v); }, std::move(arg)); \
34 }
35
37KDBINDINGS_DEFINE_UNARY_OP(~) // Bitwise not
40
41// Helper macro to declare free standing binary operators for Property and Node.
42// The combinations we need are:
43//
44// operator op (Property<A> &a, B&& b) [Property, value]
45// operator op (A&& a, Property<B> &b) [value, Property]
46// operator op (Property<A> &a, Property<B> &b) [Property, Property]
47//
48// operator op (Node<A>&& a, B&& b) [Node value]
49// operator op (A&& a, Node<B>&& b) [value, Node]
50// operator op (Node<A>&& a, Node<B>&& b) [Node, Node]
51//
52// operator op (Property<A> &a, Node<B>&& b) [Property, Node]
53// operaotr op (Node<A>&& a, Property<B> &b) [Node, Property]
54
55#define KDBINDINGS_DEFINE_BINARY_OP(OP) \
56 template<typename B, typename... A> \
57 inline auto operator OP(Property<A...> &a, B &&b) noexcept(noexcept(a.get() OP b)) \
58 ->std::enable_if_t<!Private::is_bindable<B>::value, \
59 Private::Node<decltype(a.get() OP b)>> \
60 { \
61 return Private::makeNode([](auto &&av, auto &&bv) { return (av OP bv); }, a, std::forward<B>(b)); \
62 } \
63 \
64 template<typename A, typename... B> \
65 inline auto operator OP(A &&a, Property<B...> &b) noexcept(noexcept(a OP b.get())) \
66 ->std::enable_if_t<!Private::is_bindable<A>::value, \
67 Private::Node<decltype(a OP b.get())>> \
68 { \
69 return Private::makeNode([](auto &&av, auto &&bv) { return (av OP bv); }, std::forward<A>(a), b); \
70 } \
71 \
72 template<typename A, typename B> \
73 inline auto operator OP(Property<A> &a, Property<B> &b) noexcept(noexcept(a.get() OP b.get())) \
74 ->Private::Node<decltype(a.get() OP b.get())> \
75 { \
76 return Private::makeNode([](auto &&av, auto &&bv) { return (av OP bv); }, a, b); \
77 } \
78 \
79 template<typename A, typename B> \
80 inline auto operator OP(Private::Node<A> &&a, B &&b) noexcept(noexcept(a.evaluate() OP b)) \
81 ->std::enable_if_t<!Private::is_bindable<B>::value, \
82 Private::Node<decltype(a.evaluate() OP b)>> \
83 { \
84 return Private::makeNode([](auto &&av, auto &&bv) { return (av OP bv); }, std::move(a), std::forward<B>(b)); \
85 } \
86 \
87 template<typename A, typename B> \
88 inline auto operator OP(A &&a, Private::Node<B> &&b) noexcept(noexcept(a OP b.evaluate())) \
89 ->std::enable_if_t<!Private::is_bindable<A>::value, \
90 Private::Node<decltype(a OP b.evaluate())>> \
91 { \
92 return Private::makeNode([](auto &&av, auto &&bv) { return (av OP bv); }, std::forward<A>(a), std::move(b)); \
93 } \
94 \
95 template<typename A, typename B> \
96 inline auto operator OP(Private::Node<A> &&a, Private::Node<B> &&b) noexcept(noexcept(a.evaluate() OP b.evaluate())) \
97 ->Private::Node<decltype(a.evaluate() OP b.evaluate())> \
98 { \
99 return Private::makeNode([](auto &&av, auto &&bv) { return (av OP bv); }, std::move(a), std::move(b)); \
100 } \
101 \
102 template<typename B, typename A> \
103 inline auto operator OP(Property<A> &a, Private::Node<B> &&b) noexcept(noexcept(a.get() OP b.evaluate())) \
104 ->Private::Node<decltype(a.get() OP b.evaluate())> \
105 { \
106 return Private::makeNode([](auto &&av, auto &&bv) { return (av OP bv); }, a, std::move(b)); \
107 } \
108 \
109 template<typename A, typename B> \
110 inline auto operator OP(Private::Node<A> &&a, Property<B> &b) noexcept(noexcept(a.evaluate() OP b.get())) \
111 ->Private::Node<decltype(a.evaluate() OP b.get())> \
112 { \
113 return Private::makeNode([](auto &&av, auto &&bv) { return (av OP bv); }, std::move(a), b); \
114 }
115
134
135} // namespace KDBindings
The main namespace of the KDBindings library.
Definition binding.h:21
#define KDBINDINGS_DEFINE_UNARY_OP(OP)
#define KDBINDINGS_DEFINE_BINARY_OP(OP)

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDDockWidgets
Advanced Dock Widget Framework for Qt
https://www.kdab.com/development-resources/qt-tools/kddockwidgets/
Generated by doxygen 1.9.8