2 //=============================================================================
6 * @author Carlos O'Ryan <coryan@atdesk.com>
8 //=============================================================================
9 #ifndef ACE_AUTO_FUNCTOR_H
10 #define ACE_AUTO_FUNCTOR_H
11 #include /**/ "ace/pre.h"
13 #include /**/ "ace/config-all.h"
15 #if !defined (ACE_LACKS_PRAGMA_ONCE)
17 #endif /* ACE_LACKS_PRAGMA_ONCE */
19 #include "ace/Global_Macros.h"
21 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
26 * @class Auto_Functor_Ref
28 * @brief Helper class to implement assignment and copy-construction
31 template<typename X
, typename Functor
>
32 struct Auto_Functor_Ref
37 Auto_Functor_Ref(X
* p
, Functor f
);
43 * @brief Helper template to implement auto_ptr<>-like classes, but
44 * executing a functor in the destructor, instead of always
47 * The functor is called in the destructor, and it must implement:
49 * Functor() throw();<BR>
50 * Functor(Functor const &) throw();<BR>
51 * Functor & operator=(Functor const &) throw();<BR>
52 * void operator()(X * p) throw();<BR>
54 template<typename X
, typename Functor
>
58 typedef X element_type
;
59 typedef Functor functor_type
;
62 explicit Auto_Functor (X
* p
= 0,
63 Functor functor
= Functor()); // throw()
65 Auto_Functor (Auto_Functor
& rhs
); // throw()
67 Auto_Functor
<X
,Functor
>& operator= (Auto_Functor
& rhs
); // throw()
70 Auto_Functor(Auto_Functor
<Y
,Functor
>& rhs
); // throw()
73 Auto_Functor
<X
,Functor
>& operator= (Auto_Functor
<Y
,Functor
>& rhs
); // throw()
75 ~Auto_Functor(); // throw()
77 X
& operator*() const; // throw()
79 X
* operator->() const; // throw()
83 X
* release(); // throw()
85 void reset (X
* p
= 0); // throw()
87 void reset (X
* p
, Functor f
); // throw()
89 Functor
const & functor() const; // throw()
91 Auto_Functor(Auto_Functor_Ref
<X
,Functor
> rhs
); // throw()
93 Auto_Functor
<X
,Functor
> & operator=(Auto_Functor_Ref
<X
,Functor
> rhs
); // throw()
95 template<typename Y
> operator Auto_Functor_Ref
<Y
,Functor
>(); // throw()
97 template<typename Y
> operator Auto_Functor
<Y
,Functor
>(); // throw()
105 } // namespace ACE_Utils
107 ACE_END_VERSIONED_NAMESPACE_DECL
109 #if defined(__ACE_INLINE__)
110 # include "ace/Auto_Functor.inl"
111 #endif /* __ACE_INLINE__ */
113 #if defined(ACE_TEMPLATES_REQUIRE_SOURCE)
114 # include "ace/Auto_Functor.cpp"
115 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
117 #include /**/ "ace/post.h"
118 #endif /* ACE_AUTO_FUNCTOR_H*/