BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bbldc_basicbasicdaycountadapter.h
Go to the documentation of this file.
1/// @file bbldc_basicbasicdaycountadapter.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bbldc_basicbasicdaycountadapter.h -*-C++-*-
8#ifndef INCLUDED_BBLDC_BASICBASICDAYCOUNTADAPTER
9#define INCLUDED_BBLDC_BASICBASICDAYCOUNTADAPTER
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bbldc_basicbasicdaycountadapter bbldc_basicbasicdaycountadapter
15/// @brief Provide a parameterized day-count convention implementation.
16/// @addtogroup bbl
17/// @{
18/// @addtogroup bbldc
19/// @{
20/// @addtogroup bbldc_basicbasicdaycountadapter
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bbldc_basicbasicdaycountadapter-purpose"> Purpose</a>
25/// * <a href="#bbldc_basicbasicdaycountadapter-classes"> Classes </a>
26/// * <a href="#bbldc_basicbasicdaycountadapter-description"> Description </a>
27/// * <a href="#bbldc_basicbasicdaycountadapter-usage"> Usage </a>
28/// * <a href="#bbldc_basicbasicdaycountadapter-example-1-adapting-bbldc-basicisma30360"> Example 1: Adapting bbldc::BasicIsma30360 </a>
29///
30/// # Purpose {#bbldc_basicbasicdaycountadapter-purpose}
31/// Provide a parameterized day-count convention implementation.
32///
33/// # Classes {#bbldc_basicbasicdaycountadapter-classes}
34///
35/// - bbldc::BasicBasicDayCountAdapter: `bbldc::BasicDayCount` realization
36///
37/// # Description {#bbldc_basicbasicdaycountadapter-description}
38/// This component provides a parameterized (template)
39/// implementation, `bbldc::BasicBasicDayCountAdapter`, of the
40/// `bbldc::BasicDayCount` protocol. The template argument can be any type
41/// supporting the following two class methods.
42/// @code
43/// int daysDiff(const bdlt::Date& beginDate, const bdlt::Date& endDate);
44///
45/// double yearsDiff(const bdlt::Date& beginDate, const bdlt::Date& endDate);
46/// @endcode
47/// The template class `bbldc::BasicBasicDayCountAdapter` provides convenient
48/// support for run-time polymorphic choice of day-count conventions (via
49/// conventional use of a base-class pointer or reference) without having to
50/// implement each derived type explicitly. In this sense,
51/// `bbldc::BasicBasicDayCountAdapter` adapts the various concrete "basic"
52/// day-count convention classes (e.g., `bbldc::BasicIsma30360`) to a run-time
53/// binding mechanism.
54///
55/// ## Usage {#bbldc_basicbasicdaycountadapter-usage}
56///
57///
58/// This section illustrates intended use of this component.
59///
60/// ### Example 1: Adapting bbldc::BasicIsma30360 {#bbldc_basicbasicdaycountadapter-example-1-adapting-bbldc-basicisma30360}
61///
62///
63/// This example shows the procedure for using
64/// `bbldc::BasicBasicDayCountAdapter` to adapt the `bbldc::BasicIsma30360`
65/// day-count convention to the `bbldc::BasicDayCount` protocol, and then the
66/// use of the day-count methods. First, we define an instance of the adapted
67/// day-count convention and obtain a reference to the `bbldc::BasicDayCount`:
68/// @code
69/// const bbldc::BasicBasicDayCountAdapter<bbldc::BasicIsma30360> myDcc =
70/// bbldc::BasicBasicDayCountAdapter<bbldc::BasicIsma30360>();
71/// const bbldc::BasicDayCount& dcc = myDcc;
72/// @endcode
73/// Then, create two `bdlt::Date` variables, `d1` and `d2`, with which to use
74/// the day-count convention methods:
75/// @code
76/// const bdlt::Date d1(2003, 10, 18);
77/// const bdlt::Date d2(2003, 12, 31);
78/// @endcode
79/// Now, use the base-class reference to compute the day count between the two
80/// dates:
81/// @code
82/// const int daysDiff = dcc.daysDiff(d1, d2);
83/// assert(72 == daysDiff);
84/// @endcode
85/// Finally, use the base-class reference to compute the year fraction between
86/// the two dates:
87/// @code
88/// const double yearsDiff = dcc.yearsDiff(d1, d2);
89/// // Need fuzzy comparison since 'yearsDiff' is a 'double'.
90/// assert(0.1999 < yearsDiff && 0.2001 > yearsDiff);
91/// @endcode
92/// @}
93/** @} */
94/** @} */
95
96/** @addtogroup bbl
97 * @{
98 */
99/** @addtogroup bbldc
100 * @{
101 */
102/** @addtogroup bbldc_basicbasicdaycountadapter
103 * @{
104 */
105
106#include <bblscm_version.h>
107
108#include <bbldc_basicdaycount.h>
109
110#include <bdlt_date.h>
111
112#include <bsls_keyword.h>
113
114
115
116
117namespace bbldc {
118
119 // ===============================
120 // class BasicBasicDayCountAdapter
121 // ===============================
122
123/// This `class` provides an "adapter" from the specified `CONVENTION` to
124/// the `bbldc::BasicDayCount` protocol that can be used for determining
125/// values based on dates according to the day-count `CONVENTION`.
126///
127/// See @ref bbldc_basicbasicdaycountadapter
128template <class CONVENTION>
130
131 public:
132 // ACCESSORS
133 int daysDiff(const bdlt::Date& beginDate, const bdlt::Date& endDate) const
135 // Return the (signed) number of days between the specified 'beginDate'
136 // and 'endDate' as per the 'CONVENTION' template policy. If
137 // 'beginDate <= endDate', then the result is non-negative. Note that
138 // reversing the order of 'beginDate' and 'endDate' negates the result.
139
140 /// Return the (signed fractional) number of years between the specified
141 /// `beginDate` and `endDate` as per the `CONVENTION` template policy.
142 /// If `beginDate <= endDate`, then the result is non-negative. Note
143 /// that reversing the order of `beginDate` and `endDate` negates the
144 /// result; specifically,
145 /// `|yearsDiff(b, e) + yearsDiff(e, b)| <= 1.0e-15` for all dates `b`
146 /// and `e`.
147 double yearsDiff(const bdlt::Date& beginDate,
148 const bdlt::Date& endDate) const BSLS_KEYWORD_OVERRIDE;
149};
150
151// ============================================================================
152// INLINE DEFINITIONS
153// ============================================================================
154
155 // -------------------------------
156 // class BasicBasicDayCountAdapter
157 // -------------------------------
158
159// ACCESSORS
160template <class CONVENTION>
161inline
163 const bdlt::Date& beginDate,
164 const bdlt::Date& endDate) const
165{
166 return CONVENTION::daysDiff(beginDate, endDate);
167}
168
169template <class CONVENTION>
170inline
171double
173 const bdlt::Date& beginDate,
174 const bdlt::Date& endDate) const
175{
176 return CONVENTION::yearsDiff(beginDate, endDate);
177}
178
179} // close package namespace
180
181
182#endif
183
184// ----------------------------------------------------------------------------
185// Copyright 2015 Bloomberg Finance L.P.
186//
187// Licensed under the Apache License, Version 2.0 (the "License");
188// you may not use this file except in compliance with the License.
189// You may obtain a copy of the License at
190//
191// http://www.apache.org/licenses/LICENSE-2.0
192//
193// Unless required by applicable law or agreed to in writing, software
194// distributed under the License is distributed on an "AS IS" BASIS,
195// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
196// See the License for the specific language governing permissions and
197// limitations under the License.
198// ----------------------------- END-OF-FILE ----------------------------------
199
200/** @} */
201/** @} */
202/** @} */
Definition bbldc_basicbasicdaycountadapter.h:129
double yearsDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate) const BSLS_KEYWORD_OVERRIDE
Definition bbldc_basicbasicdaycountadapter.h:172
int daysDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate) const BSLS_KEYWORD_OVERRIDE
Definition bbldc_basicbasicdaycountadapter.h:162
Definition bbldc_basicdaycount.h:163
Definition bdlt_date.h:294
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:653
Definition bbldc_basicactual360.h:107