BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslma_managedptr_factorydeleter.h
Go to the documentation of this file.
1/// @file bslma_managedptr_factorydeleter.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslma_managedptr_factorydeleter.h -*-C++-*-
8#ifndef INCLUDED_BSLMA_MANAGEDPTR_FACTORYDELETER
9#define INCLUDED_BSLMA_MANAGEDPTR_FACTORYDELETER
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id$ $CSID$")
13
14/// @defgroup bslma_managedptr_factorydeleter bslma_managedptr_factorydeleter
15/// @brief Provide a factory-based deleter for the managed pointer class.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslma
19/// @{
20/// @addtogroup bslma_managedptr_factorydeleter
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslma_managedptr_factorydeleter-purpose"> Purpose</a>
25/// * <a href="#bslma_managedptr_factorydeleter-classes"> Classes </a>
26/// * <a href="#bslma_managedptr_factorydeleter-description"> Description </a>
27///
28/// # Purpose {#bslma_managedptr_factorydeleter-purpose}
29/// Provide a factory-based deleter for the managed pointer class.
30///
31/// # Classes {#bslma_managedptr_factorydeleter-classes}
32///
33/// - bslma::ManagedPtr_FactoryDeleter: deduced deleter used by bslma::ManagedPtr
34///
35/// @see bslma_managedptr
36///
37/// # Description {#bslma_managedptr_factorydeleter-description}
38/// This component provides a utility `struct`,
39/// `bslma::ManagedPtr_FactoryDeleter`, used as an implementation detail by
40/// `bslma::ManagedPtr` to produce a type-erasing deleter function that destroys
41/// an object of (template parameter) `OBJECT_TYPE`, using a factory of
42/// (template parameter) `FACTORY` type that provides a `deleteObject` method.
43/// @}
44/** @} */
45/** @} */
46
47/** @addtogroup bsl
48 * @{
49 */
50/** @addtogroup bslma
51 * @{
52 */
53/** @addtogroup bslma_managedptr_factorydeleter
54 * @{
55 */
56
57#include <bslscm_version.h>
58
59#include <bsls_assert.h>
60
61
62namespace bslma {
63
64 // ================================
65 // struct ManagedPtr_FactoryDeleter
66 // ================================
67
68/// This utility provides a general deleter for factories that provide a
69/// `deleteObject` operation (e.g., `bslma::Allocator`, `bdlma::Pool`).
70///
71/// See @ref bslma_managedptr_factorydeleter
72template <class OBJECT_TYPE, class FACTORY>
74
75 // CLASS METHODS
76
77 /// Delete the specified `object` by invoking `deleteObject` on the
78 /// specified `factory`, casting `object` to `OBJECT_TYPE *` and `factory` to `FACTORY *`.
79 ///
80 /// \pre The behavior is undefined unless
81 /// `factory` points to an object of type `FACTORY`, and `object` points
82 /// to a complete object of type `OBJECT_TYPE` or `OBJECT_TYPE` has a
83 /// virtual destructor and `object` points to an object whose dynamic
84 /// type derives from 'OBJECT_TYPE.
85 static void deleter(void *object, void *factory);
86};
87
88// ============================================================================
89// INLINE DEFINITIONS
90// ============================================================================
91
92 // --------------------------------
93 // struct ManagedPtr_FactoryDeleter
94 // --------------------------------
95
96// CLASS METHODS
97template <class OBJECT_TYPE, class FACTORY>
98inline
100 void *factory)
101{
102 BSLS_ASSERT_SAFE(0 != object);
103 BSLS_ASSERT_SAFE(0 != factory);
104
105 static_cast<FACTORY *>(factory)->deleteObject(
106 static_cast<OBJECT_TYPE *>(object));
107}
108
109} // close package namespace
110
111
112#endif
113
114// ----------------------------------------------------------------------------
115// Copyright 2016 Bloomberg Finance L.P.
116//
117// Licensed under the Apache License, Version 2.0 (the "License");
118// you may not use this file except in compliance with the License.
119// You may obtain a copy of the License at
120//
121// http://www.apache.org/licenses/LICENSE-2.0
122//
123// Unless required by applicable law or agreed to in writing, software
124// distributed under the License is distributed on an "AS IS" BASIS,
125// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
126// See the License for the specific language governing permissions and
127// limitations under the License.
128// ----------------------------- END-OF-FILE ----------------------------------
129
130/** @} */
131/** @} */
132/** @} */
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition baljsn_encoder_testtypes.h:76
Definition bslma_managedptr_factorydeleter.h:73
static void deleter(void *object, void *factory)
Definition bslma_managedptr_factorydeleter.h:99