BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlar_arrayvtableutil.h
Go to the documentation of this file.
1/// @file bdlar_arrayvtableutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlar_arrayvtableutil.h -*-C++-*-
8#ifndef INCLUDED_BDLAR_ARRAYVTABLEUTIL
9#define INCLUDED_BDLAR_ARRAYVTABLEUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlar_arrayvtableutil bdlar_arrayvtableutil
15/// @brief Provide ...
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlar
19/// @{
20/// @addtogroup bdlar_arrayvtableutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlar_arrayvtableutil-purpose"> Purpose</a>
25/// * <a href="#bdlar_arrayvtableutil-classes"> Classes </a>
26/// * <a href="#bdlar_arrayvtableutil-description"> Description </a>
27///
28/// # Purpose {#bdlar_arrayvtableutil-purpose}
29/// Provide ...
30///
31/// # Classes {#bdlar_arrayvtableutil-classes}
32///
33/// - bdlar::ArrayVtableUtil: ...
34///
35/// # Description {#bdlar_arrayvtableutil-description}
36/// This component provides ...
37///
38/// @}
39/** @} */
40/** @} */
41
42/** @addtogroup bdl
43 * @{
44 */
45/** @addtogroup bdlar
46 * @{
47 */
48/** @addtogroup bdlar_arrayvtableutil
49 * @{
50 */
51
52#include <bdlar_arrayvtable.h>
53#include <bdlar_typecategory.h>
54
56#include <bdlat_typename.h>
58
59
60namespace bdlar {
61
62 // =====================
63 // class ArrayVtableUtil
64 // =====================
65
67 // PRIVATE CLASS METHODS
68
69 /// Invoke the specified `accessor` on the element of the specified `array`
70 /// at the specified `index`. Return the value from the invocation of `accessor`.
71 ///
72 /// \pre The behavior is undefined unless
73 /// `0 <= index < size(array)`.
74 template <class t_ARRAY>
75 static int accessElement(const void *array,
76 AccessorRef& accessor,
77 int index);
78
79 /// Return the element type category of the specified `t_ARRAY` type.
80 template <class t_ARRAY>
81 static bdlat_TypeCategory::Value elementCategory();
82
83 /// Invoke the specified `manipulator` on the element of the specified
84 /// `array` at the specified `index`. Return the value from the invocation of `manipulator`.
85 ///
86 /// \pre The behavior is undefined unless
87 /// `0 <= index < size(array)`.
88 template <class t_ARRAY>
89 static int manipulateElement(void *array,
90 ManipulatorRef& manipulator,
91 int index);
92
93 /// Reset the object pointed by the specified `object` to the default
94 /// value.
95 template <class t_ARRAY>
96 static void reset(void *object);
97
98 /// Set the size of the specified modifiable `array` to the specified
99 /// `newSize`. If `newSize > size(array)`, then `newSize - size(array)`
100 /// elements with default values are appended to `array`. If
101 /// `newSize < size(array)`, then the `size(array) - newSize` elements at the end of `array` are destroyed.
102 ///
103 /// \pre The behavior is undefined unless
104 /// `0 <= newSize`.
105 template <class t_ARRAY>
106 static void resize(void *array, int newSize);
107
108 /// Return the number of elements in the specified `array`.
109 template <class t_ARRAY>
110 static bsl::size_t size(const void *array);
111
112 /// Return the `bdlat_TypeName::xsdName` value for `object`.
113 template <class t_ARRAY>
114 static const char *xsdName(const void *object, int format);
115
116 public:
117 // TYPES
120
121 // CLASS METHODS
122
123 /// Construct and return a `ArrayConstVtable` object with a series of
124 /// function pointers that implement the "array" type category.
125 template <class t_ARRAY>
126 static const ArrayConstVtable *getConstVtable();
127
128 /// Construct and return a `ArrayVtable` object with a series of function
129 /// pointers that implement the "array" type category.
130 template <class t_ARRAY>
131 static const ArrayVtable *getVtable();
132};
133
134// ============================================================================
135// INLINE DEFINITIONS
136// ============================================================================
137
138 // ---------------------
139 // class ArrayVtableUtil
140 // ---------------------
141
142// PRIVATE CLASS METHODS
143template <class t_ARRAY>
144int ArrayVtableUtil::accessElement(const void *array,
145 AccessorRef& accessor,
146 int index)
147{
149 *static_cast<const t_ARRAY *>(array),
150 accessor,
151 index);
152}
153
154template <class t_ARRAY>
155bdlat_TypeCategory::Value ArrayVtableUtil::elementCategory()
156{
158 ElementType;
160}
161
162template <class t_ARRAY>
163int ArrayVtableUtil::manipulateElement(void *array,
164 ManipulatorRef& manipulator,
165 int index)
166{
168 static_cast<t_ARRAY *>(array),
169 manipulator,
170 index);
171}
172
173template <class t_ARRAY>
174void ArrayVtableUtil::reset(void *object)
175{
176 bdlat_ValueTypeFunctions::reset(static_cast<t_ARRAY *>(object));
177}
178
179template <class t_ARRAY>
180void ArrayVtableUtil::resize(void *array, int newSize)
181{
182 bdlat_ArrayFunctions::resize(static_cast<t_ARRAY *>(array), newSize);
183}
184
185template <class t_ARRAY>
186bsl::size_t ArrayVtableUtil::size(const void *array)
187{
188 return bdlat_ArrayFunctions::size(*static_cast<const t_ARRAY *>(array));
189}
190
191template <class t_ARRAY>
192const char *ArrayVtableUtil::xsdName(const void *object, int format)
193{
194 return bdlat_TypeName::xsdName(*static_cast<const t_ARRAY *>(object),
195 format);
196}
197
198// CLASS METHODS
199template <class t_ARRAY>
201{
202 static const ArrayConstVtable vtable = {
203 &elementCategory<t_ARRAY>,
204 &accessElement<t_ARRAY>,
205 &size<t_ARRAY>,
206 &xsdName<t_ARRAY>
207 };
208 return &vtable;
209}
210
211template <class t_ARRAY>
213{
214 static const ArrayVtable vtable = {
215 {
216 &elementCategory<t_ARRAY>,
217 &accessElement<t_ARRAY>,
218 &size<t_ARRAY>,
219 &xsdName<t_ARRAY>
220 },
221 &manipulateElement<t_ARRAY>,
222 &reset<t_ARRAY>,
223 &resize<t_ARRAY>
224 };
225 return &vtable;
226}
227
228} // close package namespace
229
230
231#endif
232
233// ----------------------------------------------------------------------------
234// Copyright 2024 Bloomberg Finance L.P.
235//
236// Licensed under the Apache License, Version 2.0 (the "License");
237// you may not use this file except in compliance with the License.
238// You may obtain a copy of the License at
239//
240// http://www.apache.org/licenses/LICENSE-2.0
241//
242// Unless required by applicable law or agreed to in writing, software
243// distributed under the License is distributed on an "AS IS" BASIS,
244// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
245// See the License for the specific language governing permissions and
246// limitations under the License.
247// ----------------------------- END-OF-FILE ----------------------------------
248
249/** @} */
250/** @} */
251/** @} */
Definition bdlar_accessorref.h:65
Definition bdlar_arrayvtableutil.h:66
ArrayVtable VtableType
Definition bdlar_arrayvtableutil.h:118
static const ArrayVtable * getVtable()
Definition bdlar_arrayvtableutil.h:212
static const ArrayConstVtable * getConstVtable()
Definition bdlar_arrayvtableutil.h:200
ArrayConstVtable ConstVtableType
Definition bdlar_arrayvtableutil.h:119
Definition bdlar_manipulatorref.h:65
static const char * xsdName(const TYPE &object, int format)
Definition bdlat_typename.h:1047
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlar_accessorref.h:59
int manipulateElement(TYPE *array, MANIPULATOR &manipulator, int index)
void resize(TYPE *array, int newSize)
bsl::size_t size(const TYPE &array)
Return the number of elements in the specified array.
int accessElement(const TYPE &array, ACCESSOR &accessor, int index)
void reset(TYPE *object)
Reset the value of the specified object to its default value.
Definition bdlar_arrayvtable.h:71
Definition bdlar_arrayvtable.h:96
static const BSLS_KEYWORD_CONSTEXPR bdlat_TypeCategory::Value e_SELECTION
Definition bdlar_typecategory.h:156
Definition bdlat_arrayfunctions.h:756
Value
Definition bdlat_typecategory.h:1046