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() noexcept;<BR>
50 * Functor(Functor const &) noexcept;<BR>
51 * Functor & operator=(Functor const &) noexcept;<BR>
52 * void operator()(X * p) noexcept;<BR>
54 template<typename X
, typename Functor
>
58 typedef X element_type
;
59 typedef Functor functor_type
;
62 explicit Auto_Functor (X
* p
= nullptr,
63 Functor functor
= Functor()); // noexcept
65 Auto_Functor (Auto_Functor
& rhs
); // noexcept
67 Auto_Functor
<X
,Functor
>& operator= (Auto_Functor
& rhs
); // noexcept
70 Auto_Functor(Auto_Functor
<Y
,Functor
>& rhs
); // noexcept
73 Auto_Functor
<X
,Functor
>& operator= (Auto_Functor
<Y
,Functor
>& rhs
); // noexcept
75 ~Auto_Functor(); // noexcept
77 X
& operator*() const; // noexcept
79 X
* operator->() const; // noexcept
81 X
* get(); // noexcept
83 X
* release(); // noexcept
85 void reset (X
* p
= nullptr); // noexcept
87 void reset (X
* p
, Functor f
); // noexcept
89 Functor
const & functor() const; // noexcept
91 Auto_Functor(Auto_Functor_Ref
<X
,Functor
> rhs
); // noexcept
93 Auto_Functor
<X
,Functor
> & operator=(Auto_Functor_Ref
<X
,Functor
> rhs
); // noexcept
95 template<typename Y
> operator Auto_Functor_Ref
<Y
,Functor
>(); // noexcept
97 template<typename Y
> operator Auto_Functor
<Y
,Functor
>(); // noexcept
103 } // namespace ACE_Utils
105 ACE_END_VERSIONED_NAMESPACE_DECL
107 #if defined(__ACE_INLINE__)
108 # include "ace/Auto_Functor.inl"
109 #endif /* __ACE_INLINE__ */
111 #include "ace/Auto_Functor.cpp"
113 #include /**/ "ace/post.h"
114 #endif /* ACE_AUTO_FUNCTOR_H*/