3 //==========================================================================
7 * Non-templatized classes and class template specializations for
8 * implementing function objects that are used in various places
9 * in ACE. There are currently two major categories of function
10 * objects in ACE: GoF Command Pattern objects, and STL-style
11 * functors for comparison of container elements. The command objects
12 * are invoked via an execute () method, while the STL-style functors are
13 * invoked via an operator() () method.
14 * Non-templatized classes for implementing the GoF Command Pattern,
15 * also known as functors or function objects.
17 * @author Chris Gill <cdgill@cs.wustl.edu>
18 * @author Based on Command Pattern implementations originally done by
19 * @author Carlos O'Ryan <coryan@cs.wustl.edu>
20 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
21 * @author Sergio Flores-Gaitan <sergio@cs.wustl.edu>
22 * @author and on STL-style functor implementations originally done by
23 * @author Irfan Pyarali <irfan@cs.wustl.edu>
25 //==========================================================================
30 #include /**/ "ace/pre.h"
32 #include /**/ "ace/config-all.h"
34 #if !defined (ACE_LACKS_PRAGMA_ONCE)
36 #endif /* ACE_LACKS_PRAGMA_ONCE */
38 #include /**/ "ace/ACE_export.h"
39 #include "ace/Basic_Types.h"
41 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
43 //////////////////////////////////////////////////////////////
44 // GOF Command Pattern Classes and Template Specializations //
45 //////////////////////////////////////////////////////////////
48 * @class ACE_Command_Base
50 * @brief Defines an abstract class that allows us to invoke commands
51 * without knowing anything about the implementation.
53 * This class declares an interface to execute a command
54 * independent of the effect of the command, or the objects used
57 class ACE_Export ACE_Command_Base
60 /// Default constructor.
61 ACE_Command_Base (void);
63 /// Virtual destructor.
64 virtual ~ACE_Command_Base (void);
67 * Invokes the method encapsulated by the command, passing along the
68 * passed argument (if any). Users of classes derived from this
69 * class must ensure that the resulting invocation can tolerate a
70 * null void pointer being passed, or otherwise ensure that this
73 virtual int execute (void *arg
= 0) = 0;
77 * @class ACE_Noop_Command
79 * Implements a ACE_Command_Base with an empty execute() body.
82 class ACE_Export ACE_Noop_Command
83 : public ACE_Command_Base
89 /// Implement the empty execute() member function
90 virtual int execute(void*);
93 ////////////////////////////////////////////////////////////
94 // STL-style Functor Classes and Template Specializations //
95 ////////////////////////////////////////////////////////////
97 // Forward declaration since we are going to specialize that template
98 // here. The template itself requires this file so every user of the
99 // template should also see the specialization.
100 template <class TYPE
> class ACE_Hash
;
101 template <class TYPE
> class ACE_Equal_To
;
102 template <class TYPE
> class ACE_Less_Than
;
105 * @brief Function object for hashing a char
108 class ACE_Export ACE_Hash
<char>
112 unsigned long operator () (char t
) const;
116 * @brief Function object for hashing a signed char
119 class ACE_Export ACE_Hash
<signed char>
123 unsigned long operator () (signed char t
) const;
127 * @brief Function object for hashing an unsigned char
130 class ACE_Export ACE_Hash
<unsigned char>
134 unsigned long operator () (unsigned char t
) const;
138 * @brief Function object for hashing a short number
141 class ACE_Export ACE_Hash
<short>
145 unsigned long operator () (short t
) const;
149 * @brief Function object for hashing an unsigned short number
152 class ACE_Export ACE_Hash
<unsigned short>
156 unsigned long operator () (unsigned short t
) const;
160 * @brief Function object for hashing an int number
163 class ACE_Export ACE_Hash
<int>
167 unsigned long operator () (int t
) const;
171 * @brief Function object for hashing an unsigned int number
174 class ACE_Export ACE_Hash
<unsigned int>
178 unsigned long operator () (unsigned int t
) const;
182 * @brief Function object for hashing a long number
185 class ACE_Export ACE_Hash
<long>
189 unsigned long operator () (long t
) const;
193 * @brief Function object for hashing an unsigned long number
196 class ACE_Export ACE_Hash
<unsigned long>
200 unsigned long operator () (unsigned long t
) const;
203 #if (ACE_SIZEOF_LONG == 8)
205 * @brief Function object for hashing a long long number
208 class ACE_Export ACE_Hash
<long long>
212 unsigned long operator () (long long t
) const;
214 #endif /* ACE_SIZEOF_LONG == 8 */
216 #if (ACE_SIZEOF_LONG == 8)
218 * @brief Function object for hashing an unsigned long long number
221 class ACE_Export ACE_Hash
<unsigned long long>
225 unsigned long operator () (unsigned long long t
) const;
227 #endif /* ACE_SIZEOF_LONG == 8 */
229 #if (ACE_SIZEOF_LONG < 8)
231 * @brief Function object for hashing a signed 64-bit number
234 class ACE_Export ACE_Hash
<ACE_INT64
>
238 unsigned long operator () (ACE_INT64 t
) const;
240 #endif /* ACE_SIZEOF_LONG < 8 */
242 #if (ACE_SIZEOF_LONG < 8)
244 * @brief Function object for hashing an unsigned 64-bit number
247 class ACE_Export ACE_Hash
<ACE_UINT64
>
251 unsigned long operator () (const ACE_UINT64
&t
) const;
253 #endif /* ACE_SIZEOF_LONG < 8 */
256 * @brief Function object for hashing a const string
259 class ACE_Export ACE_Hash
<const char *>
262 /// Calls ACE::hash_pjw
263 unsigned long operator () (const char *t
) const;
267 * @brief Function object for hashing a string
270 class ACE_Export ACE_Hash
<char *>
273 /// Calls ACE::hash_pjw
274 unsigned long operator () (const char *t
) const;
278 * @brief Function object for hashing a void */
280 class ACE_Export ACE_Hash
<void *>
283 unsigned long operator () (const void *) const;
287 * @brief Function object for determining whether two const strings are equal.
290 class ACE_Export ACE_Equal_To
<const char *>
293 /// Simply calls ACE_OS::strcmp
294 int operator () (const char *lhs
,
295 const char *rhs
) const;
299 * @brief Function object for determining whether two non-const
303 class ACE_Export ACE_Equal_To
<char *>
306 /// Simply calls ACE_OS::strcmp
307 int operator () (const char *lhs
,
308 const char *rhs
) const;
312 * @brief Function object for determining whether two unsigned
313 * 16 bit ints are equal.
316 class ACE_Export ACE_Equal_To
<ACE_UINT16
>
319 /// Simply calls built-in operators
320 int operator () (const ACE_UINT16 lhs
,
321 const ACE_UINT16 rhs
) const;
325 * @brief Function object for determining whether two
326 * 16 bit ints are equal.
329 class ACE_Export ACE_Equal_To
<ACE_INT16
>
332 /// Simply calls built-in operators
333 int operator () (const ACE_INT16 lhs
,
334 const ACE_INT16 rhs
) const;
338 * @brief Function object for determining whether two unsigned
339 * 32 bit ints are equal.
342 class ACE_Export ACE_Equal_To
<ACE_UINT32
>
345 /// Simply calls built-in operators
346 int operator () (const ACE_UINT32 lhs
,
347 const ACE_UINT32 rhs
) const;
351 * @brief Function object for determining whether two
352 * 32 bit ints are equal.
355 class ACE_Export ACE_Equal_To
<ACE_INT32
>
358 /// Simply calls built-in operators
359 int operator () (const ACE_INT32 lhs
,
360 const ACE_INT32 rhs
) const;
364 * @brief Function object for determining whether two unsigned
365 * 64 bit ints are equal.
368 class ACE_Export ACE_Equal_To
<ACE_UINT64
>
371 /// Simply calls built-in operators
372 int operator () (const ACE_UINT64 lhs
,
373 const ACE_UINT64 rhs
) const;
377 * @brief Function object for determining whether the first const string
378 * is less than the second const string.
381 class ACE_Export ACE_Less_Than
<const char *>
384 /// Simply calls ACE_OS::strcmp
385 int operator () (const char *lhs
,
386 const char *rhs
) const;
390 * @brief Function object for determining whether the first string
391 * is less than the second string.
394 class ACE_Export ACE_Less_Than
<char *>
397 /// Simply calls ACE_OS::strcmp
398 int operator () (const char *lhs
,
399 const char *rhs
) const;
402 #if defined (ACE_HAS_WCHAR)
404 # if ! defined (ACE_LACKS_NATIVE_WCHAR_T)
406 * @brief Function object for hashing a wchar_t
409 class ACE_Export ACE_Hash
<wchar_t>
413 unsigned long operator () (wchar_t t
) const;
415 # endif /* ACE_LACKS_NATIVE_WCHAR_T */
417 * @brief Function object for hashing a const string
420 class ACE_Export ACE_Hash
<const wchar_t *>
423 /// Calls ACE::hash_pjw
424 unsigned long operator () (const wchar_t *t
) const;
428 * @brief Function object for hashing a string
431 class ACE_Export ACE_Hash
<wchar_t *>
434 /// Calls ACE::hash_pjw
435 unsigned long operator () (const wchar_t *t
) const;
439 * @brief Function object for determining whether two const strings are equal.
442 class ACE_Export ACE_Equal_To
<const wchar_t *>
445 /// Simply calls ACE_OS::strcmp
446 int operator () (const wchar_t *lhs
,
447 const wchar_t *rhs
) const;
451 * @brief Function object for determining whether two non-const
455 class ACE_Export ACE_Equal_To
<wchar_t *>
458 /// Simply calls ACE_OS::strcmp
459 int operator () (const wchar_t *lhs
,
460 const wchar_t *rhs
) const;
464 * @brief Function object for determining whether the first const string
465 * is less than the second const string.
468 class ACE_Export ACE_Less_Than
<const wchar_t *>
471 /// Simply calls ACE_OS::strcmp
472 int operator () (const wchar_t *lhs
,
473 const wchar_t *rhs
) const;
477 * @brief Function object for determining whether the first string
478 * is less than the second string.
481 class ACE_Export ACE_Less_Than
<wchar_t *>
484 /// Simply calls ACE_OS::strcmp
485 int operator () (const wchar_t *lhs
,
486 const wchar_t *rhs
) const;
489 #endif // ACE_HAS_WCHAR
491 ACE_END_VERSIONED_NAMESPACE_DECL
493 #if defined (__ACE_INLINE__)
494 #include "ace/Functor.inl"
495 #endif /* __ACE_INLINE__ */
497 #include /**/ "ace/post.h"
498 #endif /* ACE_FUNCTOR_H */