Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Auto_Functor.h
blob278db800b1e235b582cdb654210bb6cfa0937421
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 = nullptr,
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 = 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
99 private:
100 X * p_;
101 Functor f_;
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*/