Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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 
39 namespace ogdf {
40 namespace fast_multipole_embedder {
41 
43 struct 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 
52 template<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 
70 template<typename Func>
72  Func cond_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 
88 template<typename Func>
89 static inline not_condition_functor<Func> not_condition(const Func& func) {
90  return not_condition_functor<Func>(func);
91 }
92 
94 template<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 
125 template<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 
132 template<typename CondType, typename ThenType>
133 static 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 
139 template<typename F, typename A>
141  F func;
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 
152 template<typename F, typename A>
153 static inline pair_call_functor<F, A> pair_call(F f, A a) {
154  return pair_call_functor<F, A>(f, a);
155 }
156 
158 template<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 
180 template<typename FuncFirst, typename FuncSecond>
181 static inline composition_functor<FuncFirst, FuncSecond> func_comp(const FuncFirst& first,
182  const FuncSecond& second) {
183  return composition_functor<FuncFirst, FuncSecond>(first, second);
184 }
185 
187 template<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 
201 template<typename Func>
202 static inline pair_vice_versa_functor<Func> pair_vice_versa(const Func& f) {
204 }
205 
207 template<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 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::fast_multipole_embedder::if_then_else_functor::thenFunc
ThenType thenFunc
Definition: FMEFunctional.h:97
ogdf::fast_multipole_embedder::pair_vice_versa_functor::func
Func func
Definition: FMEFunctional.h:189
ogdf::fast_multipole_embedder::if_then_else_functor::if_then_else_functor
if_then_else_functor(const CondType &c, const ThenType &f1, const ElseType &f2)
Definition: FMEFunctional.h:102
ogdf::fast_multipole_embedder::not_condition_functor
functor for negating a condition
Definition: FMEFunctional.h:71
ogdf::fast_multipole_embedder::composition_functor::composition_functor
composition_functor(const FuncFirst &first, const FuncSecond &second)
Definition: FMEFunctional.h:163
ogdf::whaType::A
@ A
ogdf::fast_multipole_embedder::pair_call
static pair_call_functor< F, A > pair_call(F f, A a)
creates a pair call resulting in a call f(a, *)
Definition: FMEFunctional.h:153
ogdf::fast_multipole_embedder::min_max_functor::operator()
void operator()(uint32_t i)
Definition: FMEFunctional.h:219
ogdf::fast_multipole_embedder::composition_functor::secondFunc
FuncSecond secondFunc
Definition: FMEFunctional.h:161
ogdf::fast_multipole_embedder::if_then_else_functor::condFunc
CondType condFunc
Definition: FMEFunctional.h:96
ogdf::fast_multipole_embedder::min_max_functor::min_max_functor
min_max_functor(const T *ptr, T &min_var, T &max_var)
Definition: FMEFunctional.h:213
ogdf::fast_multipole_embedder::pair_call_functor::func
F func
Definition: FMEFunctional.h:141
ogdf::fast_multipole_embedder::pair_vice_versa_functor::pair_vice_versa_functor
pair_vice_versa_functor(const Func &f)
Definition: FMEFunctional.h:191
ogdf::fast_multipole_embedder::pair_vice_versa_functor::operator()
void operator()(A a, B b)
Definition: FMEFunctional.h:194
ogdf::fast_multipole_embedder::composition_functor::operator()
void operator()(A a)
Definition: FMEFunctional.h:167
ogdf::fast_multipole_embedder::composition_functor::operator()
void operator()(A a, B b)
Definition: FMEFunctional.h:173
ogdf::fast_multipole_embedder::composition_functor
Functor for composing two other functors.
Definition: FMEFunctional.h:159
ogdf::fast_multipole_embedder::pair_vice_versa
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)
Definition: FMEFunctional.h:202
ogdf::fast_multipole_embedder::not_condition_functor::not_condition_functor
not_condition_functor(const Func &cond)
Definition: FMEFunctional.h:74
ogdf::fast_multipole_embedder::not_condition
static not_condition_functor< Func > not_condition(const Func &func)
creator of the negator
Definition: FMEFunctional.h:89
ogdf::fast_multipole_embedder::pair_call_functor::operator()
void operator()(B second)
Definition: FMEFunctional.h:146
ogdf::fast_multipole_embedder::const_condition
condition functor for returning a constant boolean value
Definition: FMEFunctional.h:53
ogdf::fast_multipole_embedder::const_condition::operator()
bool operator()(A a, B b)
Definition: FMEFunctional.h:60
ogdf::fast_multipole_embedder::composition_functor::firstFunc
FuncFirst firstFunc
Definition: FMEFunctional.h:160
ogdf::fast_multipole_embedder::pair_call_functor::first
A first
Definition: FMEFunctional.h:142
ogdf::fast_multipole_embedder::pair_call_functor::pair_call_functor
pair_call_functor(F f, A a)
Definition: FMEFunctional.h:143
ogdf::fast_multipole_embedder::func_comp
static composition_functor< FuncFirst, FuncSecond > func_comp(const FuncFirst &first, const FuncSecond &second)
create a functor composition of two functors
Definition: FMEFunctional.h:181
ogdf::fast_multipole_embedder::pair_vice_versa_functor
functor for invoking a functor for a pair(u,v) and then (v,u)
Definition: FMEFunctional.h:188
ogdf::fast_multipole_embedder::do_nothing
the useless do nothing function
Definition: FMEFunctional.h:43
ogdf::fast_multipole_embedder::not_condition_functor::operator()
bool operator()(A a)
Definition: FMEFunctional.h:77
ogdf::fast_multipole_embedder::min_max_functor::a
const T * a
Definition: FMEFunctional.h:209
ogdf::fast_multipole_embedder::min_max_functor::min_value
T & min_value
Definition: FMEFunctional.h:210
ogdf::fast_multipole_embedder::min_max_functor
generic min max functor for an array
Definition: FMEFunctional.h:208
ogdf::fast_multipole_embedder::if_then_else_functor::operator()
void operator()(A a, B b)
Definition: FMEFunctional.h:115
ogdf::fast_multipole_embedder::not_condition_functor::operator()
void operator()(A a, B b)
Definition: FMEFunctional.h:82
basic.h
Basic declarations, included by all source files.
ogdf::fast_multipole_embedder::do_nothing::operator()
void operator()(A a, B b)
Definition: FMEFunctional.h:48
ogdf::fast_multipole_embedder::pair_call_functor
helper functor to generate a pair as parameters
Definition: FMEFunctional.h:140
ogdf::fast_multipole_embedder::const_condition::operator()
bool operator()(A a)
Definition: FMEFunctional.h:55
ogdf::fast_multipole_embedder::min_max_functor::max_value
T & max_value
Definition: FMEFunctional.h:211
ogdf::fast_multipole_embedder::if_then_else_functor
Functor for conditional usage of a functor.
Definition: FMEFunctional.h:95
ogdf::fast_multipole_embedder::if_then
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
Definition: FMEFunctional.h:133
ogdf::fast_multipole_embedder::if_then_else_functor::elseFunc
ElseType elseFunc
Definition: FMEFunctional.h:98
ogdf::fast_multipole_embedder::do_nothing::operator()
void operator()(A a)
Definition: FMEFunctional.h:45
ogdf::fast_multipole_embedder::not_condition_functor::cond_func
Func cond_func
Definition: FMEFunctional.h:72
ogdf::fast_multipole_embedder::if_then_else_functor::if_then_else_functor
if_then_else_functor(const CondType &c, const ThenType &f1)
Definition: FMEFunctional.h:100
ogdf::fast_multipole_embedder::if_then_else
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
Definition: FMEFunctional.h:126
ogdf::fast_multipole_embedder::if_then_else_functor::operator()
void operator()(A a)
Definition: FMEFunctional.h:106