1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
// IBM_PROLOG_BEGIN_TAG
// This is an automatically generated prolog.
//
// $Source: src/include/util/functor.H $
//
// IBM CONFIDENTIAL
//
// COPYRIGHT International Business Machines Corp. 2011
//
// p1
//
// Object Code Only (OCO) source materials
// Licensed Internal Code Source Materials
// IBM HostBoot Licensed Internal Code
//
// The source code for this program is not published or other-
// wise divested of its trade secrets, irrespective of what has
// been deposited with the U.S. Copyright Office.
//
// Origin: 30
//
// IBM_PROLOG_END
#ifndef __UTIL_FUNCTOR_H
#define __UTIL_FUNCTOR_H
#include <builtins.h>
namespace Util
{
template <typename _ARG, typename _RESULT>
class unary_functor
{
public:
typedef _ARG argument_type;
typedef _RESULT result_type;
public:
virtual ~unary_functor() {};
virtual result_type operator()(argument_type) = 0;
};
template <typename _ARG1, typename _ARG2, typename _RESULT>
class binary_functor
{
public:
typedef _ARG1 first_argument_type;
typedef _ARG2 second_argument_type;
typedef _RESULT result_type;
public:
virtual ~binary_functor() {};
virtual result_type operator()
(first_argument_type, second_argument_type) = 0;
};
// Function pointer wrappers for functors.
template <typename _ARG, typename _RESULT>
class ptr_to_unary_function : public unary_functor<_ARG, _RESULT>
{
public:
typedef _RESULT(*function_type)(_ARG);
private:
function_type function;
public:
ptr_to_unary_function(function_type f) : function(f) {};
_RESULT operator()(_ARG t)
{
return function(t);
}
};
template <typename _ARG, typename _RESULT>
ALWAYS_INLINE
ptr_to_unary_function<_ARG, _RESULT> ptr_fun(_RESULT (*f)(_ARG))
{
return ptr_to_unary_function<_ARG,_RESULT>(f);
}
#define PTR_FUN1_T(ARG_T, RESULT_T) \
ptr_to_unary_function<_ARG, _RESULT>
template <typename _ARG, typename _RESULT, typename _CLASS>
class mem_ptr_to_unary_function : public unary_functor<_ARG, _RESULT>
{
public:
typedef _CLASS member_type;
typedef _RESULT(member_type::*function_type)(_ARG);
private:
member_type& object;
function_type function;
public:
mem_ptr_to_unary_function(member_type& o, function_type f)
: object(o), function(f) {};
_RESULT operator()(_ARG t)
{
return (object.*function)(t);
}
};
template <typename _ARG, typename _RESULT, typename _CLASS>
ALWAYS_INLINE
mem_ptr_to_unary_function<_ARG, _RESULT, _CLASS>
mem_ptr_fun(_CLASS& o, _RESULT (_CLASS::*f)(_ARG))
{
return mem_ptr_to_unary_function<_ARG,_RESULT,_CLASS>(o, f);
}
#define MEM_PTR_FUN1_T(CLASS_T, ARG_T, RESULT_T) \
mem_ptr_to_unary_function<ARG_T, RESULT_T, CLASS_T>
};
#endif
|