00001 /* -*- C++ -*- */ 00002 00003 //============================================================================= 00004 /** 00005 * @file Functor_T.h 00006 * 00007 * $Id: Functor_T.h 69051 2005-10-28 16:14:56Z ossama $ 00008 * 00009 * Templatized classes for implementing function objects that are 00010 * used in various places in ACE. There are currently two major 00011 * categories of function objects in ACE: GOF Command Pattern 00012 * objects, and STL-style functors for comparison of container 00013 * elements. The command objects are invoked via an <execute> 00014 * method, while the STL-style functors are invoked via an 00015 * <operator()> method. 00016 * 00017 * 00018 * @author Chris Gill <cdgill@cs.wustl.edu> 00019 * @author Based on Command Pattern implementations originally done by 00020 * @author Carlos O'Ryan <coryan@cs.wustl.edu> 00021 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00022 * @author Sergio Flores-Gaitan <sergio@cs.wustl.edu> 00023 * @author and on STL-style functor implementations originally done by 00024 * @author Irfan Pyarali <irfan@cs.wustl.edu> 00025 */ 00026 //============================================================================= 00027 00028 00029 #ifndef ACE_FUNCTOR_T_H 00030 #define ACE_FUNCTOR_T_H 00031 #include /**/ "ace/pre.h" 00032 00033 #include "ace/Functor.h" 00034 00035 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00036 # pragma once 00037 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00038 00039 #include "ace/Functor_String.h" 00040 00041 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00042 00043 /////////////////////////////////// 00044 // GOF Command Pattern Templates // 00045 /////////////////////////////////// 00046 00047 /** 00048 * @class ACE_Command_Callback 00049 * 00050 * @brief Defines a class template that allows us to invoke a GOF 00051 * command style callback to an object without knowing anything 00052 * about the object except its type. 00053 * 00054 * This class declares an interface to execute operations, 00055 * binding a RECEIVER object with an ACTION. The RECEIVER knows 00056 * how to implement the operation. A class can invoke operations 00057 * without knowing anything about it, or how it was implemented. 00058 */ 00059 template <class RECEIVER, class ACTION> 00060 class ACE_Command_Callback : public ACE_Command_Base 00061 { 00062 public: 00063 /// Constructor: sets the <receiver_> of the Command to recvr, and the 00064 /// <action_> of the Command to <action>. 00065 ACE_Command_Callback (RECEIVER &recvr, ACTION action); 00066 00067 /// Virtual destructor. 00068 virtual ~ACE_Command_Callback (void); 00069 00070 /// Invokes the method <action_> from the object <receiver_>. 00071 virtual int execute (void *arg = 0); 00072 00073 private: 00074 /// Object where the method resides. 00075 RECEIVER &receiver_; 00076 00077 /// Method that is going to be invoked. 00078 ACTION action_; 00079 }; 00080 00081 ///////////////////////////////// 00082 // STL-style Functor Templates // 00083 ///////////////////////////////// 00084 00085 /** 00086 * @class ACE_Hash 00087 * 00088 * @brief Function object for hashing 00089 */ 00090 template <class TYPE> 00091 class ACE_Hash 00092 { 00093 public: 00094 /// Simply calls t.hash () 00095 unsigned long operator () (const TYPE &t) const; 00096 }; 00097 00098 /** 00099 * @class ACE_Pointer_Hash 00100 * 00101 * @brief Function object for hashing pointers 00102 */ 00103 template <class TYPE> 00104 class ACE_Pointer_Hash 00105 { 00106 public: 00107 /// Simply returns t. 00108 unsigned long operator () (TYPE t) const; 00109 }; 00110 00111 /** 00112 * @class ACE_Equal_To 00113 * 00114 * @brief Function object for comparing two objects of 00115 * the given type for equality. 00116 */ 00117 template <class TYPE> 00118 class ACE_Equal_To 00119 { 00120 public: 00121 /// Simply calls operator== 00122 bool operator () (const TYPE &lhs, 00123 const TYPE &rhs) const; 00124 }; 00125 00126 /** 00127 * @class ACE_Less_Than 00128 * 00129 * @brief Function object for determining whether the first object of 00130 * the given type is less than the second object of the same 00131 * type. 00132 */ 00133 template <class TYPE> 00134 class ACE_Less_Than 00135 { 00136 public: 00137 /// Simply calls operator< 00138 bool operator () (const TYPE &lhs, 00139 const TYPE &rhs) const; 00140 }; 00141 00142 ACE_END_VERSIONED_NAMESPACE_DECL 00143 00144 #if defined (__ACE_INLINE__) 00145 #include "ace/Functor_T.inl" 00146 #endif /* __ACE_INLINE__ */ 00147 00148 00149 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00150 #include "ace/Functor_T.cpp" 00151 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00152 00153 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00154 #pragma implementation ("Functor_T.cpp") 00155 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00156 00157 #include /**/ "ace/post.h" 00158 #endif /* ACE_FUNCTOR_T_H */