BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlar_choicevtableutil.h
Go to the documentation of this file.
1/// @file bdlar_choicevtableutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlar_choicevtableutil.h -*-C++-*-
8#ifndef INCLUDED_BDLAR_CHOICEVTABLEUTIL
9#define INCLUDED_BDLAR_CHOICEVTABLEUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlar_choicevtableutil bdlar_choicevtableutil
15/// @brief Provide ...
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlar
19/// @{
20/// @addtogroup bdlar_choicevtableutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlar_choicevtableutil-purpose"> Purpose</a>
25/// * <a href="#bdlar_choicevtableutil-classes"> Classes </a>
26/// * <a href="#bdlar_choicevtableutil-description"> Description </a>
27///
28/// # Purpose {#bdlar_choicevtableutil-purpose}
29/// Provide ...
30///
31/// # Classes {#bdlar_choicevtableutil-classes}
32///
33/// - bdlar::ChoiceVtableUtil: ...
34///
35/// # Description {#bdlar_choicevtableutil-description}
36/// This component provides ...
37///
38/// @}
39/** @} */
40/** @} */
41
42/** @addtogroup bdl
43 * @{
44 */
45/** @addtogroup bdlar
46 * @{
47 */
48/** @addtogroup bdlar_choicevtableutil
49 * @{
50 */
51
52#include <bdlar_choicevtable.h>
53
55#include <bdlat_typename.h>
57
58
59namespace bdlar {
60
61 // ======================
62 // class ChoiceVtableUtil
63 // ======================
64
66 // PRIVATE CLASS METHODS
67
68 /// Invoke the specified `accessor` on the (non-modifiable) selection,
69 /// supplying `accessor` with the corresponding selection information
70 /// structure. Return the value returned from the invocation of `accessor`.
71 ///
72 /// \pre The behavior is undefined unless
73 /// `selectionId(object) != -1`.
74 template <class t_CHOICE>
75 static int accessSelection(const void *object,
76 AccessorWithInfoRef& accessor);
77
78 /// Return true if the specified `object` has a selection with the
79 /// specified `selectionId`, and `false` otherwise.
80 template <class t_CHOICE>
81 static bool hasSelectionId(const void *object, int selectionId);
82
83 /// Return true if the specified `object` has a selection with the
84 /// specified `selectionName` of the specified `selectionNameLength`, and
85 /// `false` otherwise.
86 template <class t_CHOICE>
87 static bool hasSelectionName(const void *object,
88 const char *selectionName,
89 int selectionNameLength);
90
91 /// Set the value of the specified `object` to be the default for the
92 /// selection indicated by the specified `selectionId`. Return 0 on
93 /// success, and non-zero value otherwise (i.e., the selection is not
94 /// found).
95 template <class t_CHOICE>
96 static int makeSelectionById(void *object, int selectionId);
97
98 /// Set the value of the specified `object` to be the default for the
99 /// selection indicated by the specified `selectionName` of the specified
100 /// `selectionNameLength`. Return 0 on success, and non-zero value
101 /// otherwise (i.e., the selection is not found).
102 template <class t_CHOICE>
103 static int makeSelectionByName(void *object,
104 const char *selectionName,
105 int selectionNameLength);
106
107 /// Invoke the specified `manipulator` on the address of the (modifiable)
108 /// selection, supplying `manipulator` with the corresponding selection
109 /// information structure. Return the value returned from the invocation of `manipulator`.
110 ///
111 /// \pre The behavior is undefined unless
112 /// `selectionId(object) != -1`.
113 template <class t_CHOICE>
114 static int manipulateSelection(void *object,
115 ManipulatorWithInfoRef& manipulator);
116
117 /// Reset the object pointed by the specified `object` to the default
118 /// value.
119 template <class t_CHOICE>
120 static void reset(void *object);
121
122 /// Return the id of the current selection if the selection is defined, and
123 /// -1 otherwise.
124 template <class t_CHOICE>
125 static int selectionId(const void *object);
126
127 /// Return the `bdlat_TypeName::xsdName` value for `object`.
128 template <class t_CHOICE>
129 static const char *xsdName(const void *object, int format);
130
131 public:
132 // TYPES
135
136 // CLASS METHODS
137
138 /// Construct and return a `ChoiceConstVtable` object with a series of
139 /// function pointers that implement the "choice" type category.
140 template <class t_CHOICE>
141 static const ChoiceConstVtable *getConstVtable();
142
143 /// Construct and return a `ChoiceVtable` object with a series of function
144 /// pointers that implement the "choice" type category.
145 template <class t_CHOICE>
146 static const ChoiceVtable *getVtable();
147};
148
149// ============================================================================
150// INLINE DEFINITIONS
151// ============================================================================
152
153 // ----------------------
154 // class ChoiceVtableUtil
155 // ----------------------
156
157// PRIVATE CLASS METHODS
158template <class t_CHOICE>
159int ChoiceVtableUtil::accessSelection(const void *object,
160 AccessorWithInfoRef& accessor)
161{
163 *static_cast<const t_CHOICE *>(object),
164 accessor);
165}
166
167template <class t_CHOICE>
168bool ChoiceVtableUtil::hasSelectionId(const void *object, int selectionId)
169{
171 *static_cast<const t_CHOICE *>(object),
172 selectionId);
173}
174
175template <class t_CHOICE>
176bool ChoiceVtableUtil::hasSelectionName(const void *object,
177 const char *selectionName,
178 int selectionNameLength)
179{
181 *static_cast<const t_CHOICE *>(object),
182 selectionName,
183 selectionNameLength);
184}
185
186template <class t_CHOICE>
187int ChoiceVtableUtil::makeSelectionById(void *object, int selectionId)
188{
190 static_cast<t_CHOICE *>(object),
191 selectionId);
192}
193
194template <class t_CHOICE>
195int ChoiceVtableUtil::makeSelectionByName(void *object,
196 const char *selectionName,
197 int selectionNameLength)
198{
200 static_cast<t_CHOICE *>(object),
201 selectionName,
202 selectionNameLength);
203}
204
205template <class t_CHOICE>
206int ChoiceVtableUtil::manipulateSelection(void *object,
207 ManipulatorWithInfoRef& manipulator)
208{
210 static_cast<t_CHOICE *>(object),
211 manipulator);
212}
213
214template <class t_CHOICE>
215void ChoiceVtableUtil::reset(void *object)
216{
217 bdlat_ValueTypeFunctions::reset(static_cast<t_CHOICE *>(object));
218}
219
220template <class t_CHOICE>
221int ChoiceVtableUtil::selectionId(const void *object)
222{
224 *static_cast<const t_CHOICE *>(object));
225}
226
227template <class t_CHOICE>
228const char *ChoiceVtableUtil::xsdName(const void *object, int format)
229{
230 return bdlat_TypeName::xsdName(*static_cast<const t_CHOICE *>(object),
231 format);
232}
233
234// CLASS METHODS
235template <class t_CHOICE>
237{
238 static const ChoiceConstVtable vtable = {
239 &selectionId<t_CHOICE>,
240 &hasSelectionId<t_CHOICE>,
241 &hasSelectionName<t_CHOICE>,
242 &accessSelection<t_CHOICE>,
243 &xsdName<t_CHOICE>
244 };
245 return &vtable;
246}
247
248template <class t_CHOICE>
250{
251 static const ChoiceVtable vtable = {
252 {
253 &selectionId<t_CHOICE>,
254 &hasSelectionId<t_CHOICE>,
255 &hasSelectionName<t_CHOICE>,
256 &accessSelection<t_CHOICE>,
257 &xsdName<t_CHOICE>
258 },
259 &makeSelectionById<t_CHOICE>,
260 &makeSelectionByName<t_CHOICE>,
261 &manipulateSelection<t_CHOICE>,
262 &reset<t_CHOICE>
263 };
264 return &vtable;
265}
266
267} // close package namespace
268
269
270#endif
271
272// ----------------------------------------------------------------------------
273// Copyright 2024 Bloomberg Finance L.P.
274//
275// Licensed under the Apache License, Version 2.0 (the "License");
276// you may not use this file except in compliance with the License.
277// You may obtain a copy of the License at
278//
279// http://www.apache.org/licenses/LICENSE-2.0
280//
281// Unless required by applicable law or agreed to in writing, software
282// distributed under the License is distributed on an "AS IS" BASIS,
283// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
284// See the License for the specific language governing permissions and
285// limitations under the License.
286// ----------------------------- END-OF-FILE ----------------------------------
287
288/** @} */
289/** @} */
290/** @} */
Definition bdlar_accessorref.h:109
Definition bdlar_choicevtableutil.h:65
static const ChoiceConstVtable * getConstVtable()
Definition bdlar_choicevtableutil.h:236
ChoiceVtable VtableType
Definition bdlar_choicevtableutil.h:133
ChoiceConstVtable ConstVtableType
Definition bdlar_choicevtableutil.h:134
static const ChoiceVtable * getVtable()
Definition bdlar_choicevtableutil.h:249
Definition bdlar_manipulatorref.h:109
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
bool hasSelection(const TYPE &object, const char *selectionName, int selectionNameLength)
int manipulateSelection(TYPE *object, MANIPULATOR &manipulator)
int makeSelection(TYPE *object, int selectionId)
int accessSelection(const TYPE &object, ACCESSOR &accessor)
int selectionId(const TYPE &object)
void reset(TYPE *object)
Reset the value of the specified object to its default value.
Definition bdlar_choicevtable.h:69
Definition bdlar_choicevtable.h:97