BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlt_monthofyear.h
Go to the documentation of this file.
1/// @file bdlt_monthofyear.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlt_monthofyear.h -*-C++-*-
8#ifndef INCLUDED_BDLT_MONTHOFYEAR
9#define INCLUDED_BDLT_MONTHOFYEAR
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlt_monthofyear bdlt_monthofyear
15/// @brief Enumerate the set of month-of-year values.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlt
19/// @{
20/// @addtogroup bdlt_monthofyear
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlt_monthofyear-purpose"> Purpose</a>
25/// * <a href="#bdlt_monthofyear-classes"> Classes </a>
26/// * <a href="#bdlt_monthofyear-description"> Description </a>
27/// * <a href="#bdlt_monthofyear-enumerators"> Enumerators </a>
28/// * <a href="#bdlt_monthofyear-usage"> Usage </a>
29/// * <a href="#bdlt_monthofyear-example-1-basic-syntax"> Example 1: Basic Syntax </a>
30///
31/// # Purpose {#bdlt_monthofyear-purpose}
32/// Enumerate the set of month-of-year values.
33///
34/// # Classes {#bdlt_monthofyear-classes}
35///
36/// - bdlt::MonthOfYear: namespace for month-of-year `enum`
37///
38/// # Description {#bdlt_monthofyear-description}
39/// This component provides a namespace for the `enum` type,
40/// `bdlt::MonthOfYear::Enum`, that enumerates the set of month-of-year values.
41///
42/// ## Enumerators {#bdlt_monthofyear-enumerators}
43///
44///
45/// @code
46/// Name Description
47/// ------------------- ----------------------------------
48/// e_JANUARY, e_JAN Enumerators representing January
49/// e_FEBRUARY, e_FEB Enumerators representing February
50/// e_MARCH, e_MAR Enumerators representing March
51/// e_APRIL, e_APR Enumerators representing April
52/// e_MAY Enumerator representing May
53/// e_JUNE, e_JUN Enumerators representing June
54/// e_JULY, e_JUL Enumerators representing July
55/// e_AUGUST, e_AUG Enumerators representing August
56/// e_SEPTEMBER, e_SEP Enumerators representing September
57/// e_OCTOBER, e_OCT Enumerators representing October
58/// e_NOVEMBER, e_NOV Enumerators representing November
59/// e_DECEMBER, e_DEC Enumerators representing December
60///
61/// k_NUM_MONTHS Number of enumerators in the range
62/// '[ e_JAN .. e_DEC ]'.
63/// @endcode
64///
65/// ## Usage {#bdlt_monthofyear-usage}
66///
67///
68/// This section illustrates intended use of this component.
69///
70/// ### Example 1: Basic Syntax {#bdlt_monthofyear-example-1-basic-syntax}
71///
72///
73/// The following snippets of code provide a simple illustration of
74/// `bdlt::MonthOfYear` usage.
75///
76/// First, we create a variable `value` of type `bdlt::MonthOfYear::Enum` and
77/// initialize it to the value `bdlt::MonthOfYear::e_APRIL`:
78/// @code
79/// bdlt::MonthOfYear::Enum value = bdlt::MonthOfYear::e_APRIL;
80/// @endcode
81/// Next, we store a pointer to its ASCII representation in a variable
82/// `asciiValue` of type `const char *`:
83/// @code
84/// const char *asciiValue = bdlt::MonthOfYear::toAscii(value);
85/// assert(0 == bsl::strcmp(asciiValue, "APR"));
86/// @endcode
87/// Finally, we print the value to `bsl::cout`:
88/// @code
89/// bsl::cout << value << bsl::endl;
90/// @endcode
91/// This statement produces the following output on `stdout`:
92/// @code
93/// APR
94/// @endcode
95/// @}
96/** @} */
97/** @} */
98
99/** @addtogroup bdl
100 * @{
101 */
102/** @addtogroup bdlt
103 * @{
104 */
105/** @addtogroup bdlt_monthofyear
106 * @{
107 */
108
109#include <bdlscm_version.h>
110
111#include <bsls_annotation.h>
112
113#include <bsl_iosfwd.h>
114
115
116namespace bdlt {
117
118 // ==================
119 // struct MonthOfYear
120 // ==================
121
122/// This `struct` provides a namespace for enumerating month-of-year
123/// values. See `Enum` in the TYPES sub-section for details.
124///
125/// This `struct`:
126/// * supports a complete set of *enumeration* operations
127/// For terminology see @ref bsldoc_glossary .
129
130 public:
131 // TYPES
132
133 /// Define the list of month-of-year values.
134 enum Enum {
135
148
149#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
150
151#if !defined(JAN) && !defined(JANUARY)
164
176#endif // !defined(JAN) && !defined(JANUARY)
177
178#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
179
180#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
193#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
194 };
195
196 /// Define `k_NUM_MONTHS` to be the number of consecutively valued
197 /// enumerators in the range `[ e_JAN .. e_DEC ]`.
198 enum {
200
201#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
203#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
204#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
206
207#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
208 };
209
210#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
211
212 /// Define an alias, `Month`, to the enum type, `Enum` defined by this
213 /// component.
214 typedef Enum Month;
215#endif
216
217 // CLASS METHODS
218
219 /// Assign to the specified `variable` the value read from the specified
220 /// input `stream` using the specified `version` format, and return a
221 /// reference to `stream`. If `stream` is initially invalid, this
222 /// operation has no effect. If `version` is not supported, `variable`
223 /// is unaltered and `stream` is invalidated, but otherwise unmodified.
224 /// If `version` is supported but `stream` becomes invalid during this
225 /// operation, `variable` has an undefined, but valid, state. Note that
226 /// no version is read from `stream`. See the `bslx` package-level
227 /// documentation for more information on BDEX streaming of
228 /// value-semantic types and containers.
229 template <class STREAM>
230 static STREAM& bdexStreamIn(STREAM& stream,
231 MonthOfYear::Enum& variable,
232 int version);
233
234 /// Write the value of the specified `value`, using the specified
235 /// `version` format, to the specified output `stream`, and return a
236 /// reference to `stream`. If `stream` is initially invalid, this
237 /// operation has no effect. If `version` is not supported, `stream` is
238 /// invalidated, but otherwise unmodified. Note that `version` is not
239 /// written to `stream`. See the `bslx` package-level documentation for
240 /// more information on BDEX streaming of value-semantic types and
241 /// containers.
242 template <class STREAM>
243 static STREAM& bdexStreamOut(STREAM& stream,
244 MonthOfYear::Enum value,
245 int version);
246
247 /// Return the maximum valid BDEX format version, as indicated by the
248 /// specified `versionSelector`, to be passed to the `bdexStreamOut`
249 /// method. Note that it is highly recommended that `versionSelector`
250 /// be formatted as "YYYYMMDD", a date representation. Also note that
251 /// `versionSelector` should be a *compile*-time-chosen value that
252 /// selects a format version supported by both externalizer and
253 /// unexternalizer. See the `bslx` package-level documentation for more
254 /// information on BDEX streaming of value-semantic types and
255 /// containers.
256 static int maxSupportedBdexVersion(int versionSelector);
257
258 /// Write the string representation of the specified enumeration `value`
259 /// to the specified output `stream`, and return a reference to
260 /// `stream`. Optionally specify an initial indentation `level`, whose
261 /// absolute value is incremented recursively for nested objects. If
262 /// `level` is specified, optionally specify `spacesPerLevel`, whose
263 /// absolute value indicates the number of spaces per indentation level
264 /// for this and all of its nested objects. If `level` is negative,
265 /// suppress indentation of the first line. If `spacesPerLevel` is
266 /// negative, format the entire output on one line, suppressing all but
267 /// the initial indentation (as governed by `level`). See `toAscii` for
268 /// what constitutes the string representation of a `MonthOfYear::Enum`
269 /// value.
270 static bsl::ostream& print(bsl::ostream& stream,
271 MonthOfYear::Enum value,
272 int level = 0,
273 int spacesPerLevel = 4);
274
275 /// Return the non-modifiable string representation corresponding to the
276 /// specified enumeration `value`, if it exists, and a unique (error)
277 /// string otherwise. The string representation of `value` matches the
278 /// first 3 characters of its corresponding enumerator name with the
279 /// "e_" prefix elided. For example:
280 /// @code
281 /// bsl::cout << bdlt::MonthOfYear::toAscii(
282 /// bdlt::MonthOfYear::e_JANUARY);
283 /// @endcode
284 /// will print the following on standard output:
285 /// @code
286 /// JAN
287 /// @endcode
288 /// Note that specifying a `value` that does not match any of the
289 /// enumerators will result in a string representation that is distinct
290 /// from any of those corresponding to the enumerators, but is otherwise
291 /// unspecified.
292 static const char *toAscii(MonthOfYear::Enum value);
293
294#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
295
296 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
297 ///
298 /// Return the most current BDEX streaming version number supported by
299 /// this struct.
300 static int maxSupportedBdexVersion();
301
302#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
303};
304
305// FREE OPERATORS
306
307/// Write the string representation of the specified enumeration `value` to
308/// the specified output `stream` in a single-line format, and return a
309/// reference to `stream`. See `toAscii` for what constitutes the string
310/// representation of a `bdlt::MonthOfYear::Enum` value. Note that this
311/// method has the same behavior as
312/// @code
313/// bdlt::MonthOfYear::print(stream, value, 0, -1);
314/// @endcode
315bsl::ostream& operator<<(bsl::ostream& stream, MonthOfYear::Enum value);
316
317// FREE FUNCTIONS
318
319/// Load into the specified `variable` the `MonthOfYear::Enum` value read
320/// from the specified input `stream` using the specified `version` format,
321/// and return a reference to `stream`. If `stream` is initially invalid,
322/// this operation has no effect. If `version` is not supported by
323/// `MonthOfYear`, `variable` is unaltered and `stream` is invalidated, but
324/// otherwise unmodified. If `version` is supported by `MonthOfYear` but
325/// `stream` becomes invalid during this operation, `variable` has an
326/// undefined, but valid, state. The behavior is undefined unless `STREAM`
327/// is BDEX-compliant. Note that no version is read from `stream`. See the
328/// `bslx` package-level documentation for more information on BDEX
329/// streaming of value-semantic types and containers.
330template <class STREAM>
331STREAM& bdexStreamIn(STREAM& stream, MonthOfYear::Enum& variable, int version);
332
333/// Write the specified `value`, using the specified `version` format, to
334/// the specified output `stream`, and return a reference to `stream`. If
335/// `stream` is initially invalid, this operation has no effect. If
336/// `version` is not supported by `MonthOfYear`, `stream` is invalidated,
337/// but otherwise unmodified. The behavior is undefined unless `STREAM` is
338/// BDEX-compliant. Note that `version` is not written to `stream`. See
339/// the `bslx` package-level documentation for more information on BDEX
340/// streaming of value-semantic types and containers.
341template <class STREAM>
342STREAM& bdexStreamOut(STREAM& stream,
343 const MonthOfYear::Enum& value,
344 int version);
345
346/// Return the maximum valid BDEX format version, as indicated by the
347/// specified `versionSelector`, to be passed to the `bdexStreamOut` method
348/// while streaming an object of the type `MonthOfYear::Enum`. Note that it
349/// is highly recommended that `versionSelector` be formatted as "YYYYMMDD",
350/// a date representation. Also note that `versionSelector` should be a
351/// *compile*-time-chosen value that selects a format version supported by
352/// both externalizer and unexternalizer. See the `bslx` package-level
353/// documentation for more information on BDEX streaming of value-semantic
354/// types and containers.
355int maxSupportedBdexVersion(const MonthOfYear::Enum *, int versionSelector);
356
357// ============================================================================
358// INLINE DEFINITIONS
359// ============================================================================
360
361 // ------------------
362 // struct MonthOfYear
363 // ------------------
364
365// CLASS METHODS
366template <class STREAM>
367STREAM& MonthOfYear::bdexStreamIn(STREAM& stream,
368 MonthOfYear::Enum& variable,
369 int version)
370{
371 if (stream) {
372 switch (version) { // switch on the schema version
373 case 1: {
374 char newValue;
375 stream.getInt8(newValue);
376 if (stream && e_JAN <= newValue && e_DEC >= newValue) {
377 variable = static_cast<MonthOfYear::Enum>(newValue);
378 }
379 else {
380 stream.invalidate();
381 }
382 } break;
383 default: {
384 stream.invalidate(); // unrecognized version number
385 }
386 }
387 }
388 return stream;
389}
390
391template <class STREAM>
392inline
393STREAM& MonthOfYear::bdexStreamOut(STREAM& stream,
394 MonthOfYear::Enum value,
395 int version)
396{
397 if (stream) {
398 switch (version) { // switch on the schema version
399 case 1: {
400 stream.putInt8(static_cast<char>(value));
401 } break;
402 default: {
403 stream.invalidate(); // unrecognized version number
404 }
405 }
406 }
407 return stream;
408}
409
410inline
411int MonthOfYear::maxSupportedBdexVersion(int /* versionSelector */)
412{
413 return 1;
414}
415
416#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
417
418inline
423
424#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
425
426} // close package namespace
427
428// FREE OPERATORS
429inline
430bsl::ostream& bdlt::operator<<(bsl::ostream& stream,
432{
433 return bdlt::MonthOfYear::print(stream, value, 0, -1);
434}
435
436// FREE FUNCTIONS
437template <class STREAM>
438STREAM& bdlt::bdexStreamIn(STREAM& stream,
439 bdlt::MonthOfYear::Enum& variable,
440 int version)
441{
442 return bdlt::MonthOfYear::bdexStreamIn(stream, variable, version);
443}
444
445template <class STREAM>
446STREAM& bdlt::bdexStreamOut(STREAM& stream,
447 const bdlt::MonthOfYear::Enum& value,
448 int version)
449{
450 return bdlt::MonthOfYear::bdexStreamOut(stream, value, version);
451}
452
453inline
455 int versionSelector)
456{
457 return bdlt::MonthOfYear::maxSupportedBdexVersion(versionSelector);
458}
459
460#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
461
462// BDEX STREAMING SUPPORT
463
464namespace bdex_InStreamFunctions {
465
466template <class STREAM>
467inline
468STREAM& streamIn(STREAM& stream,
469 bdlt::MonthOfYear::Enum& variable,
470 int version)
471{
472 return bdlt::MonthOfYear::bdexStreamIn(stream, variable, version);
473}
474
475} // close namespace bdex_InStreamFunctions
476
477namespace bdex_OutStreamFunctions {
478
479template <class STREAM>
480inline
481STREAM& streamOut(STREAM& stream,
482 const bdlt::MonthOfYear::Enum& value,
483 int version)
484{
485 return bdlt::MonthOfYear::bdexStreamOut(stream, value, version);
486}
487
488} // close namespace bdex_OutStreamFunctions
489
490namespace bdex_VersionFunctions {
491
492inline
497
498} // close namespace bdex_VersionFunctions
499
500#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
501
502
503
504#endif
505
506// ----------------------------------------------------------------------------
507// Copyright 2014 Bloomberg Finance L.P.
508//
509// Licensed under the Apache License, Version 2.0 (the "License");
510// you may not use this file except in compliance with the License.
511// You may obtain a copy of the License at
512//
513// http://www.apache.org/licenses/LICENSE-2.0
514//
515// Unless required by applicable law or agreed to in writing, software
516// distributed under the License is distributed on an "AS IS" BASIS,
517// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
518// See the License for the specific language governing permissions and
519// limitations under the License.
520// ----------------------------- END-OF-FILE ----------------------------------
521
522/** @} */
523/** @} */
524/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlt_dayofweek.h:410
STREAM & streamIn(STREAM &stream, bdlt::DayOfWeek::Enum &variable, int version)
Definition bdlt_dayofweek.h:414
Definition bdlt_dayofweek.h:423
STREAM & streamOut(STREAM &stream, const bdlt::DayOfWeek::Enum &value, int version)
Definition bdlt_dayofweek.h:427
Definition bdlt_dayofweek.h:436
int maxSupportedVersion(bdlt::DayOfWeek::Enum)
Definition bdlt_dayofweek.h:439
Definition bbldc_basicisma30360.h:112
STREAM & bdexStreamOut(STREAM &stream, const DayOfWeek::Enum &value, int version)
int maxSupportedBdexVersion(const DayOfWeek::Enum *, int versionSelector)
STREAM & bdexStreamIn(STREAM &stream, DayOfWeek::Enum &variable, int version)
bsl::ostream & operator<<(bsl::ostream &stream, const Calendar &calendar)
Definition bdlt_monthofyear.h:128
static int maxSupportedBdexVersion()
Definition bdlt_monthofyear.h:419
static const char * toAscii(MonthOfYear::Enum value)
@ BDET_LENGTH
Definition bdlt_monthofyear.h:205
@ k_NUM_MONTHS
Definition bdlt_monthofyear.h:199
@ LENGTH
Definition bdlt_monthofyear.h:202
Enum
Define the list of month-of-year values.
Definition bdlt_monthofyear.h:134
@ OCTOBER
Definition bdlt_monthofyear.h:173
@ BDET_SEP
Definition bdlt_monthofyear.h:189
@ NOVEMBER
Definition bdlt_monthofyear.h:174
@ MAR
Definition bdlt_monthofyear.h:154
@ BDET_FEB
Definition bdlt_monthofyear.h:182
@ BDET_AUG
Definition bdlt_monthofyear.h:188
@ JUN
Definition bdlt_monthofyear.h:157
@ FEB
Definition bdlt_monthofyear.h:153
@ DEC
Definition bdlt_monthofyear.h:163
@ e_NOVEMBER
Definition bdlt_monthofyear.h:146
@ BDET_JUN
Definition bdlt_monthofyear.h:186
@ JAN
Definition bdlt_monthofyear.h:152
@ BDET_NOV
Definition bdlt_monthofyear.h:191
@ e_SEP
Definition bdlt_monthofyear.h:144
@ e_JANUARY
Definition bdlt_monthofyear.h:136
@ MAY
Definition bdlt_monthofyear.h:156
@ e_JUNE
Definition bdlt_monthofyear.h:141
@ BDET_DEC
Definition bdlt_monthofyear.h:192
@ OCT
Definition bdlt_monthofyear.h:161
@ e_MAY
Definition bdlt_monthofyear.h:140
@ BDET_MAR
Definition bdlt_monthofyear.h:183
@ BDET_DECEMBER
Definition bdlt_monthofyear.h:192
@ e_MAR
Definition bdlt_monthofyear.h:138
@ e_JUL
Definition bdlt_monthofyear.h:142
@ JUNE
Definition bdlt_monthofyear.h:169
@ e_AUG
Definition bdlt_monthofyear.h:143
@ BDET_JUL
Definition bdlt_monthofyear.h:187
@ APR
Definition bdlt_monthofyear.h:155
@ FEBRUARY
Definition bdlt_monthofyear.h:166
@ BDET_JAN
Definition bdlt_monthofyear.h:181
@ SEPTEMBER
Definition bdlt_monthofyear.h:172
@ e_JAN
Definition bdlt_monthofyear.h:136
@ BDET_OCTOBER
Definition bdlt_monthofyear.h:190
@ e_OCT
Definition bdlt_monthofyear.h:145
@ DECEMBER
Definition bdlt_monthofyear.h:175
@ BDET_APR
Definition bdlt_monthofyear.h:184
@ BDET_JULY
Definition bdlt_monthofyear.h:187
@ e_NOV
Definition bdlt_monthofyear.h:146
@ BDET_MAY
Definition bdlt_monthofyear.h:185
@ e_APRIL
Definition bdlt_monthofyear.h:139
@ BDET_JANUARY
Definition bdlt_monthofyear.h:181
@ JUL
Definition bdlt_monthofyear.h:158
@ e_OCTOBER
Definition bdlt_monthofyear.h:145
@ e_DECEMBER
Definition bdlt_monthofyear.h:147
@ e_MARCH
Definition bdlt_monthofyear.h:138
@ MARCH
Definition bdlt_monthofyear.h:167
@ BDET_AUGUST
Definition bdlt_monthofyear.h:188
@ APRIL
Definition bdlt_monthofyear.h:168
@ e_JUN
Definition bdlt_monthofyear.h:141
@ e_FEB
Definition bdlt_monthofyear.h:137
@ e_FEBRUARY
Definition bdlt_monthofyear.h:137
@ BDET_MARCH
Definition bdlt_monthofyear.h:183
@ AUG
Definition bdlt_monthofyear.h:159
@ e_APR
Definition bdlt_monthofyear.h:139
@ BDET_APRIL
Definition bdlt_monthofyear.h:184
@ AUGUST
Definition bdlt_monthofyear.h:171
@ BDET_NOVEMBER
Definition bdlt_monthofyear.h:191
@ JULY
Definition bdlt_monthofyear.h:170
@ SEP
Definition bdlt_monthofyear.h:160
@ JANUARY
Definition bdlt_monthofyear.h:165
@ e_SEPTEMBER
Definition bdlt_monthofyear.h:144
@ e_AUGUST
Definition bdlt_monthofyear.h:143
@ e_JULY
Definition bdlt_monthofyear.h:142
@ BDET_FEBRUARY
Definition bdlt_monthofyear.h:182
@ e_DEC
Definition bdlt_monthofyear.h:147
@ BDET_JUNE
Definition bdlt_monthofyear.h:186
@ NOV
Definition bdlt_monthofyear.h:162
@ BDET_OCT
Definition bdlt_monthofyear.h:190
@ BDET_SEPTEMBER
Definition bdlt_monthofyear.h:189
static STREAM & bdexStreamOut(STREAM &stream, MonthOfYear::Enum value, int version)
Definition bdlt_monthofyear.h:393
static STREAM & bdexStreamIn(STREAM &stream, MonthOfYear::Enum &variable, int version)
Definition bdlt_monthofyear.h:367
static bsl::ostream & print(bsl::ostream &stream, MonthOfYear::Enum value, int level=0, int spacesPerLevel=4)
Enum Month
Definition bdlt_monthofyear.h:214