BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslalg_autoscalardestructor.h
Go to the documentation of this file.
1/// @file bslalg_autoscalardestructor.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslalg_autoscalardestructor.h -*-C++-*-
8#ifndef INCLUDED_BSLALG_AUTOSCALARDESTRUCTOR
9#define INCLUDED_BSLALG_AUTOSCALARDESTRUCTOR
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslalg_autoscalardestructor bslalg_autoscalardestructor
15/// @brief Provide a proctor for destroying an object.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslalg
19/// @{
20/// @addtogroup bslalg_autoscalardestructor
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslalg_autoscalardestructor-purpose"> Purpose</a>
25/// * <a href="#bslalg_autoscalardestructor-classes"> Classes </a>
26/// * <a href="#bslalg_autoscalardestructor-description"> Description </a>
27/// * <a href="#bslalg_autoscalardestructor-usage"> Usage </a>
28///
29/// # Purpose {#bslalg_autoscalardestructor-purpose}
30/// Provide a proctor for destroying an object.
31///
32/// # Classes {#bslalg_autoscalardestructor-classes}
33///
34/// - bslalg::AutoScalarDestructor: exception-neutrality proctor for an object
35///
36/// @see bslma_autodestructor, bslma_destructionutil
37///
38/// # Description {#bslalg_autoscalardestructor-description}
39/// This component provides a proctor object to manage an
40/// otherwise-unmanaged instance of a user-defined type. If not explicitly
41/// released, the instance managed by the proctor object is automatically
42/// destroyed by the proctor's destructor, using the `bslma::DestructionUtil`
43/// utility.
44///
45/// ## Usage {#bslalg_autoscalardestructor-usage}
46///
47///
48/// @}
49/** @} */
50/** @} */
51
52/** @addtogroup bsl
53 * @{
54 */
55/** @addtogroup bslalg
56 * @{
57 */
58/** @addtogroup bslalg_autoscalardestructor
59 * @{
60 */
61
62#include <bslscm_version.h>
63
65
66#include <bsls_assert.h>
67
68#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
70#endif
71
72
73
74namespace bslalg {
75
76 // ==========================
77 // class AutoScalarDestructor
78 // ==========================
79
80/// This `class` provides a specialized proctor object that, upon
81/// destruction and unless the `release` method is called, destroys the
82/// guarded object of the parameterized `OBJECT_TYPE`.
83///
84/// See @ref bslalg_autoscalardestructor
85template <class OBJECT_TYPE>
87
88 // DATA
89 OBJECT_TYPE *d_object_p; // address of guarded object
90
91 private:
92 // NOT IMPLEMENTED
95
96 public:
97 // CREATORS
98
99 /// Create a guard object, proctoring the specified `object` of the
100 /// parameterized `OBJECT_TYPE` (if non-zero), that will invoke the
101 /// destructor of `object` upon destruction.
102 AutoScalarDestructor(OBJECT_TYPE *object);
103
104 /// Call the destructor on the object of the parameterized `OBJECT_TYPE`
105 /// that is proctored by this guard object, if any, and destroy this
106 /// object.
108
109 // MANIPULATORS
110
111 /// Set the address of the object proctored by this guard object to 0,
112 /// thereby releasing from management the object currently managed by
113 /// this proctor, if any.
114 void release();
115
116 /// Set this guard object to manage the specified `object`, thereby
117 /// releasing from management any object currently managed by this
118 /// proctor, if any.
119 void reset(OBJECT_TYPE *object);
120};
121
122// ============================================================================
123// TEMPLATE FUNCTION DEFINITIONS
124// ============================================================================
125
126 // --------------------------
127 // class AutoScalarDestructor
128 // --------------------------
129
130// CREATORS
131template <class OBJECT_TYPE>
132inline
134: d_object_p(object)
135{
136}
137
138template <class OBJECT_TYPE>
139inline
141{
142 if (d_object_p) {
143 bslma::DestructionUtil::destroy(d_object_p);
144 }
145}
146
147// MANIPULATORS
148template <class OBJECT_TYPE>
149inline
151{
152 d_object_p = 0;
153}
154
155template <class OBJECT_TYPE>
156inline
158{
159 d_object_p = object;
160}
161
162} // close package namespace
163
164#ifndef BDE_OPENSOURCE_PUBLICATION // BACKWARD_COMPATIBILITY
165// ============================================================================
166// BACKWARD COMPATIBILITY
167// ============================================================================
168
169#ifdef bslalg_AutoScalarDestructor
170#undef bslalg_AutoScalarDestructor
171#endif
172/// This alias is defined for backward compatibility.
173#define bslalg_AutoScalarDestructor bslalg::AutoScalarDestructor
174#endif // BDE_OPENSOURCE_PUBLICATION -- BACKWARD_COMPATIBILITY
175
176
177
178#endif
179
180// ----------------------------------------------------------------------------
181// Copyright 2013 Bloomberg Finance L.P.
182//
183// Licensed under the Apache License, Version 2.0 (the "License");
184// you may not use this file except in compliance with the License.
185// You may obtain a copy of the License at
186//
187// http://www.apache.org/licenses/LICENSE-2.0
188//
189// Unless required by applicable law or agreed to in writing, software
190// distributed under the License is distributed on an "AS IS" BASIS,
191// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
192// See the License for the specific language governing permissions and
193// limitations under the License.
194// ----------------------------- END-OF-FILE ----------------------------------
195
196/** @} */
197/** @} */
198/** @} */
Definition bslalg_autoscalardestructor.h:86
void reset(OBJECT_TYPE *object)
Definition bslalg_autoscalardestructor.h:157
void release()
Definition bslalg_autoscalardestructor.h:150
~AutoScalarDestructor()
Definition bslalg_autoscalardestructor.h:140
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlc_flathashmap.h:1805