3 //==========================================================================
7 * $Id: Functor.h 80826 2008-03-04 14:51:23Z wotte $
9 * Non-templatized classes and class template specializations for
10 * implementing function objects that are used in various places
11 * in ACE. There are currently two major categories of function
12 * objects in ACE: GoF Command Pattern objects, and STL-style
13 * functors for comparison of container elements. The command objects
14 * are invoked via an execute () method, while the STL-style functors are
15 * invoked via an operator() () method.
16 * Non-templatized classes for implementing the GoF Command Pattern,
17 * also known as functors or function objects.
20 * @author Chris Gill <cdgill@cs.wustl.edu>
21 * @author Based on Command Pattern implementations originally done by
22 * @author Carlos O'Ryan <coryan@cs.wustl.edu>
23 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
24 * @author Sergio Flores-Gaitan <sergio@cs.wustl.edu>
25 * @author and on STL-style functor implementations originally done by
26 * @author Irfan Pyarali <irfan@cs.wustl.edu>
28 //==========================================================================
33 #include /**/ "ace/pre.h"
35 #include /**/ "ace/config-all.h"
37 #if !defined (ACE_LACKS_PRAGMA_ONCE)
39 #endif /* ACE_LACKS_PRAGMA_ONCE */
41 #include /**/ "ace/ACE_export.h"
42 #include "ace/Basic_Types.h"
44 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
46 //////////////////////////////////////////////////////////////
47 // GOF Command Pattern Classes and Template Specializations //
48 //////////////////////////////////////////////////////////////
51 * @class ACE_Command_Base
53 * @brief Defines an abstract class that allows us to invoke commands
54 * without knowing anything about the implementation.
56 * This class declares an interface to execute a command
57 * independent of the effect of the command, or the objects used
60 class ACE_Export ACE_Command_Base
63 // = Initialization and termination methods.
64 /// Default constructor.
65 ACE_Command_Base (void);
67 /// Virtual destructor.
68 virtual ~ACE_Command_Base (void);
71 * Invokes the method encapsulated by the command, passing along the
72 * passed argument (if any). Users of classes derived from this
73 * class must ensure that the resulting invocation can tolerate a
74 * null void pointer being passed, or otherwise ensure that this
77 virtual int execute (void *arg
= 0) = 0;
80 ////////////////////////////////////////////////////////////
81 // STL-style Functor Classes and Template Specializations //
82 ////////////////////////////////////////////////////////////
84 // Forward declaration since we are going to specialize that template
85 // here. The template itself requires this file so every user of the
86 // template should also see the specialization.
87 template <class TYPE
> class ACE_Hash
;
88 template <class TYPE
> class ACE_Equal_To
;
89 template <class TYPE
> class ACE_Less_Than
;
92 * @class ACE_Hash<char>
94 * @brief Function object for hashing a char
97 class ACE_Export ACE_Hash
<char>
101 unsigned long operator () (char t
) const;
105 * @class ACE_Hash<signed char>
107 * @brief Function object for hashing a signed char
110 class ACE_Export ACE_Hash
<signed char>
114 unsigned long operator () (signed char t
) const;
118 * @class ACE_Hash<unsigned char>
120 * @brief Function object for hashing an unsigned char
123 class ACE_Export ACE_Hash
<unsigned char>
127 unsigned long operator () (unsigned char t
) const;
131 // @@ ADD HASHES FOR ACE TYPES
134 * @class ACE_Hash<ACE_INT16>
136 * @brief Function object for hashing a 16-bit signed number
139 class ACE_Export ACE_Hash
<ACE_INT16
>
143 unsigned long operator () (ACE_INT16 t
) const;
147 * @class ACE_Hash<ACE_UINT16>
149 * @brief Function object for hashing a 16-bit unsigned number
152 class ACE_Export ACE_Hash
<ACE_UINT16
>
156 unsigned long operator () (ACE_UINT16 t
) const;
160 * @class ACE_Hash<ACE_INT32>
162 * @brief Function object for hashing a 32-bit signed number
165 class ACE_Export ACE_Hash
<ACE_INT32
>
169 unsigned long operator () (ACE_INT32 t
) const;
173 * @class ACE_Hash<ACE_UINT32>
175 * @brief Function object for hashing a 32-bit unsigned number
178 class ACE_Export ACE_Hash
<ACE_UINT32
>
182 unsigned long operator () (ACE_UINT32 t
) const;
186 * @class ACE_Hash<ACE_UINT64>
188 * @brief Function object for hashing a 64-bit unsigned number
191 class ACE_Export ACE_Hash
<ACE_UINT64
>
195 unsigned long operator () (ACE_UINT64 t
) const;
198 // @@ DONE ADDING HASHES FOR ACE TYPES
202 * @class ACE_Hash<short>
204 * @brief Function object for hashing a short number
207 class ACE_Export ACE_Hash
<short>
211 unsigned long operator () (short t
) const;
215 * @class ACE_Hash<unsigned short>
217 * @brief Function object for hashing an unsigned short number
220 class ACE_Export ACE_Hash
<unsigned short>
224 unsigned long operator () (unsigned short t
) const;
228 * @class ACE_Hash<int>
230 * @brief Function object for hashing an int number
233 class ACE_Export ACE_Hash
<int>
237 unsigned long operator () (int t
) const;
241 * @class ACE_Hash<unsigned int>
243 * @brief Function object for hashing an unsigned int number
246 class ACE_Export ACE_Hash
<unsigned int>
250 unsigned long operator () (unsigned int t
) const;
254 * @class ACE_Hash<long>
256 * @brief Function object for hashing a long number
259 class ACE_Export ACE_Hash
<long>
263 unsigned long operator () (long t
) const;
267 * @class ACE_Hash<unsigned long>
269 * @brief Function object for hashing an unsigned long number
272 class ACE_Export ACE_Hash
<unsigned long>
276 unsigned long operator () (unsigned long t
) const;
279 #if !defined (ACE_LACKS_LONGLONG_T) && (ACE_SIZEOF_LONG < 8)
281 * @class ACE_Hash<ACE_INT64>
283 * @brief Function object for hashing a signed 64-bit number
286 class ACE_Export ACE_Hash
<ACE_INT64
>
290 unsigned long operator () (ACE_INT64 t
) const;
292 #endif /* !ACE_LACKS_LONGLONG_T && ACE_SIZEOF_LONG < 8 */
294 // We can do this even if ACE_LACKS_UNSIGNEDLONGLONG_T because there's an
295 // emulation for it in ACE_U_LongLong.
296 #if (ACE_SIZEOF_LONG < 8)
298 * @class ACE_Hash<ACE_UINT64>
300 * @brief Function object for hashing an unsigned 64-bit number
303 class ACE_Export ACE_Hash
<ACE_UINT64
>
307 unsigned long operator () (const ACE_UINT64
&t
) const;
309 #endif /* ACE_SIZEOF_LONG < 8 */
312 * @class ACE_Hash<const char *>
314 * @brief Function object for hashing a const string
317 class ACE_Export ACE_Hash
<const char *>
320 /// Calls ACE::hash_pjw
321 unsigned long operator () (const char *t
) const;
325 * @class ACE_Hash<char *>
327 * @brief Function object for hashing a string
330 class ACE_Export ACE_Hash
<char *>
333 /// Calls ACE::hash_pjw
334 unsigned long operator () (const char *t
) const;
338 * @class ACE_Hash<void *>
340 * @brief Function object for hashing a void *
343 class ACE_Export ACE_Hash
<void *>
346 unsigned long operator () (const void *) const;
350 * @class ACE_Equal_To<const char *>
352 * @brief Function object for determining whether two const strings are equal.
355 class ACE_Export ACE_Equal_To
<const char *>
358 /// Simply calls ACE_OS::strcmp
359 int operator () (const char *lhs
,
360 const char *rhs
) const;
364 * @class ACE_Equal_To<char *>
366 * @brief Function object for determining whether two non-const
370 class ACE_Export ACE_Equal_To
<char *>
373 /// Simply calls ACE_OS::strcmp
374 int operator () (const char *lhs
,
375 const char *rhs
) const;
379 * @class ACE_Equal_To<ACE_UINT16>
381 * @brief Function object for determining whether two unsigned
382 * 16 bit ints are equal.
385 class ACE_Export ACE_Equal_To
<ACE_UINT16
>
388 /// Simply calls built-in operators
389 int operator () (const ACE_UINT16 lhs
,
390 const ACE_UINT16 rhs
) const;
394 * @class ACE_Equal_To<ACE_INT16>
396 * @brief Function object for determining whether two
397 * 16 bit ints are equal.
400 class ACE_Export ACE_Equal_To
<ACE_INT16
>
403 /// Simply calls built-in operators
404 int operator () (const ACE_INT16 lhs
,
405 const ACE_INT16 rhs
) const;
409 * @class ACE_Equal_To<ACE_UINT32>
411 * @brief Function object for determining whether two unsigned
412 * 32 bit ints are equal.
415 class ACE_Export ACE_Equal_To
<ACE_UINT32
>
418 /// Simply calls built-in operators
419 int operator () (const ACE_UINT32 lhs
,
420 const ACE_UINT32 rhs
) const;
424 * @class ACE_Equal_To<ACE_INT32>
426 * @brief Function object for determining whether two
427 * 32 bit ints are equal.
430 class ACE_Export ACE_Equal_To
<ACE_INT32
>
433 /// Simply calls built-in operators
434 int operator () (const ACE_INT32 lhs
,
435 const ACE_INT32 rhs
) const;
439 * @class ACE_Equal_To<ACE_UINT64>
441 * @brief Function object for determining whether two unsigned
442 * 64 bit ints are equal.
445 class ACE_Export ACE_Equal_To
<ACE_UINT64
>
448 /// Simply calls built-in operators
449 int operator () (const ACE_UINT64 lhs
,
450 const ACE_UINT64 rhs
) const;
454 * @class ACE_Less_Than<const char*>
456 * @brief Function object for determining whether the first const string
457 * is less than the second const string.
460 class ACE_Export ACE_Less_Than
<const char *>
463 /// Simply calls ACE_OS::strcmp
464 int operator () (const char *lhs
,
465 const char *rhs
) const;
469 * @class ACE_Less_Than<char *>
471 * @brief Function object for determining whether the first string
472 * is less than the second string.
475 class ACE_Export ACE_Less_Than
<char *>
478 /// Simply calls ACE_OS::strcmp
479 int operator () (const char *lhs
,
480 const char *rhs
) const;
483 #if defined (ACE_HAS_WCHAR)
485 # if ! defined (ACE_LACKS_NATIVE_WCHAR_T)
487 * @class ACE_Hash<wchar_t>
489 * @brief Function object for hashing a wchar_t
492 class ACE_Export ACE_Hash
<wchar_t>
496 unsigned long operator () (wchar_t t
) const;
498 # endif /* ACE_LACKS_NATIVE_WCHAR_T */
500 * @class ACE_Hash<const wchar_t *>
502 * @brief Function object for hashing a const string
505 class ACE_Export ACE_Hash
<const wchar_t *>
508 /// Calls ACE::hash_pjw
509 unsigned long operator () (const wchar_t *t
) const;
513 * @class ACE_Hash<wchar_t *>
515 * @brief Function object for hashing a string
518 class ACE_Export ACE_Hash
<wchar_t *>
521 /// Calls ACE::hash_pjw
522 unsigned long operator () (const wchar_t *t
) const;
526 * @class ACE_Equal_To<const wchar_t *>
528 * @brief Function object for determining whether two const strings are equal.
531 class ACE_Export ACE_Equal_To
<const wchar_t *>
534 /// Simply calls ACE_OS::strcmp
535 int operator () (const wchar_t *lhs
,
536 const wchar_t *rhs
) const;
540 * @class ACE_Equal_To<wchar_t *>
542 * @brief Function object for determining whether two non-const
546 class ACE_Export ACE_Equal_To
<wchar_t *>
549 /// Simply calls ACE_OS::strcmp
550 int operator () (const wchar_t *lhs
,
551 const wchar_t *rhs
) const;
555 * @class ACE_Less_Than<const wchar_t *>
557 * @brief Function object for determining whether the first const string
558 * is less than the second const string.
561 class ACE_Export ACE_Less_Than
<const wchar_t *>
564 /// Simply calls ACE_OS::strcmp
565 int operator () (const wchar_t *lhs
,
566 const wchar_t *rhs
) const;
570 * @class ACE_Less_Than<wchar_t *>
572 * @brief Function object for determining whether the first string
573 * is less than the second string.
576 class ACE_Export ACE_Less_Than
<wchar_t *>
579 /// Simply calls ACE_OS::strcmp
580 int operator () (const wchar_t *lhs
,
581 const wchar_t *rhs
) const;
584 #endif // ACE_HAS_WCHAR
586 ACE_END_VERSIONED_NAMESPACE_DECL
588 #if defined (__ACE_INLINE__)
589 #include "ace/Functor.inl"
590 #endif /* __ACE_INLINE__ */
592 #include /**/ "ace/post.h"
593 #endif /* ACE_FUNCTOR_H */