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