Document return values
[ACE_TAO.git] / ACE / ace / Auto_Functor.h
blobe64bcdf6bb315b6b3cb9011545e2c34b91ce0828
1 // -*- C++ -*-
2 //=============================================================================
3 /**
4 * @file Auto_Functor.h
6 * @author Carlos O'Ryan <coryan@atdesk.com>
7 */
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)
16 # pragma once
17 #endif /* ACE_LACKS_PRAGMA_ONCE */
19 #include "ace/Global_Macros.h"
21 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
23 namespace ACE_Utils
25 /**
26 * @class Auto_Functor_Ref
28 * @brief Helper class to implement assignment and copy-construction
29 * as expected
31 template<typename X, typename Functor>
32 struct Auto_Functor_Ref
34 X * p_;
35 Functor f_;
37 Auto_Functor_Ref(X * p, Functor f);
40 /**
41 * @class Auto_Functor
43 * @brief Helper template to implement auto_ptr<>-like classes, but
44 * executing a functor in the destructor, instead of always
45 * deleting things.
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>
55 class Auto_Functor
57 public:
58 typedef X element_type;
59 typedef Functor functor_type;
61 /// Constructor
62 explicit Auto_Functor (X * p = 0,
63 Functor functor = Functor()); // noexcept
65 Auto_Functor (Auto_Functor & rhs); // noexcept
67 Auto_Functor<X,Functor>& operator= (Auto_Functor & rhs); // noexcept
69 template<typename Y>
70 Auto_Functor(Auto_Functor<Y,Functor>& rhs); // noexcept
72 template<typename Y>
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 = 0); // 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
99 private:
100 X * p_;
102 Functor f_;
104 } // namespace ACE_Utils
106 ACE_END_VERSIONED_NAMESPACE_DECL
108 #if defined(__ACE_INLINE__)
109 # include "ace/Auto_Functor.inl"
110 #endif /* __ACE_INLINE__ */
112 #include "ace/Auto_Functor.cpp"
114 #include /**/ "ace/post.h"
115 #endif /* ACE_AUTO_FUNCTOR_H*/