BDE 4.14.0 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`).
70template <class OBJECT_TYPE, class FACTORY>
72
73 // CLASS METHODS
74
75 /// Delete the specified `object` by invoking `deleteObject` on the
76 /// specified `factory`, casting `object` to `OBJECT_TYPE *` and
77 /// `factory` to `FACTORY *`. The behavior is undefined unless
78 /// `factory` points to an object of type `FACTORY`, and `object` points
79 /// to a complete object of type `OBJECT_TYPE` or `OBJECT_TYPE` has a
80 /// virtual destructor and `object` points to an object whose dynamic
81 /// type derives from 'OBJECT_TYPE.
82 static void deleter(void *object, void *factory);
83};
84
85// ============================================================================
86// INLINE DEFINITIONS
87// ============================================================================
88
89 // --------------------------------
90 // struct ManagedPtr_FactoryDeleter
91 // --------------------------------
92
93// CLASS METHODS
94template <class OBJECT_TYPE, class FACTORY>
95inline
97 void *factory)
98{
99 BSLS_ASSERT_SAFE(0 != object);
100 BSLS_ASSERT_SAFE(0 != factory);
101
102 static_cast<FACTORY *>(factory)->deleteObject(
103 static_cast<OBJECT_TYPE *>(object));
104}
105
106} // close package namespace
107
108
109#endif
110
111// ----------------------------------------------------------------------------
112// Copyright 2016 Bloomberg Finance L.P.
113//
114// Licensed under the Apache License, Version 2.0 (the "License");
115// you may not use this file except in compliance with the License.
116// You may obtain a copy of the License at
117//
118// http://www.apache.org/licenses/LICENSE-2.0
119//
120// Unless required by applicable law or agreed to in writing, software
121// distributed under the License is distributed on an "AS IS" BASIS,
122// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123// See the License for the specific language governing permissions and
124// limitations under the License.
125// ----------------------------- END-OF-FILE ----------------------------------
126
127/** @} */
128/** @} */
129/** @} */
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition balxml_encoderoptions.h:68
Definition bslma_managedptr_factorydeleter.h:71
static void deleter(void *object, void *factory)
Definition bslma_managedptr_factorydeleter.h:96