Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
FMEFunctional.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/basic.h> // IWYU pragma: keep
35
36#include <algorithm>
37#include <cstdint>
38
39namespace ogdf {
40namespace fast_multipole_embedder {
41
43struct do_nothing {
44 template<typename A>
45 inline void operator()(A a) { }
46
47 template<typename A, typename B>
48 inline void operator()(A a, B b) { }
49};
50
52template<bool result>
54 template<typename A>
55 inline bool operator()(A a) {
56 return result;
57 }
58
59 template<typename A, typename B>
60 inline bool operator()(A a, B b) {
61 return result;
62 }
63};
64
68
70template<typename Func>
73
74 not_condition_functor(const Func& cond) : cond_func(cond) { }
75
76 template<typename A>
77 inline bool operator()(A a) {
78 return !cond_func(a);
79 }
80
81 template<typename A, typename B>
82 inline void operator()(A a, B b) {
83 return !cond_func(a, b);
84 }
85};
86
88template<typename Func>
89static inline not_condition_functor<Func> not_condition(const Func& func) {
90 return not_condition_functor<Func>(func);
91}
92
94template<typename CondType, typename ThenType, typename ElseType = do_nothing>
96 CondType condFunc;
97 ThenType thenFunc;
98 ElseType elseFunc;
99
100 if_then_else_functor(const CondType& c, const ThenType& f1) : condFunc(c), thenFunc(f1) { }
101
102 if_then_else_functor(const CondType& c, const ThenType& f1, const ElseType& f2)
103 : condFunc(c), thenFunc(f1), elseFunc(f2) { }
104
105 template<typename A>
106 inline void operator()(A a) {
107 if (condFunc(a)) {
108 thenFunc(a);
109 } else {
110 elseFunc(a);
111 }
112 }
113
114 template<typename A, typename B>
115 inline void operator()(A a, B b) {
116 if (condFunc(a, b)) {
117 thenFunc(a, b);
118 } else {
119 elseFunc(a, b);
120 }
121 }
122};
123
125template<typename CondType, typename ThenType, typename ElseType>
127 const ThenType& thenFunc, const ElseType& elseFunc) {
128 return if_then_else_functor<CondType, ThenType, ElseType>(cond, thenFunc, elseFunc);
129}
130
132template<typename CondType, typename ThenType>
133static inline if_then_else_functor<CondType, ThenType> if_then(const CondType& cond,
134 const ThenType& thenFunc) {
135 return if_then_else_functor<CondType, ThenType>(cond, thenFunc);
136}
137
139template<typename F, typename A>
143 pair_call_functor(F f, A a) : func(f), first(a) {};
144
145 template<typename B>
146 inline void operator()(B second) {
147 func(first, second);
148 }
149};
150
152template<typename F, typename A>
153static inline pair_call_functor<F, A> pair_call(F f, A a) {
154 return pair_call_functor<F, A>(f, a);
155}
156
158template<typename FuncFirst, typename FuncSecond>
160 FuncFirst firstFunc;
161 FuncSecond secondFunc;
162
163 composition_functor(const FuncFirst& first, const FuncSecond& second)
164 : firstFunc(first), secondFunc(second) {};
165
166 template<typename A>
167 void operator()(A a) {
168 firstFunc(a);
169 secondFunc(a);
170 }
171
172 template<typename A, typename B>
173 void operator()(A a, B b) {
174 firstFunc(a, b);
175 secondFunc(a, b);
176 }
177};
178
180template<typename FuncFirst, typename FuncSecond>
181static inline composition_functor<FuncFirst, FuncSecond> func_comp(const FuncFirst& first,
182 const FuncSecond& second) {
183 return composition_functor<FuncFirst, FuncSecond>(first, second);
184}
185
187template<typename Func>
189 Func func;
190
191 pair_vice_versa_functor(const Func& f) : func(f) { }
192
193 template<typename A, typename B>
194 void operator()(A a, B b) {
195 func(a, b);
196 func(b, a);
197 }
198};
199
201template<typename Func>
202static inline pair_vice_versa_functor<Func> pair_vice_versa(const Func& f) {
204}
205
207template<typename T>
209 const T* a;
212
213 min_max_functor(const T* ptr, T& min_var, T& max_var)
214 : a(ptr), min_value(min_var), max_value(max_var) {
215 min_value = a[0];
216 max_value = a[0];
217 }
218
219 inline void operator()(uint32_t i) {
220 min_value = min<T>(min_value, a[i]);
221 max_value = max<T>(max_value, a[i]);
222 }
223};
224
225}
226}
Basic declarations, included by all source files.
static pair_call_functor< F, A > pair_call(F f, A a)
creates a pair call resulting in a call f(a, *)
static if_then_else_functor< CondType, ThenType > if_then(const CondType &cond, const ThenType &thenFunc)
creates an if then functor with a condition and a then functor
static if_then_else_functor< CondType, ThenType, ElseType > if_then_else(const CondType &cond, const ThenType &thenFunc, const ElseType &elseFunc)
creates an if then else functor with a condition and a then and an else functor
static pair_vice_versa_functor< Func > pair_vice_versa(const Func &f)
creates a functor for invoking a functor for a pair(u,v) and then (v,u)
static not_condition_functor< Func > not_condition(const Func &func)
creator of the negator
static composition_functor< FuncFirst, FuncSecond > func_comp(const FuncFirst &first, const FuncSecond &second)
create a functor composition of two functors
The namespace for all OGDF objects.
Functor for composing two other functors.
composition_functor(const FuncFirst &first, const FuncSecond &second)
condition functor for returning a constant boolean value
the useless do nothing function
Functor for conditional usage of a functor.
if_then_else_functor(const CondType &c, const ThenType &f1, const ElseType &f2)
if_then_else_functor(const CondType &c, const ThenType &f1)
generic min max functor for an array
min_max_functor(const T *ptr, T &min_var, T &max_var)
helper functor to generate a pair as parameters
functor for invoking a functor for a pair(u,v) and then (v,u)