BDE 4.39.x 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 <bsla_deprecated.h>
112
113#include <bsls_annotation.h>
114
115#include <bsl_iosfwd.h>
116
117
118namespace bdlt {
119
120 // ==================
121 // struct MonthOfYear
122 // ==================
123
124/// This `struct` provides a namespace for enumerating month-of-year
125/// values. See `Enum` in the TYPES sub-section for details.
126///
127/// This `struct`:
128/// * supports a complete set of *enumeration* operations
129/// For terminology see @ref bsldoc_glossary .
130///
131/// See @ref bdlt_monthofyear
133
134 public:
135 // TYPES
136
137 /// Define the list of month-of-year values.
138 enum Enum {
139
152
153#ifndef BDE_OMIT_INTERNAL_DEPRECATED
154
155#if !defined(JAN) && !defined(JANUARY)
158 , MAR BSLA_DEPRECATED = e_MAR
159 , APR BSLA_DEPRECATED = e_APR
160 , MAY BSLA_DEPRECATED = e_MAY
161 , JUN BSLA_DEPRECATED = e_JUN
162 , JUL BSLA_DEPRECATED = e_JUL
163 , AUG BSLA_DEPRECATED = e_AUG
164 , SEP BSLA_DEPRECATED = e_SEP
165 , OCT BSLA_DEPRECATED = e_OCT
166 , NOV BSLA_DEPRECATED = e_NOV
167 , DEC BSLA_DEPRECATED = e_DEC
168
169 , JANUARY BSLA_DEPRECATED = e_JANUARY
170 , FEBRUARY BSLA_DEPRECATED = e_FEBRUARY
171 , MARCH BSLA_DEPRECATED = e_MARCH
172 , APRIL BSLA_DEPRECATED = e_APRIL
173 , JUNE BSLA_DEPRECATED = e_JUNE
174 , JULY BSLA_DEPRECATED = e_JULY
175 , AUGUST BSLA_DEPRECATED = e_AUGUST
176 , SEPTEMBER BSLA_DEPRECATED = e_SEPTEMBER
177 , OCTOBER BSLA_DEPRECATED = e_OCTOBER
178 , NOVEMBER BSLA_DEPRECATED = e_NOVEMBER
179 , DECEMBER BSLA_DEPRECATED = e_DECEMBER
180#endif // !defined(JAN) && !defined(JANUARY)
181
182#endif // BDE_OMIT_INTERNAL_DEPRECATED
183
184#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
185 , BDET_FEB BSLA_DEPRECATED = e_FEB
186 , BDET_DECEMBER BSLA_DEPRECATED = e_DEC
187#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
188 };
189
190 /// Define `k_NUM_MONTHS` to be the number of consecutively valued
191 /// enumerators in the range `[ e_JAN .. e_DEC ]`.
192 enum {
194
195#ifndef BDE_OMIT_INTERNAL_DEPRECATED
197#endif
198 };
199
200#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
201
202 /// Define an alias, `Month`, to the enum type, `Enum` defined by this
203 /// component.
204 typedef Enum Month;
205#endif
206
207 // CLASS METHODS
208
209 /// Assign to the specified `variable` the value read from the specified
210 /// input `stream` using the specified `version` format, and return a
211 /// reference to `stream`. If `stream` is initially invalid, this
212 /// operation has no effect. If `version` is not supported, `variable`
213 /// is unaltered and `stream` is invalidated, but otherwise unmodified.
214 /// If `version` is supported but `stream` becomes invalid during this
215 /// operation, `variable` has an undefined, but valid, state.
216 ///
217 /// \note Note that no version is read from `stream`. See the `bslx` package-level
218 /// documentation for more information on BDEX streaming of
219 /// value-semantic types and containers.
220 template <class STREAM>
221 static STREAM& bdexStreamIn(STREAM& stream,
222 MonthOfYear::Enum& variable,
223 int version);
224
225 /// Write the value of the specified `value`, using the specified
226 /// `version` format, to the specified output `stream`, and return a
227 /// reference to `stream`. If `stream` is initially invalid, this
228 /// operation has no effect. If `version` is not supported, `stream` is invalidated, but otherwise unmodified.
229 ///
230 /// \note Note that `version` is not
231 /// written to `stream`. See the `bslx` package-level documentation for
232 /// more information on BDEX streaming of value-semantic types and
233 /// containers.
234 template <class STREAM>
235 static STREAM& bdexStreamOut(STREAM& stream,
236 MonthOfYear::Enum value,
237 int version);
238
239 /// Return the maximum valid BDEX format version, as indicated by the
240 /// specified `versionSelector`, to be passed to the `bdexStreamOut` method.
241 ///
242 /// \note Note that it is highly recommended that `versionSelector`
243 /// be formatted as "YYYYMMDD", a date representation. Also note that
244 /// `versionSelector` should be a *compile*-time-chosen value that
245 /// selects a format version supported by both externalizer and
246 /// unexternalizer. See the `bslx` package-level documentation for more
247 /// information on BDEX streaming of value-semantic types and
248 /// containers.
249 static int maxSupportedBdexVersion(int versionSelector);
250
251 /// Write the string representation of the specified enumeration `value`
252 /// to the specified output `stream`, and return a reference to
253 /// `stream`. Optionally specify an initial indentation `level`, whose
254 /// absolute value is incremented recursively for nested objects. If
255 /// `level` is specified, optionally specify `spacesPerLevel`, whose
256 /// absolute value indicates the number of spaces per indentation level
257 /// for this and all of its nested objects. If `level` is negative,
258 /// suppress indentation of the first line. If `spacesPerLevel` is
259 /// negative, format the entire output on one line, suppressing all but
260 /// the initial indentation (as governed by `level`). See `toAscii` for
261 /// what constitutes the string representation of a `MonthOfYear::Enum`
262 /// value.
263 static bsl::ostream& print(bsl::ostream& stream,
264 MonthOfYear::Enum value,
265 int level = 0,
266 int spacesPerLevel = 4);
267
268 /// Return the non-modifiable string representation corresponding to the
269 /// specified enumeration `value`, if it exists, and a unique (error)
270 /// string otherwise. The string representation of `value` matches the
271 /// first 3 characters of its corresponding enumerator name with the
272 /// "e_" prefix elided. For example:
273 /// @code
274 /// bsl::cout << bdlt::MonthOfYear::toAscii(
275 /// bdlt::MonthOfYear::e_JANUARY);
276 /// @endcode
277 /// will print the following on standard output:
278 /// @code
279 /// JAN
280 /// @endcode
281 ///
282 /// \note Note that specifying a `value` that does not match any of the
283 /// enumerators will result in a string representation that is distinct
284 /// from any of those corresponding to the enumerators, but is otherwise
285 /// unspecified.
286 static const char *toAscii(MonthOfYear::Enum value);
287
288#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
289
290 /// Return the most current BDEX streaming version number supported by
291 /// this struct.
292 ///
293 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
294 static int maxSupportedBdexVersion();
295
296#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
297};
298
299// FREE OPERATORS
300
301/// Write the string representation of the specified enumeration `value` to
302/// the specified output `stream` in a single-line format, and return a
303/// reference to `stream`. See `toAscii` for what constitutes the string representation of a `bdlt::MonthOfYear::Enum` value.
304///
305/// \note Note that this
306/// method has the same behavior as
307/// @code
308/// bdlt::MonthOfYear::print(stream, value, 0, -1);
309/// @endcode
310bsl::ostream& operator<<(bsl::ostream& stream, MonthOfYear::Enum value);
311
312// FREE FUNCTIONS
313
314/// Load into the specified `variable` the `MonthOfYear::Enum` value read
315/// from the specified input `stream` using the specified `version` format,
316/// and return a reference to `stream`. If `stream` is initially invalid,
317/// this operation has no effect. If `version` is not supported by
318/// `MonthOfYear`, `variable` is unaltered and `stream` is invalidated, but
319/// otherwise unmodified. If `version` is supported by `MonthOfYear` but
320/// `stream` becomes invalid during this operation, `variable` has an undefined, but valid, state.
321///
322/// \pre The behavior is undefined unless `STREAM` is BDEX-compliant.
323///
324/// \note Note that no version is read from `stream`. See the
325/// `bslx` package-level documentation for more information on BDEX
326/// streaming of value-semantic types and containers.
327template <class STREAM>
328STREAM& bdexStreamIn(STREAM& stream, MonthOfYear::Enum& variable, int version);
329
330/// Write the specified `value`, using the specified `version` format, to
331/// the specified output `stream`, and return a reference to `stream`. If
332/// `stream` is initially invalid, this operation has no effect. If
333/// `version` is not supported by `MonthOfYear`, `stream` is invalidated, but otherwise unmodified.
334///
335/// \pre The behavior is undefined unless `STREAM` is BDEX-compliant.
336///
337/// \note Note that `version` is not written to `stream`. See
338/// the `bslx` package-level documentation for more information on BDEX
339/// streaming of value-semantic types and containers.
340template <class STREAM>
341STREAM& bdexStreamOut(STREAM& stream,
342 const MonthOfYear::Enum& value,
343 int version);
344
345/// Return the maximum valid BDEX format version, as indicated by the
346/// specified `versionSelector`, to be passed to the `bdexStreamOut` method while streaming an object of the type `MonthOfYear::Enum`.
347///
348/// \note 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)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlt_dayofweek.h:423
STREAM & streamIn(STREAM &stream, bdlt::DayOfWeek::Enum &variable, int version)
Definition bdlt_dayofweek.h:427
Definition bdlt_dayofweek.h:436
STREAM & streamOut(STREAM &stream, const bdlt::DayOfWeek::Enum &value, int version)
Definition bdlt_dayofweek.h:440
Definition bdlt_dayofweek.h:449
int maxSupportedVersion(bdlt::DayOfWeek::Enum)
Definition bdlt_dayofweek.h:452
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:132
static int maxSupportedBdexVersion()
Definition bdlt_monthofyear.h:419
static const char * toAscii(MonthOfYear::Enum value)
Enum
Define the list of month-of-year values.
Definition bdlt_monthofyear.h:138
@ e_NOVEMBER
Definition bdlt_monthofyear.h:150
@ e_SEP
Definition bdlt_monthofyear.h:148
@ e_JANUARY
Definition bdlt_monthofyear.h:140
@ e_JUNE
Definition bdlt_monthofyear.h:145
@ e_MAY
Definition bdlt_monthofyear.h:144
@ e_MAR
Definition bdlt_monthofyear.h:142
@ e_JUL
Definition bdlt_monthofyear.h:146
@ BSLA_DEPRECATED
Definition bdlt_monthofyear.h:156
@ e_AUG
Definition bdlt_monthofyear.h:147
@ e_JAN
Definition bdlt_monthofyear.h:140
@ e_OCT
Definition bdlt_monthofyear.h:149
@ e_NOV
Definition bdlt_monthofyear.h:150
@ e_APRIL
Definition bdlt_monthofyear.h:143
@ e_OCTOBER
Definition bdlt_monthofyear.h:149
@ e_DECEMBER
Definition bdlt_monthofyear.h:151
@ e_MARCH
Definition bdlt_monthofyear.h:142
@ e_JUN
Definition bdlt_monthofyear.h:145
@ e_FEB
Definition bdlt_monthofyear.h:141
@ e_FEBRUARY
Definition bdlt_monthofyear.h:141
@ e_APR
Definition bdlt_monthofyear.h:143
@ e_SEPTEMBER
Definition bdlt_monthofyear.h:148
@ e_AUGUST
Definition bdlt_monthofyear.h:147
@ e_JULY
Definition bdlt_monthofyear.h:146
@ e_DEC
Definition bdlt_monthofyear.h:151
static STREAM & bdexStreamOut(STREAM &stream, MonthOfYear::Enum value, int version)
Definition bdlt_monthofyear.h:393
@ k_NUM_MONTHS
Definition bdlt_monthofyear.h:193
@ LENGTH
Definition bdlt_monthofyear.h:196
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:204