BDE 4.14.0 Production release
Loading...
Searching...
No Matches
s_baltst_employee.h
Go to the documentation of this file.
1/// @file s_baltst_employee.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// s_baltst_employee.h *DO NOT EDIT* @generated -*-C++-*-
8#ifndef INCLUDED_S_BALTST_EMPLOYEE
9#define INCLUDED_S_BALTST_EMPLOYEE
10
11#include <bsls_ident.h>
12BSLS_IDENT_RCSID(s_baltst_employee_h, "$Id$ $CSID$")
14
15/// @defgroup s_baltst_employee s_baltst_employee
16/// @brief Provide value-semantic attribute classes
17/// @addtogroup Standalones
18/// @{
19/// @addtogroup s_baltst
20/// @{
21/// @addtogroup s_baltst_employee
22/// @{
23///
24/// <h1> Outline </h1>
25/// * <a href="#s_baltst_employee-purpose"> Purpose</a>
26///
27/// # Purpose {#s_baltst_employee-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_employee
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 <s_baltst_address.h>
60
61#include <bsl_iosfwd.h>
62#include <bsl_limits.h>
63
64
65
66namespace bslma { class Allocator; }
67
68namespace s_baltst { class Employee; }
69namespace s_baltst {
70
71 // ==============
72 // class Employee
73 // ==============
74
75class Employee {
76
77 // INSTANCE DATA
78 s_baltst::Address d_homeAddress;
79 bsl::string d_name;
80 int d_age;
81
82 public:
83 // TYPES
84 enum {
88 };
89
90 enum {
92 };
93
94 enum {
98 };
99
100 // CONSTANTS
101 static const char CLASS_NAME[];
102
104
105 public:
106 // CLASS METHODS
107
108 /// Return attribute information for the attribute indicated by the
109 /// specified `id` if the attribute exists, and 0 otherwise.
111
112 /// Return attribute information for the attribute indicated by the
113 /// specified `name` of the specified `nameLength` if the attribute
114 /// exists, and 0 otherwise.
116 const char *name,
117 int nameLength);
118
119 // CREATORS
120
121 /// Create an object of type `Employee` having the default value. Use
122 /// the optionally specified `basicAllocator` to supply memory. If
123 /// `basicAllocator` is 0, the currently installed default allocator is
124 /// used.
125 explicit Employee(bslma::Allocator *basicAllocator = 0);
126
127 /// Create an object of type `Employee` having the value of the
128 /// specified `original` object. Use the optionally specified
129 /// `basicAllocator` to supply memory. If `basicAllocator` is 0, the
130 /// currently installed default allocator is used.
131 Employee(const Employee& original,
132 bslma::Allocator *basicAllocator = 0);
133
134#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) \
135 && defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT)
136 /// Create an object of type `Employee` having the value of the
137 /// specified `original` object. After performing this action, the
138 /// `original` object will be left in a valid, but unspecified state.
139 Employee(Employee&& original) noexcept;
140
141 /// Create an object of type `Employee` having the value of the
142 /// specified `original` object. After performing this action, the
143 /// `original` object will be left in a valid, but unspecified state.
144 /// Use the optionally specified `basicAllocator` to supply memory. If
145 /// `basicAllocator` is 0, the currently installed default allocator is
146 /// used.
147 Employee(Employee&& original,
148 bslma::Allocator *basicAllocator);
149#endif
150
151 /// Destroy this object.
153
154 // MANIPULATORS
155
156 /// Assign to this object the value of the specified `rhs` object.
158
159#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) \
160 && defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT)
161 /// Assign to this object the value of the specified `rhs` object.
162 /// After performing this action, the `rhs` object will be left in a
163 /// valid, but unspecified state.
165#endif
166
167 /// Reset this object to the default value (i.e., its value upon
168 /// default construction).
169 void reset();
170
171 /// Invoke the specified `manipulator` sequentially on the address of
172 /// each (modifiable) attribute of this object, supplying `manipulator`
173 /// with the corresponding attribute information structure until such
174 /// invocation returns a non-zero value. Return the value from the
175 /// last invocation of `manipulator` (i.e., the invocation that
176 /// terminated the sequence).
177 template<class MANIPULATOR>
178 int manipulateAttributes(MANIPULATOR& manipulator);
179
180 /// Invoke the specified `manipulator` on the address of
181 /// the (modifiable) attribute indicated by the specified `id`,
182 /// supplying `manipulator` with the corresponding attribute
183 /// information structure. Return the value returned from the
184 /// invocation of `manipulator` if `id` identifies an attribute of this
185 /// class, and -1 otherwise.
186 template<class MANIPULATOR>
187 int manipulateAttribute(MANIPULATOR& manipulator, int id);
188
189 /// Invoke the specified `manipulator` on the address of
190 /// the (modifiable) attribute indicated by the specified `name` of the
191 /// specified `nameLength`, supplying `manipulator` with the
192 /// corresponding attribute information structure. Return the value
193 /// returned from the invocation of `manipulator` if `name` identifies
194 /// an attribute of this class, and -1 otherwise.
195 template<class MANIPULATOR>
196 int manipulateAttribute(MANIPULATOR& manipulator,
197 const char *name,
198 int nameLength);
199
200 /// Return a reference to the modifiable "Name" attribute of this
201 /// object.
202 bsl::string& name();
203
204 /// Return a reference to the modifiable "HomeAddress" attribute of this
205 /// object.
207
208 /// Return a reference to the modifiable "Age" attribute of this object.
209 int& age();
210
211 // ACCESSORS
212
213 /// Format this object to the specified output `stream` at the
214 /// optionally specified indentation `level` and return a reference to
215 /// the modifiable `stream`. If `level` is specified, optionally
216 /// specify `spacesPerLevel`, the number of spaces per indentation level
217 /// for this and all of its nested objects. Each line is indented by
218 /// the absolute value of `level * spacesPerLevel`. If `level` is
219 /// negative, suppress indentation of the first line. If
220 /// `spacesPerLevel` is negative, suppress line breaks and format the
221 /// entire output on one line. If `stream` is initially invalid, this
222 /// operation has no effect. 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<class ACCESSOR>
235 int accessAttributes(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<class ACCESSOR>
243 int accessAttribute(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<class ACCESSOR>
252 int accessAttribute(ACCESSOR& accessor,
253 const char *name,
254 int nameLength) const;
255
256 /// Return a reference offering non-modifiable access to the "Name"
257 /// attribute of this object.
258 const bsl::string& name() const;
259
260 /// Return a reference offering non-modifiable access to the
261 /// "HomeAddress" attribute of this object.
262 const s_baltst::Address& homeAddress() const;
263
264 /// Return the value of the "Age" attribute of this object.
265 int age() 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 Employee& lhs, const Employee& 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 Employee& lhs, const Employee& 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 Employee& 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 Employee
302 // --------------
303
304// CLASS METHODS
305// MANIPULATORS
306template <class MANIPULATOR>
307int Employee::manipulateAttributes(MANIPULATOR& manipulator)
308{
309 int ret;
310
311 ret = manipulator(&d_name, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_NAME]);
312 if (ret) {
313 return ret;
314 }
315
316 ret = manipulator(&d_homeAddress, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_HOME_ADDRESS]);
317 if (ret) {
318 return ret;
319 }
320
321 ret = manipulator(&d_age, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_AGE]);
322 if (ret) {
323 return ret;
324 }
325
326 return 0;
327}
328
329template <class MANIPULATOR>
330int Employee::manipulateAttribute(MANIPULATOR& manipulator, int id)
331{
332 enum { NOT_FOUND = -1 };
333
334 switch (id) {
335 case ATTRIBUTE_ID_NAME: {
336 return manipulator(&d_name, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_NAME]);
337 }
339 return manipulator(&d_homeAddress, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_HOME_ADDRESS]);
340 }
341 case ATTRIBUTE_ID_AGE: {
342 return manipulator(&d_age, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_AGE]);
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_name;
370}
371
372inline
374{
375 return d_homeAddress;
376}
377
378inline
380{
381 return d_age;
382}
383
384// ACCESSORS
385template <class ACCESSOR>
386int Employee::accessAttributes(ACCESSOR& accessor) const
387{
388 int ret;
389
390 ret = accessor(d_name, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_NAME]);
391 if (ret) {
392 return ret;
393 }
394
395 ret = accessor(d_homeAddress, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_HOME_ADDRESS]);
396 if (ret) {
397 return ret;
398 }
399
400 ret = accessor(d_age, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_AGE]);
401 if (ret) {
402 return ret;
403 }
404
405 return 0;
406}
407
408template <class ACCESSOR>
409int Employee::accessAttribute(ACCESSOR& accessor, int id) const
410{
411 enum { NOT_FOUND = -1 };
412
413 switch (id) {
414 case ATTRIBUTE_ID_NAME: {
415 return accessor(d_name, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_NAME]);
416 }
418 return accessor(d_homeAddress, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_HOME_ADDRESS]);
419 }
420 case ATTRIBUTE_ID_AGE: {
421 return accessor(d_age, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_AGE]);
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_name;
449}
450
451inline
453{
454 return d_homeAddress;
455}
456
457inline
458int Employee::age() const
459{
460 return d_age;
461}
462
463} // close package namespace
464
465// FREE FUNCTIONS
466
467inline
469 const s_baltst::Employee& lhs,
470 const s_baltst::Employee& rhs)
471{
472 return lhs.name() == rhs.name()
473 && lhs.homeAddress() == rhs.homeAddress()
474 && lhs.age() == rhs.age();
475}
476
477inline
479 const s_baltst::Employee& lhs,
480 const s_baltst::Employee& rhs)
481{
482 return !(lhs == rhs);
483}
484
485inline
486bsl::ostream& s_baltst::operator<<(
487 bsl::ostream& stream,
488 const s_baltst::Employee& 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_employee.xsd --mode msg --includedir . --msgComponent employee --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
Definition s_baltst_employee.h:75
int & age()
Return a reference to the modifiable "Age" attribute of this object.
Definition s_baltst_employee.h:379
Employee(const Employee &original, bslma::Allocator *basicAllocator=0)
static const char CLASS_NAME[]
Definition s_baltst_employee.h:101
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
@ ATTRIBUTE_ID_AGE
Definition s_baltst_employee.h:87
@ ATTRIBUTE_ID_NAME
Definition s_baltst_employee.h:85
@ ATTRIBUTE_ID_HOME_ADDRESS
Definition s_baltst_employee.h:86
static const bdlat_AttributeInfo ATTRIBUTE_INFO_ARRAY[]
Definition s_baltst_employee.h:103
static const bdlat_AttributeInfo * lookupAttributeInfo(const char *name, int nameLength)
int manipulateAttributes(MANIPULATOR &manipulator)
Definition s_baltst_employee.h:307
static const bdlat_AttributeInfo * lookupAttributeInfo(int id)
Employee(bslma::Allocator *basicAllocator=0)
Employee & operator=(const Employee &rhs)
Assign to this object the value of the specified rhs object.
int manipulateAttribute(MANIPULATOR &manipulator, int id)
Definition s_baltst_employee.h:330
~Employee()
Destroy this object.
int accessAttributes(ACCESSOR &accessor) const
Definition s_baltst_employee.h:386
int accessAttribute(ACCESSOR &accessor, int id) const
Definition s_baltst_employee.h:409
s_baltst::Address & homeAddress()
Definition s_baltst_employee.h:373
bsl::string & name()
Definition s_baltst_employee.h:367
@ NUM_ATTRIBUTES
Definition s_baltst_employee.h:91
@ ATTRIBUTE_INDEX_AGE
Definition s_baltst_employee.h:97
@ ATTRIBUTE_INDEX_HOME_ADDRESS
Definition s_baltst_employee.h:96
@ ATTRIBUTE_INDEX_NAME
Definition s_baltst_employee.h:95
#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