MethodFunction.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2003-2013 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// psrchive/psrchive/Util/units/MethodFunction.h
10
11#ifndef __MethodFunction_h
12#define __MethodFunction_h
13
14template<class C, class T, class Get, class Arg>
15class MethodGetFunction
16{
17 Get get;
18 Arg arg;
19
20 public:
21
22 typedef C* first_argument_type;
23 typedef T result_type;
24
25 MethodGetFunction (Get _get, Arg _arg)
26 {
27 get = _get;
28 arg = _arg;
29 }
30
31 T operator () (C* ptr)
32 {
33 return (ptr->*get) (arg);
34 }
35
36 const T operator () (const C* ptr) const
37 {
38 return (const_cast<C*>(ptr)->*get) (arg);
39 }
40};
41
42template<class C, class T, class Arg>
43MethodGetFunction<C, T, T (C::*)(Arg), Arg>
44method_function (T (C::*get)(Arg), Arg arg)
45{
46 return MethodGetFunction<C, T, T (C::*)(Arg), Arg> (get, arg);
47}
48
49template<class C, class T, class Arg>
50MethodGetFunction<C, T, T (C::*)(const Arg&), Arg>
51method_function (T (C::*get)(const Arg&), Arg arg)
52{
53 return MethodGetFunction<C, T, T (C::*)(const Arg&), Arg> (get, arg);
54}
55
56template<class C, class T, class Arg>
57MethodGetFunction<C, T, T (C::*)(const Arg&) const, Arg>
58method_function (T (C::*get)(const Arg&) const, Arg arg)
59{
60 return MethodGetFunction<C, T, T (C::*)(const Arg&) const, Arg> (get, arg);
61}
62
63template<class C, class T, class Set, class Arg, class Value>
64class MethodSetFunction
65{
66 Set set;
67 Arg arg;
68
69 public:
70
71 typedef C* first_argument_type;
72 typedef Value second_argument_type;
73
74 MethodSetFunction (Set _set, Arg _arg)
75 {
76 set = _set;
77 arg = _arg;
78 }
79
80 void operator () (C* ptr, const Value& value)
81 {
82 (ptr->*set) (arg, value);
83 }
84};
85
86template<class C, class T, class Arg>
87MethodSetFunction<C, T, void (C::*)(Arg, const T&), Arg, T>
88method_function (void (C::*set)(Arg, const T&), const Arg& arg)
89{
90 return MethodSetFunction<C, T, void (C::*)(Arg, const T&), Arg, T> (set, arg);
91}
92
93template<class C, class T, class Arg>
94MethodSetFunction<C, T, void (C::*)(Arg, T), Arg, T>
95method_function (void (C::*set)(Arg, T), const Arg& arg)
96{
97 return MethodSetFunction<C, T, void (C::*)(Arg, T), Arg, T> (set, arg);
98}
99
100template<class C, class T, class Arg>
101MethodSetFunction<C, T, void (C::*)(const Arg&, const T&), Arg, T>
102method_function (void (C::*set)(const Arg&, const T&), const Arg& arg)
103{
104 return MethodSetFunction<C, T, void (C::*)(const Arg&, const T&), Arg, T> (set, arg);
105}
106
107template<class C, class T, class Arg>
108MethodSetFunction<C, T, void (C::*)(const Arg&, T), Arg, T>
109method_function (void (C::*set)(const Arg&, T), const Arg& arg)
110{
111 return MethodSetFunction<C, T, void (C::*)(const Arg&, T), Arg, T> (set, arg);
112}
113
114#endif
115

Generated using doxygen 1.14.0