BDE 4.14.0 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 .
117struct DayOfWeek {
118
119 public:
120 // TYPES
121
122 /// Enumerated day-of-week values.
123 enum Enum {
124
132
133#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
148
149#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
150#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
158#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
159 };
160
161#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
162 typedef Enum Day;
163#endif
164
165 // CLASS METHODS
166
167 /// Assign to the specified `variable` the value read from the specified
168 /// input `stream` using the specified `version` format, and return a
169 /// reference to `stream`. If `stream` is initially invalid, this
170 /// operation has no effect. If `version` is not supported, `variable`
171 /// is unaltered and `stream` is invalidated, but otherwise unmodified.
172 /// If `version` is supported but `stream` becomes invalid during this
173 /// operation, `variable` has an undefined, but valid, state. Note that
174 /// no version is read from `stream`. See the `bslx` package-level
175 /// documentation for more information on BDEX streaming of
176 /// value-semantic types and containers.
177 template <class STREAM>
178 static STREAM& bdexStreamIn(STREAM& stream,
179 DayOfWeek::Enum& variable,
180 int version);
181
182 /// Write the value of the specified `value`, using the specified
183 /// `version` format, to the specified output `stream`, and return a
184 /// reference to `stream`. If `stream` is initially invalid, this
185 /// operation has no effect. If `version` is not supported, `stream` is
186 /// invalidated, but otherwise unmodified. Note that `version` is not
187 /// written to `stream`. See the `bslx` package-level documentation for
188 /// more information on BDEX streaming of value-semantic types and
189 /// containers.
190 template <class STREAM>
191 static STREAM& bdexStreamOut(STREAM& stream,
192 DayOfWeek::Enum value,
193 int version);
194
195 /// Return the maximum valid BDEX format version, as indicated by the
196 /// specified `versionSelector`, to be passed to the `bdexStreamOut`
197 /// method. Note that it is highly recommended that `versionSelector`
198 /// be formatted as "YYYYMMDD", a date representation. Also note that
199 /// `versionSelector` should be a *compile*-time-chosen value that
200 /// selects a format version supported by both externalizer and
201 /// unexternalizer. See the `bslx` package-level documentation for more
202 /// information on BDEX streaming of value-semantic types and
203 /// containers.
204 static int maxSupportedBdexVersion(int versionSelector);
205
206 /// Write the string representation of the specified enumeration `value`
207 /// to the specified output `stream`, and return a reference to
208 /// `stream`. Optionally specify an initial indentation `level`, whose
209 /// absolute value is incremented recursively for nested objects. If
210 /// `level` is specified, optionally specify `spacesPerLevel`, whose
211 /// absolute value indicates the number of spaces per indentation level
212 /// for this and all of its nested objects. If `level` is negative,
213 /// suppress indentation of the first line. If `spacesPerLevel` is
214 /// negative, format the entire output on one line, suppressing all but
215 /// the initial indentation (as governed by `level`). The behavior is
216 /// undefined unless `dayOfWeek` is in the range `[ e_SUN .. e_SAT ]`.
217 /// See `toAscii` for what constitutes the string representation of a
218 /// `bdlt::DayOfWeek::Enum` value.
219 static bsl::ostream& print(bsl::ostream& stream,
220 DayOfWeek::Enum value,
221 int level = 0,
222 int spacesPerLevel = 4);
223
224 /// Return the abbreviated character-string representation of the
225 /// enumerator corresponding to the specified `dayOfWeek`. This
226 /// representation matches the enumerator's three-character name (e.g.,
227 /// `e_SUN`) with the "e_" prefix elided. For example:
228 /// @code
229 /// bsl::cout << bdlt::DayOfWeek::toAscii(bdlt::DayOfWeek::e_SUN);
230 /// @endcode
231 /// prints the following on standard output:
232 /// @code
233 /// SUN
234 /// @endcode
235 /// Note that specifying a `dayOfWeek` that does not match any of the
236 /// enumerators will result in an unspecified string representation
237 /// being returned that is distinct from the values returned for any
238 /// valid enumeration.
239 static const char *toAscii(Enum dayOfWeek);
240
241#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
242
243 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
244 ///
245 /// Return the most current BDEX streaming version number supported by
246 /// this struct.
247 static int maxSupportedBdexVersion();
248
249#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
250};
251
252// FREE OPERATORS
253
254/// Write the string representation of the specified enumeration `value` to
255/// the specified output `stream` in a single-line format, and return a
256/// reference to `stream`. See `toAscii` for what constitutes the string
257/// representation of a `bdlt::DayOfWeek::Enum` value. Note that this
258/// method has the same behavior as
259/// @code
260/// bdlt::DayOfWeek::print(stream, value, 0, -1);
261/// @endcode
262bsl::ostream& operator<<(bsl::ostream& stream, DayOfWeek::Enum value);
263
264// FREE FUNCTIONS
265
266/// Load into the specified `variable` the `DayOfWeek::Enum` value read from
267/// the specified input `stream` using the specified `version` format, and
268/// return a reference to `stream`. If `stream` is initially invalid, this
269/// operation has no effect. If `version` is not supported by `DayOfWeek`,
270/// `variable` is unaltered and `stream` is invalidated, but otherwise
271/// unmodified. If `version` is supported by `DayOfWeek` but `stream`
272/// becomes invalid during this operation, `variable` has an undefined, but
273/// valid, state. The behavior is undefined unless `STREAM` is
274/// BDEX-compliant. Note that no version is read from `stream`. See the
275/// `bslx` package-level documentation for more information on BDEX
276/// streaming of value-semantic types and containers.
277template <class STREAM>
278STREAM& bdexStreamIn(STREAM& stream, DayOfWeek::Enum& variable, int version);
279
280/// Write the specified `value`, using the specified `version` format, to
281/// the specified output `stream`, and return a reference to `stream`. If
282/// `stream` is initially invalid, this operation has no effect. If
283/// `version` is not supported by `DayOfWeek`, `stream` is invalidated, but
284/// otherwise unmodified. The behavior is undefined unless `STREAM` is
285/// BDEX-compliant. Note that `version` is not written to `stream`. See
286/// the `bslx` package-level documentation for more information on BDEX
287/// streaming of value-semantic types and containers.
288template <class STREAM>
289STREAM& bdexStreamOut(STREAM& stream,
290 const DayOfWeek::Enum& value,
291 int version);
292
293/// Return the maximum valid BDEX format version, as indicated by the
294/// specified `versionSelector`, to be passed to the `bdexStreamOut` method
295/// while streaming an object of the type `DayOfWeek::Enum`. Note that it
296/// is highly recommended that `versionSelector` be formatted as "YYYYMMDD",
297/// a date representation. Also note that `versionSelector` should be a
298/// *compile*-time-chosen value that selects a format version supported by
299/// both externalizer and unexternalizer. See the `bslx` package-level
300/// documentation for more information on BDEX streaming of value-semantic
301/// types and containers.
302int maxSupportedBdexVersion(const DayOfWeek::Enum *, int versionSelector);
303
304// ============================================================================
305// INLINE DEFINITIONS
306// ============================================================================
307
308 // ---------------
309 // class DayOfWeek
310 // ---------------
311
312// CLASS METHODS
313template <class STREAM>
314STREAM& DayOfWeek::bdexStreamIn(STREAM& stream,
315 DayOfWeek::Enum& variable,
316 int version)
317{
318 if (stream) {
319 switch (version) { // switch on the schema version
320 case 1: {
321 char newValue;
322 stream.getInt8(newValue);
323 if (stream && e_SUN <= newValue && e_SAT >= newValue) {
324 variable = static_cast<DayOfWeek::Enum>(newValue);
325 }
326 else {
327 stream.invalidate();
328 }
329 } break;
330 default: {
331 stream.invalidate(); // unrecognized version number
332 }
333 }
334 }
335 return stream;
336}
337
338template <class STREAM>
339STREAM& DayOfWeek::bdexStreamOut(STREAM& stream,
340 DayOfWeek::Enum value,
341 int version)
342{
343 if (stream) {
344 switch (version) { // switch on the schema version
345 case 1: {
346 stream.putInt8(static_cast<char>(value));
347 } break;
348 default: {
349 stream.invalidate(); // unrecognized version number
350 }
351 }
352 }
353 return stream;
354}
355
356inline
357int DayOfWeek::maxSupportedBdexVersion(int /* versionSelector */)
358{
359 return 1;
360}
361
362#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
363
364inline
369
370#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
371
372} // close package namespace
373
374// FREE OPERATORS
375inline
376bsl::ostream& bdlt::operator<<(bsl::ostream& stream,
378{
379 return bdlt::DayOfWeek::print(stream, value, 0, -1);
380}
381
382// FREE FUNCTIONS
383template <class STREAM>
384STREAM& bdlt::bdexStreamIn(STREAM& stream,
385 bdlt::DayOfWeek::Enum& variable,
386 int version)
387{
388 return bdlt::DayOfWeek::bdexStreamIn(stream, variable, version);
389}
390
391template <class STREAM>
392STREAM& bdlt::bdexStreamOut(STREAM& stream,
393 const bdlt::DayOfWeek::Enum& value,
394 int version)
395{
396 return bdlt::DayOfWeek::bdexStreamOut(stream, value, version);
397}
398
399inline
401 int versionSelector)
402{
403 return bdlt::DayOfWeek::maxSupportedBdexVersion(versionSelector);
404}
405
406#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
407
408// BDEX STREAMING SUPPORT
409
411
412template <class STREAM>
413inline
414STREAM& streamIn(STREAM& stream,
415 bdlt::DayOfWeek::Enum& variable,
416 int version)
417{
418 return bdlt::DayOfWeek::bdexStreamIn(stream, variable, version);
419}
420
421} // close namespace bdex_InStreamFunctions
422
424
425template <class STREAM>
426inline
427STREAM& streamOut(STREAM& stream,
428 const bdlt::DayOfWeek::Enum& value,
429 int version)
430{
431 return bdlt::DayOfWeek::bdexStreamOut(stream, value, version);
432}
433
434} // close namespace bdex_OutStreamFunctions
435
437
438inline
443
444} // close namespace bdex_VersionFunctions
445
446#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
447
448
449
450#endif
451
452// ----------------------------------------------------------------------------
453// Copyright 2014 Bloomberg Finance L.P.
454//
455// Licensed under the Apache License, Version 2.0 (the "License");
456// you may not use this file except in compliance with the License.
457// You may obtain a copy of the License at
458//
459// http://www.apache.org/licenses/LICENSE-2.0
460//
461// Unless required by applicable law or agreed to in writing, software
462// distributed under the License is distributed on an "AS IS" BASIS,
463// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
464// See the License for the specific language governing permissions and
465// limitations under the License.
466// ----------------------------- END-OF-FILE ----------------------------------
467
468/** @} */
469/** @} */
470/** @} */
#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_dayofweek.h:117
Enum
Enumerated day-of-week values.
Definition bdlt_dayofweek.h:123
@ THURSDAY
Definition bdlt_dayofweek.h:145
@ e_MONDAY
Definition bdlt_dayofweek.h:126
@ e_SUN
Definition bdlt_dayofweek.h:125
@ e_FRI
Definition bdlt_dayofweek.h:130
@ SUN
Definition bdlt_dayofweek.h:134
@ BDET_THU
Definition bdlt_dayofweek.h:155
@ e_TUE
Definition bdlt_dayofweek.h:127
@ MON
Definition bdlt_dayofweek.h:135
@ BDET_SUN
Definition bdlt_dayofweek.h:151
@ BDET_MON
Definition bdlt_dayofweek.h:152
@ SAT
Definition bdlt_dayofweek.h:140
@ BDET_WED
Definition bdlt_dayofweek.h:154
@ TUESDAY
Definition bdlt_dayofweek.h:143
@ BDET_THURSDAY
Definition bdlt_dayofweek.h:155
@ BDET_TUE
Definition bdlt_dayofweek.h:153
@ TUE
Definition bdlt_dayofweek.h:136
@ e_FRIDAY
Definition bdlt_dayofweek.h:130
@ e_THURSDAY
Definition bdlt_dayofweek.h:129
@ e_WED
Definition bdlt_dayofweek.h:128
@ FRI
Definition bdlt_dayofweek.h:139
@ e_MON
Definition bdlt_dayofweek.h:126
@ BDET_MONDAY
Definition bdlt_dayofweek.h:152
@ BDET_SUNDAY
Definition bdlt_dayofweek.h:151
@ MONDAY
Definition bdlt_dayofweek.h:142
@ WEDNESDAY
Definition bdlt_dayofweek.h:144
@ SATURDAY
Definition bdlt_dayofweek.h:147
@ BDET_SATURDAY
Definition bdlt_dayofweek.h:157
@ e_WEDNESDAY
Definition bdlt_dayofweek.h:128
@ SUNDAY
Definition bdlt_dayofweek.h:141
@ e_SAT
Definition bdlt_dayofweek.h:131
@ e_THU
Definition bdlt_dayofweek.h:129
@ FRIDAY
Definition bdlt_dayofweek.h:146
@ BDET_FRI
Definition bdlt_dayofweek.h:156
@ e_SUNDAY
Definition bdlt_dayofweek.h:125
@ BDET_TUESDAY
Definition bdlt_dayofweek.h:153
@ WED
Definition bdlt_dayofweek.h:137
@ THU
Definition bdlt_dayofweek.h:138
@ BDET_FRIDAY
Definition bdlt_dayofweek.h:156
@ BDET_SAT
Definition bdlt_dayofweek.h:157
@ BDET_WEDNESDAY
Definition bdlt_dayofweek.h:154
@ e_SATURDAY
Definition bdlt_dayofweek.h:131
@ e_TUESDAY
Definition bdlt_dayofweek.h:127
static int maxSupportedBdexVersion()
Definition bdlt_dayofweek.h:365
static STREAM & bdexStreamIn(STREAM &stream, DayOfWeek::Enum &variable, int version)
Definition bdlt_dayofweek.h:314
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:339
Enum Day
Definition bdlt_dayofweek.h:162