Auto_Functor.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //=============================================================================
00003 /**
00004  * @file Auto_Functor.h
00005  *
00006  * Auto_Functor.h,v 1.2 2005/10/28 16:14:51 ossama Exp
00007  *
00008  * @author Carlos O'Ryan <coryan@atdesk.com>
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 /* ACE_LACKS_PRAGMA_ONCE */
00020 
00021 #include "ace/Global_Macros.h"
00022 
00023 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00024 
00025 namespace ACE_Utils
00026 {
00027 /**
00028  * @class Auto_Functor_Ref
00029  *
00030  * @brief Helper class to implement assignment and copy-construction
00031  *        as expected
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  * @class Auto_Functor
00044  *
00045  * @brief Helper template to implement auto_ptr<>-like classes, but
00046  *    executing a functor in the destructor, instead of always
00047  *    deleting things.
00048  *
00049  * The functor is called in the destructor, and it must implement:
00050  *
00051  * Functor() throw();<BR>
00052  * Functor(Functor const &) throw();<BR>
00053  * Functor & operator=(Functor const &) throw();<BR>
00054  * void operator()(X * p) throw();<BR>
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   /// Constructor
00065   explicit Auto_Functor (X * p = 0,
00066       Functor functor = Functor())
00067     ACE_THROW_SPEC (());
00068 
00069   Auto_Functor (Auto_Functor & rhs)
00070     ACE_THROW_SPEC (());
00071 
00072   Auto_Functor<X,Functor>& operator= (Auto_Functor & rhs)
00073     ACE_THROW_SPEC (());
00074 
00075 #if !defined(ACE_LACKS_MEMBER_TEMPLATES)
00076   template<typename Y>
00077   Auto_Functor(Auto_Functor<Y,Functor>& rhs)
00078     ACE_THROW_SPEC (());
00079 
00080   template<typename Y>
00081   Auto_Functor<X,Functor>& operator= (Auto_Functor<Y,Functor>& rhs)
00082     ACE_THROW_SPEC (());
00083 #endif /* ACE_LACKS_MEMBER_TEMPLATES */
00084 
00085   ~Auto_Functor()
00086     ACE_THROW_SPEC (());
00087 
00088   X & operator*() const
00089     ACE_THROW_SPEC (());
00090 
00091   X * operator->() const
00092     ACE_THROW_SPEC (());
00093 
00094   X * get()
00095     ACE_THROW_SPEC (());
00096 
00097   X * release()
00098     ACE_THROW_SPEC (());
00099 
00100   void reset (X * p = 0)
00101     ACE_THROW_SPEC (());
00102 
00103   void reset (X * p, Functor f)
00104     ACE_THROW_SPEC (());
00105 
00106   Functor const & functor() const
00107     ACE_THROW_SPEC (());
00108 
00109   Auto_Functor(Auto_Functor_Ref<X,Functor> rhs)
00110     ACE_THROW_SPEC (());
00111 
00112   Auto_Functor<X,Functor> & operator=(Auto_Functor_Ref<X,Functor> rhs)
00113     ACE_THROW_SPEC (());
00114 
00115 #if !defined(ACE_LACKS_MEMBER_TEMPLATES)
00116   template<typename Y> operator Auto_Functor_Ref<Y,Functor>()
00117     ACE_THROW_SPEC (());
00118 
00119   template<typename Y> operator Auto_Functor<Y,Functor>()
00120     ACE_THROW_SPEC (());
00121 #else
00122   operator Auto_Functor_Ref<X,Functor>()
00123     ACE_THROW_SPEC (());
00124 #endif /* ACE_LACKS_MEMBER_TEMPLATES */
00125 
00126 private:
00127   X * p_;
00128 
00129   Functor f_;
00130 };
00131 
00132 } // namespace ACE_Utils
00133 
00134 ACE_END_VERSIONED_NAMESPACE_DECL
00135 
00136 #if defined(__ACE_INLINE__)
00137 # include "ace/Auto_Functor.inl"
00138 #endif /* __ACE_INLINE__ */
00139 
00140 #if defined(ACE_TEMPLATES_REQUIRE_SOURCE)
00141 # include "ace/Auto_Functor.cpp"
00142 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00143 
00144 #include /**/ "ace/post.h"
00145 #endif /* ACE_AUTO_FUNCTOR_H*/

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