summaryrefslogtreecommitdiff
path: root/ace/Functor_T.h
blob: 1df69f4a6e275a2edbb4e77676914c6dc052157f (plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/* -*- C++ -*- */
// $Id$

// ============================================================================
//
// = LIBRARY
//    ace
//
// = FILENAME
//    Functor_T.h
//
// = DESCRIPTION
//     Templatized classes for implementing the GOF Command Pattern,
//     also known as functors or function objects.
//
// = AUTHOR
//     Chris Gill          <cdgill@cs.wustl.edu>
//
//     Based on Command Pattern implementations originally done by
//
//    Carlos O'Ryan        <coryan@cs.wustl.edu>  and
//    Douglas C. Schmidt   <schmidt@cs.wustl.edu> and
//    Sergio Flores-Gaitan <sergio@cs.wustl.edu>
//
// ============================================================================

#ifndef ACE_FUNCTOR_T_H
#define ACE_FUNCTOR_T_H

#include "ace/Functor.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

template <class RECEIVER, class ACTION>
class ACE_Command_Callback : public ACE_Command_Base
{
  // = TITLE
  //    Defines a class template that allows us to invoke a callback to an
  //    object without knowing anything about the object except its type.
  //
  // = DESCRIPTION
  //    This class declares an interface to execute operations,
  //    binding a RECEIVER object with an ACTION.  The RECEIVER knows
  //    how to implement the operation.  A class can invoke operations
  //    without knowing anything about it, or how it was implemented.
public:

  ACE_Command_Callback (RECEIVER &recvr, ACTION action);
  // Constructor: sets the <receiver_> of the Command to recvr, and the
  // <action_> of the Command to <action>.

  virtual ~ACE_Command_Callback (void) {}
  // Virtual destructor.

  virtual int execute (void *arg = 0);
  // Invokes the method <action_> from the object <receiver_>.

private:

  RECEIVER &receiver_;
  // Object where the method resides.

  ACTION action_;
  // Method that is going to be invoked.
};

/////////////////////////////
// Unary functor templates //
/////////////////////////////

template <class OPERAND>
class ACE_Unary_Functor_Base
{
  // = TITLE
  //    Defines a class template that allows us to invoke a function object
  //    over a single non-const parameterized type without knowing anything
  //    about the function and operand objects except their types.
  //
  // = DESCRIPTION
  //    This class declares an interface to execute a unary operation over a
  //    single object of the non-const paramterized type.  A class can invoke
  //    such operation without knowing anything about it, or how it was
  //    implemented.
  //
public:

  virtual ~ACE_Unary_Functor_Base () {};
  // Virtual destructor.

  virtual int execute (OPERAND &operand) = 0;
  // Invokes the function object.

  virtual ACE_Unary_Functor_Base * clone () = 0;
  // Creates another object of the same type.
};

template <class OPERAND>
class ACE_Const_Unary_Functor_Base
{
  // = TITLE
  //    Defines a class template that allows us to invoke a function object
  //    over a single parameterized type without knowing anything about
  //    the function and operand objects except their types.
  //
  // = DESCRIPTION
  //    This class declares an interface to execute a unary operation over a
  //    single object of the paramterized type.  A class can invoke such
  //    an operation without knowing anything about it, or its implementation.
  //
public:

  virtual ~ACE_Const_Unary_Functor_Base () {};
  // Virtual destructor.

  virtual int execute (const OPERAND &operand) = 0;
  // Invokes the function object.

  virtual ACE_Const_Unary_Functor_Base * clone () = 0;
  // Creates another object of the same type.
};

/////////////////////////////
// Binary functor templates //
/////////////////////////////

template <class OPERAND1, class OPERAND2>
class ACE_Binary_Functor_Base
{
  // = TITLE
  //    Defines a class template that allows us to invoke a binary function
  //    object over two non-const parameterized types without knowing anything
  //    about the function and operand objects except their types.
  //
  // = DESCRIPTION
  //    This class declares an interface to execute a binary operation over two
  //    objects of the paramterized non-const types.  A class can invoke such
  //    an operation without knowing anything about it, or its implementation.
  //
public:

  virtual ~ACE_Binary_Functor_Base () {};
  // Virtual destructor.

  virtual int execute (OPERAND1 &operand1, OPERAND2 &operand2) = 0;
  // Invokes the function object.

  virtual ACE_Binary_Functor_Base * clone () = 0;
  // Creates another object of the same type.
};

template <class OPERAND1, class OPERAND2>
class ACE_Const_Binary_Functor_Base
{
  // = TITLE
  //    Defines a class template that allows us to invoke a binary function
  //    object over two parameterized types without knowing anything about
  //    the function and operand objects except their types.
  //
  // = DESCRIPTION
  //    This class declares an interface to execute a binary operation over two
  //    objects of the paramterized types.  A class can invoke such
  //    an operation without knowing anything about it, or its implementation.
  //
public:

  virtual ~ACE_Const_Binary_Functor_Base () {};
  // Virtual destructor.

  virtual int execute (const OPERAND1 &operand1, const OPERAND2 &operand2) = 0;
  // Invokes the function object.

  virtual ACE_Const_Binary_Functor_Base * clone () = 0;
  // Creates another object of the same type.
};


template <class OPERAND1, class OPERAND2>
class ACE_Less_Than_Functor :
  public ACE_Const_Binary_Functor_Base<OPERAND1, OPERAND2>
{
  // = TITLE
  //    Defines a class template that allows us to invoke a binary less than
  //    function over two parameterized types without knowing anything about
  //    the function and operand objects except their types.
  //
  // = DESCRIPTION
  //    This class depends on the definition
  //    objects of the paramterized types.  A class can invoke such
  //    an operation without knowing anything about it, or its implementation.
  //
public:

  virtual int execute (const OPERAND1 &operand1, const OPERAND2 &operand2);
  // Invokes the function object.

  virtual
    ACE_Const_Binary_Functor_Base<OPERAND1, OPERAND2>
          * clone ();
  // Creates another object of the same type.
};


#if defined (__ACE_INLINE__)
#include "ace/Functor_T.i"
#endif /* __ACE_INLINE__ */


#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "ace/Functor_T.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("Functor_T.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */

#endif /* ACE_FUNCTOR_T_H */