BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bbldc_daycountconvention.h
Go to the documentation of this file.
1/// @file bbldc_daycountconvention.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bbldc_daycountconvention.h -*-C++-*-
8#ifndef INCLUDED_BBLDC_DAYCOUNTCONVENTION
9#define INCLUDED_BBLDC_DAYCOUNTCONVENTION
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bbldc_daycountconvention bbldc_daycountconvention
15/// @brief Provide an enumeration of `bbldc` day-count conventions.
16/// @addtogroup bbl
17/// @{
18/// @addtogroup bbldc
19/// @{
20/// @addtogroup bbldc_daycountconvention
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bbldc_daycountconvention-purpose"> Purpose</a>
25/// * <a href="#bbldc_daycountconvention-classes"> Classes </a>
26/// * <a href="#bbldc_daycountconvention-description"> Description </a>
27/// * <a href="#bbldc_daycountconvention-enumerators"> Enumerators </a>
28/// * <a href="#bbldc_daycountconvention-usage"> Usage </a>
29/// * <a href="#bbldc_daycountconvention-example-1-basic-syntax"> Example 1: Basic Syntax </a>
30///
31/// # Purpose {#bbldc_daycountconvention-purpose}
32/// Provide an enumeration of `bbldc` day-count conventions.
33///
34/// # Classes {#bbldc_daycountconvention-classes}
35///
36/// - bbldc::DayCountConvention: namespace for day-count convention enumeration
37///
38/// # Description {#bbldc_daycountconvention-description}
39/// This component provides a namespace,
40/// `bbldc::DayCountConvention`, for the `enum` type
41/// `bbldc::DayCountConvention::Enum`, that enumerates the list of day-count
42/// conventions supported by the `bbldc` package.
43///
44/// ## Enumerators {#bbldc_daycountconvention-enumerators}
45///
46///
47/// @code
48/// Name Description
49/// --------------------------- ----------------------------------------------
50/// e_ACTUAL_360 Convention is Actual/360.
51/// e_ACTUAL_365_25 Convention is Actual/365.25.
52/// e_ACTUAL_365_FIXED Convention is Actual/365 (fixed).
53/// e_ISDA_ACTUAL_ACTUAL Convention is ISDA Actual/Actual.
54/// e_ISMA_30_360 Convention is ISMA 30/360.
55/// e_PSA_30_360_EOM Convention is PSA 30/360 end-of-month.
56/// e_SIA_30_360_EOM Convention is SIA 30/360 end-of-month.
57/// e_SIA_30_360_NEOM Convention is SIA 30/360 no-end-of-month.
58/// e_PERIOD_ICMA_ACTUAL_ACTUAL Convention is period-based ICMA Actual/Actual.
59/// e_CALENDAR_BUS_252 Convention is calendar-based BUS-252.
60/// e_ISDA_30_360_EOM Convention is ISDA 30/360 end-of-month.
61/// e_NL_365 Convention is NL/365.
62/// e_ISDA_1_1 Convention is ISDA 1/1.
63/// @endcode
64///
65/// ## Usage {#bbldc_daycountconvention-usage}
66///
67///
68/// This section illustrates intended use of this component.
69///
70/// ### Example 1: Basic Syntax {#bbldc_daycountconvention-example-1-basic-syntax}
71///
72///
73/// The following snippets of code provide a simple illustration of using
74/// `bbldc::DayCountConvention`.
75///
76/// First, we create a variable `convention` of type
77/// `bbldc::DayCountConvention::Enum` and initialize it to the value
78/// `bbldc::DayCountConvention::e_ISMA_30_360`:
79/// @code
80/// bbldc::DayCountConvention::Enum convention =
81/// bbldc::DayCountConvention::e_ISMA_30_360;
82/// @endcode
83/// Now, we store the address of its ASCII representation in a pointer variable,
84/// `asciiValue`, of type `const char *`:
85/// @code
86/// const char *asciiValue = bbldc::DayCountConvention::toAscii(convention);
87/// assert(0 == bsl::strcmp(asciiValue, "ISMA_30_360"));
88/// @endcode
89/// Finally, we print `convention` to `bsl::cout`;
90/// @code
91/// bsl::cout << convention << bsl::endl;
92/// @endcode
93/// This statement produces the following output on `stdout`:
94/// @code
95/// ISMA_30_360
96/// @endcode
97/// @}
98/** @} */
99/** @} */
100
101/** @addtogroup bbl
102 * @{
103 */
104/** @addtogroup bbldc
105 * @{
106 */
107/** @addtogroup bbldc_daycountconvention
108 * @{
109 */
110
111#include <bblscm_version.h>
112
113#include <bsl_iosfwd.h>
114
115
116namespace bbldc {
117
118 // =========================
119 // struct DayCountConvention
120 // =========================
121
122/// This `struct` provides a namespace for enumerating the set of day-count
123/// conventions supported within `bbldc`. See `Enum` in the `TYPES`
124/// sub-section for details.
125///
126/// This `struct`:
127/// * supports a complete set of *enumeration* operations
128/// For terminology see @ref bsldoc_glossary .
129///
130/// See @ref bbldc_daycountconvention
132
133 // TYPES
178
179#ifndef BDE_OMIT_INTERNAL_DEPRECATED
180 typedef Enum Type;
181#endif // BDE_OMIT_INTERNAL_DEPRECATED
182
183 // CLASS METHODS
184
185 /// Assign to the specified `variable` the value read from the specified
186 /// input `stream` using the specified `version` format, and return a
187 /// reference to `stream`. If `stream` is initially invalid, this
188 /// operation has no effect. If `version` is not supported, `variable`
189 /// is unaltered and `stream` is invalidated, but otherwise unmodified.
190 /// If `version` is supported but `stream` becomes invalid during this
191 /// operation, `variable` has an undefined, but valid, state.
192 ///
193 /// \note Note that no version is read from `stream`. See the `bslx` package-level
194 /// documentation for more information on BDEX streaming of
195 /// value-semantic types and containers.
196 template <class STREAM>
197 static STREAM& bdexStreamIn(STREAM& stream,
198 DayCountConvention::Enum& variable,
199 int version);
200
201 /// Write the value of the specified `value`, using the specified
202 /// `version` format, to the specified output `stream`, and return a
203 /// reference to `stream`. If `stream` is initially invalid, this
204 /// operation has no effect. If `version` is not supported, `stream` is invalidated, but otherwise unmodified.
205 ///
206 /// \note Note that `version` is not
207 /// written to `stream`. See the `bslx` package-level documentation for
208 /// more information on BDEX streaming of value-semantic types and
209 /// containers.
210 template <class STREAM>
211 static STREAM& bdexStreamOut(STREAM& stream,
213 int version);
214
215 /// Return the maximum valid BDEX format version, as indicated by the
216 /// specified `versionSelector`, to be passed to the `bdexStreamOut` method.
217 ///
218 /// \note Note that it is highly recommended that `versionSelector`
219 /// be formatted as "YYYYMMDD", a date representation. Also note that
220 /// `versionSelector` should be a *compile*-time-chosen value that
221 /// selects a format version supported by both externalizer and
222 /// unexternalizer. See the `bslx` package-level documentation for more
223 /// information on BDEX streaming of value-semantic types and
224 /// containers.
225 static int maxSupportedBdexVersion(int versionSelector);
226
227 /// Write the string representation of the specified enumeration `value`
228 /// to the specified output `stream`, and return a reference to
229 /// `stream`. Optionally specify an initial indentation `level`, whose
230 /// absolute value is incremented recursively for nested objects. If
231 /// `level` is specified, optionally specify `spacesPerLevel`, whose
232 /// absolute value indicates the number of spaces per indentation level
233 /// for this and all of its nested objects. If `level` is negative,
234 /// suppress indentation of the first line. If `spacesPerLevel` is
235 /// negative, format the entire output on one line, suppressing all but
236 /// the initial indentation (as governed by `level`).
237 ///
238 /// \pre The behavior is undefined unless `value` is in the range
239 /// `[e_ACTUAL_360 .. e_ISDA_1_1]`. See `toAscii` for what constitutes the
240 /// string representation of a `bbldc::DayCountConvention::Enum` value.
241 static bsl::ostream& print(bsl::ostream& stream,
243 int level = 0,
244 int spacesPerLevel = 4);
245
246 /// Return the abbreviated character-string representation of the
247 /// enumerator corresponding to the specified `convention`. This
248 /// representation matches the enumerator's name (e.g., `e_ACTUAL_360`)
249 /// with the "e_" prefix elided. For example:
250 /// @code
251 /// bsl::cout << bbldc::DayCountConvention::toAscii(
252 /// bbldc::DayCountConvention::e_ACTUAL_360);
253 /// @endcode
254 /// prints the following on standard output:
255 /// @code
256 /// ACTUAL_360
257 /// @endcode
258 ///
259 /// \note Note that specifying a `convention` that does not match any of the
260 /// enumerators will result in an unspecified string representation
261 /// being returned that is distinct from the values returned for any
262 /// valid enumerator.
263 static const char *toAscii(Enum convention);
264
265#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
266
267 // DEPRECATED METHODS
268
269 /// Return the most current BDEX streaming version number supported by
270 /// this class.
271 ///
272 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
273 static int maxSupportedBdexVersion();
274
275#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
276};
277
278// FREE OPERATORS
279
280/// Write the string representation of the specified enumeration `value` to
281/// the specified output `stream` in a single-line format, and return a
282/// reference to `stream`. See `toAscii` for what constitutes the string
283/// representation of a `bbldc::DayCountConvention::Enum` value.
284///
285/// \note Note that this method has the same behavior as
286/// @code
287/// bbldc::DayCountConvention::print(stream, value, 0, -1);
288/// @endcode
289bsl::ostream& operator<<(bsl::ostream& stream,
291
292// FREE FUNCTIONS
293
294/// Load into the specified `variable` the `DayCountConvention::Enum` value
295/// read from the specified input `stream` using the specified `version`
296/// format, and return a reference to `stream`. If `stream` is initially
297/// invalid, this operation has no effect. If `version` is not supported by
298/// `DayCountConvention`, `variable` is unaltered and `stream` is
299/// invalidated, but otherwise unmodified. If `version` is supported by
300/// `DayCountConvention` but `stream` becomes invalid during this operation,
301/// `variable` has an undefined, but valid, state.
302///
303/// \pre The behavior is undefined unless `STREAM` is BDEX-compliant.
304/// \note Note that no version is
305/// read from `stream`. See the `bslx` package-level documentation for more
306/// information on BDEX streaming of value-semantic types and containers.
307template <class STREAM>
308STREAM& bdexStreamIn(STREAM& stream,
309 DayCountConvention::Enum& variable,
310 int version);
311
312/// Write the specified `value`, using the specified `version` format, to
313/// the specified output `stream`, and return a reference to `stream`. If
314/// `stream` is initially invalid, this operation has no effect. If
315/// `version` is not supported by `DayCountConvention`, `stream` is invalidated, but otherwise unmodified.
316///
317/// \pre The behavior is undefined unless `STREAM` is BDEX-compliant.
318///
319/// \note Note that `version` is not written to
320/// `stream`. See the `bslx` package-level documentation for more
321/// information on BDEX streaming of value-semantic types and containers.
322template <class STREAM>
323STREAM& bdexStreamOut(STREAM& stream,
324 const DayCountConvention::Enum& value,
325 int version);
326
327/// Return the maximum valid BDEX format version, as indicated by the
328/// specified `versionSelector`, to be passed to the `bdexStreamOut` method
329/// while streaming an object of the type `DayCountConvention::Enum`.
330///
331/// \note Note that it is highly recommended that `versionSelector` be formatted as
332/// "YYYYMMDD", a date representation. Also note that `versionSelector`
333/// should be a *compile*-time-chosen value that selects a format version
334/// supported by both externalizer and unexternalizer. See the `bslx`
335/// package-level documentation for more information on BDEX streaming of
336/// value-semantic types and containers.
338 int versionSelector);
339
340// ============================================================================
341// INLINE DEFINITIONS
342// ============================================================================
343
344 // -------------------------
345 // struct DayCountConvention
346 // -------------------------
347
348// CLASS METHODS
349template <class STREAM>
350STREAM& DayCountConvention::bdexStreamIn(STREAM& stream,
351 DayCountConvention::Enum& variable,
352 int version)
353{
354 if (stream) {
355 switch (version) { // switch on the schema version
356 case 1: {
357 char newValue;
358 stream.getInt8(newValue);
359 if ( stream
360 && e_ACTUAL_360 <= newValue
361 && e_ISDA_1_1 >= newValue) {
362 variable = static_cast<DayCountConvention::Enum>(newValue);
363 }
364 else {
365 stream.invalidate();
366 }
367 } break;
368 default: {
369 stream.invalidate(); // unrecognized version number
370 }
371 }
372 }
373 return stream;
374}
375
376template <class STREAM>
379 int version)
380{
381 if (stream) {
382 switch (version) { // switch on the schema version
383 case 1: {
384 stream.putInt8(static_cast<char>(value));
385 } break;
386 default: {
387 stream.invalidate(); // unrecognized version number
388 }
389 }
390 }
391 return stream;
392}
393
394inline
396{
397 return 1;
398}
399
400#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
401
402// DEPRECATED METHODS
403inline
408
409#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
410
411} // close package namespace
412
413// FREE OPERATORS
414inline
415bsl::ostream& bbldc::operator<<(bsl::ostream& stream,
417{
418 return bbldc::DayCountConvention::print(stream, value, 0, -1);
419}
420
421// FREE FUNCTIONS
422template <class STREAM>
423STREAM& bbldc::bdexStreamIn(STREAM& stream,
425 int version)
426{
427 return bbldc::DayCountConvention::bdexStreamIn(stream, variable, version);
428}
429
430template <class STREAM>
431STREAM& bbldc::bdexStreamOut(STREAM& stream,
433 int version)
434{
435 return bbldc::DayCountConvention::bdexStreamOut(stream, value, version);
436}
437
438inline
441 int versionSelector)
442{
444}
445
446
447
448#endif
449
450// ----------------------------------------------------------------------------
451// Copyright 2025 Bloomberg Finance L.P.
452//
453// Licensed under the Apache License, Version 2.0 (the "License");
454// you may not use this file except in compliance with the License.
455// You may obtain a copy of the License at
456//
457// http://www.apache.org/licenses/LICENSE-2.0
458//
459// Unless required by applicable law or agreed to in writing, software
460// distributed under the License is distributed on an "AS IS" BASIS,
461// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
462// See the License for the specific language governing permissions and
463// limitations under the License.
464// ----------------------------- END-OF-FILE ----------------------------------
465
466/** @} */
467/** @} */
468/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bbldc_basicactual360.h:107
STREAM & bdexStreamOut(STREAM &stream, const DayCountConvention::Enum &value, int version)
int maxSupportedBdexVersion(const DayCountConvention::Enum *, int versionSelector)
bsl::ostream & operator<<(bsl::ostream &stream, DayCountConvention::Enum value)
STREAM & bdexStreamIn(STREAM &stream, DayCountConvention::Enum &variable, int version)
Definition bbldc_daycountconvention.h:131
Enum Type
Definition bbldc_daycountconvention.h:180
static bsl::ostream & print(bsl::ostream &stream, DayCountConvention::Enum value, int level=0, int spacesPerLevel=4)
Enum
Definition bbldc_daycountconvention.h:134
@ e_SIA_30_360_EOM
Definition bbldc_daycountconvention.h:144
@ e_SIA_30_360_NEOM
Definition bbldc_daycountconvention.h:145
@ BBEDC_ISMA_30_360
Definition bbldc_daycountconvention.h:159
@ ICMA_ACTUAL_ACTUAL_NOT_IMPLEMENTED
Definition bbldc_daycountconvention.h:166
@ e_ISDA_ACTUAL_ACTUAL
Definition bbldc_daycountconvention.h:140
@ e_ISMA_30_360
Definition bbldc_daycountconvention.h:142
@ e_PSA_30_360_EOM
Definition bbldc_daycountconvention.h:143
@ BBEDC_ACTUAL_360
Definition bbldc_daycountconvention.h:154
@ BBEDC_ICMA_ACTUAL_ACTUAL_NOT_IMPLEMENTED
Definition bbldc_daycountconvention.h:156
@ e_CALENDAR_BUS_252
Definition bbldc_daycountconvention.h:147
@ BBEDC_ACTUAL_365_FIXED
Definition bbldc_daycountconvention.h:155
@ BBEDC_ISMA_ACTUAL_ACTUAL_NOT_IMPLEMENTED
Definition bbldc_daycountconvention.h:158
@ SIA_30_360_NEOM
Definition bbldc_daycountconvention.h:174
@ e_ISDA_1_1
Definition bbldc_daycountconvention.h:151
@ PSA_30_360_EOM
Definition bbldc_daycountconvention.h:172
@ e_ACTUAL_365_25
Definition bbldc_daycountconvention.h:150
@ BBEDC_SIA_30_360_EOM
Definition bbldc_daycountconvention.h:161
@ BBEDC_PSA_30_360_EOM
Definition bbldc_daycountconvention.h:160
@ e_NL_365
Definition bbldc_daycountconvention.h:149
@ BBEDC_SIA_30_360_NEOM
Definition bbldc_daycountconvention.h:162
@ e_ISDA_30_360_EOM
Definition bbldc_daycountconvention.h:148
@ ACTUAL_365_FIXED
Definition bbldc_daycountconvention.h:165
@ SIA_30_360_EOM
Definition bbldc_daycountconvention.h:173
@ e_ACTUAL_365_FIXED
Definition bbldc_daycountconvention.h:138
@ ISDA_ACTUAL_ACTUAL
Definition bbldc_daycountconvention.h:168
@ e_ACTUAL_360
Definition bbldc_daycountconvention.h:137
@ BBEDC_ISDA_ACTUAL_ACTUAL
Definition bbldc_daycountconvention.h:157
@ ACTUAL_360
Definition bbldc_daycountconvention.h:164
@ ISMA_30_360
Definition bbldc_daycountconvention.h:171
@ ISMA_ACTUAL_ACTUAL_NOT_IMPLEMENTED
Definition bbldc_daycountconvention.h:169
@ e_PERIOD_ICMA_ACTUAL_ACTUAL
Definition bbldc_daycountconvention.h:146
static STREAM & bdexStreamOut(STREAM &stream, DayCountConvention::Enum value, int version)
Definition bbldc_daycountconvention.h:377
static const char * toAscii(Enum convention)
static int maxSupportedBdexVersion()
Definition bbldc_daycountconvention.h:404
static STREAM & bdexStreamIn(STREAM &stream, DayCountConvention::Enum &variable, int version)
Definition bbldc_daycountconvention.h:350