BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlbb_simpleblobbufferfactory.h
Go to the documentation of this file.
1/// @file bdlbb_simpleblobbufferfactory.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlbb_simpleblobbufferfactory.h -*-C++-*-
8#ifndef INCLUDED_BDLBB_SIMPLEBLOBBUFFERFACTORY
9#define INCLUDED_BDLBB_SIMPLEBLOBBUFFERFACTORY
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlbb_simpleblobbufferfactory bdlbb_simpleblobbufferfactory
15/// @brief Provide a simple implementation of `bdlbb::BlobBufferFactory`.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlbb
19/// @{
20/// @addtogroup bdlbb_simpleblobbufferfactory
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlbb_simpleblobbufferfactory-purpose"> Purpose</a>
25/// * <a href="#bdlbb_simpleblobbufferfactory-classes"> Classes </a>
26/// * <a href="#bdlbb_simpleblobbufferfactory-description"> Description </a>
27/// * <a href="#bdlbb_simpleblobbufferfactory-usage"> Usage </a>
28/// * <a href="#bdlbb_simpleblobbufferfactory-example-1-simple-blob-buffer-factory"> Example 1: Simple Blob Buffer Factory </a>
29///
30/// # Purpose {#bdlbb_simpleblobbufferfactory-purpose}
31/// Provide a simple implementation of `bdlbb::BlobBufferFactory`.
32///
33/// # Classes {#bdlbb_simpleblobbufferfactory-classes}
34///
35/// - bdlbb::SimpleBlobBufferFactory: a simple `bdlbb::BlobBufferFactory`
36///
37/// # Description {#bdlbb_simpleblobbufferfactory-description}
38/// This component provides a mechanism,
39/// `bdlbb::SimpleBlobBufferFactory`, that implements the
40/// `bdlbb::BlobBufferFactory` protocol and creates `bdlbb::BlobBuffer` objects
41/// of a fixed sized specified at the time the factory is constructed. The blob
42/// buffers created by this factory refer the a (shared) buffer allocated by the
43/// allocator supplied at construction, or the default allocator if no allocator
44/// is explicitly supplied.
45///
46/// ## Usage {#bdlbb_simpleblobbufferfactory-usage}
47///
48///
49/// In this section we show intended usage of this component.
50///
51/// ### Example 1: Simple Blob Buffer Factory {#bdlbb_simpleblobbufferfactory-example-1-simple-blob-buffer-factory}
52///
53///
54/// Suppose we want to make a blob that can be grown via calls to `setLength`,
55/// meaning that it must have a factory, and suppose you want all the memory for
56/// the blob buffers created for the factory to be allocated directly from a
57/// certain test allocator for test purposes. We use a
58/// `SimpleBlobBufferFactory`.
59///
60/// First, we create our allocator:
61/// @code
62/// bslma::TestAllocator testAllocator;
63/// @endcode
64/// Then, we create our factor using that allocator:
65/// @code
66/// bdlbb::SimpleBlobBufferFactory factory(1024, &testAllocator);
67/// assert(factory.bufferSize() == 1024);
68/// @endcode
69/// Next, we create our blob using that factory:
70/// @code
71/// bdlbb::Blob blob(&factory);
72/// @endcode
73/// Next, we set the length big enough to require 20 blob buffers:
74/// @code
75/// blob.setLength(1024 * 20);
76/// @endcode
77/// Then, we verify that the memory came from `testAllocator`. Note that since
78/// the blob buffers contain shared pointers, additional memory other than the
79/// writable areas of the blob buffers is allocated:
80/// @code
81/// assert(1024 * 20 < testAllocator.numBytesInUse());
82/// @endcode
83/// Now, we examine the state of the blob:
84/// @code
85/// assert(20 == blob.numDataBuffers());
86/// assert(20 == blob.numBuffers());
87/// assert(1024 * 20 == blob.length());
88/// @endcode
89/// Finally, we examine the blob buffers:
90/// @code
91/// for (int ii = 0; ii < blob.numDataBuffers(); ++ii) {
92/// assert(1024 == blob.buffer(ii).size());
93/// }
94/// @endcode
95/// @}
96/** @} */
97/** @} */
98
99/** @addtogroup bdl
100 * @{
101 */
102/** @addtogroup bdlbb
103 * @{
104 */
105/** @addtogroup bdlbb_simpleblobbufferfactory
106 * @{
107 */
108
109#include <bdlscm_version.h>
110
111#include <bdlbb_blob.h>
112
113#include <bslma_allocator.h>
117
118#include <bsls_keyword.h>
119
120#include <bsl_cstddef.h>
121
122
123namespace bdlbb {
124
125 // =============================
126 // class SimpleBlobBufferFactory
127 // =============================
128
129/// This `class` declares an implementation of `BlobBufferFactory` where
130/// each segment loaded to a `BlobBuffer` is created with a separate calls
131/// to the allocator specified at construction, or the default allocator is
132/// no allocator was specified.
133///
134/// See @ref bdlbb_simpleblobbufferfactory
136
137 // PRIVATE DATA
138 int d_size;
139 bslma::Allocator *d_allocator_p;
140
141 public:
146
147 private:
148 // NOT IMPLEMENTED
151
152 public:
153 // CREATORS
154
155 /// Create a `SimpleBlobBufferFactory` object that will create blob
156 /// buffers of specified length `bufferSize`. Optionally specify a
157 /// `basicAllocator` used to supply memory. If `basicAllocator` is 0,
158 /// the currently installed default allocator is used.
159 explicit
161 bslma::Allocator *basicAllocator = 0);
162
163 /// Destroy this `SimpleBlobBufferFactory` object.
165
166 // MANIPULATORS
167
168 /// Allocate a blob buffer from this blob buffer factory, and load it
169 /// into the specified `buffer`.
171
172 /// Set the buffer size for future buffers created by this factory to
173 /// the specified `bufferSize`.
175
176 // ACCESSORS
177
178 /// Return the current size with which this factory will allocate
179 /// buffers.
180 int bufferSize() const;
181};
182
183} // close package namespace
184
185
186#endif
187
188// ----------------------------------------------------------------------------
189// Copyright 2019 Bloomberg Finance L.P.
190//
191// Licensed under the Apache License, Version 2.0 (the "License");
192// you may not use this file except in compliance with the License.
193// You may obtain a copy of the License at
194//
195// http://www.apache.org/licenses/LICENSE-2.0
196//
197// Unless required by applicable law or agreed to in writing, software
198// distributed under the License is distributed on an "AS IS" BASIS,
199// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200// See the License for the specific language governing permissions and
201// limitations under the License.
202// ----------------------------- END-OF-FILE ----------------------------------
203
204/** @} */
205/** @} */
206/** @} */
Definition bdlbb_blob.h:616
Definition bdlbb_blob.h:455
Definition bdlbb_simpleblobbufferfactory.h:135
~SimpleBlobBufferFactory() BSLS_KEYWORD_OVERRIDE
Destroy this SimpleBlobBufferFactory object.
SimpleBlobBufferFactory(int bufferSize, bslma::Allocator *basicAllocator=0)
BSLMF_NESTED_TRAIT_DECLARATION(SimpleBlobBufferFactory, bslmf::IsBitwiseMoveable)
BSLMF_NESTED_TRAIT_DECLARATION(SimpleBlobBufferFactory, bslma::UsesBslmaAllocator)
void allocate(bdlbb::BlobBuffer *buffer) BSLS_KEYWORD_OVERRIDE
void setBufferSize(int bufferSize)
Definition bslma_allocator.h:457
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:653
Definition bdlbb_blob.h:442
Definition bslma_usesbslmaallocator.h:343
Definition bslmf_isbitwisemoveable.h:718