Functor.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //==========================================================================
00004 /**
00005  *  @file    Functor.h
00006  *
00007  *  Functor.h,v 4.35 2006/01/12 16:51:57 shuston Exp
00008  *
00009  *   Non-templatized classes and class template specializations for
00010  *   implementing function objects that are used in  various places
00011  *   in ACE.  There are currently two major categories of function
00012  *   objects in ACE: GoF Command Pattern objects, and STL-style
00013  *   functors for comparison of container elements.  The command objects
00014  *   are invoked via an execute () method, while the STL-style functors are
00015  *   invoked via an operator() () method.
00016  *  Non-templatized classes for implementing the GoF Command Pattern,
00017  *  also known as functors or function objects.
00018  *
00019  *
00020  *  @author Chris Gill <cdgill@cs.wustl.edu>
00021  *  @author Based on Command Pattern implementations originally done by
00022  *  @author Carlos O'Ryan <coryan@cs.wustl.edu>
00023  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00024  *  @author Sergio Flores-Gaitan <sergio@cs.wustl.edu>
00025  *  @author and on STL-style functor implementations originally done by
00026  *  @author Irfan Pyarali  <irfan@cs.wustl.edu>
00027  */
00028 //==========================================================================
00029 
00030 
00031 #ifndef ACE_FUNCTOR_H
00032 #define ACE_FUNCTOR_H
00033 #include /**/ "ace/pre.h"
00034 
00035 #include "ace/config-all.h"
00036 
00037 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00038 # pragma once
00039 #endif /* ACE_LACKS_PRAGMA_ONCE */
00040 
00041 #include "ace/ACE_export.h"
00042 #include "ace/Basic_Types.h"
00043 
00044 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00045 
00046 //////////////////////////////////////////////////////////////
00047 // GOF Command Pattern Classes and Template Specializations //
00048 //////////////////////////////////////////////////////////////
00049 
00050 /**
00051  * @class ACE_Command_Base
00052  *
00053  * @brief Defines an abstract class that allows us to invoke commands
00054  * without knowing anything about the implementation.
00055  *
00056  * This class declares an interface to execute a command
00057  * independent of the effect of the command, or the objects used
00058  * to implement it.
00059  */
00060 class ACE_Export ACE_Command_Base
00061 {
00062 public:
00063   // = Initialization and termination methods.
00064   /// Default constructor.
00065   ACE_Command_Base (void);
00066 
00067   /// Virtual destructor.
00068   virtual ~ACE_Command_Base (void);
00069 
00070   /**
00071    * Invokes the method encapsulated by the command, passing along the
00072    * passed argument (if any).  Users of classes derived from this
00073    * class must ensure that the resulting invocation can tolerate a
00074    * null void pointer being passed, or otherwise ensure that this
00075    * will never occur.
00076    */
00077   virtual int execute (void *arg = 0) = 0;
00078 };
00079 
00080 ////////////////////////////////////////////////////////////
00081 // STL-style Functor Classes and Template Specializations //
00082 ////////////////////////////////////////////////////////////
00083 
00084 // Forward declaration since we are going to specialize that template
00085 // here. The template itself requires this file so every user of the
00086 // template should also see the specialization.
00087 template <class TYPE> class ACE_Hash;
00088 template <class TYPE> class ACE_Equal_To;
00089 template <class TYPE> class ACE_Less_Than;
00090 
00091 /**
00092  * @class ACE_Hash<char>
00093  *
00094  * @brief Function object for hashing a char
00095  */
00096 template<>
00097 class ACE_Export ACE_Hash<char>
00098 {
00099 public:
00100   /// Simply returns t
00101   unsigned long operator () (char t) const;
00102 };
00103 
00104 /**
00105  * @class ACE_Hash<signed char>
00106  *
00107  * @brief Function object for hashing a signed char
00108  */
00109 template<>
00110 class ACE_Export ACE_Hash<signed char>
00111 {
00112 public:
00113   /// Simply returns t
00114   unsigned long operator () (signed char t) const;
00115 };
00116 
00117 /**
00118  * @class ACE_Hash<unsigned char>
00119  *
00120  * @brief Function object for hashing an unsigned char
00121  */
00122 template<>
00123 class ACE_Export ACE_Hash<unsigned char>
00124 {
00125 public:
00126   /// Simply returns t
00127   unsigned long operator () (unsigned char t) const;
00128 };
00129 
00130 #if 0
00131 // @@ ADD HASHES FOR ACE TYPES
00132 
00133 /**
00134  * @class ACE_Hash<ACE_INT16>
00135  *
00136  * @brief Function object for hashing a 16-bit signed number
00137  */
00138 template<>
00139 class ACE_Export ACE_Hash<ACE_INT16>
00140 {
00141 public:
00142   /// Simply returns t
00143   unsigned long operator () (ACE_INT16 t) const;
00144 };
00145 
00146 /**
00147  * @class ACE_Hash<ACE_UINT16>
00148  *
00149  * @brief Function object for hashing a 16-bit unsigned number
00150  */
00151 template<>
00152 class ACE_Export ACE_Hash<ACE_UINT16>
00153 {
00154 public:
00155   /// Simply returns t
00156   unsigned long operator () (ACE_UINT16 t) const;
00157 };
00158 
00159 /**
00160  * @class ACE_Hash<ACE_INT32>
00161  *
00162  * @brief Function object for hashing a 32-bit signed number
00163  */
00164 template<>
00165 class ACE_Export ACE_Hash<ACE_INT32>
00166 {
00167 public:
00168   /// Simply returns t
00169   unsigned long operator () (ACE_INT32 t) const;
00170 };
00171 
00172 /**
00173  * @class ACE_Hash<ACE_UINT32>
00174  *
00175  * @brief Function object for hashing a 32-bit unsigned number
00176  */
00177 template<>
00178 class ACE_Export ACE_Hash<ACE_UINT32>
00179 {
00180 public:
00181   /// Simply returns t
00182   unsigned long operator () (ACE_UINT32 t) const;
00183 };
00184 
00185 /**
00186  * @class ACE_Hash<ACE_UINT64>
00187  *
00188  * @brief Function object for hashing a 64-bit unsigned number
00189  */
00190 template<>
00191 class ACE_Export ACE_Hash<ACE_UINT64>
00192 {
00193 public:
00194   /// Simply returns t
00195   unsigned long operator () (ACE_UINT64 t) const;
00196 };
00197 
00198 // @@ DONE ADDING HASHES FOR ACE TYPES
00199 #endif
00200 
00201 /**
00202  * @class ACE_Hash<short>
00203  *
00204  * @brief Function object for hashing a short number
00205  */
00206 template<>
00207 class ACE_Export ACE_Hash<short>
00208 {
00209 public:
00210   /// Simply returns t
00211   unsigned long operator () (short t) const;
00212 };
00213 
00214 /**
00215  * @class ACE_Hash<unsigned short>
00216  *
00217  * @brief Function object for hashing an unsigned short number
00218  */
00219 template<>
00220 class ACE_Export ACE_Hash<unsigned short>
00221 {
00222 public:
00223   /// Simply returns t
00224   unsigned long operator () (unsigned short t) const;
00225 };
00226 
00227 /**
00228  * @class ACE_Hash<int>
00229  *
00230  * @brief Function object for hashing an int number
00231  */
00232 template<>
00233 class ACE_Export ACE_Hash<int>
00234 {
00235 public:
00236   /// Simply returns t
00237   unsigned long operator () (int t) const;
00238 };
00239 
00240 /**
00241  * @class ACE_Hash<unsigned int>
00242  *
00243  * @brief Function object for hashing an unsigned int number
00244  */
00245 template<>
00246 class ACE_Export ACE_Hash<unsigned int>
00247 {
00248 public:
00249   /// Simply returns t
00250   unsigned long operator () (unsigned int t) const;
00251 };
00252 
00253 /**
00254  * @class ACE_Hash<long>
00255  *
00256  * @brief Function object for hashing a long number
00257  */
00258 template<>
00259 class ACE_Export ACE_Hash<long>
00260 {
00261 public:
00262   /// Simply returns t
00263   unsigned long operator () (long t) const;
00264 };
00265 
00266 /**
00267  * @class ACE_Hash<unsigned long>
00268  *
00269  * @brief Function object for hashing an unsigned long number
00270  */
00271 template<>
00272 class ACE_Export ACE_Hash<unsigned long>
00273 {
00274 public:
00275   /// Simply returns t
00276   unsigned long operator () (unsigned long t) const;
00277 };
00278 
00279 #if !defined (ACE_LACKS_LONGLONG_T) && (ACE_SIZEOF_LONG < 8)
00280 /**
00281  * @class ACE_Hash<ACE_INT64>
00282  *
00283  * @brief Function object for hashing a signed 64-bit number
00284  */
00285 template<>
00286 class ACE_Export ACE_Hash<ACE_INT64>
00287 {
00288 public:
00289   /// Simply returns t
00290   unsigned long operator () (ACE_INT64 t) const;
00291 };
00292 #endif /* !ACE_LACKS_LONGLONG_T && ACE_SIZEOF_LONG < 8 */
00293 
00294 // We can do this even if ACE_LACKS_UNSIGNEDLONGLONG_T because there's an
00295 // emulation for it in ACE_U_LongLong.
00296 #if (ACE_SIZEOF_LONG < 8)
00297 /**
00298  * @class ACE_Hash<ACE_UINT64>
00299  *
00300  * @brief Function object for hashing an unsigned 64-bit number
00301  */
00302 template<>
00303 class ACE_Export ACE_Hash<ACE_UINT64>
00304 {
00305 public:
00306   /// Simply returns t
00307   unsigned long operator () (const ACE_UINT64 &t) const;
00308 };
00309 #endif /* ACE_SIZEOF_LONG < 8 */
00310 
00311 /**
00312  * @class ACE_Hash<const char *>
00313  *
00314  * @brief Function object for hashing a const string
00315  */
00316 template<>
00317 class ACE_Export ACE_Hash<const char *>
00318 {
00319 public:
00320   /// Calls ACE::hash_pjw
00321   unsigned long operator () (const char *t) const;
00322 };
00323 
00324 /**
00325  * @class ACE_Hash<char *>
00326  *
00327  * @brief Function object for hashing a string
00328  */
00329 template<>
00330 class ACE_Export ACE_Hash<char *>
00331 {
00332 public:
00333   /// Calls ACE::hash_pjw
00334   unsigned long operator () (const char *t) const;
00335 };
00336 
00337 /**
00338  * @class ACE_Hash<void *>
00339  *
00340  * @brief Function object for hashing a void *
00341  */
00342 template<>
00343 class ACE_Export ACE_Hash<void *>
00344 {
00345 public:
00346   unsigned long operator () (const void *) const;
00347 };
00348 
00349 /**
00350  * @class ACE_Equal_To<const char *>
00351  *
00352  * @brief Function object for determining whether two const strings are equal.
00353  */
00354 template<>
00355 class ACE_Export ACE_Equal_To<const char *>
00356 {
00357 public:
00358   /// Simply calls ACE_OS::strcmp
00359   int operator () (const char *lhs,
00360                    const char *rhs) const;
00361 };
00362 
00363 /**
00364  * @class ACE_Equal_To<char *>
00365  *
00366  * @brief Function object for determining whether two non-const
00367  * strings are equal.
00368  */
00369 template<>
00370 class ACE_Export ACE_Equal_To<char *>
00371 {
00372 public:
00373   /// Simply calls ACE_OS::strcmp
00374   int operator () (const char *lhs,
00375                    const char *rhs) const;
00376 };
00377 
00378 /**
00379  * @class ACE_Equal_To<ACE_UINT16>
00380  *
00381  * @brief Function object for determining whether two unsigned
00382  * 16 bit ints are equal.
00383  */
00384 template<>
00385 class ACE_Export ACE_Equal_To<ACE_UINT16>
00386 {
00387 public:
00388   /// Simply calls built-in operators
00389   int operator () (const ACE_UINT16 lhs,
00390                    const ACE_UINT16 rhs) const;
00391 };
00392 
00393 /**
00394  * @class ACE_Equal_To<ACE_INT16>
00395  *
00396  * @brief Function object for determining whether two
00397  * 16 bit ints are equal.
00398  */
00399 template<>
00400 class ACE_Export ACE_Equal_To<ACE_INT16>
00401 {
00402 public:
00403   /// Simply calls built-in operators
00404   int operator () (const ACE_INT16 lhs,
00405                    const ACE_INT16 rhs) const;
00406 };
00407 
00408 /**
00409  * @class ACE_Equal_To<ACE_UINT32>
00410  *
00411  * @brief Function object for determining whether two unsigned
00412  * 32 bit ints are equal.
00413  */
00414 template<>
00415 class ACE_Export ACE_Equal_To<ACE_UINT32>
00416 {
00417 public:
00418   /// Simply calls built-in operators
00419   int operator () (const ACE_UINT32 lhs,
00420                    const ACE_UINT32 rhs) const;
00421 };
00422 
00423 /**
00424  * @class ACE_Equal_To<ACE_INT32>
00425  *
00426  * @brief Function object for determining whether two
00427  * 32 bit ints are equal.
00428  */
00429 template<>
00430 class ACE_Export ACE_Equal_To<ACE_INT32>
00431 {
00432 public:
00433   /// Simply calls built-in operators
00434   int operator () (const ACE_INT32 lhs,
00435                    const ACE_INT32 rhs) const;
00436 };
00437 
00438 /**
00439  * @class ACE_Equal_To<ACE_UINT64>
00440  *
00441  * @brief Function object for determining whether two unsigned
00442  * 64 bit ints are equal.
00443  */
00444 template<>
00445 class ACE_Export ACE_Equal_To<ACE_UINT64>
00446 {
00447 public:
00448   /// Simply calls built-in operators
00449   int operator () (const ACE_UINT64 lhs,
00450                    const ACE_UINT64 rhs) const;
00451 };
00452 
00453 /**
00454  * @class ACE_Less_Than<const char*>
00455  *
00456  * @brief Function object for determining whether the first const string
00457  * is less than the second const string.
00458  */
00459 template<>
00460 class ACE_Export ACE_Less_Than<const char *>
00461 {
00462 public:
00463   /// Simply calls ACE_OS::strcmp
00464   int operator () (const char *lhs,
00465                    const char *rhs) const;
00466 };
00467 
00468 /**
00469  * @class ACE_Less_Than<char *>
00470  *
00471  * @brief Function object for determining whether the first string
00472  * is less than the second string.
00473  */
00474 template<>
00475 class ACE_Export ACE_Less_Than<char *>
00476 {
00477 public:
00478   /// Simply calls ACE_OS::strcmp
00479   int operator () (const char *lhs,
00480                    const char *rhs) const;
00481 };
00482 
00483 #if defined (ACE_HAS_WCHAR)
00484 
00485 #  if ! defined (ACE_LACKS_NATIVE_WCHAR_T)
00486 /**
00487  * @class ACE_Hash<wchar_t>
00488  *
00489  * @brief Function object for hashing a wchar_t
00490  */
00491 template<>
00492 class ACE_Export ACE_Hash<wchar_t>
00493 {
00494 public:
00495   /// Simply returns t
00496   unsigned long operator () (wchar_t t) const;
00497 };
00498 #  endif /* ACE_LACKS_NATIVE_WCHAR_T */
00499 /**
00500  * @class ACE_Hash<const wchar_t *>
00501  *
00502  * @brief Function object for hashing a const string
00503  */
00504 template<>
00505 class ACE_Export ACE_Hash<const wchar_t *>
00506 {
00507 public:
00508   /// Calls ACE::hash_pjw
00509   unsigned long operator () (const wchar_t *t) const;
00510 };
00511 
00512 /**
00513  * @class ACE_Hash<wchar_t *>
00514  *
00515  * @brief Function object for hashing a string
00516  */
00517 template<>
00518 class ACE_Export ACE_Hash<wchar_t *>
00519 {
00520 public:
00521   /// Calls ACE::hash_pjw
00522   unsigned long operator () (const wchar_t *t) const;
00523 };
00524 
00525 /**
00526  * @class ACE_Equal_To<const wchar_t *>
00527  *
00528  * @brief Function object for determining whether two const strings are equal.
00529  */
00530 template<>
00531 class ACE_Export ACE_Equal_To<const wchar_t *>
00532 {
00533 public:
00534   /// Simply calls ACE_OS::strcmp
00535   int operator () (const wchar_t *lhs,
00536                    const wchar_t *rhs) const;
00537 };
00538 
00539 /**
00540  * @class ACE_Equal_To<wchar_t *>
00541  *
00542  * @brief Function object for determining whether two non-const
00543  * strings are equal.
00544  */
00545 template<>
00546 class ACE_Export ACE_Equal_To<wchar_t *>
00547 {
00548 public:
00549   /// Simply calls ACE_OS::strcmp
00550   int operator () (const wchar_t *lhs,
00551                    const wchar_t *rhs) const;
00552 };
00553 
00554 /**
00555  * @class ACE_Less_Than<const wchar_t *>
00556  *
00557  * @brief Function object for determining whether the first const string
00558  * is less than the second const string.
00559  */
00560 template<>
00561 class ACE_Export ACE_Less_Than<const wchar_t *>
00562 {
00563 public:
00564   /// Simply calls ACE_OS::strcmp
00565   int operator () (const wchar_t *lhs,
00566                    const wchar_t *rhs) const;
00567 };
00568 
00569 /**
00570  * @class ACE_Less_Than<wchar_t *>
00571  *
00572  * @brief Function object for determining whether the first string
00573  * is less than the second string.
00574  */
00575 template<>
00576 class ACE_Export ACE_Less_Than<wchar_t *>
00577 {
00578 public:
00579   /// Simply calls ACE_OS::strcmp
00580   int operator () (const wchar_t *lhs,
00581                    const wchar_t *rhs) const;
00582 };
00583 
00584 #endif  // ACE_HAS_WCHAR
00585 
00586 ACE_END_VERSIONED_NAMESPACE_DECL
00587 
00588 #if defined (__ACE_INLINE__)
00589 #include "ace/Functor.inl"
00590 #endif /* __ACE_INLINE__ */
00591 
00592 #include /**/ "ace/post.h"
00593 #endif /* ACE_FUNCTOR_H */

Generated on Thu Nov 9 09:41:51 2006 for ACE by doxygen 1.3.6