Open
Graph Drawing
Framework

 v. 2022.02 (Dogwood)
 

FMEFunctional.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/basic.h>
35 
36 namespace ogdf {
37 namespace fast_multipole_embedder {
38 
40 struct do_nothing
41 {
42  template<typename A> inline void operator()(A a) { }
43  template<typename A, typename B> inline void operator()(A a, B b) { }
44 };
45 
47 template<bool result>
49 {
50  template<typename A> inline bool operator()(A a) { return result; }
51  template<typename A, typename B> inline bool operator()(A a, B b) { return result; }
52 };
53 
57 
59 template<typename Func>
61 {
62  Func cond_func;
63 
64  not_condition_functor(const Func& cond) : cond_func(cond) { }
65 
66  template<typename A> inline bool operator()(A a) { return !cond_func(a); }
67  template<typename A, typename B> inline void operator()(A a, B b) { return !cond_func(a, b); }
68 };
69 
71 template<typename Func>
72 static inline not_condition_functor<Func> not_condition(const Func& func)
73 {
74  return not_condition_functor<Func>(func);
75 }
76 
78 template<typename CondType, typename ThenType, typename ElseType = do_nothing>
80 {
81  CondType condFunc;
82  ThenType thenFunc;
83  ElseType elseFunc;
84 
85  if_then_else_functor(const CondType& c, const ThenType& f1) : condFunc(c), thenFunc(f1) { }
86 
87  if_then_else_functor(const CondType& c, const ThenType& f1, const ElseType& f2) : condFunc(c), thenFunc(f1), elseFunc(f2) { }
88 
89  template<typename A>
90  inline void operator()(A a)
91  {
92  if (condFunc(a))
93  thenFunc(a);
94  else
95  elseFunc(a);
96  }
97 
98  template<typename A, typename B>
99  inline void operator()(A a, B b)
100  {
101  if (condFunc(a, b))
102  thenFunc(a, b);
103  else
104  elseFunc(a, b);
105  }
106 };
107 
109 template<typename CondType, typename ThenType, typename ElseType>
110 static inline if_then_else_functor<CondType, ThenType, ElseType> if_then_else(const CondType& cond, const ThenType& thenFunc, const ElseType& elseFunc)
111 {
112  return if_then_else_functor<CondType, ThenType, ElseType>(cond, thenFunc, elseFunc);
113 }
114 
116 template<typename CondType, typename ThenType>
117 static inline if_then_else_functor<CondType, ThenType> if_then(const CondType& cond, const ThenType& thenFunc)
118 {
119  return if_then_else_functor<CondType, ThenType>(cond, thenFunc);
120 }
121 
122 
124 template<typename F, typename A>
126 {
127  F func;
129  pair_call_functor(F f, A a) : func(f), first(a) {};
130 
131  template<typename B>
132  inline void operator()(B second)
133  {
134  func(first, second);
135  }
136 };
137 
138 
140 template<typename F, typename A>
141 static inline pair_call_functor<F, A> pair_call(F f, A a)
142 {
143  return pair_call_functor<F, A>(f, a);
144 }
145 
146 
148 template<typename FuncFirst, typename FuncSecond>
150 {
151  FuncFirst firstFunc;
152  FuncSecond secondFunc;
153 
154  composition_functor(const FuncFirst& first, const FuncSecond& second) : firstFunc(first), secondFunc(second) {};
155  template<typename A>
156  void operator()(A a)
157  {
158  firstFunc(a);
159  secondFunc(a);
160  }
161 
162  template<typename A, typename B>
163  void operator()(A a, B b)
164  {
165  firstFunc(a, b);
166  secondFunc(a, b);
167  }
168 };
169 
170 
172 template<typename FuncFirst, typename FuncSecond>
173 static inline composition_functor<FuncFirst, FuncSecond> func_comp(const FuncFirst& first, const FuncSecond& second)
174 {
175  return composition_functor<FuncFirst, FuncSecond>(first, second);
176 }
177 
178 
180 template<typename Func>
182 {
183  Func func;
184 
185  pair_vice_versa_functor(const Func& f) : func(f) { }
186 
187  template<typename A, typename B>
188  void operator()(A a, B b)
189  {
190  func(a, b);
191  func(b, a);
192  }
193 };
194 
195 
197 template<typename Func>
198 static inline pair_vice_versa_functor<Func> pair_vice_versa(const Func& f)
199 {
201 }
202 
203 
205 template<typename T>
207 {
208  const T* a;
211 
212  min_max_functor(const T* ptr, T& min_var, T& max_var) : a(ptr), min_value(min_var), max_value(max_var)
213  {
214  min_value = a[0];
215  max_value = a[0];
216  }
217 
218  inline void operator()(uint32_t i)
219  {
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: AugmentationModule.h:36
ogdf::fast_multipole_embedder::if_then_else_functor::thenFunc
ThenType thenFunc
Definition: FMEFunctional.h:82
ogdf::fast_multipole_embedder::pair_vice_versa_functor::func
Func func
Definition: FMEFunctional.h:183
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:87
ogdf::fast_multipole_embedder::not_condition_functor
functor for negating a condition
Definition: FMEFunctional.h:60
ogdf::fast_multipole_embedder::composition_functor::composition_functor
composition_functor(const FuncFirst &first, const FuncSecond &second)
Definition: FMEFunctional.h:154
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:141
ogdf::fast_multipole_embedder::min_max_functor::operator()
void operator()(uint32_t i)
Definition: FMEFunctional.h:218
ogdf::fast_multipole_embedder::composition_functor::secondFunc
FuncSecond secondFunc
Definition: FMEFunctional.h:152
ogdf::fast_multipole_embedder::if_then_else_functor::condFunc
CondType condFunc
Definition: FMEFunctional.h:81
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:212
ogdf::fast_multipole_embedder::pair_call_functor::func
F func
Definition: FMEFunctional.h:127
ogdf::fast_multipole_embedder::pair_vice_versa_functor::pair_vice_versa_functor
pair_vice_versa_functor(const Func &f)
Definition: FMEFunctional.h:185
ogdf::fast_multipole_embedder::pair_vice_versa_functor::operator()
void operator()(A a, B b)
Definition: FMEFunctional.h:188
ogdf::fast_multipole_embedder::composition_functor::operator()
void operator()(A a)
Definition: FMEFunctional.h:156
ogdf::fast_multipole_embedder::composition_functor::operator()
void operator()(A a, B b)
Definition: FMEFunctional.h:163
ogdf::fast_multipole_embedder::composition_functor
Functor for composing two other functors.
Definition: FMEFunctional.h:149
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:198
ogdf::fast_multipole_embedder::not_condition_functor::not_condition_functor
not_condition_functor(const Func &cond)
Definition: FMEFunctional.h:64
ogdf::fast_multipole_embedder::not_condition
static not_condition_functor< Func > not_condition(const Func &func)
creator of the negator
Definition: FMEFunctional.h:72
ogdf::fast_multipole_embedder::pair_call_functor::operator()
void operator()(B second)
Definition: FMEFunctional.h:132
ogdf::fast_multipole_embedder::const_condition
condition functor for returning a constant boolean value
Definition: FMEFunctional.h:48
ogdf::fast_multipole_embedder::const_condition::operator()
bool operator()(A a, B b)
Definition: FMEFunctional.h:51
ogdf::fast_multipole_embedder::composition_functor::firstFunc
FuncFirst firstFunc
Definition: FMEFunctional.h:151
ogdf::fast_multipole_embedder::pair_call_functor::first
A first
Definition: FMEFunctional.h:128
ogdf::fast_multipole_embedder::pair_call_functor::pair_call_functor
pair_call_functor(F f, A a)
Definition: FMEFunctional.h:129
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:173
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:181
ogdf::fast_multipole_embedder::do_nothing
the useless do nothing function
Definition: FMEFunctional.h:40
ogdf::fast_multipole_embedder::not_condition_functor::operator()
bool operator()(A a)
Definition: FMEFunctional.h:66
ogdf::fast_multipole_embedder::min_max_functor::a
const T * a
Definition: FMEFunctional.h:208
ogdf::fast_multipole_embedder::min_max_functor::min_value
T & min_value
Definition: FMEFunctional.h:209
ogdf::fast_multipole_embedder::min_max_functor
generic min max functor for an array
Definition: FMEFunctional.h:206
ogdf::fast_multipole_embedder::if_then_else_functor::operator()
void operator()(A a, B b)
Definition: FMEFunctional.h:99
ogdf::fast_multipole_embedder::not_condition_functor::operator()
void operator()(A a, B b)
Definition: FMEFunctional.h:67
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:43
ogdf::fast_multipole_embedder::pair_call_functor
helper functor to generate a pair as parameters
Definition: FMEFunctional.h:125
ogdf::fast_multipole_embedder::const_condition::operator()
bool operator()(A a)
Definition: FMEFunctional.h:50
ogdf::fast_multipole_embedder::min_max_functor::max_value
T & max_value
Definition: FMEFunctional.h:210
ogdf::fast_multipole_embedder::if_then_else_functor
Functor for conditional usage of a functor.
Definition: FMEFunctional.h:79
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:117
ogdf::fast_multipole_embedder::if_then_else_functor::elseFunc
ElseType elseFunc
Definition: FMEFunctional.h:83
ogdf::fast_multipole_embedder::do_nothing::operator()
void operator()(A a)
Definition: FMEFunctional.h:42
ogdf::fast_multipole_embedder::not_condition_functor::cond_func
Func cond_func
Definition: FMEFunctional.h:62
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:85
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:110
ogdf::fast_multipole_embedder::if_then_else_functor::operator()
void operator()(A a)
Definition: FMEFunctional.h:90