BDE 4.39.x 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 <typename t_MANIPULATOR>
178 int manipulateAttributes(t_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 <typename t_MANIPULATOR>
187 int manipulateAttribute(t_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 <typename t_MANIPULATOR>
196 int manipulateAttribute(t_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 operation has no effect.
222 ///
223 /// \note Note that a trailing newline is provided
224 /// in multiline mode only.
225 bsl::ostream& print(bsl::ostream& stream,
226 int level = 0,
227 int spacesPerLevel = 4) const;
228
229 /// Invoke the specified `accessor` sequentially on each
230 /// (non-modifiable) attribute of this object, supplying `accessor`
231 /// with the corresponding attribute information structure until such
232 /// invocation returns a non-zero value. Return the value from the
233 /// last invocation of `accessor` (i.e., the invocation that terminated
234 /// the sequence).
235 template <typename t_ACCESSOR>
236 int accessAttributes(t_ACCESSOR& accessor) const;
237
238 /// Invoke the specified `accessor` on the (non-modifiable) attribute
239 /// of this object indicated by the specified `id`, supplying `accessor`
240 /// with the corresponding attribute information structure. Return the
241 /// value returned from the invocation of `accessor` if `id` identifies
242 /// an attribute of this class, and -1 otherwise.
243 template <typename t_ACCESSOR>
244 int accessAttribute(t_ACCESSOR& accessor, int id) const;
245
246 /// Invoke the specified `accessor` on the (non-modifiable) attribute
247 /// of this object indicated by the specified `name` of the specified
248 /// `nameLength`, supplying `accessor` with the corresponding attribute
249 /// information structure. Return the value returned from the
250 /// invocation of `accessor` if `name` identifies an attribute of this
251 /// class, and -1 otherwise.
252 template <typename t_ACCESSOR>
253 int accessAttribute(t_ACCESSOR& accessor,
254 const char *name,
255 int nameLength) const;
256
257 /// Return a reference offering non-modifiable access to the "Name"
258 /// attribute of this object.
259 const bsl::string& name() const;
260
261 /// Return a reference offering non-modifiable access to the
262 /// "HomeAddress" attribute of this object.
263 const s_baltst::Address& homeAddress() const;
264
265 /// Return the value of the "Age" attribute of this object.
266 int age() 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 Employee& lhs, const Employee& rhs)
274 {
275 return lhs.name() == rhs.name() &&
276 lhs.homeAddress() == rhs.homeAddress() &&
277 lhs.age() == rhs.age();
278 }
279
280 /// Returns `!(lhs == rhs)`
281 friend bool operator!=(const Employee& lhs, const Employee& 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 Employee& 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 Employee
310 // --------------
311
312// CLASS METHODS
313// MANIPULATORS
314template <typename t_MANIPULATOR>
315int Employee::manipulateAttributes(t_MANIPULATOR& manipulator)
316{
317 int ret;
318
319 ret = manipulator(&d_name, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_NAME]);
320 if (ret) {
321 return ret;
322 }
323
324 ret = manipulator(&d_homeAddress, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_HOME_ADDRESS]);
325 if (ret) {
326 return ret;
327 }
328
329 ret = manipulator(&d_age, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_AGE]);
330 if (ret) {
331 return ret;
332 }
333
334 return 0;
335}
336
337template <typename t_MANIPULATOR>
338int Employee::manipulateAttribute(t_MANIPULATOR& manipulator, int id)
339{
340 enum { NOT_FOUND = -1 };
341
342 switch (id) {
343 case ATTRIBUTE_ID_NAME: {
344 return manipulator(&d_name, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_NAME]);
345 }
347 return manipulator(&d_homeAddress, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_HOME_ADDRESS]);
348 }
349 case ATTRIBUTE_ID_AGE: {
350 return manipulator(&d_age, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_AGE]);
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_name;
378}
379
380inline
382{
383 return d_homeAddress;
384}
385
386inline
388{
389 return d_age;
390}
391
392// ACCESSORS
393template <typename t_ACCESSOR>
394int Employee::accessAttributes(t_ACCESSOR& accessor) const
395{
396 int ret;
397
398 ret = accessor(d_name, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_NAME]);
399 if (ret) {
400 return ret;
401 }
402
403 ret = accessor(d_homeAddress, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_HOME_ADDRESS]);
404 if (ret) {
405 return ret;
406 }
407
408 ret = accessor(d_age, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_AGE]);
409 if (ret) {
410 return ret;
411 }
412
413 return 0;
414}
415
416template <typename t_ACCESSOR>
417int Employee::accessAttribute(t_ACCESSOR& accessor, int id) const
418{
419 enum { NOT_FOUND = -1 };
420
421 switch (id) {
422 case ATTRIBUTE_ID_NAME: {
423 return accessor(d_name, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_NAME]);
424 }
426 return accessor(d_homeAddress, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_HOME_ADDRESS]);
427 }
428 case ATTRIBUTE_ID_AGE: {
429 return accessor(d_age, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_AGE]);
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_name;
457}
458
459inline
461{
462 return d_homeAddress;
463}
464
465inline
466int Employee::age() const
467{
468 return d_age;
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_employee.xsd --mode msg --includedir . --msgComponent employee --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
Definition s_baltst_employee.h:75
int & age()
Return a reference to the modifiable "Age" attribute of this object.
Definition s_baltst_employee.h:387
Employee(const Employee &original, bslma::Allocator *basicAllocator=0)
friend bool operator!=(const Employee &lhs, const Employee &rhs)
Returns !(lhs == rhs)
Definition s_baltst_employee.h:281
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_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
int accessAttribute(t_ACCESSOR &accessor, int id) const
Definition s_baltst_employee.h:417
static const bdlat_AttributeInfo ATTRIBUTE_INFO_ARRAY[]
Definition s_baltst_employee.h:103
int manipulateAttributes(t_MANIPULATOR &manipulator)
Definition s_baltst_employee.h:315
static const bdlat_AttributeInfo * lookupAttributeInfo(const char *name, int nameLength)
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.
~Employee()
Destroy this object.
friend bool operator==(const Employee &lhs, const Employee &rhs)
Definition s_baltst_employee.h:273
int accessAttributes(t_ACCESSOR &accessor) const
Definition s_baltst_employee.h:394
@ NUM_ATTRIBUTES
Definition s_baltst_employee.h:91
@ 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
s_baltst::Address & homeAddress()
Definition s_baltst_employee.h:381
bsl::string & name()
Definition s_baltst_employee.h:375
int manipulateAttribute(t_MANIPULATOR &manipulator, int id)
Definition s_baltst_employee.h:338
friend bsl::ostream & operator<<(bsl::ostream &stream, const Employee &rhs)
Definition s_baltst_employee.h:288
#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