00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #ifndef ACE_AUTO_FUNCTOR_H
00012 #define ACE_AUTO_FUNCTOR_H
00013 #include  "ace/pre.h"
00014 
00015 #include  "ace/config-all.h"
00016 
00017 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00018 # pragma once
00019 #endif 
00020 
00021 #include "ace/Global_Macros.h"
00022 
00023 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00024 
00025 namespace ACE_Utils
00026 {
00027 
00028 
00029 
00030 
00031 
00032 
00033 template<typename X, typename Functor>
00034 struct Auto_Functor_Ref
00035 {
00036   X * p_;
00037   Functor f_;
00038 
00039   Auto_Functor_Ref(X * p, Functor f);
00040 };
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 template<typename X, typename Functor>
00058 class Auto_Functor
00059 {
00060 public:
00061   typedef X element_type;
00062   typedef Functor functor_type;
00063 
00064 
00065   explicit Auto_Functor (X * p = 0,
00066       Functor functor = Functor()); 
00067 
00068   Auto_Functor (Auto_Functor & rhs); 
00069 
00070   Auto_Functor<X,Functor>& operator= (Auto_Functor & rhs); 
00071 
00072 #if !defined(ACE_LACKS_MEMBER_TEMPLATES)
00073   template<typename Y>
00074   Auto_Functor(Auto_Functor<Y,Functor>& rhs); 
00075 
00076   template<typename Y>
00077   Auto_Functor<X,Functor>& operator= (Auto_Functor<Y,Functor>& rhs); 
00078 #endif 
00079 
00080   ~Auto_Functor(); 
00081 
00082   X & operator*() const; 
00083 
00084   X * operator->() const; 
00085 
00086   X * get(); 
00087 
00088   X * release(); 
00089 
00090   void reset (X * p = 0); 
00091 
00092   void reset (X * p, Functor f); 
00093 
00094   Functor const & functor() const; 
00095 
00096   Auto_Functor(Auto_Functor_Ref<X,Functor> rhs); 
00097 
00098   Auto_Functor<X,Functor> & operator=(Auto_Functor_Ref<X,Functor> rhs); 
00099 
00100 #if !defined(ACE_LACKS_MEMBER_TEMPLATES)
00101   template<typename Y> operator Auto_Functor_Ref<Y,Functor>(); 
00102 
00103   template<typename Y> operator Auto_Functor<Y,Functor>(); 
00104 #else
00105   operator Auto_Functor_Ref<X,Functor>(); 
00106 #endif 
00107 
00108 private:
00109   X * p_;
00110 
00111   Functor f_;
00112 };
00113 
00114 } 
00115 
00116 ACE_END_VERSIONED_NAMESPACE_DECL
00117 
00118 #if defined(__ACE_INLINE__)
00119 # include "ace/Auto_Functor.inl"
00120 #endif 
00121 
00122 #if defined(ACE_TEMPLATES_REQUIRE_SOURCE)
00123 # include "ace/Auto_Functor.cpp"
00124 #endif 
00125 
00126 #include  "ace/post.h"
00127 #endif