3 //=============================================================================
7 * @author Doug Schmidt <d.schmidt@vanderbilt.edu>
8 * @author Irfan Pyarali <irfan@cs.wustl.edu>
9 * @author Jack Reeves <jack@fx.com>
10 * @author Dr. Harald M. Mueller <mueller@garwein.hai.siemens.co.at>
12 //=============================================================================
14 #ifndef ACE_AUTO_PTR_H
15 #define ACE_AUTO_PTR_H
16 #include /**/ "ace/pre.h"
18 #include /**/ "ace/config-all.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 // C++17 removed std::auto_ptr<>, so also disable the ACE versions when
26 #if !defined (ACE_HAS_CPP17)
28 #if defined (_MSC_VER)
29 // Suppress warning e.g. "return type for
30 // 'ACE_Auto_Array_Pointer<type>::operator ->' is 'type *' (i.e., not a UDT
31 // or reference to a UDT. Will produce errors if applied using infix
33 # pragma warning(push)
34 # pragma warning(disable: 4284)
37 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
40 * @class ACE_Auto_Basic_Ptr
42 * @brief Implements the draft C++ standard auto_ptr abstraction.
43 * This class allows one to work on non-object (basic) types
46 class ACE_Auto_Basic_Ptr
49 typedef X element_type
;
51 explicit ACE_Auto_Basic_Ptr (X
* p
= nullptr) : p_ (p
) {}
53 ACE_Auto_Basic_Ptr (ACE_Auto_Basic_Ptr
<X
> & ap
);
54 ACE_Auto_Basic_Ptr
<X
> &operator= (ACE_Auto_Basic_Ptr
<X
> & rhs
);
55 ~ACE_Auto_Basic_Ptr ();
57 // = Accessor methods.
58 X
&operator *() const;
61 void reset (X
* p
= nullptr);
63 /// Dump the state of an object.
66 /// Declare the dynamic allocation hooks.
67 ACE_ALLOC_HOOK_DECLARE
;
73 ACE_END_VERSIONED_NAMESPACE_DECL
75 #if !defined (ACE_LACKS_AUTO_PTR)
78 #else /* !ACE_LACKS_AUTO_PTR */
80 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
85 * @brief Implements the draft C++ standard auto_ptr abstraction.
88 class auto_ptr
: public ACE_Auto_Basic_Ptr
<X
>
91 typedef X element_type
;
93 explicit auto_ptr (X
* p
= 0) : ACE_Auto_Basic_Ptr
<X
> (p
) {}
94 auto_ptr (auto_ptr
<X
> & ap
) : ACE_Auto_Basic_Ptr
<X
> (ap
.release ()) {}
96 X
*operator-> () const;
99 ACE_END_VERSIONED_NAMESPACE_DECL
101 #endif /* !ACE_LACKS_AUTO_PTR */
103 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
106 * @brief Implements the draft C++ standard auto_ptr abstraction.
107 * This version can be used instead of auto_ptr<T>
109 template <typename X
>
110 class ACE_Auto_Ptr
: public ACE_Auto_Basic_Ptr
<X
>
113 typedef X element_type
;
115 explicit ACE_Auto_Ptr (X
* p
= 0) : ACE_Auto_Basic_Ptr
<X
> (p
) {}
117 X
*operator-> () const;
121 * @class ACE_Auto_Basic_Array_Ptr
123 * @brief Implements an extension to the draft C++ standard auto_ptr
124 * abstraction. This class allows one to work on non-object
125 * (basic) types that must be treated as an array, e.g.,
126 * deallocated via "delete [] foo".
129 class ACE_Auto_Basic_Array_Ptr
132 typedef X element_type
;
134 explicit ACE_Auto_Basic_Array_Ptr (X
* p
= 0) : p_ (p
) {}
136 ACE_Auto_Basic_Array_Ptr (ACE_Auto_Basic_Array_Ptr
<X
> & ap
);
137 ACE_Auto_Basic_Array_Ptr
<X
> &operator= (ACE_Auto_Basic_Array_Ptr
<X
> & rhs
);
138 ~ACE_Auto_Basic_Array_Ptr ();
140 // = Accessor methods.
141 X
& operator* () const;
142 X
& operator[] (int i
) const;
145 void reset (X
* p
= 0);
147 /// Dump the state of an object.
150 /// Declare the dynamic allocation hooks.
151 ACE_ALLOC_HOOK_DECLARE
;
158 * @class ACE_Auto_Array_Ptr
160 * @brief Implements an extension to the draft C++ standard auto_ptr
164 class ACE_Auto_Array_Ptr
: public ACE_Auto_Basic_Array_Ptr
<X
>
167 typedef X element_type
;
169 explicit ACE_Auto_Array_Ptr (X
*p
= 0)
170 : ACE_Auto_Basic_Array_Ptr
<X
> (p
) {}
172 X
*operator-> () const;
177 * @brief Reset given @c auto_ptr element to new element.
179 * Some platforms have an older version of auto_ptr support, which
180 * lacks reset, and cannot be disabled easily. Portability to these
181 * platforms requires use of this function template. This function
182 * template also works for the @c ACE_Auto_{Basic_}Array_Ptr class
185 template<typename AUTO_PTR_TYPE
, typename PTR_TYPE
>
187 ACE_auto_ptr_reset (AUTO_PTR_TYPE
& ap
, PTR_TYPE
* p
)
192 ACE_END_VERSIONED_NAMESPACE_DECL
194 #if defined (__ACE_INLINE__)
195 #include "ace/Auto_Ptr.inl"
196 #endif /* __ACE_INLINE__ */
198 #include "ace/Auto_Ptr.cpp"
200 #if defined (_MSC_VER)
201 // Restore the warning state to what it was before entry.
202 # pragma warning(pop)
203 #endif /* _MSC_VER */
205 #endif /* ACE_HAS_CPP17 */
207 #include /**/ "ace/post.h"
208 #endif /* ACE_AUTO_PTR_H */