BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlt_dayofweek.h
Go to the documentation of this file.
1/// @file bdlt_dayofweek.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlt_dayofweek.h -*-C++-*-
8#ifndef INCLUDED_BDLT_DAYOFWEEK
9#define INCLUDED_BDLT_DAYOFWEEK
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlt_dayofweek bdlt_dayofweek
15/// @brief Provide an enumeration of the set of days of the week.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlt
19/// @{
20/// @addtogroup bdlt_dayofweek
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlt_dayofweek-purpose"> Purpose</a>
25/// * <a href="#bdlt_dayofweek-classes"> Classes </a>
26/// * <a href="#bdlt_dayofweek-description"> Description </a>
27/// * <a href="#bdlt_dayofweek-enumerators"> Enumerators </a>
28/// * <a href="#bdlt_dayofweek-usage"> Usage </a>
29/// * <a href="#bdlt_dayofweek-example-1-basic-syntax"> Example 1: Basic Syntax </a>
30///
31/// # Purpose {#bdlt_dayofweek-purpose}
32/// Provide an enumeration of the set of days of the week.
33///
34/// # Classes {#bdlt_dayofweek-classes}
35///
36/// - bdlt::DayOfWeek: namespace for day-of-week enumeration (and its operations)
37///
38/// # Description {#bdlt_dayofweek-description}
39/// This component provides a namespace for the `enum` type
40/// `bdlt::DayOfWeek::Enum`, which enumerates the set of days of the week.
41///
42/// ## Enumerators {#bdlt_dayofweek-enumerators}
43///
44///
45/// @code
46/// Long Name Short Name Description
47/// ----------- ---------- -----------
48/// e_SUNDAY e_SUN Sunday
49/// e_MONDAY e_MON Monday
50/// e_TUESDAY e_TUE Tuesday
51/// e_WEDNESDAY e_WED Wednesday
52/// e_THURSDAY e_THU Thursday
53/// e_FRIDAY e_FRI Friday
54/// e_SATURDAY e_SAT Saturday
55/// @endcode
56///
57/// ## Usage {#bdlt_dayofweek-usage}
58///
59///
60/// This section illustrates intended use of this component.
61///
62/// ### Example 1: Basic Syntax {#bdlt_dayofweek-example-1-basic-syntax}
63///
64///
65/// The following snippets of code provide a simple illustration of
66/// `bdlt::DayOfWeek` operation.
67///
68/// First, create a variable, `day`, of type `bdlt::DayOfWeek::Enum`, and
69/// initialize it to the value `bdlt::DayOfWeek::e_MONDAY`:
70/// @code
71/// bdlt::DayOfWeek::Enum day = bdlt::DayOfWeek::e_MONDAY;
72/// @endcode
73/// Next, store its representation in a variable, `rep`, of type `const char *`:
74/// @code
75/// const char *rep = bdlt::DayOfWeek::toAscii(day);
76/// assert(0 == bsl::strcmp(rep, "MON"));
77/// @endcode
78/// Finally, we print the value of `day` to `stdout`:
79/// @code
80/// bsl::cout << day << bsl::endl;
81/// @endcode
82/// This statement produces the following output on `stdout`:
83/// @code
84/// MON
85/// @endcode
86/// @}
87/** @} */
88/** @} */
89
90/** @addtogroup bdl
91 * @{
92 */
93/** @addtogroup bdlt
94 * @{
95 */
96/** @addtogroup bdlt_dayofweek
97 * @{
98 */
99
100#include <bdlscm_version.h>
101
102#include <bsl_ostream.h>
103
104
105namespace bdlt {
106
107 // ===============
108 // class DayOfWeek
109 // ===============
110
111/// This `struct` provides a namespace for enumerating day-of-week values.
112/// See `Enum` in the TYPES sub-section for details.
113///
114/// This `struct`:
115/// * supports a complete set of *enumeration* operations
116/// For terminology see @ref bsldoc_glossary .
117///
118/// See @ref bdlt_dayofweek
119struct DayOfWeek {
120
121 public:
122 // TYPES
123
124 /// Enumerated day-of-week values.
125 enum Enum {
126
134
135#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
150
151#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
152#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
160#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
161 };
162
163#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
164 typedef Enum Day;
165#endif
166
167 // CLASS METHODS
168
169 /// Assign to the specified `variable` the value read from the specified
170 /// input `stream` using the specified `version` format, and return a
171 /// reference to `stream`. If `stream` is initially invalid, this
172 /// operation has no effect. If `version` is not supported, `variable`
173 /// is unaltered and `stream` is invalidated, but otherwise unmodified.
174 /// If `version` is supported but `stream` becomes invalid during this
175 /// operation, `variable` has an undefined, but valid, state.
176 ///
177 /// \note Note that no version is read from `stream`. See the `bslx` package-level
178 /// documentation for more information on BDEX streaming of
179 /// value-semantic types and containers.
180 template <class STREAM>
181 static STREAM& bdexStreamIn(STREAM& stream,
182 DayOfWeek::Enum& variable,
183 int version);
184
185 /// Write the value of the specified `value`, using the specified
186 /// `version` format, to the specified output `stream`, and return a
187 /// reference to `stream`. If `stream` is initially invalid, this
188 /// operation has no effect. If `version` is not supported, `stream` is invalidated, but otherwise unmodified.
189 ///
190 /// \note Note that `version` is not
191 /// written to `stream`. See the `bslx` package-level documentation for
192 /// more information on BDEX streaming of value-semantic types and
193 /// containers.
194 template <class STREAM>
195 static STREAM& bdexStreamOut(STREAM& stream,
196 DayOfWeek::Enum value,
197 int version);
198
199 /// Return the maximum valid BDEX format version, as indicated by the
200 /// specified `versionSelector`, to be passed to the `bdexStreamOut` method.
201 ///
202 /// \note Note that it is highly recommended that `versionSelector`
203 /// be formatted as "YYYYMMDD", a date representation. Also note that
204 /// `versionSelector` should be a *compile*-time-chosen value that
205 /// selects a format version supported by both externalizer and
206 /// unexternalizer. See the `bslx` package-level documentation for more
207 /// information on BDEX streaming of value-semantic types and
208 /// containers.
209 static int maxSupportedBdexVersion(int versionSelector);
210
211 /// Write the string representation of the specified enumeration `value`
212 /// to the specified output `stream`, and return a reference to
213 /// `stream`. Optionally specify an initial indentation `level`, whose
214 /// absolute value is incremented recursively for nested objects. If
215 /// `level` is specified, optionally specify `spacesPerLevel`, whose
216 /// absolute value indicates the number of spaces per indentation level
217 /// for this and all of its nested objects. If `level` is negative,
218 /// suppress indentation of the first line. If `spacesPerLevel` is
219 /// negative, format the entire output on one line, suppressing all but
220 /// the initial indentation (as governed by `level`).
221 ///
222 /// \pre The behavior is undefined unless `dayOfWeek` is in the range `[ e_SUN .. e_SAT ]`.
223 /// See `toAscii` for what constitutes the string representation of a
224 /// `bdlt::DayOfWeek::Enum` value.
225 static bsl::ostream& print(bsl::ostream& stream,
226 DayOfWeek::Enum value,
227 int level = 0,
228 int spacesPerLevel = 4);
229
230 /// Return the abbreviated character-string representation of the
231 /// enumerator corresponding to the specified `dayOfWeek`. This
232 /// representation matches the enumerator's three-character name (e.g.,
233 /// `e_SUN`) with the "e_" prefix elided. For example:
234 /// @code
235 /// bsl::cout << bdlt::DayOfWeek::toAscii(bdlt::DayOfWeek::e_SUN);
236 /// @endcode
237 /// prints the following on standard output:
238 /// @code
239 /// SUN
240 /// @endcode
241 ///
242 /// \note Note that specifying a `dayOfWeek` that does not match any of the
243 /// enumerators will result in an unspecified string representation
244 /// being returned that is distinct from the values returned for any
245 /// valid enumeration.
246 static const char *toAscii(Enum dayOfWeek);
247
248#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
249
250 /// Return the most current BDEX streaming version number supported by
251 /// this struct.
252 ///
253 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
254 static int maxSupportedBdexVersion();
255
256#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
257};
258
259// FREE OPERATORS
260
261/// Write the string representation of the specified enumeration `value` to
262/// the specified output `stream` in a single-line format, and return a
263/// reference to `stream`. See `toAscii` for what constitutes the string representation of a `bdlt::DayOfWeek::Enum` value.
264///
265/// \note Note that this
266/// method has the same behavior as
267/// @code
268/// bdlt::DayOfWeek::print(stream, value, 0, -1);
269/// @endcode
270bsl::ostream& operator<<(bsl::ostream& stream, DayOfWeek::Enum value);
271
272// FREE FUNCTIONS
273
274/// Load into the specified `variable` the `DayOfWeek::Enum` value read from
275/// the specified input `stream` using the specified `version` format, and
276/// return a reference to `stream`. If `stream` is initially invalid, this
277/// operation has no effect. If `version` is not supported by `DayOfWeek`,
278/// `variable` is unaltered and `stream` is invalidated, but otherwise
279/// unmodified. If `version` is supported by `DayOfWeek` but `stream`
280/// becomes invalid during this operation, `variable` has an undefined, but valid, state.
281///
282/// \pre The behavior is undefined unless `STREAM` is BDEX-compliant.
283///
284/// \note Note that no version is read from `stream`. See the
285/// `bslx` package-level documentation for more information on BDEX
286/// streaming of value-semantic types and containers.
287template <class STREAM>
288STREAM& bdexStreamIn(STREAM& stream, DayOfWeek::Enum& variable, int version);
289
290/// Write the specified `value`, using the specified `version` format, to
291/// the specified output `stream`, and return a reference to `stream`. If
292/// `stream` is initially invalid, this operation has no effect. If
293/// `version` is not supported by `DayOfWeek`, `stream` is invalidated, but otherwise unmodified.
294///
295/// \pre The behavior is undefined unless `STREAM` is BDEX-compliant.
296///
297/// \note Note that `version` is not written to `stream`. See
298/// the `bslx` package-level documentation for more information on BDEX
299/// streaming of value-semantic types and containers.
300template <class STREAM>
301STREAM& bdexStreamOut(STREAM& stream,
302 const DayOfWeek::Enum& value,
303 int version);
304
305/// Return the maximum valid BDEX format version, as indicated by the
306/// specified `versionSelector`, to be passed to the `bdexStreamOut` method while streaming an object of the type `DayOfWeek::Enum`.
307///
308/// \note Note that it
309/// is highly recommended that `versionSelector` be formatted as "YYYYMMDD",
310/// a date representation. Also note that `versionSelector` should be a
311/// *compile*-time-chosen value that selects a format version supported by
312/// both externalizer and unexternalizer. See the `bslx` package-level
313/// documentation for more information on BDEX streaming of value-semantic
314/// types and containers.
315int maxSupportedBdexVersion(const DayOfWeek::Enum *, int versionSelector);
316
317// ============================================================================
318// INLINE DEFINITIONS
319// ============================================================================
320
321 // ---------------
322 // class DayOfWeek
323 // ---------------
324
325// CLASS METHODS
326template <class STREAM>
327STREAM& DayOfWeek::bdexStreamIn(STREAM& stream,
328 DayOfWeek::Enum& variable,
329 int version)
330{
331 if (stream) {
332 switch (version) { // switch on the schema version
333 case 1: {
334 char newValue;
335 stream.getInt8(newValue);
336 if (stream && e_SUN <= newValue && e_SAT >= newValue) {
337 variable = static_cast<DayOfWeek::Enum>(newValue);
338 }
339 else {
340 stream.invalidate();
341 }
342 } break;
343 default: {
344 stream.invalidate(); // unrecognized version number
345 }
346 }
347 }
348 return stream;
349}
350
351template <class STREAM>
352STREAM& DayOfWeek::bdexStreamOut(STREAM& stream,
353 DayOfWeek::Enum value,
354 int version)
355{
356 if (stream) {
357 switch (version) { // switch on the schema version
358 case 1: {
359 stream.putInt8(static_cast<char>(value));
360 } break;
361 default: {
362 stream.invalidate(); // unrecognized version number
363 }
364 }
365 }
366 return stream;
367}
368
369inline
370int DayOfWeek::maxSupportedBdexVersion(int /* versionSelector */)
371{
372 return 1;
373}
374
375#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
376
377inline
382
383#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
384
385} // close package namespace
386
387// FREE OPERATORS
388inline
389bsl::ostream& bdlt::operator<<(bsl::ostream& stream,
391{
392 return bdlt::DayOfWeek::print(stream, value, 0, -1);
393}
394
395// FREE FUNCTIONS
396template <class STREAM>
397STREAM& bdlt::bdexStreamIn(STREAM& stream,
398 bdlt::DayOfWeek::Enum& variable,
399 int version)
400{
401 return bdlt::DayOfWeek::bdexStreamIn(stream, variable, version);
402}
403
404template <class STREAM>
405STREAM& bdlt::bdexStreamOut(STREAM& stream,
406 const bdlt::DayOfWeek::Enum& value,
407 int version)
408{
409 return bdlt::DayOfWeek::bdexStreamOut(stream, value, version);
410}
411
412inline
414 int versionSelector)
415{
416 return bdlt::DayOfWeek::maxSupportedBdexVersion(versionSelector);
417}
418
419#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
420
421// BDEX STREAMING SUPPORT
422
424
425template <class STREAM>
426inline
427STREAM& streamIn(STREAM& stream,
428 bdlt::DayOfWeek::Enum& variable,
429 int version)
430{
431 return bdlt::DayOfWeek::bdexStreamIn(stream, variable, version);
432}
433
434} // close namespace bdex_InStreamFunctions
435
437
438template <class STREAM>
439inline
440STREAM& streamOut(STREAM& stream,
441 const bdlt::DayOfWeek::Enum& value,
442 int version)
443{
444 return bdlt::DayOfWeek::bdexStreamOut(stream, value, version);
445}
446
447} // close namespace bdex_OutStreamFunctions
448
450
451inline
456
457} // close namespace bdex_VersionFunctions
458
459#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
460
461
462
463#endif
464
465// ----------------------------------------------------------------------------
466// Copyright 2014 Bloomberg Finance L.P.
467//
468// Licensed under the Apache License, Version 2.0 (the "License");
469// you may not use this file except in compliance with the License.
470// You may obtain a copy of the License at
471//
472// http://www.apache.org/licenses/LICENSE-2.0
473//
474// Unless required by applicable law or agreed to in writing, software
475// distributed under the License is distributed on an "AS IS" BASIS,
476// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
477// See the License for the specific language governing permissions and
478// limitations under the License.
479// ----------------------------- END-OF-FILE ----------------------------------
480
481/** @} */
482/** @} */
483/** @} */
#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_dayofweek.h:119
Enum
Enumerated day-of-week values.
Definition bdlt_dayofweek.h:125
@ THURSDAY
Definition bdlt_dayofweek.h:147
@ e_MONDAY
Definition bdlt_dayofweek.h:128
@ e_SUN
Definition bdlt_dayofweek.h:127
@ e_FRI
Definition bdlt_dayofweek.h:132
@ SUN
Definition bdlt_dayofweek.h:136
@ BDET_THU
Definition bdlt_dayofweek.h:157
@ e_TUE
Definition bdlt_dayofweek.h:129
@ MON
Definition bdlt_dayofweek.h:137
@ BDET_SUN
Definition bdlt_dayofweek.h:153
@ BDET_MON
Definition bdlt_dayofweek.h:154
@ SAT
Definition bdlt_dayofweek.h:142
@ BDET_WED
Definition bdlt_dayofweek.h:156
@ TUESDAY
Definition bdlt_dayofweek.h:145
@ BDET_THURSDAY
Definition bdlt_dayofweek.h:157
@ BDET_TUE
Definition bdlt_dayofweek.h:155
@ TUE
Definition bdlt_dayofweek.h:138
@ e_FRIDAY
Definition bdlt_dayofweek.h:132
@ e_THURSDAY
Definition bdlt_dayofweek.h:131
@ e_WED
Definition bdlt_dayofweek.h:130
@ FRI
Definition bdlt_dayofweek.h:141
@ e_MON
Definition bdlt_dayofweek.h:128
@ BDET_SUNDAY
Definition bdlt_dayofweek.h:153
@ MONDAY
Definition bdlt_dayofweek.h:144
@ WEDNESDAY
Definition bdlt_dayofweek.h:146
@ SATURDAY
Definition bdlt_dayofweek.h:149
@ BDET_SATURDAY
Definition bdlt_dayofweek.h:159
@ e_WEDNESDAY
Definition bdlt_dayofweek.h:130
@ SUNDAY
Definition bdlt_dayofweek.h:143
@ e_SAT
Definition bdlt_dayofweek.h:133
@ e_THU
Definition bdlt_dayofweek.h:131
@ FRIDAY
Definition bdlt_dayofweek.h:148
@ BDET_FRI
Definition bdlt_dayofweek.h:158
@ e_SUNDAY
Definition bdlt_dayofweek.h:127
@ BDET_TUESDAY
Definition bdlt_dayofweek.h:155
@ WED
Definition bdlt_dayofweek.h:139
@ THU
Definition bdlt_dayofweek.h:140
@ BDET_FRIDAY
Definition bdlt_dayofweek.h:158
@ BDET_SAT
Definition bdlt_dayofweek.h:159
@ e_SATURDAY
Definition bdlt_dayofweek.h:133
@ e_TUESDAY
Definition bdlt_dayofweek.h:129
static int maxSupportedBdexVersion()
Definition bdlt_dayofweek.h:378
static STREAM & bdexStreamIn(STREAM &stream, DayOfWeek::Enum &variable, int version)
Definition bdlt_dayofweek.h:327
static const char * toAscii(Enum dayOfWeek)
static bsl::ostream & print(bsl::ostream &stream, DayOfWeek::Enum value, int level=0, int spacesPerLevel=4)
static STREAM & bdexStreamOut(STREAM &stream, DayOfWeek::Enum value, int version)
Definition bdlt_dayofweek.h:352
Enum Day
Definition bdlt_dayofweek.h:164