BDE 4.39.x Production Release
Loading...
Searching...
No Matches
s_baltst_address.h
Go to the documentation of this file.
1/// @file s_baltst_address.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// s_baltst_address.h *DO NOT EDIT* @generated -*-C++-*-
8#ifndef INCLUDED_S_BALTST_ADDRESS
9#define INCLUDED_S_BALTST_ADDRESS
10
11#include <bsls_ident.h>
12BSLS_IDENT_RCSID(s_baltst_address_h, "$Id$ $CSID$")
14
15/// @defgroup s_baltst_address s_baltst_address
16/// @brief Provide value-semantic attribute classes
17/// @addtogroup Standalones
18/// @{
19/// @addtogroup s_baltst
20/// @{
21/// @addtogroup s_baltst_address
22/// @{
23///
24/// <h1> Outline </h1>
25/// * <a href="#s_baltst_address-purpose"> Purpose</a>
26///
27/// # Purpose {#s_baltst_address-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_address
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 Address; }
67namespace s_baltst {
68
69 // =============
70 // class Address
71 // =============
72
73class Address {
74
75 // INSTANCE DATA
76 bsl::string d_street;
77 bsl::string d_city;
78 bsl::string d_state;
79
80 public:
81 // TYPES
82 enum {
86 };
87
88 enum {
90 };
91
92 enum {
96 };
97
98 // CONSTANTS
99 static const char CLASS_NAME[];
100
102
103 public:
104 // CLASS METHODS
105
106 /// Return attribute information for the attribute indicated by the
107 /// specified `id` if the attribute exists, and 0 otherwise.
109
110 /// Return attribute information for the attribute indicated by the
111 /// specified `name` of the specified `nameLength` if the attribute
112 /// exists, and 0 otherwise.
114 const char *name,
115 int nameLength);
116
117 // CREATORS
118
119 /// Create an object of type `Address` having the default value. Use
120 /// the optionally specified `basicAllocator` to supply memory. If
121 /// `basicAllocator` is 0, the currently installed default allocator is
122 /// used.
123 explicit Address(bslma::Allocator *basicAllocator = 0);
124
125 /// Create an object of type `Address` having the value of the specified
126 /// `original` object. Use the optionally specified `basicAllocator` to
127 /// supply memory. If `basicAllocator` is 0, the currently installed
128 /// default allocator is used.
129 Address(const Address& original,
130 bslma::Allocator *basicAllocator = 0);
131
132#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) \
133 && defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT)
134 /// Create an object of type `Address` having the value of the specified
135 /// `original` object. After performing this action, the `original`
136 /// object will be left in a valid, but unspecified state.
137 Address(Address&& original) noexcept;
138
139 /// Create an object of type `Address` having the value of the specified
140 /// `original` object. After performing this action, the `original`
141 /// object will be left in a valid, but unspecified state. Use the
142 /// optionally specified `basicAllocator` to supply memory. If
143 /// `basicAllocator` is 0, the currently installed default allocator is
144 /// used.
145 Address(Address&& original,
146 bslma::Allocator *basicAllocator);
147#endif
148
149 /// Destroy this object.
151
152 // MANIPULATORS
153
154 /// Assign to this object the value of the specified `rhs` object.
156
157#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) \
158 && defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT)
159 /// Assign to this object the value of the specified `rhs` object.
160 /// After performing this action, the `rhs` object will be left in a
161 /// valid, but unspecified state.
162 Address& operator=(Address&& rhs);
163#endif
164
165 /// Reset this object to the default value (i.e., its value upon
166 /// default construction).
167 void reset();
168
169 /// Invoke the specified `manipulator` sequentially on the address of
170 /// each (modifiable) attribute of this object, supplying `manipulator`
171 /// with the corresponding attribute information structure until such
172 /// invocation returns a non-zero value. Return the value from the
173 /// last invocation of `manipulator` (i.e., the invocation that
174 /// terminated the sequence).
175 template <typename t_MANIPULATOR>
176 int manipulateAttributes(t_MANIPULATOR& manipulator);
177
178 /// Invoke the specified `manipulator` on the address of
179 /// the (modifiable) attribute indicated by the specified `id`,
180 /// supplying `manipulator` with the corresponding attribute
181 /// information structure. Return the value returned from the
182 /// invocation of `manipulator` if `id` identifies an attribute of this
183 /// class, and -1 otherwise.
184 template <typename t_MANIPULATOR>
185 int manipulateAttribute(t_MANIPULATOR& manipulator, int id);
186
187 /// Invoke the specified `manipulator` on the address of
188 /// the (modifiable) attribute indicated by the specified `name` of the
189 /// specified `nameLength`, supplying `manipulator` with the
190 /// corresponding attribute information structure. Return the value
191 /// returned from the invocation of `manipulator` if `name` identifies
192 /// an attribute of this class, and -1 otherwise.
193 template <typename t_MANIPULATOR>
194 int manipulateAttribute(t_MANIPULATOR& manipulator,
195 const char *name,
196 int nameLength);
197
198 /// Return a reference to the modifiable "Street" attribute of this
199 /// object.
201
202 /// Return a reference to the modifiable "City" attribute of this
203 /// object.
204 bsl::string& city();
205
206 /// Return a reference to the modifiable "State" attribute of this
207 /// object.
209
210 // ACCESSORS
211
212 /// Format this object to the specified output `stream` at the
213 /// optionally specified indentation `level` and return a reference to
214 /// the modifiable `stream`. If `level` is specified, optionally
215 /// specify `spacesPerLevel`, the number of spaces per indentation level
216 /// for this and all of its nested objects. Each line is indented by
217 /// the absolute value of `level * spacesPerLevel`. If `level` is
218 /// negative, suppress indentation of the first line. If
219 /// `spacesPerLevel` is negative, suppress line breaks and format the
220 /// entire output on one line. If `stream` is initially invalid, this operation has no effect.
221 ///
222 /// \note Note that a trailing newline is provided
223 /// in multiline mode only.
224 bsl::ostream& print(bsl::ostream& stream,
225 int level = 0,
226 int spacesPerLevel = 4) const;
227
228 /// Invoke the specified `accessor` sequentially on each
229 /// (non-modifiable) attribute of this object, supplying `accessor`
230 /// with the corresponding attribute information structure until such
231 /// invocation returns a non-zero value. Return the value from the
232 /// last invocation of `accessor` (i.e., the invocation that terminated
233 /// the sequence).
234 template <typename t_ACCESSOR>
235 int accessAttributes(t_ACCESSOR& accessor) const;
236
237 /// Invoke the specified `accessor` on the (non-modifiable) attribute
238 /// of this object indicated by the specified `id`, supplying `accessor`
239 /// with the corresponding attribute information structure. Return the
240 /// value returned from the invocation of `accessor` if `id` identifies
241 /// an attribute of this class, and -1 otherwise.
242 template <typename t_ACCESSOR>
243 int accessAttribute(t_ACCESSOR& accessor, int id) const;
244
245 /// Invoke the specified `accessor` on the (non-modifiable) attribute
246 /// of this object indicated by the specified `name` of the specified
247 /// `nameLength`, supplying `accessor` with the corresponding attribute
248 /// information structure. Return the value returned from the
249 /// invocation of `accessor` if `name` identifies an attribute of this
250 /// class, and -1 otherwise.
251 template <typename t_ACCESSOR>
252 int accessAttribute(t_ACCESSOR& accessor,
253 const char *name,
254 int nameLength) const;
255
256 /// Return a reference offering non-modifiable access to the "Street"
257 /// attribute of this object.
258 const bsl::string& street() const;
259
260 /// Return a reference offering non-modifiable access to the "City"
261 /// attribute of this object.
262 const bsl::string& city() const;
263
264 /// Return a reference offering non-modifiable access to the "State"
265 /// attribute of this object.
266 const bsl::string& state() const;
267
268 // HIDDEN FRIENDS
269
270 /// Return `true` if the specified `lhs` and `rhs` attribute objects
271 /// have the same value, and `false` otherwise. Two attribute objects
272 /// have the same value if each respective attribute has the same value.
273 friend bool operator==(const Address& lhs, const Address& rhs)
274 {
275 return lhs.street() == rhs.street() &&
276 lhs.city() == rhs.city() &&
277 lhs.state() == rhs.state();
278 }
279
280 /// Returns `!(lhs == rhs)`
281 friend bool operator!=(const Address& lhs, const Address& rhs)
282 {
283 return !(lhs == rhs);
284 }
285
286 /// Format the specified `rhs` to the specified output `stream` and
287 /// return a reference to the modifiable `stream`.
288 friend bsl::ostream& operator<<(bsl::ostream& stream, const Address& rhs)
289 {
290 return rhs.print(stream, 0, -1);
291 }
292};
293
294} // close package namespace
295
296// TRAITS
297
299template <>
301
302// ============================================================================
303// INLINE DEFINITIONS
304// ============================================================================
305
306namespace s_baltst {
307
308 // -------------
309 // class Address
310 // -------------
311
312// CLASS METHODS
313// MANIPULATORS
314template <typename t_MANIPULATOR>
315int Address::manipulateAttributes(t_MANIPULATOR& manipulator)
316{
317 int ret;
318
319 ret = manipulator(&d_street, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STREET]);
320 if (ret) {
321 return ret;
322 }
323
324 ret = manipulator(&d_city, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_CITY]);
325 if (ret) {
326 return ret;
327 }
328
329 ret = manipulator(&d_state, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STATE]);
330 if (ret) {
331 return ret;
332 }
333
334 return 0;
335}
336
337template <typename t_MANIPULATOR>
338int Address::manipulateAttribute(t_MANIPULATOR& manipulator, int id)
339{
340 enum { NOT_FOUND = -1 };
341
342 switch (id) {
343 case ATTRIBUTE_ID_STREET: {
344 return manipulator(&d_street, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STREET]);
345 }
346 case ATTRIBUTE_ID_CITY: {
347 return manipulator(&d_city, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_CITY]);
348 }
349 case ATTRIBUTE_ID_STATE: {
350 return manipulator(&d_state, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STATE]);
351 }
352 default:
353 return NOT_FOUND;
354 }
355}
356
357template <typename t_MANIPULATOR>
359 t_MANIPULATOR& manipulator,
360 const char *name,
361 int nameLength)
362{
363 enum { NOT_FOUND = -1 };
364
365 const bdlat_AttributeInfo *attributeInfo =
366 lookupAttributeInfo(name, nameLength);
367 if (0 == attributeInfo) {
368 return NOT_FOUND;
369 }
370
371 return manipulateAttribute(manipulator, attributeInfo->d_id);
372}
373
374inline
376{
377 return d_street;
378}
379
380inline
382{
383 return d_city;
384}
385
386inline
388{
389 return d_state;
390}
391
392// ACCESSORS
393template <typename t_ACCESSOR>
394int Address::accessAttributes(t_ACCESSOR& accessor) const
395{
396 int ret;
397
398 ret = accessor(d_street, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STREET]);
399 if (ret) {
400 return ret;
401 }
402
403 ret = accessor(d_city, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_CITY]);
404 if (ret) {
405 return ret;
406 }
407
408 ret = accessor(d_state, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STATE]);
409 if (ret) {
410 return ret;
411 }
412
413 return 0;
414}
415
416template <typename t_ACCESSOR>
417int Address::accessAttribute(t_ACCESSOR& accessor, int id) const
418{
419 enum { NOT_FOUND = -1 };
420
421 switch (id) {
422 case ATTRIBUTE_ID_STREET: {
423 return accessor(d_street, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STREET]);
424 }
425 case ATTRIBUTE_ID_CITY: {
426 return accessor(d_city, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_CITY]);
427 }
428 case ATTRIBUTE_ID_STATE: {
429 return accessor(d_state, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STATE]);
430 }
431 default:
432 return NOT_FOUND;
433 }
434}
435
436template <typename t_ACCESSOR>
438 t_ACCESSOR& accessor,
439 const char *name,
440 int nameLength) const
441{
442 enum { NOT_FOUND = -1 };
443
444 const bdlat_AttributeInfo *attributeInfo =
445 lookupAttributeInfo(name, nameLength);
446 if (0 == attributeInfo) {
447 return NOT_FOUND;
448 }
449
450 return accessAttribute(accessor, attributeInfo->d_id);
451}
452
453inline
455{
456 return d_street;
457}
458
459inline
461{
462 return d_city;
463}
464
465inline
467{
468 return d_state;
469}
470
471} // close package namespace
472
473// FREE FUNCTIONS
474
475
476#endif
477
478// GENERATED BY BLP_BAS_CODEGEN_2025.08.21
479// USING bas_codegen.pl s_baltst_address.xsd --mode msg --includedir . --msgComponent address --noRecurse --noExternalization --noHashSupport --noAggregateConversion
480// ----------------------------------------------------------------------------
481// NOTICE:
482// Copyright 2025 Bloomberg Finance L.P. All rights reserved.
483// Property of Bloomberg Finance L.P. (BFLP)
484// This software is made available solely pursuant to the
485// terms of a BFLP license agreement which governs its use.
486// ------------------------------- END-OF-FILE --------------------------------
487
488/** @} */
489/** @} */
490/** @} */
Definition bslstl_string.h:1252
Definition bslma_allocator.h:545
Definition s_baltst_address.h:73
bsl::string & city()
Definition s_baltst_address.h:381
static const bdlat_AttributeInfo * lookupAttributeInfo(int id)
@ NUM_ATTRIBUTES
Definition s_baltst_address.h:89
@ ATTRIBUTE_ID_STATE
Definition s_baltst_address.h:85
@ ATTRIBUTE_ID_STREET
Definition s_baltst_address.h:83
@ ATTRIBUTE_ID_CITY
Definition s_baltst_address.h:84
~Address()
Destroy this object.
int accessAttributes(t_ACCESSOR &accessor) const
Definition s_baltst_address.h:394
bsl::string & state()
Definition s_baltst_address.h:387
static const bdlat_AttributeInfo ATTRIBUTE_INFO_ARRAY[]
Definition s_baltst_address.h:101
static const bdlat_AttributeInfo * lookupAttributeInfo(const char *name, int nameLength)
static const char CLASS_NAME[]
Definition s_baltst_address.h:99
bsl::string & street()
Definition s_baltst_address.h:375
int accessAttribute(t_ACCESSOR &accessor, int id) const
Definition s_baltst_address.h:417
Address(const Address &original, bslma::Allocator *basicAllocator=0)
friend bool operator!=(const Address &lhs, const Address &rhs)
Returns !(lhs == rhs)
Definition s_baltst_address.h:281
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
friend bsl::ostream & operator<<(bsl::ostream &stream, const Address &rhs)
Definition s_baltst_address.h:288
int manipulateAttributes(t_MANIPULATOR &manipulator)
Definition s_baltst_address.h:315
Address & operator=(const Address &rhs)
Assign to this object the value of the specified rhs object.
Address(bslma::Allocator *basicAllocator=0)
friend bool operator==(const Address &lhs, const Address &rhs)
Definition s_baltst_address.h:273
int manipulateAttribute(t_MANIPULATOR &manipulator, int id)
Definition s_baltst_address.h:338
@ ATTRIBUTE_INDEX_CITY
Definition s_baltst_address.h:94
@ ATTRIBUTE_INDEX_STATE
Definition s_baltst_address.h:95
@ ATTRIBUTE_INDEX_STREET
Definition s_baltst_address.h:93
#define BDLAT_DECL_SEQUENCE_WITH_ALLOCATOR_BITWISEMOVEABLE_TRAITS(ClassName)
Definition bdlat_typetraits.h:301
#define BSLS_IDENT_RCSID(tag, str)
BSLS_IDENT_RCSID() - insert ident str (specific to platform/compiler)
Definition bsls_ident.h:244
#define BSLS_IDENT_PRAGMA_ONCE
BSLS_IDENT_PRAGMA_ONCE - macro to avoid multiple inclusion
Definition bsls_ident.h:263
Definition baljsn_encoder_testtypes.h:76
Definition s_baltst_address.h:66
Definition bdlat_attributeinfo.h:139
int d_id
Definition bdlat_attributeinfo.h:142
Definition bdlat_typetraits.h:146