BDE 4.14.0 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<class MANIPULATOR>
176 int manipulateAttributes(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<class MANIPULATOR>
185 int manipulateAttribute(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<class MANIPULATOR>
194 int manipulateAttribute(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
221 /// operation has no effect. Note that a trailing newline is provided
222 /// in multiline mode only.
223 bsl::ostream& print(bsl::ostream& stream,
224 int level = 0,
225 int spacesPerLevel = 4) const;
226
227 /// Invoke the specified `accessor` sequentially on each
228 /// (non-modifiable) attribute of this object, supplying `accessor`
229 /// with the corresponding attribute information structure until such
230 /// invocation returns a non-zero value. Return the value from the
231 /// last invocation of `accessor` (i.e., the invocation that terminated
232 /// the sequence).
233 template<class ACCESSOR>
234 int accessAttributes(ACCESSOR& accessor) const;
235
236 /// Invoke the specified `accessor` on the (non-modifiable) attribute
237 /// of this object indicated by the specified `id`, supplying `accessor`
238 /// with the corresponding attribute information structure. Return the
239 /// value returned from the invocation of `accessor` if `id` identifies
240 /// an attribute of this class, and -1 otherwise.
241 template<class ACCESSOR>
242 int accessAttribute(ACCESSOR& accessor, int id) const;
243
244 /// Invoke the specified `accessor` on the (non-modifiable) attribute
245 /// of this object indicated by the specified `name` of the specified
246 /// `nameLength`, supplying `accessor` with the corresponding attribute
247 /// information structure. Return the value returned from the
248 /// invocation of `accessor` if `name` identifies an attribute of this
249 /// class, and -1 otherwise.
250 template<class ACCESSOR>
251 int accessAttribute(ACCESSOR& accessor,
252 const char *name,
253 int nameLength) const;
254
255 /// Return a reference offering non-modifiable access to the "Street"
256 /// attribute of this object.
257 const bsl::string& street() const;
258
259 /// Return a reference offering non-modifiable access to the "City"
260 /// attribute of this object.
261 const bsl::string& city() const;
262
263 /// Return a reference offering non-modifiable access to the "State"
264 /// attribute of this object.
265 const bsl::string& state() const;
266};
267
268// FREE OPERATORS
269
270/// Return `true` if the specified `lhs` and `rhs` attribute objects have
271/// the same value, and `false` otherwise. Two attribute objects have the
272/// same value if each respective attribute has the same value.
273inline
274bool operator==(const Address& lhs, const Address& rhs);
275
276/// Return `true` if the specified `lhs` and `rhs` attribute objects do not
277/// have the same value, and `false` otherwise. Two attribute objects do
278/// not have the same value if one or more respective attributes differ in
279/// values.
280inline
281bool operator!=(const Address& lhs, const Address& rhs);
282
283/// Format the specified `rhs` to the specified output `stream` and
284/// return a reference to the modifiable `stream`.
285inline
286bsl::ostream& operator<<(bsl::ostream& stream, const Address& rhs);
287
288} // close package namespace
289
290// TRAITS
291
293
294// ============================================================================
295// INLINE FUNCTION DEFINITIONS
296// ============================================================================
297
298namespace s_baltst {
299
300 // -------------
301 // class Address
302 // -------------
303
304// CLASS METHODS
305// MANIPULATORS
306template <class MANIPULATOR>
307int Address::manipulateAttributes(MANIPULATOR& manipulator)
308{
309 int ret;
310
311 ret = manipulator(&d_street, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STREET]);
312 if (ret) {
313 return ret;
314 }
315
316 ret = manipulator(&d_city, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_CITY]);
317 if (ret) {
318 return ret;
319 }
320
321 ret = manipulator(&d_state, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STATE]);
322 if (ret) {
323 return ret;
324 }
325
326 return 0;
327}
328
329template <class MANIPULATOR>
330int Address::manipulateAttribute(MANIPULATOR& manipulator, int id)
331{
332 enum { NOT_FOUND = -1 };
333
334 switch (id) {
335 case ATTRIBUTE_ID_STREET: {
336 return manipulator(&d_street, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STREET]);
337 }
338 case ATTRIBUTE_ID_CITY: {
339 return manipulator(&d_city, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_CITY]);
340 }
341 case ATTRIBUTE_ID_STATE: {
342 return manipulator(&d_state, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STATE]);
343 }
344 default:
345 return NOT_FOUND;
346 }
347}
348
349template <class MANIPULATOR>
351 MANIPULATOR& manipulator,
352 const char *name,
353 int nameLength)
354{
355 enum { NOT_FOUND = -1 };
356
357 const bdlat_AttributeInfo *attributeInfo =
358 lookupAttributeInfo(name, nameLength);
359 if (0 == attributeInfo) {
360 return NOT_FOUND;
361 }
362
363 return manipulateAttribute(manipulator, attributeInfo->d_id);
364}
365
366inline
368{
369 return d_street;
370}
371
372inline
374{
375 return d_city;
376}
377
378inline
380{
381 return d_state;
382}
383
384// ACCESSORS
385template <class ACCESSOR>
386int Address::accessAttributes(ACCESSOR& accessor) const
387{
388 int ret;
389
390 ret = accessor(d_street, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STREET]);
391 if (ret) {
392 return ret;
393 }
394
395 ret = accessor(d_city, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_CITY]);
396 if (ret) {
397 return ret;
398 }
399
400 ret = accessor(d_state, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STATE]);
401 if (ret) {
402 return ret;
403 }
404
405 return 0;
406}
407
408template <class ACCESSOR>
409int Address::accessAttribute(ACCESSOR& accessor, int id) const
410{
411 enum { NOT_FOUND = -1 };
412
413 switch (id) {
414 case ATTRIBUTE_ID_STREET: {
415 return accessor(d_street, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STREET]);
416 }
417 case ATTRIBUTE_ID_CITY: {
418 return accessor(d_city, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_CITY]);
419 }
420 case ATTRIBUTE_ID_STATE: {
421 return accessor(d_state, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_STATE]);
422 }
423 default:
424 return NOT_FOUND;
425 }
426}
427
428template <class ACCESSOR>
430 ACCESSOR& accessor,
431 const char *name,
432 int nameLength) const
433{
434 enum { NOT_FOUND = -1 };
435
436 const bdlat_AttributeInfo *attributeInfo =
437 lookupAttributeInfo(name, nameLength);
438 if (0 == attributeInfo) {
439 return NOT_FOUND;
440 }
441
442 return accessAttribute(accessor, attributeInfo->d_id);
443}
444
445inline
447{
448 return d_street;
449}
450
451inline
453{
454 return d_city;
455}
456
457inline
459{
460 return d_state;
461}
462
463} // close package namespace
464
465// FREE FUNCTIONS
466
467inline
469 const s_baltst::Address& lhs,
470 const s_baltst::Address& rhs)
471{
472 return lhs.street() == rhs.street()
473 && lhs.city() == rhs.city()
474 && lhs.state() == rhs.state();
475}
476
477inline
479 const s_baltst::Address& lhs,
480 const s_baltst::Address& rhs)
481{
482 return !(lhs == rhs);
483}
484
485inline
486bsl::ostream& s_baltst::operator<<(
487 bsl::ostream& stream,
488 const s_baltst::Address& rhs)
489{
490 return rhs.print(stream, 0, -1);
491}
492
493
494#endif
495
496// GENERATED BY @BLP_BAS_CODEGEN_VERSION@
497// USING bas_codegen.pl s_baltst_address.xsd --mode msg --includedir . --msgComponent address --noRecurse --noExternalization --noHashSupport --noAggregateConversion
498// ----------------------------------------------------------------------------
499// NOTICE:
500// Copyright 2022 Bloomberg Finance L.P. All rights reserved.
501// Property of Bloomberg Finance L.P. (BFLP)
502// This software is made available solely pursuant to the
503// terms of a BFLP license agreement which governs its use.
504// ------------------------------- END-OF-FILE --------------------------------
505
506/** @} */
507/** @} */
508/** @} */
Definition bslstl_string.h:1281
Definition bslma_allocator.h:457
Definition s_baltst_address.h:73
int accessAttribute(ACCESSOR &accessor, int id) const
Definition s_baltst_address.h:409
int accessAttributes(ACCESSOR &accessor) const
Definition s_baltst_address.h:386
@ 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
bsl::string & city()
Definition s_baltst_address.h:373
static const bdlat_AttributeInfo * lookupAttributeInfo(int id)
~Address()
Destroy this object.
bsl::string & state()
Definition s_baltst_address.h:379
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:367
@ 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(const Address &original, bslma::Allocator *basicAllocator=0)
int manipulateAttributes(MANIPULATOR &manipulator)
Definition s_baltst_address.h:307
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
Address & operator=(const Address &rhs)
Assign to this object the value of the specified rhs object.
Address(bslma::Allocator *basicAllocator=0)
int manipulateAttribute(MANIPULATOR &manipulator, int id)
Definition s_baltst_address.h:330
@ NUM_ATTRIBUTES
Definition s_baltst_address.h:89
#define BDLAT_DECL_SEQUENCE_WITH_ALLOCATOR_BITWISEMOVEABLE_TRAITS(ClassName)
Definition bdlat_typetraits.h:282
#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_attributeinfo.h:137
int d_id
Definition bdlat_attributeinfo.h:140