Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Functor.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //==========================================================================
00004 /**
00005  *  @file    Functor.h
00006  *
00007  *  $Id: Functor.h,v 1.1.1.4 2003/02/21 18:36:32 chad 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/ACE.h"
00036 
00037 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00038 # pragma once
00039 #endif /* ACE_LACKS_PRAGMA_ONCE */
00040 
00041 //////////////////////////////////////////////////////////////
00042 // GOF Command Pattern Classes and Template Specializations //
00043 //////////////////////////////////////////////////////////////
00044 
00045 /**
00046  * @class ACE_Command_Base
00047  *
00048  * @brief Defines an abstract class that allows us to invoke commands
00049  * without knowing anything about the implementation.
00050  *
00051  * This class declares an interface to execute a command
00052  * independent of the effect of the command, or the objects used
00053  * to implement it.
00054  */
00055 class ACE_Export ACE_Command_Base
00056 {
00057 public:
00058   // = Initialization and termination methods.
00059   /// Default constructor.
00060   ACE_Command_Base (void);
00061 
00062   /// Virtual destructor.
00063   virtual ~ACE_Command_Base (void);
00064 
00065   /**
00066    * Invokes the method encapsulated by the command, passing along the
00067    * passed argument (if any).  Users of classes derived from this
00068    * class must ensure that the resulting invocation can tolerate a
00069    * null void pointer being passed, or otherwise ensure that this
00070    * will never occur.
00071    */
00072   virtual int execute (void *arg = 0) = 0;
00073 };
00074 
00075 ////////////////////////////////////////////////////////////
00076 // STL-style Functor Classes and Template Specializations //
00077 ////////////////////////////////////////////////////////////
00078 
00079 // Forward declaration since we are going to specialize that template
00080 // here. The template itself requires this file so every user of the
00081 // template should also see the specialization.
00082 template <class TYPE> class ACE_Hash;
00083 template <class TYPE> class ACE_Equal_To;
00084 template <class TYPE> class ACE_Less_Than;
00085 
00086 ACE_TEMPLATE_SPECIALIZATION
00087 /**
00088  * @class ACE_Hash<char>
00089  *
00090  * @brief Function object for hashing a char
00091  */
00092 class ACE_Export ACE_Hash<char>
00093 {
00094 public:
00095   /// Simply returns t
00096   u_long operator () (char t) const;
00097 };
00098 
00099 ACE_TEMPLATE_SPECIALIZATION
00100 /**
00101  * @class ACE_Hash<signed
00102  *
00103  * @brief Function object for hashing a signed char
00104  */
00105 class ACE_Export ACE_Hash<signed char>
00106 {
00107 public:
00108   /// Simply returns t
00109   u_long operator () (signed char t) const;
00110 };
00111 
00112 ACE_TEMPLATE_SPECIALIZATION
00113 /**
00114  * @class ACE_Hash<unsigned
00115  *
00116  * @brief Function object for hashing an unsigned char
00117  */
00118 class ACE_Export ACE_Hash<unsigned char>
00119 {
00120 public:
00121   /// Simply returns t
00122   u_long operator () (unsigned char t) const;
00123 };
00124 
00125 // @@ ADD HASHES FOR ACE TYPES
00126 
00127 ACE_TEMPLATE_SPECIALIZATION
00128 /**
00129  * @class ACE_Hash<ACE_INT16>
00130  *
00131  * @brief Function object for hashing a 16-bit signed number
00132  */
00133 class ACE_Export ACE_Hash<ACE_INT16>
00134 {
00135 public:
00136   /// Simply returns t
00137   u_long operator () (ACE_INT16 t) const;
00138 };
00139 
00140 ACE_TEMPLATE_SPECIALIZATION
00141 /**
00142  * @class ACE_Hash<ACE_UINT16>
00143  *
00144  * @brief Function object for hashing a 16-bit unsigned number
00145  */
00146 class ACE_Export ACE_Hash<ACE_UINT16>
00147 {
00148 public:
00149   /// Simply returns t
00150   u_long operator () (ACE_UINT16 t) const;
00151 };
00152 
00153 ACE_TEMPLATE_SPECIALIZATION
00154 /**
00155  * @class ACE_Hash<ACE_INT32>
00156  *
00157  * @brief Function object for hashing a 32-bit signed number
00158  */
00159 class ACE_Export ACE_Hash<ACE_INT32>
00160 {
00161 public:
00162   /// Simply returns t
00163   u_long operator () (ACE_INT32 t) const;
00164 };
00165 
00166 ACE_TEMPLATE_SPECIALIZATION
00167 /**
00168  * @class ACE_Hash<ACE_UINT32>
00169  *
00170  * @brief Function object for hashing a 32-bit unsigned number
00171  */
00172 class ACE_Export ACE_Hash<ACE_UINT32>
00173 {
00174 public:
00175   /// Simply returns t
00176   u_long operator () (ACE_UINT32 t) const;
00177 };
00178 
00179 ACE_TEMPLATE_SPECIALIZATION
00180 /**
00181  * @class ACE_Hash<ACE_UINT64>
00182  *
00183  * @brief Function object for hashing a 64-bit unsigned number
00184  */
00185 class ACE_Export ACE_Hash<ACE_UINT64>
00186 {
00187 public:
00188   /// Simply returns t
00189   u_long operator () (ACE_UINT64 t) const;
00190 };
00191 
00192 // @@ DONE ADDING HASHES FOR ACE TYPES
00193 
00194 ACE_TEMPLATE_SPECIALIZATION
00195 /**
00196  * @class ACE_Hash<const
00197  *
00198  * @brief Function object for hashing a const string
00199  */
00200 class ACE_Export ACE_Hash<const ACE_TCHAR *>
00201 {
00202 public:
00203   /// Calls ACE::hash_pjw
00204   u_long operator () (const ACE_TCHAR *t) const;
00205 };
00206 
00207 ACE_TEMPLATE_SPECIALIZATION
00208 /**
00209  * @class ACE_Hash<ACE_TCHAR
00210  *
00211  * @brief Function object for hashing a string
00212  */
00213 class ACE_Export ACE_Hash<ACE_TCHAR *>
00214 {
00215 public:
00216   /// Calls ACE::hash_pjw
00217   u_long operator () (const ACE_TCHAR *t) const;
00218 };
00219 
00220 ACE_TEMPLATE_SPECIALIZATION
00221 /**
00222  * @class ACE_Hash<void *>
00223  *
00224  * @brief Function object for hashing a void *
00225  */
00226 class ACE_Export ACE_Hash<void *>
00227 {
00228 public:
00229   u_long operator () (const void *) const;
00230 };
00231 
00232 ACE_TEMPLATE_SPECIALIZATION
00233 /**
00234  * @class ACE_Equal_To<const
00235  *
00236  * @brief Function object for determining whether two const strings are equal.
00237  */
00238 class ACE_Export ACE_Equal_To<const ACE_TCHAR *>
00239 {
00240 public:
00241   /// Simply calls ACE_OS::strcmp
00242   int operator () (const ACE_TCHAR *lhs,
00243                    const ACE_TCHAR *rhs) const;
00244 };
00245 
00246 ACE_TEMPLATE_SPECIALIZATION
00247 /**
00248  * @class ACE_Equal_To<ACE_TCHAR
00249  *
00250  * @brief Function object for determining whether two non-const
00251  * strings are equal.
00252  */
00253 class ACE_Export ACE_Equal_To<ACE_TCHAR *>
00254 {
00255 public:
00256   /// Simply calls ACE_OS::strcmp
00257   int operator () (const ACE_TCHAR *lhs,
00258                    const ACE_TCHAR *rhs) const;
00259 };
00260 
00261  ACE_TEMPLATE_SPECIALIZATION
00262  /**
00263  * @class ACE_Equal_To<ACE_UINT16>
00264  *
00265  * @brief Function object for determining whether two unsigned
00266  * 16 bit ints are equal.
00267  */
00268 class ACE_Export ACE_Equal_To<ACE_UINT16>
00269 {
00270 public:
00271   /// Simply calls built-in operators
00272   int operator () (const ACE_UINT16 lhs,
00273                    const ACE_UINT16 rhs) const;
00274 };
00275 
00276 ACE_TEMPLATE_SPECIALIZATION
00277 /**
00278  * @class ACE_Equal_To<ACE_INT16>
00279  *
00280  * @brief Function object for determining whether two
00281  * 16 bit ints are equal.
00282  */
00283 class ACE_Export ACE_Equal_To<ACE_INT16>
00284 {
00285 public:
00286   /// Simply calls built-in operators
00287   int operator () (const ACE_INT16 lhs,
00288                    const ACE_INT16 rhs) const;
00289 };
00290 
00291 ACE_TEMPLATE_SPECIALIZATION
00292 /**
00293  * @class ACE_Equal_To<ACE_UINT32>
00294  *
00295  * @brief Function object for determining whether two unsigned
00296  * 32 bit ints are equal.
00297  */
00298 class ACE_Export ACE_Equal_To<ACE_UINT32>
00299 {
00300 public:
00301   /// Simply calls built-in operators
00302   int operator () (const ACE_UINT32 lhs,
00303                    const ACE_UINT32 rhs) const;
00304 };
00305 
00306 ACE_TEMPLATE_SPECIALIZATION
00307 /**
00308  * @class ACE_Equal_To<ACE_INT32>
00309  *
00310  * @brief Function object for determining whether two
00311  * 32 bit ints are equal.
00312  */
00313 class ACE_Export ACE_Equal_To<ACE_INT32>
00314 {
00315 public:
00316   /// Simply calls built-in operators
00317   int operator () (const ACE_INT32 lhs,
00318                    const ACE_INT32 rhs) const;
00319 };
00320 
00321 ACE_TEMPLATE_SPECIALIZATION
00322 /**
00323  * @class ACE_Equal_To<ACE_UINT64>
00324  *
00325  * @brief Function object for determining whether two unsigned
00326  * 64 bit ints are equal.
00327  */
00328 class ACE_Export ACE_Equal_To<ACE_UINT64>
00329 {
00330 public:
00331   /// Simply calls built-in operators
00332   int operator () (const ACE_UINT64 lhs,
00333                    const ACE_UINT64 rhs) const;
00334 };
00335 
00336 
00337 ACE_TEMPLATE_SPECIALIZATION
00338 /**
00339  * @class ACE_Less_Than<const
00340  *
00341  * @brief Function object for determining whether the first const string
00342  * is less than the second const string.
00343  */
00344 class ACE_Export ACE_Less_Than<const ACE_TCHAR *>
00345 {
00346 public:
00347   /// Simply calls ACE_OS::strcmp
00348   int operator () (const ACE_TCHAR *lhs,
00349                    const ACE_TCHAR *rhs) const;
00350 };
00351 
00352 ACE_TEMPLATE_SPECIALIZATION
00353 /**
00354  * @class ACE_Less_Than<ACE_TCHAR
00355  *
00356  * @brief Function object for determining whether the first string
00357  * is less than the second string.
00358  */
00359 class ACE_Export ACE_Less_Than<ACE_TCHAR *>
00360 {
00361 public:
00362   /// Simply calls ACE_OS::strcmp
00363   int operator () (const ACE_TCHAR *lhs,
00364                    const ACE_TCHAR *rhs) const;
00365 };
00366 
00367 #if defined (ACE_USES_WCHAR)
00368 
00369 ACE_TEMPLATE_SPECIALIZATION
00370 /**
00371  * @class ACE_Less_Than<const
00372  *
00373  * @brief Function object for determining whether the first const string
00374  * is less than the second const string.
00375  */
00376 class ACE_Export ACE_Less_Than<const ACE_ANTI_TCHAR *>
00377 {
00378 public:
00379   /// Simply calls ACE_OS::strcmp
00380   int operator () (const ACE_ANTI_TCHAR *lhs,
00381                    const ACE_ANTI_TCHAR *rhs) const;
00382 };
00383 
00384 ACE_TEMPLATE_SPECIALIZATION
00385 /**
00386  * @class ACE_Less_Than<ACE_ANTI_TCHAR
00387  *
00388  * @brief Function object for determining whether the first string
00389  * is less than the second string.
00390  */
00391 class ACE_Export ACE_Less_Than<ACE_ANTI_TCHAR *>
00392 {
00393 public:
00394   /// Simply calls ACE_OS::strcmp
00395   int operator () (const ACE_ANTI_TCHAR *lhs,
00396                    const ACE_ANTI_TCHAR *rhs) const;
00397 };
00398 
00399 ACE_TEMPLATE_SPECIALIZATION
00400 /**
00401  * @class ACE_Hash<const
00402  *
00403  * @brief Function object for hashing a const string
00404  */
00405 class ACE_Export ACE_Hash<const ACE_ANTI_TCHAR *>
00406 {
00407 public:
00408   /// Calls ACE::hash_pjw
00409   u_long operator () (const ACE_ANTI_TCHAR *t) const;
00410 };
00411 
00412 ACE_TEMPLATE_SPECIALIZATION
00413 /**
00414  * @class ACE_Hash<ACE_ANTI_TCHAR
00415  *
00416  * @brief Function object for hashing a string
00417  */
00418 class ACE_Export ACE_Hash<ACE_ANTI_TCHAR *>
00419 {
00420 public:
00421   /// Calls ACE::hash_pjw
00422   u_long operator () (const ACE_ANTI_TCHAR *t) const;
00423 };
00424 
00425 ACE_TEMPLATE_SPECIALIZATION
00426 /**
00427  * @class ACE_Equal_To<const
00428  *
00429  * @brief Function object for determining whether two const strings are equal.
00430  */
00431 class ACE_Export ACE_Equal_To<const ACE_ANTI_TCHAR *>
00432 {
00433 public:
00434   /// Simply calls ACE_OS::strcmp
00435   int operator () (const ACE_ANTI_TCHAR *lhs,
00436                    const ACE_ANTI_TCHAR *rhs) const;
00437 };
00438 
00439 ACE_TEMPLATE_SPECIALIZATION
00440 /**
00441  * @class ACE_Equal_To<ACE_ANTI_TCHAR
00442  *
00443  * @brief Function object for determining whether two non-const
00444  * strings are equal.
00445  */
00446 class ACE_Export ACE_Equal_To<ACE_ANTI_TCHAR *>
00447 {
00448 public:
00449   /// Simply calls ACE_OS::strcmp
00450   int operator () (const ACE_ANTI_TCHAR *lhs,
00451                    const ACE_ANTI_TCHAR *rhs) const;
00452 };
00453 
00454 #endif  // ACE_USES_WCHAR
00455 
00456 #if defined (__ACE_INLINE__)
00457 #include "ace/Functor.i"
00458 #endif /* __ACE_INLINE__ */
00459 
00460 // Include the templates here.
00461 #include "ace/Functor_T.h"
00462 
00463 #include "ace/post.h"
00464 #endif /* ACE_FUNCTOR_H */

Generated on Mon Jun 16 11:19:43 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002