BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlar_nullablevalueref.h
Go to the documentation of this file.
1/// @file bdlar_nullablevalueref.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlar_nullablevalueref.h -*-C++-*-
8#ifndef INCLUDED_BDLAR_NULLABLEVALUEREF
9#define INCLUDED_BDLAR_NULLABLEVALUEREF
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlar_nullablevalueref bdlar_nullablevalueref
15/// @brief Provide ...
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlar
19/// @{
20/// @addtogroup bdlar_nullablevalueref
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlar_nullablevalueref-purpose"> Purpose</a>
25/// * <a href="#bdlar_nullablevalueref-classes"> Classes </a>
26/// * <a href="#bdlar_nullablevalueref-description"> Description </a>
27///
28/// # Purpose {#bdlar_nullablevalueref-purpose}
29/// Provide ...
30///
31/// # Classes {#bdlar_nullablevalueref-classes}
32///
33/// - bdlar::NullableValueRef: ...
34/// - bdlar::NullableValueConstRef: ...
35///
36/// # Description {#bdlar_nullablevalueref-description}
37/// This component provides ...
38///
39/// @}
40/** @} */
41/** @} */
42
43/** @addtogroup bdl
44 * @{
45 */
46/** @addtogroup bdlar
47 * @{
48 */
49/** @addtogroup bdlar_nullablevalueref
50 * @{
51 */
52
53#include <bdlar_nullablevaluevtable.h>
55#include <bdlar_typecategory.h>
56
58
59#include <bslmf_enableif.h>
60
61
62namespace bdlar {
63
64// Forward
65class AnyRef;
66class AnyConstRef;
67
68 // ======================
69 // class NullableValueRef
70 // ======================
71
73 // DATA
74 void *d_object_p;
75 const NullableValueVtable *d_vtable_p;
76
77 public:
78 // TYPES
80
81 // CREATORS
82
83 /// Create `NullableValueRef` object that type erases the supplied
84 /// `nullable` object.
85 template <class t_NULLABLE>
86 explicit NullableValueRef(t_NULLABLE& nullable,
87 typename bsl::enable_if<
89
90 /// Create `NullableValueRef` object.
91 /// \pre The behaviour is undefined unless
92 /// `objectAddress` and `vtable` point to the valid objects.
94
95 // MANIPULATORS
96
97 /// Assign to the referred object the default value for the contained type.
98 void makeValue() const;
99
100 /// Invoke the specified `manipulator` on the referred non-null value. The
101 /// supplied `manipulator` must be a callable type that can be called as if
102 /// it had the following signature:
103 /// @code
104 /// int manipulator(VALUE *refOrValue);
105 /// @endcode
106 /// Return the value from the invocation of `manipulator`.
107 ///
108 /// \pre The behavior is undefined if the referred object is null.
109 template <class t_MANIPULATOR>
110 int manipulateValue(t_MANIPULATOR& manipulator) const;
111
112 /// Reset the referred object to the default value.
113 void reset() const;
114
115 // ACCESSORS
116
117 /// Invoke the specified `accessor` on the referred non-null value. The
118 /// supplied `accessor` must be a callable type that can be called as if it
119 /// had the following signature:
120 /// @code
121 /// int accessor(const VALUE& refOrValue);
122 /// @endcode
123 /// Return the value from the invocation of `accessor`.
124 ///
125 /// \pre The behavior is undefined if the referred object is null.
126 template <class t_ACCESSOR>
127 int accessValue(t_ACCESSOR& accessor) const;
128
129 /// Return a pointer to the vtable.
130 const NullableValueVtable *vtable() const;
131
132 /// Return `true` if the referred object contains a null value, and `false`
133 /// otherwise.
134 bool isNull() const;
135
136 /// Return a pointer to the wrapped object.
137 void *objectAddress() const;
138
139 /// Return the value type category.
141};
142
143 // ===========================
144 // class NullableValueConstRef
145 // ===========================
146
148 // DATA
149 const void *d_object_p;
150 const NullableValueConstVtable *d_vtable_p;
151
152 public:
153 // TYPES
155
156 // CREATORS
157
158 /// Create `NullableValueConstRef` object that type erases the supplied
159 /// `nullable` object.
160 template <class t_NULLABLE>
161 explicit NullableValueConstRef(
162 const t_NULLABLE& nullable,
163 typename bsl::enable_if<
164 IsNullable<t_NULLABLE>::value>::type * = 0);
165
166 /// Create `NullableValueConstRef` object.
167 ///
168 /// \pre The behaviour is undefined unless `objectAddress` and `vtable` point to the valid objects.
171
172 /// Create `NullableValueConstRef` object that wraps the same object as the
173 /// specified `object`.
174 NullableValueConstRef(const NullableValueRef& object); // IMPLICIT
175
176 // ACCESSORS
177
178 /// Invoke the specified `accessor` on the referred non-null value. The
179 /// supplied `accessor` must be a callable type that can be called as if it
180 /// had the following signature:
181 /// @code
182 /// int accessor(const VALUE& refOrValue);
183 /// @endcode
184 /// Return the value from the invocation of `accessor`.
185 ///
186 /// \pre The behavior is undefined if the referred object is null.
187 template <class t_ACCESSOR>
188 int accessValue(t_ACCESSOR& accessor) const;
189
190 /// Return a pointer to the vtable.
191 const NullableValueConstVtable *vtable() const;
192
193 /// Return `true` if the referred object contains a null value, and `false`
194 /// otherwise.
195 bool isNull() const;
196
197 /// Return a pointer to the wrapped object.
198 const void *objectAddress() const;
199
200 /// Return the value type category.
202
203 /// Return the `bdlat_TypeName::xsdName` value for the underlying object.
204 const char *xsdName(int format) const;
205};
206
207// ============================================================================
208// INLINE DEFINITIONS
209// ============================================================================
210
211 // ----------------------
212 // class NullableValueRef
213 // ----------------------
214
215// CREATORS
216template <class t_NULLABLE>
217inline
219 typename bsl::enable_if<
221: d_object_p(&nullable)
222, d_vtable_p(NullableValueVtableUtil::getVtable<t_NULLABLE>())
223{
224}
225
226inline
228 const NullableValueVtable *vtable)
229: d_object_p(objectAddress)
230, d_vtable_p(vtable)
231{
232}
233
234// MANIPULATORS
235inline
237{
238 d_vtable_p->d_makeValue_fp(d_object_p);
239}
240
241template <class t_MANIPULATOR>
242inline
243int NullableValueRef::manipulateValue(t_MANIPULATOR& manipulator) const
244{
246 manipulatorRef(manipulator);
247 return d_vtable_p->d_manipulateValue_fp(d_object_p, manipulatorRef);
248}
249
250inline
252{
253 return d_vtable_p->d_reset_fp(d_object_p);
254}
255
256// ACCESSORS
257template <class t_ACCESSOR>
258inline
259int NullableValueRef::accessValue(t_ACCESSOR& accessor) const
260{
262 accessorRef(accessor);
263 return d_vtable_p->d_const.d_accessValue_fp(d_object_p, accessorRef);
264}
265
266inline
268{
269 return d_vtable_p;
270}
271
272inline
274{
275 return d_vtable_p->d_const.d_isNull_fp(d_object_p);
276}
277
278inline
280{
281 return d_object_p;
282}
283
284inline
289
290// FREE FUNCTIONS
291// Customization-point functions (`bdlat_NullableValueFunctions`)
292
293inline
295{
296 ref->makeValue();
297}
298
299template <class t_MANIPULATOR>
300inline
302 t_MANIPULATOR& manipulator)
303{
304 return ref->manipulateValue(manipulator);
305}
306
307template <class t_ACCESSOR>
308inline
310 t_ACCESSOR& accessor)
311{
312 return ref.accessValue(accessor);
313}
314
315inline
317{
318 return ref.isNull();
319}
320
321inline
323{
324 ref->reset();
325}
326
327 // ---------------------------
328 // class NullableValueConstRef
329 // ---------------------------
330
331// CREATORS
332template <class t_NULLABLE>
333inline
335 const t_NULLABLE& nullable,
336 typename bsl::enable_if<
338: d_object_p(&nullable)
339, d_vtable_p(NullableValueVtableUtil::getConstVtable<t_NULLABLE>())
340{
341}
342
343inline
345 const void *objectAddress,
346 const NullableValueConstVtable *vtable)
347: d_object_p(objectAddress)
348, d_vtable_p(vtable)
349{
350}
351
352inline
354: d_object_p(object.objectAddress())
355, d_vtable_p(&object.vtable()->d_const)
356{
357}
358
359// ACCESSORS
360template <class t_ACCESSOR>
361inline
362int NullableValueConstRef::accessValue(t_ACCESSOR& accessor) const
363{
365 accessorRef(accessor);
366 return d_vtable_p->d_accessValue_fp(d_object_p, accessorRef);
367}
368
369inline
371{
372 return d_vtable_p;
373}
374
375inline
377{
378 return d_vtable_p->d_isNull_fp(d_object_p);
379}
380
381inline
383{
384 return d_object_p;
385}
386
387inline
392
393inline
394const char *NullableValueConstRef::xsdName(int format) const
395{
396 return d_vtable_p->d_xsdName_fp(d_object_p, format);
397}
398
399// FREE FUNCTIONS
400// Customization-point functions (`bdlat_NullableValueFunctions`)
401
402template <class t_ACCESSOR>
403inline
405 t_ACCESSOR& accessor)
406{
407 return ref.accessValue(accessor);
408}
409
410inline
412{
413 return ref.isNull();
414}
415
416inline
418 int format)
419{
420 return ref.xsdName(format);
421}
422
423} // close package namespace
424
426
427template <>
428struct IsNullableValue<bdlar::NullableValueRef> : bsl::true_type {
429};
430
431template <>
432struct IsNullableValue<bdlar::NullableValueConstRef> : bsl::true_type {
433};
434
435template <>
436struct ValueType<bdlar::NullableValueRef> {
438};
439
440template <>
441struct ValueType<bdlar::NullableValueConstRef> {
443};
444
445} // close namespace bdlat_NullableValueFunctions
446
447
448#endif
449
450// ----------------------------------------------------------------------------
451// Copyright 2024 Bloomberg Finance L.P.
452//
453// Licensed under the Apache License, Version 2.0 (the "License");
454// you may not use this file except in compliance with the License.
455// You may obtain a copy of the License at
456//
457// http://www.apache.org/licenses/LICENSE-2.0
458//
459// Unless required by applicable law or agreed to in writing, software
460// distributed under the License is distributed on an "AS IS" BASIS,
461// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
462// See the License for the specific language governing permissions and
463// limitations under the License.
464// ----------------------------- END-OF-FILE ----------------------------------
465
466/** @} */
467/** @} */
468/** @} */
Definition bdlar_anyref.h:247
Definition bdlar_anyref.h:85
Definition bdlar_dynamictyperef.h:128
Definition bdlar_nullablevalueref.h:147
bdlat_TypeCategory::Value valueCategory() const
Return the value type category.
Definition bdlar_nullablevalueref.h:388
const NullableValueConstVtable * vtable() const
Return a pointer to the vtable.
Definition bdlar_nullablevalueref.h:370
int accessValue(t_ACCESSOR &accessor) const
Definition bdlar_nullablevalueref.h:362
bdlat_TypeCategory::NullableValue CategoryTag
Definition bdlar_nullablevalueref.h:154
NullableValueConstRef(const t_NULLABLE &nullable, typename bsl::enable_if< IsNullable< t_NULLABLE >::value >::type *=0)
Definition bdlar_nullablevalueref.h:334
bool isNull() const
Definition bdlar_nullablevalueref.h:376
const void * objectAddress() const
Return a pointer to the wrapped object.
Definition bdlar_nullablevalueref.h:382
const char * xsdName(int format) const
Return the bdlat_TypeName::xsdName value for the underlying object.
Definition bdlar_nullablevalueref.h:394
Definition bdlar_nullablevalueref.h:72
NullableValueRef(t_NULLABLE &nullable, typename bsl::enable_if< IsNullable< t_NULLABLE >::value >::type *=0)
Definition bdlar_nullablevalueref.h:218
int accessValue(t_ACCESSOR &accessor) const
Definition bdlar_nullablevalueref.h:259
bool isNull() const
Definition bdlar_nullablevalueref.h:273
int manipulateValue(t_MANIPULATOR &manipulator) const
Definition bdlar_nullablevalueref.h:243
void * objectAddress() const
Return a pointer to the wrapped object.
Definition bdlar_nullablevalueref.h:279
bdlat_TypeCategory::Value valueCategory() const
Return the value type category.
Definition bdlar_nullablevalueref.h:285
void reset() const
Reset the referred object to the default value.
Definition bdlar_nullablevalueref.h:251
void makeValue() const
Assign to the referred object the default value for the contained type.
Definition bdlar_nullablevalueref.h:236
bdlat_TypeCategory::NullableValue CategoryTag
Definition bdlar_nullablevalueref.h:79
const NullableValueVtable * vtable() const
Return a pointer to the vtable.
Definition bdlar_nullablevalueref.h:267
Definition bdlar_nullablevaluevtableutil.h:66
#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 bdlat_nullableValueIsNull(const NullableValueRef &ref)
Definition bdlar_nullablevalueref.h:316
int bdlat_nullableValueManipulateValue(NullableValueRef *ref, t_MANIPULATOR &manipulator)
Definition bdlar_nullablevalueref.h:301
const char * bdlat_TypeName_xsdName(const AnyConstRef &ref, int format)
Definition bdlar_anyref.h:716
void bdlat_valueTypeReset(AnyRef *ref)
Definition bdlar_anyref.h:550
int bdlat_nullableValueAccessValue(const NullableValueRef &ref, t_ACCESSOR &accessor)
Definition bdlar_nullablevalueref.h:309
void bdlat_nullableValueMakeValue(NullableValueRef *ref)
Definition bdlar_nullablevalueref.h:294
Definition bdlar_nullablevalueref.h:425
Definition bdlar_typecategory.h:114
Definition bdlar_nullablevaluevtable.h:71
AccessValue * d_accessValue_fp
Definition bdlar_nullablevaluevtable.h:80
IsNull * d_isNull_fp
Definition bdlar_nullablevaluevtable.h:81
XsdName * d_xsdName_fp
Definition bdlar_nullablevaluevtable.h:82
ValueCategory * d_valueCategory_fp
Definition bdlar_nullablevaluevtable.h:79
Definition bdlar_nullablevaluevtable.h:94
MakeValue * d_makeValue_fp
Definition bdlar_nullablevaluevtable.h:103
Reset * d_reset_fp
Definition bdlar_nullablevaluevtable.h:104
NullableValueConstVtable d_const
Definition bdlar_nullablevaluevtable.h:101
ManipulateValue * d_manipulateValue_fp
Definition bdlar_nullablevaluevtable.h:102
Definition bdlat_nullablevaluefunctions.h:649
bdlar::AnyConstRef Type
Definition bdlar_nullablevalueref.h:442
bdlar::AnyRef Type
Definition bdlar_nullablevalueref.h:437
Definition bdlat_nullablevaluefunctions.h:656
Definition bdlat_typecategory.h:1041
Value
Definition bdlat_typecategory.h:1046
Definition bslmf_enableif.h:530