BDE 4.14.0 Production release
Loading...
Searching...
No Matches
s_baltst_mychoice.h
Go to the documentation of this file.
1/// @file s_baltst_mychoice.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// s_baltst_mychoice.h *DO NOT EDIT* @generated -*-C++-*-
8#ifndef INCLUDED_S_BALTST_MYCHOICE
9#define INCLUDED_S_BALTST_MYCHOICE
10
11#include <bsls_ident.h>
12BSLS_IDENT_RCSID(s_baltst_mychoice_h, "$Id$ $CSID$")
14
15/// @defgroup s_baltst_mychoice s_baltst_mychoice
16/// @brief Provide value-semantic attribute classes
17/// @addtogroup Standalones
18/// @{
19/// @addtogroup s_baltst
20/// @{
21/// @addtogroup s_baltst_mychoice
22/// @{
23///
24/// <h1> Outline </h1>
25/// * <a href="#s_baltst_mychoice-purpose"> Purpose</a>
26///
27/// # Purpose {#s_baltst_mychoice-purpose}
28/// Provide value-semantic attribute classes
29/// @}
30/** @} */
31/** @} */
32
33/** @addtogroup Standalones
34 * @{
35 */
36/** @addtogroup s_baltst
37 * @{
38 */
39/** @addtogroup s_baltst_mychoice
40 * @{
41 */
42
43#include <bslalg_typetraits.h>
44
45#include <bdlat_attributeinfo.h>
46
47#include <bdlat_selectioninfo.h>
48
49#include <bdlat_typetraits.h>
50
51#include <bsls_objectbuffer.h>
52
53#include <bslma_default.h>
54
55#include <bsls_assert.h>
56
57#include <bsl_string.h>
58
59#include <bsl_iosfwd.h>
60#include <bsl_limits.h>
61
62
63
64namespace bslma { class Allocator; }
65
66namespace s_baltst { class MyChoice; }
67namespace s_baltst {
68
69 // ==============
70 // class MyChoice
71 // ==============
72
73class MyChoice {
74
75 // INSTANCE DATA
76 union {
79 };
80
81 int d_selectionId;
82 bslma::Allocator *d_allocator_p;
83
84 public:
85 // TYPES
86
87 enum {
91 };
92
93 enum {
95 };
96
97 enum {
100 };
101
102 // CONSTANTS
103 static const char CLASS_NAME[];
104
106
107 // CLASS METHODS
108
109 /// Return selection information for the selection indicated by the
110 /// specified `id` if the selection exists, and 0 otherwise.
112
113 /// Return selection information for the selection indicated by the
114 /// specified `name` of the specified `nameLength` if the selection
115 /// exists, and 0 otherwise.
117 const char *name,
118 int nameLength);
119
120 // CREATORS
121
122 /// Create an object of type `MyChoice` having the default value. Use
123 /// the optionally specified `basicAllocator` to supply memory. If
124 /// `basicAllocator` is 0, the currently installed default allocator is
125 /// used.
126 explicit MyChoice(bslma::Allocator *basicAllocator = 0);
127
128 /// Create an object of type `MyChoice` having the value of the
129 /// specified `original` object. Use the optionally specified
130 /// `basicAllocator` to supply memory. If `basicAllocator` is 0, the
131 /// currently installed default allocator is used.
132 MyChoice(const MyChoice& original,
133 bslma::Allocator *basicAllocator = 0);
134
135#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) \
136 && defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT)
137 /// Create an object of type `MyChoice` having the value of the
138 /// specified `original` object. After performing this action, the
139 /// `original` object will be left in a valid, but unspecified state.
140 MyChoice(MyChoice&& original) noexcept;
141
142 /// Create an object of type `MyChoice` having the value of the
143 /// specified `original` object. After performing this action, the
144 /// `original` object will be left in a valid, but unspecified state.
145 /// Use the optionally specified `basicAllocator` to supply memory. If
146 /// `basicAllocator` is 0, the currently installed default allocator is
147 /// used.
148 MyChoice(MyChoice&& original,
149 bslma::Allocator *basicAllocator);
150#endif
151
152 /// Destroy this object.
153 ~MyChoice();
154
155 // MANIPULATORS
156
157 /// Assign to this object the value of the specified `rhs` object.
159
160#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) \
161 && defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT)
162 /// Assign to this object the value of the specified `rhs` object.
163 /// After performing this action, the `rhs` object will be left in a
164 /// valid, but unspecified state.
166#endif
167
168 /// Reset this object to the default value (i.e., its value upon default
169 /// construction).
170 void reset();
171
172 /// Set the value of this object to be the default for the selection
173 /// indicated by the specified `selectionId`. Return 0 on success, and
174 /// non-zero value otherwise (i.e., the selection is not found).
176
177 /// Set the value of this object to be the default for the selection
178 /// indicated by the specified `name` of the specified `nameLength`.
179 /// Return 0 on success, and non-zero value otherwise (i.e., the
180 /// selection is not found).
181 int makeSelection(const char *name, int nameLength);
182
183 /// Set the value of this object to be a "Selection1" value. Optionally
184 /// specify the `value` of the "Selection1". If `value` is not
185 /// specified, the default "Selection1" value is used.
187 int& makeSelection1(int value);
188
191#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) \
192 && defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT)
194#endif
195 // Set the value of this object to be a "Selection2" value. Optionally
196 // specify the 'value' of the "Selection2". If 'value' is not
197 // specified, the default "Selection2" value is used.
198
199 /// Invoke the specified `manipulator` on the address of the modifiable
200 /// selection, supplying `manipulator` with the corresponding selection
201 /// information structure. Return the value returned from the
202 /// invocation of `manipulator` if this object has a defined selection,
203 /// and -1 otherwise.
204 template<class MANIPULATOR>
205 int manipulateSelection(MANIPULATOR& manipulator);
206
207 /// Return a reference to the modifiable "Selection1" selection of this
208 /// object if "Selection1" is the current selection. The behavior is
209 /// undefined unless "Selection1" is the selection of this object.
210 int& selection1();
211
212 /// Return a reference to the modifiable "Selection2" selection of this
213 /// object if "Selection2" is the current selection. The behavior is
214 /// undefined unless "Selection2" is the selection of this object.
216
217 // ACCESSORS
218
219 /// Format this object to the specified output `stream` at the
220 /// optionally specified indentation `level` and return a reference to
221 /// the modifiable `stream`. If `level` is specified, optionally
222 /// specify `spacesPerLevel`, the number of spaces per indentation level
223 /// for this and all of its nested objects. Each line is indented by
224 /// the absolute value of `level * spacesPerLevel`. If `level` is
225 /// negative, suppress indentation of the first line. If
226 /// `spacesPerLevel` is negative, suppress line breaks and format the
227 /// entire output on one line. If `stream` is initially invalid, this
228 /// operation has no effect. Note that a trailing newline is provided
229 /// in multiline mode only.
230 bsl::ostream& print(bsl::ostream& stream,
231 int level = 0,
232 int spacesPerLevel = 4) const;
233
234 /// Return the id of the current selection if the selection is defined,
235 /// and -1 otherwise.
236 int selectionId() const;
237
238 /// Invoke the specified `accessor` on the non-modifiable selection,
239 /// supplying `accessor` with the corresponding selection information
240 /// structure. Return the value returned from the invocation of
241 /// `accessor` if this object has a defined selection, and -1 otherwise.
242 template<class ACCESSOR>
243 int accessSelection(ACCESSOR& accessor) const;
244
245 /// Return a reference to the non-modifiable "Selection1" selection of
246 /// this object if "Selection1" is the current selection. The behavior
247 /// is undefined unless "Selection1" is the selection of this object.
248 const int& selection1() const;
249
250 /// Return a reference to the non-modifiable "Selection2" selection of
251 /// this object if "Selection2" is the current selection. The behavior
252 /// is undefined unless "Selection2" is the selection of this object.
253 const bsl::string& selection2() const;
254
255 /// Return `true` if the value of this object is a "Selection1" value,
256 /// and return `false` otherwise.
257 bool isSelection1Value() const;
258
259 /// Return `true` if the value of this object is a "Selection2" value,
260 /// and return `false` otherwise.
261 bool isSelection2Value() const;
262
263 /// Return `true` if the value of this object is undefined, and `false`
264 /// otherwise.
265 bool isUndefinedValue() const;
266
267 /// Return the symbolic name of the current selection of this object.
268 const char *selectionName() const;
269};
270
271// FREE OPERATORS
272
273/// Return `true` if the specified `lhs` and `rhs` objects have the same
274/// value, and `false` otherwise. Two `MyChoice` objects have the same
275/// value if either the selections in both objects have the same ids and
276/// the same values, or both selections are undefined.
277inline
278bool operator==(const MyChoice& lhs, const MyChoice& rhs);
279
280/// Return `true` if the specified `lhs` and `rhs` objects do not have the
281/// same values, as determined by `operator==`, and `false` otherwise.
282inline
283bool operator!=(const MyChoice& lhs, const MyChoice& rhs);
284
285/// Format the specified `rhs` to the specified output `stream` and
286/// return a reference to the modifiable `stream`.
287inline
288bsl::ostream& operator<<(bsl::ostream& stream, const MyChoice& rhs);
289
290} // close package namespace
291
292// TRAITS
293
295
296// ============================================================================
297// INLINE FUNCTION DEFINITIONS
298// ============================================================================
299
300namespace s_baltst {
301
302 // --------------
303 // class MyChoice
304 // --------------
305
306// CLASS METHODS
307// CREATORS
308inline
310: d_selectionId(SELECTION_ID_UNDEFINED)
311, d_allocator_p(bslma::Default::allocator(basicAllocator))
312{
313}
314
315inline
317{
318 reset();
319}
320
321// MANIPULATORS
322template <class MANIPULATOR>
323int MyChoice::manipulateSelection(MANIPULATOR& manipulator)
324{
325 switch (d_selectionId) {
327 return manipulator(&d_selection1.object(),
330 return manipulator(&d_selection2.object(),
332 default:
334 return -1;
335 }
336}
337
338inline
340{
341 BSLS_ASSERT(SELECTION_ID_SELECTION1 == d_selectionId);
342 return d_selection1.object();
343}
344
345inline
347{
348 BSLS_ASSERT(SELECTION_ID_SELECTION2 == d_selectionId);
349 return d_selection2.object();
350}
351
352// ACCESSORS
353inline
355{
356 return d_selectionId;
357}
358
359template <class ACCESSOR>
360int MyChoice::accessSelection(ACCESSOR& accessor) const
361{
362 switch (d_selectionId) {
364 return accessor(d_selection1.object(),
367 return accessor(d_selection2.object(),
369 default:
370 BSLS_ASSERT(SELECTION_ID_UNDEFINED == d_selectionId);
371 return -1;
372 }
373}
374
375inline
376const int& MyChoice::selection1() const
377{
378 BSLS_ASSERT(SELECTION_ID_SELECTION1 == d_selectionId);
379 return d_selection1.object();
380}
381
382inline
384{
385 BSLS_ASSERT(SELECTION_ID_SELECTION2 == d_selectionId);
386 return d_selection2.object();
387}
388
389inline
391{
392 return SELECTION_ID_SELECTION1 == d_selectionId;
393}
394
395inline
397{
398 return SELECTION_ID_SELECTION2 == d_selectionId;
399}
400
401inline
403{
404 return SELECTION_ID_UNDEFINED == d_selectionId;
405}
406} // close package namespace
407
408// FREE FUNCTIONS
409
410inline
412 const s_baltst::MyChoice& lhs,
413 const s_baltst::MyChoice& rhs)
414{
415 typedef s_baltst::MyChoice Class;
416 if (lhs.selectionId() == rhs.selectionId()) {
417 switch (rhs.selectionId()) {
418 case Class::SELECTION_ID_SELECTION1:
419 return lhs.selection1() == rhs.selection1();
420 case Class::SELECTION_ID_SELECTION2:
421 return lhs.selection2() == rhs.selection2();
422 default:
423 BSLS_ASSERT(Class::SELECTION_ID_UNDEFINED == rhs.selectionId());
424 return true;
425 }
426 }
427 else {
428 return false;
429 }
430}
431
432inline
434 const s_baltst::MyChoice& lhs,
435 const s_baltst::MyChoice& rhs)
436{
437 return !(lhs == rhs);
438}
439
440inline
441bsl::ostream& s_baltst::operator<<(
442 bsl::ostream& stream,
443 const s_baltst::MyChoice& rhs)
444{
445 return rhs.print(stream, 0, -1);
446}
447
448
449#endif
450
451// GENERATED BY @BLP_BAS_CODEGEN_VERSION@
452// USING bas_codegen.pl s_baltst_mychoice.xsd --mode msg --includedir . --msgComponent mychoice --noRecurse --noExternalization --noHashSupport --noAggregateConversion
453// ----------------------------------------------------------------------------
454// NOTICE:
455// Copyright 2022 Bloomberg Finance L.P. All rights reserved.
456// Property of Bloomberg Finance L.P. (BFLP)
457// This software is made available solely pursuant to the
458// terms of a BFLP license agreement which governs its use.
459// ------------------------------- END-OF-FILE --------------------------------
460
461/** @} */
462/** @} */
463/** @} */
Definition bslstl_string.h:1281
Definition bslma_allocator.h:457
Definition s_baltst_mychoice.h:73
static const bdlat_SelectionInfo SELECTION_INFO_ARRAY[]
Definition s_baltst_mychoice.h:105
bool isSelection1Value() const
Definition s_baltst_mychoice.h:390
const char * selectionName() const
Return the symbolic name of the current selection of this object.
@ SELECTION_ID_SELECTION1
Definition s_baltst_mychoice.h:89
@ SELECTION_ID_SELECTION2
Definition s_baltst_mychoice.h:90
@ SELECTION_ID_UNDEFINED
Definition s_baltst_mychoice.h:88
int makeSelection(int selectionId)
int makeSelection(const char *name, int nameLength)
bsls::ObjectBuffer< int > d_selection1
Definition s_baltst_mychoice.h:77
int manipulateSelection(MANIPULATOR &manipulator)
Definition s_baltst_mychoice.h:323
MyChoice & operator=(const MyChoice &rhs)
Assign to this object the value of the specified rhs object.
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
bsl::string & selection2()
Definition s_baltst_mychoice.h:346
bool isUndefinedValue() const
Definition s_baltst_mychoice.h:402
int accessSelection(ACCESSOR &accessor) const
Definition s_baltst_mychoice.h:360
@ SELECTION_INDEX_SELECTION1
Definition s_baltst_mychoice.h:98
@ SELECTION_INDEX_SELECTION2
Definition s_baltst_mychoice.h:99
static const bdlat_SelectionInfo * lookupSelectionInfo(int id)
static const bdlat_SelectionInfo * lookupSelectionInfo(const char *name, int nameLength)
bsl::string & makeSelection2(const bsl::string &value)
int & selection1()
Definition s_baltst_mychoice.h:339
bsl::string & makeSelection2()
@ NUM_SELECTIONS
Definition s_baltst_mychoice.h:94
~MyChoice()
Destroy this object.
Definition s_baltst_mychoice.h:316
static const char CLASS_NAME[]
Definition s_baltst_mychoice.h:103
int & makeSelection1(int value)
MyChoice(bslma::Allocator *basicAllocator=0)
Definition s_baltst_mychoice.h:309
MyChoice(const MyChoice &original, bslma::Allocator *basicAllocator=0)
int selectionId() const
Definition s_baltst_mychoice.h:354
bsls::ObjectBuffer< bsl::string > d_selection2
Definition s_baltst_mychoice.h:78
bool isSelection2Value() const
Definition s_baltst_mychoice.h:396
#define BDLAT_DECL_CHOICE_WITH_ALLOCATOR_BITWISEMOVEABLE_TRAITS(ClassName)
Definition bdlat_typetraits.h:249
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT_RCSID(tag, str)
Definition bsls_ident.h:260
#define BSLS_IDENT_PRAGMA_ONCE
Definition bsls_ident.h:310
Definition balxml_encoderoptions.h:68
Definition s_baltst_address.h:66
bool operator!=(const Address &lhs, const Address &rhs)
bool operator==(const Address &lhs, const Address &rhs)
bsl::ostream & operator<<(bsl::ostream &stream, const Address &rhs)
Definition bdlat_selectioninfo.h:136
TYPE & object()
Definition bsls_objectbuffer.h:351