3 //=============================================================================
7 * Templatized classes for implementing function objects that are
8 * used in various places in ACE. There are currently two major
9 * categories of function objects in ACE: GOF Command Pattern
10 * objects, and STL-style functors for comparison of container
11 * elements. The command objects are invoked via an <execute>
12 * method, while the STL-style functors are invoked via an
13 * <operator()> method.
15 * @author Chris Gill <cdgill@cs.wustl.edu>
16 * @author Based on Command Pattern implementations originally done by
17 * @author Carlos O'Ryan <coryan@cs.wustl.edu>
18 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
19 * @author Sergio Flores-Gaitan <sergio@cs.wustl.edu>
20 * @author and on STL-style functor implementations originally done by
21 * @author Irfan Pyarali <irfan@cs.wustl.edu>
23 //=============================================================================
26 #ifndef ACE_FUNCTOR_T_H
27 #define ACE_FUNCTOR_T_H
28 #include /**/ "ace/pre.h"
30 #include "ace/Functor.h"
32 #if !defined (ACE_LACKS_PRAGMA_ONCE)
34 #endif /* ACE_LACKS_PRAGMA_ONCE */
36 #include "ace/Functor_String.h"
37 #include "ace/Truncate.h"
39 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
41 ///////////////////////////////////
42 // GOF Command Pattern Templates //
43 ///////////////////////////////////
46 * @class ACE_Command_Callback
49 * Defines a class template that allows us to invoke a GOF
50 * command style callback to an object without knowing anything
51 * about the object except its type.
53 * This class declares an interface to execute operations,
54 * binding a RECEIVER object with an ACTION. The RECEIVER knows
55 * how to implement the operation. A class can invoke operations
56 * without knowing anything about it, or how it was implemented.
58 template <class RECEIVER
, class ACTION
>
59 class ACE_Command_Callback
: public ACE_Command_Base
62 /// Constructor: sets the @c receiver_ of the Command to @a recvr, and the
63 /// @c action_ of the Command to @a action.
64 ACE_Command_Callback (RECEIVER
&recvr
, ACTION action
);
66 /// Virtual destructor.
67 virtual ~ACE_Command_Callback () = default;
69 /// Invokes the method @c action_ from the object @c receiver_.
70 virtual int execute (void *arg
= 0);
72 ACE_ALLOC_HOOK_DECLARE
;
75 /// Object where the method resides.
78 /// Method that is going to be invoked.
83 * @class ACE_Member_Function_Command
85 * @brief Defines a class template that allows us to invoke a member
86 * function using the GoF command style callback.
88 template <class RECEIVER
>
89 class ACE_Member_Function_Command
: public ACE_Command_Base
92 typedef void (RECEIVER::*PTMF
)();
94 /// Con Constructor: sets the <receiver_> of the Command to @a recvr, and the
95 /// <action_> of the Command to <action>.
96 ACE_Member_Function_Command (RECEIVER
&recvr
, PTMF ptmf
);
98 /// Virtual destructor.
99 virtual ~ACE_Member_Function_Command () = default;
101 /// Invokes the method <action_> from the object <receiver_>. The
102 /// parameter is ignored
103 virtual int execute (void *);
106 /// Object where the method resides.
109 /// Method that is going to be invoked.
113 /////////////////////////////////
114 // STL-style Functor Templates //
115 /////////////////////////////////
120 * @brief Function object for hashing
122 template <class TYPE
>
126 /// Simply calls t.hash ()
127 unsigned long operator () (const TYPE
&t
) const;
131 * @class ACE_Pointer_Hash
134 * Function object for hashing pointers
136 template <class TYPE
>
137 class ACE_Pointer_Hash
140 /// Simply returns t.
141 unsigned long operator () (TYPE t
) const;
145 * @class ACE_Equal_To
148 * Function object for comparing two objects of
149 * the given type for equality.
151 template <class TYPE
>
155 /// Simply calls operator==
156 bool operator () (const TYPE
&lhs
,
157 const TYPE
&rhs
) const;
161 * @class ACE_Less_Than
164 * Function object for determining whether the first object of
165 * the given type is less than the second object of the same
168 template <class TYPE
>
172 /// Simply calls operator<
173 bool operator () (const TYPE
&lhs
,
174 const TYPE
&rhs
) const;
177 ACE_END_VERSIONED_NAMESPACE_DECL
179 #if defined (__ACE_INLINE__)
180 #include "ace/Functor_T.inl"
181 #endif /* __ACE_INLINE__ */
183 #include "ace/Functor_T.cpp"
185 #include /**/ "ace/post.h"
186 #endif /* ACE_FUNCTOR_T_H */