Ice 3.7 C++11 API Reference
Functional.h
Go to the documentation of this file.
1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 #ifndef ICE_UTIL_FUNCTIONAL_H
6 #define ICE_UTIL_FUNCTIONAL_H
7 
8 #include <IceUtil/Config.h>
9 
10 #if !defined(ICE_CPP11_MAPPING) && (ICE_CPLUSPLUS < 201703L)
11 
12 #include <IceUtil/Handle.h>
13 #include <functional>
14 
15 namespace IceUtilInternal
16 {
17 
18 // ----------------------------------------------------------------------
19 // Various function objects that work with handles instead of plain
20 // pointers.
21 // ----------------------------------------------------------------------
22 
23 template<class R, class T, class H>
24 class MemFun : public std::unary_function<H, R>
25 {
26  typedef R (T::*MemberFN)(void);
27  MemberFN _mfn;
28 
29 public:
30 
31  explicit MemFun(MemberFN p) : _mfn(p) { }
32  R operator()(H handle) const
33  {
34  return (handle.get() ->* _mfn)();
35  }
36 };
37 
38 template<class R, class T, class H, class A>
39 class MemFun1 : public std::binary_function<H, A, R>
40 {
41  typedef R (T::*MemberFN)(A);
42  MemberFN _mfn;
43 
44 public:
45 
46  explicit MemFun1(MemberFN p) : _mfn(p) { }
47  R operator()(H handle, A arg) const
48  {
49  return (handle.get() ->* _mfn)(arg);
50  }
51 };
52 
53 template<class T, class H>
54 class VoidMemFun : public std::unary_function<H, void>
55 {
56  typedef void (T::*MemberFN)(void);
57  MemberFN _mfn;
58 
59 public:
60 
61  explicit VoidMemFun(MemberFN p) : _mfn(p) { }
62  void operator()(H handle) const
63  {
64  (handle.get() ->* _mfn)();
65  }
66 };
67 
68 template<class T, class H, class A>
69 class VoidMemFun1 : public std::binary_function<H, A, void>
70 {
71  typedef void (T::*MemberFN)(A);
72  MemberFN _mfn;
73 
74 public:
75 
76  explicit VoidMemFun1(MemberFN p) : _mfn(p) { }
77  void operator()(H handle, A arg) const
78  {
79  (handle.get() ->* _mfn)(arg);
80  }
81 };
82 
83 template<class R, class K, class T, class H>
84 class SecondMemFun : public std::unary_function<std::pair<K, H>, R>
85 {
86  typedef R (T::*MemberFN)(void);
87  MemberFN _mfn;
88 
89 public:
90 
91  explicit SecondMemFun(MemberFN p) : _mfn(p) { }
92  R operator()(std::pair<K, H> pair) const
93  {
94  return (pair.second.get() ->* _mfn)();
95  }
96 };
97 
98 template<class R, class K, class T, class H, class A>
99 class SecondMemFun1 : public std::binary_function<std::pair<K, H>, A, R>
100 {
101  typedef R (T::*MemberFN)(A);
102  MemberFN _mfn;
103 
104 public:
105 
106  explicit SecondMemFun1(MemberFN p) : _mfn(p) { }
107  R operator()(std::pair<K, H> pair, A arg) const
108  {
109  return (pair.second.get() ->* _mfn)(arg);
110  }
111 };
112 
113 template<class K, class T, class H>
114 class SecondVoidMemFun : public std::unary_function<std::pair<K, H>, void>
115 {
116  typedef void (T::*MemberFN)(void);
117  MemberFN _mfn;
118 
119 public:
120 
121  explicit SecondVoidMemFun(MemberFN p) : _mfn(p) { }
122  void operator()(std::pair<K, H> pair) const
123  {
124  (pair.second.get() ->* _mfn)();
125  }
126 };
127 
128 template<class K, class T, class H, class A>
129 class SecondVoidMemFun1 : public std::binary_function<std::pair<K, H>, A, void>
130 {
131  typedef void (T::*MemberFN)(A);
132  MemberFN _mfn;
133 
134 public:
135 
136  explicit SecondVoidMemFun1(MemberFN p) : _mfn(p) { }
137  void operator()(std::pair<K, H> pair, A arg) const
138  {
139  (pair.second.get() ->* _mfn)(arg);
140  }
141 };
142 
143 template<class R, class T, class H>
144 class ConstMemFun : public std::unary_function<H, R>
145 {
146  typedef R (T::*MemberFN)(void) const;
147  MemberFN _mfn;
148 
149 public:
150 
151  explicit ConstMemFun(MemberFN p) : _mfn(p) { }
152  R operator()(H handle) const
153  {
154  return (handle.get() ->* _mfn)();
155  }
156 };
157 
158 template<class R, class T, class H, class A>
159 class ConstMemFun1 : public std::binary_function<H, A, R>
160 {
161  typedef R (T::*MemberFN)(A) const;
162  MemberFN _mfn;
163 
164 public:
165 
166  explicit ConstMemFun1(MemberFN p) : _mfn(p) { }
167  R operator()(H handle, A arg) const
168  {
169  return (handle.get() ->* _mfn)(arg);
170  }
171 };
172 
173 template<class T, class H>
174 class ConstVoidMemFun : public std::unary_function<H, void>
175 {
176  typedef void (T::*MemberFN)(void) const;
177  MemberFN _mfn;
178 
179 public:
180 
181  explicit ConstVoidMemFun(MemberFN p) : _mfn(p) { }
182  void operator()(H handle) const
183  {
184  (handle.get() ->* _mfn)();
185  }
186 };
187 
188 template<class T, class H, class A>
189 class ConstVoidMemFun1 : public std::binary_function<H, A, void>
190 {
191  typedef void (T::*MemberFN)(A) const;
192  MemberFN _mfn;
193 
194 public:
195 
196  explicit ConstVoidMemFun1(MemberFN p) : _mfn(p) { }
197  void operator()(H handle, A arg) const
198  {
199  (handle.get() ->* _mfn)(arg);
200  }
201 };
202 
203 template<class R, class K, class T, class H>
204 class SecondConstMemFun : public std::unary_function<std::pair<K, H>, R>
205 {
206  typedef R (T::*MemberFN)(void) const;
207  MemberFN _mfn;
208 
209 public:
210 
211  explicit SecondConstMemFun(MemberFN p) : _mfn(p) { }
212  R operator()(std::pair<K, H> pair) const
213  {
214  return (pair.second.get() ->* _mfn)();
215  }
216 };
217 
218 template<class R, class K, class T, class H, class A>
219 class SecondConstMemFun1 : public std::binary_function<std::pair<K, H>, A, R>
220 {
221  typedef R (T::*MemberFN)(A) const;
222  MemberFN _mfn;
223 
224 public:
225 
226  explicit SecondConstMemFun1(MemberFN p) : _mfn(p) { }
227  R operator()(std::pair<K, H> pair, A arg) const
228  {
229  return (pair.second.get() ->* _mfn)(arg);
230  }
231 };
232 
233 template<class K, class T, class H>
234 class SecondConstVoidMemFun : public std::unary_function<std::pair<K, H>, void>
235 {
236  typedef void (T::*MemberFN)(void) const;
237  MemberFN _mfn;
238 
239 public:
240 
241  explicit SecondConstVoidMemFun(MemberFN p) : _mfn(p) { }
242  void operator()(std::pair<K, H> pair) const
243  {
244  (pair.second.get() ->* _mfn)();
245  }
246 };
247 
248 template<class K, class T, class H, class A>
249 class SecondConstVoidMemFun1 : public std::binary_function<std::pair<K, H>, A, void>
250 {
251  typedef void (T::*MemberFN)(A) const;
252  MemberFN _mfn;
253 
254 public:
255 
256  explicit SecondConstVoidMemFun1(MemberFN p) : _mfn(p) { }
257  void operator()(std::pair<K, H> pair, A arg) const
258  {
259  (pair.second.get() ->* _mfn)(arg);
260  }
261 };
262 
263 }
264 
265 // ----------------------------------------------------------------------
266 // Inline functions that return function objects that work with
267 // IceUtil::Handle
268 // ----------------------------------------------------------------------
269 
270 namespace IceUtil
271 {
272 
273 template<class R, class T>
274 inline ::IceUtilInternal::MemFun<R, T, Handle<T> >
275 memFun(R (T::*p)(void))
276 {
277  return ::IceUtilInternal::MemFun<R, T, Handle<T> >(p);
278 }
279 
280 template<class R, class T, class A>
281 inline ::IceUtilInternal::MemFun1<R, T, Handle<T>, A>
282 memFun1(R (T::*p)(A))
283 {
284  return ::IceUtilInternal::MemFun1<R, T, Handle<T>, A>(p);
285 }
286 
287 template<class T>
288 inline ::IceUtilInternal::VoidMemFun<T, Handle<T> >
289 voidMemFun(void (T::*p)(void))
290 {
291  return ::IceUtilInternal::VoidMemFun<T, Handle<T> >(p);
292 }
293 
294 template<class T, class A>
295 inline ::IceUtilInternal::VoidMemFun1<T, Handle<T>, A>
296 voidMemFun1(void (T::*p)(A))
297 {
298  return ::IceUtilInternal::VoidMemFun1<T, Handle<T>, A>(p);
299 }
300 
301 template<class R, class K, class T>
302 inline ::IceUtilInternal::SecondMemFun<R, K, T, Handle<T> >
303 secondMemFun(R (T::*p)(void))
304 {
305  return ::IceUtilInternal::SecondMemFun<R, K, T, Handle<T> >(p);
306 }
307 
308 template<class R, class K, class T, class A>
309 inline ::IceUtilInternal::SecondMemFun1<R, K, T, Handle<T>, A>
310 secondMemFun1(R (T::*p)(A))
311 {
312  return ::IceUtilInternal::SecondMemFun1<R, K, T, Handle<T>, A>(p);
313 }
314 
315 template<class K, class T>
316 inline ::IceUtilInternal::SecondVoidMemFun<K, T, Handle<T> >
317 secondVoidMemFun(void (T::*p)(void))
318 {
319  return ::IceUtilInternal::SecondVoidMemFun<K, T, Handle<T> >(p);
320 }
321 
322 template<class K, class T, class A>
323 inline ::IceUtilInternal::SecondVoidMemFun1<K, T, Handle<T>, A>
324 secondVoidMemFun1(void (T::*p)(A))
325 {
326  return ::IceUtilInternal::SecondVoidMemFun1<K, T, Handle<T>, A>(p);
327 }
328 
329 template<class R, class T>
330 inline ::IceUtilInternal::ConstMemFun<R, T, Handle<T> >
331 constMemFun(R (T::*p)(void) const)
332 {
333  return ::IceUtilInternal::ConstMemFun<R, T, Handle<T> >(p);
334 }
335 
336 template<class R, class T, class A>
337 inline ::IceUtilInternal::ConstMemFun1<R, T, Handle<T>, A>
338 constMemFun1(R (T::*p)(A) const)
339 {
340  return ::IceUtilInternal::ConstMemFun1<R, T, Handle<T>, A>(p);
341 }
342 
343 template<class T>
344 inline ::IceUtilInternal::ConstVoidMemFun<T, Handle<T> >
345 constVoidMemFun(void (T::*p)(void) const)
346 {
347  return ::IceUtilInternal::ConstVoidMemFun<T, Handle<T> >(p);
348 }
349 
350 template<class T, class A>
351 inline ::IceUtilInternal::ConstVoidMemFun1<T, Handle<T>, A>
352 constVoidMemFun1(void (T::*p)(A) const)
353 {
354  return ::IceUtilInternal::ConstVoidMemFun1<T, Handle<T>, A>(p);
355 }
356 
357 template<class R, class K, class T>
358 inline ::IceUtilInternal::SecondConstMemFun<R, K, T, Handle<T> >
359 secondConstMemFun(R (T::*p)(void) const)
360 {
361  return ::IceUtilInternal::SecondConstMemFun<R, K, T, Handle<T> >(p);
362 }
363 
364 template<class R, class K, class T, class A>
365 inline ::IceUtilInternal::SecondConstMemFun1<R, K, T, Handle<T>, A>
366 secondConstMemFun1(R (T::*p)(A) const)
367 {
368  return ::IceUtilInternal::SecondConstMemFun1<R, K, T, Handle<T>, A>(p);
369 }
370 
371 template<class K, class T>
372 inline ::IceUtilInternal::SecondConstVoidMemFun<K, T, Handle<T> >
373 secondConstVoidMemFun(void (T::*p)(void) const)
374 {
375  return ::IceUtilInternal::SecondConstVoidMemFun<K, T, Handle<T> >(p);
376 }
377 
378 template<class K, class T, class A>
379 inline ::IceUtilInternal::SecondConstVoidMemFun1<K, T, Handle<T>, A>
380 secondConstVoidMemFun1(void (T::*p)(A) const)
381 {
382  return ::IceUtilInternal::SecondConstVoidMemFun1<K, T, Handle<T>, A>(p);
383 }
384 
385 }
386 
387 #endif
388 
389 #endif
Handle.h
IceUtil
Definition: Optional.h:1095
Config.h