Document return values
[ACE_TAO.git] / ACE / ace / Functor.h
blob19fa5c07770fe88599597fbf0ac6f684b4f3c6bc
1 // -*- C++ -*-
3 //==========================================================================
4 /**
5 * @file Functor.h
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 //==========================================================================
28 #ifndef ACE_FUNCTOR_H
29 #define ACE_FUNCTOR_H
30 #include /**/ "ace/pre.h"
32 #include /**/ "ace/config-all.h"
34 #if !defined (ACE_LACKS_PRAGMA_ONCE)
35 # 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 //////////////////////////////////////////////////////////////
47 /**
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
55 * to implement it.
57 class ACE_Export ACE_Command_Base
59 public:
60 /// Default constructor.
61 ACE_Command_Base ();
63 /// Virtual destructor.
64 virtual ~ACE_Command_Base () = default;
66 /**
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
71 * will never occur.
73 virtual int execute (void *arg = 0) = 0;
76 /**
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
85 public:
86 /// Constructor
87 ACE_Noop_Command() = default;
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
107 template<>
108 class ACE_Export ACE_Hash<char>
110 public:
111 /// Simply returns t
112 unsigned long operator () (char t) const;
116 * @brief Function object for hashing a signed char
118 template<>
119 class ACE_Export ACE_Hash<signed char>
121 public:
122 /// Simply returns t
123 unsigned long operator () (signed char t) const;
127 * @brief Function object for hashing an unsigned char
129 template<>
130 class ACE_Export ACE_Hash<unsigned char>
132 public:
133 /// Simply returns t
134 unsigned long operator () (unsigned char t) const;
138 * @brief Function object for hashing a short number
140 template<>
141 class ACE_Export ACE_Hash<short>
143 public:
144 /// Simply returns t
145 unsigned long operator () (short t) const;
149 * @brief Function object for hashing an unsigned short number
151 template<>
152 class ACE_Export ACE_Hash<unsigned short>
154 public:
155 /// Simply returns t
156 unsigned long operator () (unsigned short t) const;
160 * @brief Function object for hashing an int number
162 template<>
163 class ACE_Export ACE_Hash<int>
165 public:
166 /// Simply returns t
167 unsigned long operator () (int t) const;
171 * @brief Function object for hashing an unsigned int number
173 template<>
174 class ACE_Export ACE_Hash<unsigned int>
176 public:
177 /// Simply returns t
178 unsigned long operator () (unsigned int t) const;
182 * @brief Function object for hashing a long number
184 template<>
185 class ACE_Export ACE_Hash<long>
187 public:
188 /// Simply returns t
189 unsigned long operator () (long t) const;
193 * @brief Function object for hashing an unsigned long number
195 template<>
196 class ACE_Export ACE_Hash<unsigned long>
198 public:
199 /// Simply returns t
200 unsigned long operator () (unsigned long t) const;
203 #if (ACE_SIZEOF_LONG == 8)
205 * @brief Function object for hashing a long long number
207 template<>
208 class ACE_Export ACE_Hash<long long>
210 public:
211 /// Simply returns t
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
220 template<>
221 class ACE_Export ACE_Hash<unsigned long long>
223 public:
224 /// Simply returns t
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
233 template<>
234 class ACE_Export ACE_Hash<ACE_INT64>
236 public:
237 /// Simply returns t
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
246 template<>
247 class ACE_Export ACE_Hash<ACE_UINT64>
249 public:
250 /// Simply returns t
251 unsigned long operator () (const ACE_UINT64 &t) const;
253 #endif /* ACE_SIZEOF_LONG < 8 */
256 * @brief Function object for hashing a const string
258 template<>
259 class ACE_Export ACE_Hash<const char *>
261 public:
262 /// Calls ACE::hash_pjw
263 unsigned long operator () (const char *t) const;
267 * @brief Function object for hashing a string
269 template<>
270 class ACE_Export ACE_Hash<char *>
272 public:
273 /// Calls ACE::hash_pjw
274 unsigned long operator () (const char *t) const;
278 * @brief Function object for hashing a void */
279 template<>
280 class ACE_Export ACE_Hash<void *>
282 public:
283 unsigned long operator () (const void *) const;
287 * @brief Function object for determining whether two const strings are equal.
289 template<>
290 class ACE_Export ACE_Equal_To<const char *>
292 public:
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
300 * strings are equal.
302 template<>
303 class ACE_Export ACE_Equal_To<char *>
305 public:
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.
315 template<>
316 class ACE_Export ACE_Equal_To<ACE_UINT16>
318 public:
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.
328 template<>
329 class ACE_Export ACE_Equal_To<ACE_INT16>
331 public:
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.
341 template<>
342 class ACE_Export ACE_Equal_To<ACE_UINT32>
344 public:
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.
354 template<>
355 class ACE_Export ACE_Equal_To<ACE_INT32>
357 public:
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.
367 template<>
368 class ACE_Export ACE_Equal_To<ACE_UINT64>
370 public:
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.
380 template<>
381 class ACE_Export ACE_Less_Than<const char *>
383 public:
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.
393 template<>
394 class ACE_Export ACE_Less_Than<char *>
396 public:
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
408 template<>
409 class ACE_Export ACE_Hash<wchar_t>
411 public:
412 /// Simply returns 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
419 template<>
420 class ACE_Export ACE_Hash<const wchar_t *>
422 public:
423 /// Calls ACE::hash_pjw
424 unsigned long operator () (const wchar_t *t) const;
428 * @brief Function object for hashing a string
430 template<>
431 class ACE_Export ACE_Hash<wchar_t *>
433 public:
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.
441 template<>
442 class ACE_Export ACE_Equal_To<const wchar_t *>
444 public:
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
452 * strings are equal.
454 template<>
455 class ACE_Export ACE_Equal_To<wchar_t *>
457 public:
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.
467 template<>
468 class ACE_Export ACE_Less_Than<const wchar_t *>
470 public:
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.
480 template<>
481 class ACE_Export ACE_Less_Than<wchar_t *>
483 public:
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 */