Auto_Functor.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //=============================================================================
00003 /**
00004  * @file Auto_Functor.h
00005  *
00006  * $Id: Auto_Functor.h 80826 2008-03-04 14:51:23Z wotte $
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()); // throw()
00067 
00068   Auto_Functor (Auto_Functor & rhs); // throw()
00069 
00070   Auto_Functor<X,Functor>& operator= (Auto_Functor & rhs); // throw()
00071 
00072 #if !defined(ACE_LACKS_MEMBER_TEMPLATES)
00073   template<typename Y>
00074   Auto_Functor(Auto_Functor<Y,Functor>& rhs); // throw()
00075 
00076   template<typename Y>
00077   Auto_Functor<X,Functor>& operator= (Auto_Functor<Y,Functor>& rhs); // throw()
00078 #endif /* ACE_LACKS_MEMBER_TEMPLATES */
00079 
00080   ~Auto_Functor(); // throw()
00081 
00082   X & operator*() const; // throw()
00083 
00084   X * operator->() const; // throw()
00085 
00086   X * get(); // throw()
00087 
00088   X * release(); // throw()
00089 
00090   void reset (X * p = 0); // throw()
00091 
00092   void reset (X * p, Functor f); // throw()
00093 
00094   Functor const & functor() const; // throw()
00095 
00096   Auto_Functor(Auto_Functor_Ref<X,Functor> rhs); // throw()
00097 
00098   Auto_Functor<X,Functor> & operator=(Auto_Functor_Ref<X,Functor> rhs); // throw()
00099 
00100 #if !defined(ACE_LACKS_MEMBER_TEMPLATES)
00101   template<typename Y> operator Auto_Functor_Ref<Y,Functor>(); // throw()
00102 
00103   template<typename Y> operator Auto_Functor<Y,Functor>(); // throw()
00104 #else
00105   operator Auto_Functor_Ref<X,Functor>(); // throw()
00106 #endif /* ACE_LACKS_MEMBER_TEMPLATES */
00107 
00108 private:
00109   X * p_;
00110 
00111   Functor f_;
00112 };
00113 
00114 } // namespace ACE_Utils
00115 
00116 ACE_END_VERSIONED_NAMESPACE_DECL
00117 
00118 #if defined(__ACE_INLINE__)
00119 # include "ace/Auto_Functor.inl"
00120 #endif /* __ACE_INLINE__ */
00121 
00122 #if defined(ACE_TEMPLATES_REQUIRE_SOURCE)
00123 # include "ace/Auto_Functor.cpp"
00124 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00125 
00126 #include /**/ "ace/post.h"
00127 #endif /* ACE_AUTO_FUNCTOR_H*/

Generated on Tue Feb 2 17:18:38 2010 for ACE by  doxygen 1.4.7