Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Auto_Ptr.h
blob4c4d97d2e013a0917efeef43c86307d300b80d85
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file Auto_Ptr.h
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)
21 # pragma once
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 // C++17 removed std::auto_ptr<>, so also disable the ACE versions when
25 // using C++17.
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
32 // notation)"
33 # pragma warning(push)
34 # pragma warning(disable: 4284)
35 #endif /* _MSC_VER */
37 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
39 /**
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
45 template <typename X>
46 class ACE_Auto_Basic_Ptr
48 public:
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;
59 X *get () const;
60 X *release ();
61 void reset (X * p = nullptr);
63 /// Dump the state of an object.
64 void dump () const;
66 /// Declare the dynamic allocation hooks.
67 ACE_ALLOC_HOOK_DECLARE;
69 protected:
70 X *p_;
73 ACE_END_VERSIONED_NAMESPACE_DECL
75 #if !defined (ACE_LACKS_AUTO_PTR)
76 # include <memory>
77 using std::auto_ptr;
78 #else /* !ACE_LACKS_AUTO_PTR */
80 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
82 /**
83 * @class auto_ptr
85 * @brief Implements the draft C++ standard auto_ptr abstraction.
87 template <typename X>
88 class auto_ptr : public ACE_Auto_Basic_Ptr<X>
90 public:
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>
112 public:
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".
128 template<typename X>
129 class ACE_Auto_Basic_Array_Ptr
131 public:
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;
143 X * get () const;
144 X * release ();
145 void reset (X * p = 0);
147 /// Dump the state of an object.
148 void dump () const;
150 /// Declare the dynamic allocation hooks.
151 ACE_ALLOC_HOOK_DECLARE;
153 protected:
154 X * p_;
158 * @class ACE_Auto_Array_Ptr
160 * @brief Implements an extension to the draft C++ standard auto_ptr
161 * abstraction.
163 template<typename X>
164 class ACE_Auto_Array_Ptr : public ACE_Auto_Basic_Array_Ptr<X>
166 public:
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
183 * template, as well.
185 template<typename AUTO_PTR_TYPE, typename PTR_TYPE>
186 inline void
187 ACE_auto_ptr_reset (AUTO_PTR_TYPE & ap, PTR_TYPE * p)
189 ap.reset (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 */