KDBindings API Documentation  1.0.95
node_functions.h
Go to the documentation of this file.
1 /*
2  This file is part of KDBindings.
3 
4  SPDX-FileCopyrightText: 2021 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/make_node.h>
15 
16 #include <cmath>
17 
18 namespace KDBindings {
19 
20 namespace Private {
21 
22 template<typename... Ts>
23 struct any_bindables;
24 
25 // Check to see if a single type is a bindable (node or property)
26 template<typename T>
27 struct any_bindables<T> : is_bindable<T> {
28 };
29 
30 // Check the head of the typelist and recurse
31 template<typename HEAD, typename... Ts>
32 struct any_bindables<HEAD, Ts...> : std::integral_constant<
33  bool,
34  any_bindables<HEAD>::value || any_bindables<Ts...>::value> {
35 };
36 
37 } // namespace Private
38 
54 #define KDBINDINGS_DECLARE_FUNCTION(NAME, FUNC) \
55  template<typename... Ts> \
56  inline auto NAME(Ts &&...args)->std::enable_if_t<::KDBindings::Private::any_bindables<Ts...>::value, ::KDBindings::Private::Node<::KDBindings::Private::operator_node_result_t<decltype(FUNC), Ts...>>> \
57  { \
58  return ::KDBindings::Private::makeNode(FUNC, std::forward<Ts>(args)...); \
59  }
60 
72 struct node_abs {
79  template<typename... Ts>
80  auto operator()(Ts &&...x) const
81  {
82  return std::abs(std::forward<Ts>(x)...);
83  }
84 };
85 KDBINDINGS_DECLARE_FUNCTION(abs, node_abs{})
86 
100 #define KDBINDINGS_DECLARE_FUNCTION_OBJECT(NAME, FUNCTION) \
101  struct NAME { \
102  template<typename... Ts> \
103  auto operator()(Ts &&...x) const \
104  { \
105  return FUNCTION(std::forward<Ts>(x)...); \
106  } \
107  };
108 
123 #define KDBINDINGS_DECLARE_NAMESPACED_FUNCTION(NAMESPACE, NAME) \
124  KDBINDINGS_DECLARE_FUNCTION_OBJECT(node_##NAMESPACE_##NAME, NAMESPACE::NAME) \
125  KDBINDINGS_DECLARE_FUNCTION(NAME, node_##NAMESPACE_##NAME{})
126 
136 #define KDBINDINGS_DECLARE_STD_FUNCTION(NAME) \
137  KDBINDINGS_DECLARE_NAMESPACED_FUNCTION(std, NAME)
138 
139 // Define some common and useful functions
148 
149 } // namespace KDBindings
The main namespace of the KDBindings library.
Definition: binding.h:21
#define KDBINDINGS_DECLARE_FUNCTION_OBJECT(NAME, FUNCTION)
This macro declares a callable struct that wraps a function with all its overloads.
#define KDBINDINGS_DECLARE_FUNCTION(NAME, FUNC)
KDBINDINGS_DECLARE_FUNCTION is a helper macro to declare and define functions for use in data binding...
#define KDBINDINGS_DECLARE_STD_FUNCTION(NAME)
This macro is based on KDBINDINGS_DECLARE_NAMESPACED_FUNCTION(NAMESPACE, FUNC) to make it easier to d...
An example struct that is used with a call to KDBINDINGS_DECLARE_FUNCTION to declare all overloads of...
auto operator()(Ts &&...x) const
The operator() is overloaded so the struct can be used as a function object.

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDBindings
Reactive programming & data binding in C++
https://github.com/KDAB/KDBindings/
Generated by doxygen 1.9.1