BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslalg_dequeimputil.h
Go to the documentation of this file.
1/// @file bslalg_dequeimputil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslalg_dequeimputil.h -*-C++-*-
8#ifndef INCLUDED_BSLALG_DEQUEIMPUTIL
9#define INCLUDED_BSLALG_DEQUEIMPUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslalg_dequeimputil bslalg_dequeimputil
15/// @brief Provide basic parameters and primitive data structures for deques.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslalg
19/// @{
20/// @addtogroup bslalg_dequeimputil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslalg_dequeimputil-purpose"> Purpose</a>
25/// * <a href="#bslalg_dequeimputil-classes"> Classes </a>
26/// * <a href="#bslalg_dequeimputil-description"> Description </a>
27/// * <a href="#bslalg_dequeimputil-usage"> Usage </a>
28///
29/// # Purpose {#bslalg_dequeimputil-purpose}
30/// Provide basic parameters and primitive data structures for deques.
31///
32/// # Classes {#bslalg_dequeimputil-classes}
33///
34/// - bslalg::DequeImpUtil: deque parameters and primitive data structures
35///
36/// @see bslalg_dequeprimitives, bslalg_arrayprimitives
37///
38/// # Description {#bslalg_dequeimputil-description}
39/// This component provides primitive data structures for
40/// implementing a deque knowing only its value type and the number of objects
41/// in a block. Conceptually, a deque is an array of blocks pointers, each
42/// block capable of containing a fixed number of objects. An element in the
43/// deque is identified by an iterator that consists of a pointer to the block
44/// pointer array, and a pointer to a value. A deque implementation is
45/// parameterized by the `VALUE_TYPE` and a `BLOCK_LENGTH` (fixed number of
46/// objects in a block). `bslalg::DequeImpUtil` provides a namespace for the
47/// following types and constants:
48/// @code
49/// Type Short description
50/// ---- -----------------
51/// ValueType An alias for the templatized 'VALUE_TYPE'
52/// Block An array (of length 'BLOCK_LENGTH') of 'ValueType'
53/// BlockPtr An alias for a pointer to a block
54///
55/// Constant Short description
56/// -------- -----------------
57/// BLOCK_BYTES Number of bytes in a block
58/// BLOCK_ARRAY_PADDING Number of empty blocks to keep at both ends of the
59/// block array pointer (one on each side).
60/// @endcode
61///
62/// The picture is as follows:
63/// @code
64/// +-----+-----+-----+-----+-----+-----+-----+-----+
65/// | * | * | * | * | * | * | * | * | (BlockPtr array)
66/// +-----+-----+--|--+--|--+--|--+--|--+-----+-----+
67/// | | | | Block
68/// | | | | +---+---+---+---+---+---+---+---+
69/// | | | `--| V | W | X | Y | Z | | | |
70/// | | | +---+---+---+---+---+---+---+---+
71/// | | | Block
72/// | | | +---+---+---+---+---+---+---+---+
73/// | | `--| N | O | P | Q | R | S | T | U |
74/// | | +---+---+---+---+---+---+---+---+
75/// | | Block
76/// | | +---+---+---+---+---+---+---+---+
77/// | `--| F | G | H | I | J | K | L | M |
78/// | +---+---+---+---+---+---+---+---+
79/// | Block
80/// | +---+---+---+---+---+---+---+---+
81/// `--| | | | A | B | C | D | E |
82/// +---+---+---+---+---+---+---+---+
83/// @endcode
84/// Depicted above is a deque consisting of an array of eight block pointers,
85/// only four actually used to point to blocks of eight elements. In the first
86/// block, the first three elements are uninitialized, and the twenty six
87/// elements follow in sequence across the different blocks. The value of the
88/// corresponding deque would be `[ A, B, C, ... X, Y, Z ]`, its logical length
89/// 26, and its capacity would be 19 (the minimum number of prepend/append to
90/// force a reallocation of the block pointer array).
91///
92/// ## Usage {#bslalg_dequeimputil-usage}
93///
94///
95/// This component is for use by the `bslalg` package. Other clients should use
96/// the STL deque (in header `<deque>`).
97/// @}
98/** @} */
99/** @} */
100
101/** @addtogroup bsl
102 * @{
103 */
104/** @addtogroup bslalg
105 * @{
106 */
107/** @addtogroup bslalg_dequeimputil
108 * @{
109 */
110
111#include <bslscm_version.h>
112
113
114
115namespace bslalg {
116
117 // ==============
118 // class DequeImp
119 // ==============
120
121/// This `struct`, parameterized by the `VALUE_TYPE` and a `BLOCK_LENGTH`,
122/// provides the various parameters of the deque implementation.
123template <class VALUE_TYPE, int BLOCK_LENGTH>
125
126 // PUBLIC CONSTANTS
127
128 /// Actual number of bytes in a block.
129 enum { BLOCK_BYTES = BLOCK_LENGTH * sizeof(VALUE_TYPE) };
130
131 /// Minimum number of (allocated) empty blocks to keep at both ends of
132 /// the block array pointer (one on each side of the deque).
134
135 // PUBLIC TYPES
136
137 /// `ValueType` is an alias for the `VALUE_TYPE` provided as first
138 /// template parameter to this class.
139 typedef VALUE_TYPE ValueType;
140
141 /// A block of one or more data objects. A deque will be organized as a
142 /// sequence of blocks.
143 struct Block {
144
145 VALUE_TYPE d_data[BLOCK_LENGTH];
146 };
147
148 /// Pointer to a block. A deque will own an array of those.
149 typedef Block *BlockPtr;
150};
151
152} // close package namespace
153
154#ifndef BDE_OPENSOURCE_PUBLICATION // BACKWARD_COMPATIBILITY
155// ============================================================================
156// BACKWARD COMPATIBILITY
157// ============================================================================
158
159#ifdef bslalg_DequeImpUtil
160#undef bslalg_DequeImpUtil
161#endif
162/// This alias is defined for backward compatibility.
163#define bslalg_DequeImpUtil bslalg::DequeImpUtil
164#endif // BDE_OPENSOURCE_PUBLICATION -- BACKWARD_COMPATIBILITY
165
166
167
168#endif
169
170// ----------------------------------------------------------------------------
171// Copyright 2013 Bloomberg Finance L.P.
172//
173// Licensed under the Apache License, Version 2.0 (the "License");
174// you may not use this file except in compliance with the License.
175// You may obtain a copy of the License at
176//
177// http://www.apache.org/licenses/LICENSE-2.0
178//
179// Unless required by applicable law or agreed to in writing, software
180// distributed under the License is distributed on an "AS IS" BASIS,
181// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
182// See the License for the specific language governing permissions and
183// limitations under the License.
184// ----------------------------- END-OF-FILE ----------------------------------
185
186/** @} */
187/** @} */
188/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlc_flathashmap.h:1805
Definition bslalg_dequeimputil.h:143
VALUE_TYPE d_data[BLOCK_LENGTH]
Definition bslalg_dequeimputil.h:145
Definition bslalg_dequeimputil.h:124
@ BLOCK_BYTES
Definition bslalg_dequeimputil.h:129
VALUE_TYPE ValueType
Definition bslalg_dequeimputil.h:139
Block * BlockPtr
Pointer to a block. A deque will own an array of those.
Definition bslalg_dequeimputil.h:149
@ BLOCK_ARRAY_PADDING
Definition bslalg_dequeimputil.h:133