BDE 4.14.0 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/// @endcode
63///
64/// ## Usage {#bbldc_daycountconvention-usage}
65///
66///
67/// This section illustrates intended use of this component.
68///
69/// ### Example 1: Basic Syntax {#bbldc_daycountconvention-example-1-basic-syntax}
70///
71///
72/// The following snippets of code provide a simple illustration of using
73/// `bbldc::DayCountConvention`.
74///
75/// First, we create a variable `convention` of type
76/// `bbldc::DayCountConvention::Enum` and initialize it to the value
77/// `bbldc::DayCountConvention::e_ISMA_30_360`:
78/// @code
79/// bbldc::DayCountConvention::Enum convention =
80/// bbldc::DayCountConvention::e_ISMA_30_360;
81/// @endcode
82/// Now, we store the address of its ASCII representation in a pointer variable,
83/// `asciiValue`, of type `const char *`:
84/// @code
85/// const char *asciiValue = bbldc::DayCountConvention::toAscii(convention);
86/// assert(0 == bsl::strcmp(asciiValue, "ISMA_30_360"));
87/// @endcode
88/// Finally, we print `convention` to `bsl::cout`;
89/// @code
90/// bsl::cout << convention << bsl::endl;
91/// @endcode
92/// This statement produces the following output on `stdout`:
93/// @code
94/// ISMA_30_360
95/// @endcode
96/// @}
97/** @} */
98/** @} */
99
100/** @addtogroup bbl
101 * @{
102 */
103/** @addtogroup bbldc
104 * @{
105 */
106/** @addtogroup bbldc_daycountconvention
107 * @{
108 */
109
110#include <bblscm_version.h>
111
112#include <bsl_iosfwd.h>
113
114
115namespace bbldc {
116
117 // =========================
118 // struct DayCountConvention
119 // =========================
120
121/// This `struct` provides a namespace for enumerating the set of day-count
122/// conventions supported within `bbldc`. See `Enum` in the `TYPES`
123/// 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 // TYPES
174
175#ifndef BDE_OMIT_INTERNAL_DEPRECATED
176 typedef Enum Type;
177#endif // BDE_OMIT_INTERNAL_DEPRECATED
178
179 // CLASS METHODS
180
181 /// Assign to the specified `variable` the value read from the specified
182 /// input `stream` using the specified `version` format, and return a
183 /// reference to `stream`. If `stream` is initially invalid, this
184 /// operation has no effect. If `version` is not supported, `variable`
185 /// is unaltered and `stream` is invalidated, but otherwise unmodified.
186 /// If `version` is supported but `stream` becomes invalid during this
187 /// operation, `variable` has an undefined, but valid, state. Note that
188 /// no version is read from `stream`. See the `bslx` package-level
189 /// documentation for more information on BDEX streaming of
190 /// value-semantic types and containers.
191 template <class STREAM>
192 static STREAM& bdexStreamIn(STREAM& stream,
193 DayCountConvention::Enum& variable,
194 int version);
195
196 /// Write the value of the specified `value`, using the specified
197 /// `version` format, to the specified output `stream`, and return a
198 /// reference to `stream`. If `stream` is initially invalid, this
199 /// operation has no effect. If `version` is not supported, `stream` is
200 /// invalidated, but otherwise unmodified. Note that `version` is not
201 /// written to `stream`. See the `bslx` package-level documentation for
202 /// more information on BDEX streaming of value-semantic types and
203 /// containers.
204 template <class STREAM>
205 static STREAM& bdexStreamOut(STREAM& stream,
207 int version);
208
209 /// Return the maximum valid BDEX format version, as indicated by the
210 /// specified `versionSelector`, to be passed to the `bdexStreamOut`
211 /// method. Note that it is highly recommended that `versionSelector`
212 /// be formatted as "YYYYMMDD", a date representation. Also note that
213 /// `versionSelector` should be a *compile*-time-chosen value that
214 /// selects a format version supported by both externalizer and
215 /// unexternalizer. See the `bslx` package-level documentation for more
216 /// information on BDEX streaming of value-semantic types and
217 /// containers.
218 static int maxSupportedBdexVersion(int versionSelector);
219
220 /// Write the string representation of the specified enumeration `value`
221 /// to the specified output `stream`, and return a reference to
222 /// `stream`. Optionally specify an initial indentation `level`, whose
223 /// absolute value is incremented recursively for nested objects. If
224 /// `level` is specified, optionally specify `spacesPerLevel`, whose
225 /// absolute value indicates the number of spaces per indentation level
226 /// for this and all of its nested objects. If `level` is negative,
227 /// suppress indentation of the first line. If `spacesPerLevel` is
228 /// negative, format the entire output on one line, suppressing all but
229 /// the initial indentation (as governed by `level`). The behavior is
230 /// undefined unless `value` is in the range
231 /// `[e_ACTUAL_360 .. e_ACTUAL_365_35]`. See `toAscii` for what
232 /// constitutes the string representation of a
233 /// `bbldc::DayCountConvention::Enum` value.
234 static bsl::ostream& print(bsl::ostream& stream,
236 int level = 0,
237 int spacesPerLevel = 4);
238
239 /// Return the abbreviated character-string representation of the
240 /// enumerator corresponding to the specified `convention`. This
241 /// representation matches the enumerator's name (e.g., `e_ACTUAL_360`)
242 /// with the "e_" prefix elided. For example:
243 /// @code
244 /// bsl::cout << bbldc::DayCountConvention::toAscii(
245 /// bbldc::DayCountConvention::e_ACTUAL_360);
246 /// @endcode
247 /// prints the following on standard output:
248 /// @code
249 /// ACTUAL_360
250 /// @endcode
251 /// Note that specifying a `convention` that does not match any of the
252 /// enumerators will result in an unspecified string representation
253 /// being returned that is distinct from the values returned for any
254 /// valid enumerator.
255 static const char *toAscii(Enum convention);
256
257#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
258
259 // DEPRECATED METHODS
260
261 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
262 ///
263 /// Return the most current BDEX streaming version number supported by
264 /// this class.
265 static int maxSupportedBdexVersion();
266
267#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
268};
269
270// FREE OPERATORS
271
272/// Write the string representation of the specified enumeration `value` to
273/// the specified output `stream` in a single-line format, and return a
274/// reference to `stream`. See `toAscii` for what constitutes the string
275/// representation of a `bbldc::DayCountConvention::Enum` value. Note that
276/// this method has the same behavior as
277/// @code
278/// bbldc::DayCountConvention::print(stream, value, 0, -1);
279/// @endcode
280bsl::ostream& operator<<(bsl::ostream& stream,
282
283// FREE FUNCTIONS
284
285/// Load into the specified `variable` the `DayCountConvention::Enum` value
286/// read from the specified input `stream` using the specified `version`
287/// format, and return a reference to `stream`. If `stream` is initially
288/// invalid, this operation has no effect. If `version` is not supported by
289/// `DayCountConvention`, `variable` is unaltered and `stream` is
290/// invalidated, but otherwise unmodified. If `version` is supported by
291/// `DayCountConvention` but `stream` becomes invalid during this operation,
292/// `variable` has an undefined, but valid, state. The behavior is
293/// undefined unless `STREAM` is BDEX-compliant. Note that no version is
294/// read from `stream`. See the `bslx` package-level documentation for more
295/// information on BDEX streaming of value-semantic types and containers.
296template <class STREAM>
297STREAM& bdexStreamIn(STREAM& stream,
298 DayCountConvention::Enum& variable,
299 int version);
300
301/// Write the specified `value`, using the specified `version` format, to
302/// the specified output `stream`, and return a reference to `stream`. If
303/// `stream` is initially invalid, this operation has no effect. If
304/// `version` is not supported by `DayCountConvention`, `stream` is
305/// invalidated, but otherwise unmodified. The behavior is undefined unless
306/// `STREAM` is BDEX-compliant. Note that `version` is not written to
307/// `stream`. See the `bslx` package-level documentation for more
308/// information on BDEX streaming of value-semantic types and containers.
309template <class STREAM>
310STREAM& bdexStreamOut(STREAM& stream,
311 const DayCountConvention::Enum& value,
312 int version);
313
314/// Return the maximum valid BDEX format version, as indicated by the
315/// specified `versionSelector`, to be passed to the `bdexStreamOut` method
316/// while streaming an object of the type `DayCountConvention::Enum`. Note
317/// that it is highly recommended that `versionSelector` be formatted as
318/// "YYYYMMDD", a date representation. Also note that `versionSelector`
319/// should be a *compile*-time-chosen value that selects a format version
320/// supported by both externalizer and unexternalizer. See the `bslx`
321/// package-level documentation for more information on BDEX streaming of
322/// value-semantic types and containers.
324 int versionSelector);
325
326// ============================================================================
327// INLINE DEFINITIONS
328// ============================================================================
329
330 // -------------------------
331 // struct DayCountConvention
332 // -------------------------
333
334// CLASS METHODS
335template <class STREAM>
336STREAM& DayCountConvention::bdexStreamIn(STREAM& stream,
337 DayCountConvention::Enum& variable,
338 int version)
339{
340 if (stream) {
341 switch (version) { // switch on the schema version
342 case 1: {
343 char newValue;
344 stream.getInt8(newValue);
345 if ( stream
346 && e_ACTUAL_360 <= newValue
347 && e_ACTUAL_365_25 >= newValue) {
348 variable = static_cast<DayCountConvention::Enum>(newValue);
349 }
350 else {
351 stream.invalidate();
352 }
353 } break;
354 default: {
355 stream.invalidate(); // unrecognized version number
356 }
357 }
358 }
359 return stream;
360}
361
362template <class STREAM>
365 int version)
366{
367 if (stream) {
368 switch (version) { // switch on the schema version
369 case 1: {
370 stream.putInt8(static_cast<char>(value));
371 } break;
372 default: {
373 stream.invalidate(); // unrecognized version number
374 }
375 }
376 }
377 return stream;
378}
379
380inline
382{
383 return 1;
384}
385
386#ifndef BDE_OMIT_INTERNAL_DEPRECATED // BDE2.22
387
388// DEPRECATED METHODS
389inline
394
395#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22
396
397} // close package namespace
398
399// FREE OPERATORS
400inline
401bsl::ostream& bbldc::operator<<(bsl::ostream& stream,
403{
404 return bbldc::DayCountConvention::print(stream, value, 0, -1);
405}
406
407// FREE FUNCTIONS
408template <class STREAM>
409STREAM& bbldc::bdexStreamIn(STREAM& stream,
411 int version)
412{
413 return bbldc::DayCountConvention::bdexStreamIn(stream, variable, version);
414}
415
416template <class STREAM>
417STREAM& bbldc::bdexStreamOut(STREAM& stream,
419 int version)
420{
421 return bbldc::DayCountConvention::bdexStreamOut(stream, value, version);
422}
423
424inline
427 int versionSelector)
428{
430}
431
432
433
434#endif
435
436// ----------------------------------------------------------------------------
437// Copyright 2023 Bloomberg Finance L.P.
438//
439// Licensed under the Apache License, Version 2.0 (the "License");
440// you may not use this file except in compliance with the License.
441// You may obtain a copy of the License at
442//
443// http://www.apache.org/licenses/LICENSE-2.0
444//
445// Unless required by applicable law or agreed to in writing, software
446// distributed under the License is distributed on an "AS IS" BASIS,
447// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
448// See the License for the specific language governing permissions and
449// limitations under the License.
450// ----------------------------- END-OF-FILE ----------------------------------
451
452/** @} */
453/** @} */
454/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
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:128
Enum Type
Definition bbldc_daycountconvention.h:176
static bsl::ostream & print(bsl::ostream &stream, DayCountConvention::Enum value, int level=0, int spacesPerLevel=4)
Enum
Definition bbldc_daycountconvention.h:131
@ e_SIA_30_360_EOM
Definition bbldc_daycountconvention.h:141
@ e_SIA_30_360_NEOM
Definition bbldc_daycountconvention.h:142
@ BBEDC_ISMA_30_360
Definition bbldc_daycountconvention.h:155
@ ICMA_ACTUAL_ACTUAL_NOT_IMPLEMENTED
Definition bbldc_daycountconvention.h:162
@ e_ISDA_ACTUAL_ACTUAL
Definition bbldc_daycountconvention.h:137
@ e_ISMA_30_360
Definition bbldc_daycountconvention.h:139
@ e_PSA_30_360_EOM
Definition bbldc_daycountconvention.h:140
@ BBEDC_ACTUAL_360
Definition bbldc_daycountconvention.h:150
@ BBEDC_ICMA_ACTUAL_ACTUAL_NOT_IMPLEMENTED
Definition bbldc_daycountconvention.h:152
@ e_CALENDAR_BUS_252
Definition bbldc_daycountconvention.h:144
@ BBEDC_ACTUAL_365_FIXED
Definition bbldc_daycountconvention.h:151
@ BBEDC_ISMA_ACTUAL_ACTUAL_NOT_IMPLEMENTED
Definition bbldc_daycountconvention.h:154
@ SIA_30_360_NEOM
Definition bbldc_daycountconvention.h:170
@ PSA_30_360_EOM
Definition bbldc_daycountconvention.h:168
@ e_ACTUAL_365_25
Definition bbldc_daycountconvention.h:147
@ BBEDC_SIA_30_360_EOM
Definition bbldc_daycountconvention.h:157
@ BBEDC_PSA_30_360_EOM
Definition bbldc_daycountconvention.h:156
@ e_NL_365
Definition bbldc_daycountconvention.h:146
@ BBEDC_SIA_30_360_NEOM
Definition bbldc_daycountconvention.h:158
@ e_ISDA_30_360_EOM
Definition bbldc_daycountconvention.h:145
@ ACTUAL_365_FIXED
Definition bbldc_daycountconvention.h:161
@ SIA_30_360_EOM
Definition bbldc_daycountconvention.h:169
@ e_ACTUAL_365_FIXED
Definition bbldc_daycountconvention.h:135
@ ISDA_ACTUAL_ACTUAL
Definition bbldc_daycountconvention.h:164
@ e_ACTUAL_360
Definition bbldc_daycountconvention.h:134
@ BBEDC_ISDA_ACTUAL_ACTUAL
Definition bbldc_daycountconvention.h:153
@ ACTUAL_360
Definition bbldc_daycountconvention.h:160
@ ISMA_30_360
Definition bbldc_daycountconvention.h:167
@ ISMA_ACTUAL_ACTUAL_NOT_IMPLEMENTED
Definition bbldc_daycountconvention.h:165
@ e_PERIOD_ICMA_ACTUAL_ACTUAL
Definition bbldc_daycountconvention.h:143
static STREAM & bdexStreamOut(STREAM &stream, DayCountConvention::Enum value, int version)
Definition bbldc_daycountconvention.h:363
static const char * toAscii(Enum convention)
static int maxSupportedBdexVersion()
Definition bbldc_daycountconvention.h:390
static STREAM & bdexStreamIn(STREAM &stream, DayCountConvention::Enum &variable, int version)
Definition bbldc_daycountconvention.h:336