QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
settings.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007, 2011 Ferdinando Ametrano
5 Copyright (C) 2007 François du Vignaud
6 Copyright (C) 2004, 2005, 2007, 2009 StatPro Italia srl
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
26#ifndef quantlib_settings_hpp
27#define quantlib_settings_hpp
28
29#include <ql/patterns/singleton.hpp>
30#include <ql/time/date.hpp>
31#include <ql/utilities/observablevalue.hpp>
32#include <ql/optional.hpp>
33
34namespace QuantLib {
35
37 class Settings : public Singleton<Settings> {
38 friend class Singleton<Settings>;
39 private:
41 class DateProxy : public ObservableValue<Date> {
42 public:
43 DateProxy();
44 DateProxy& operator=(const Date&);
45 operator Date() const;
46 };
47 friend std::ostream& operator<<(std::ostream&, const DateProxy&);
48 public:
50
72 const DateProxy& evaluationDate() const;
73
89
96 bool includeReferenceDateEvents() const;
97
105 ext::optional<bool>& includeTodaysCashFlows();
106 ext::optional<bool> includeTodaysCashFlows() const;
107
110
111 private:
114 ext::optional<bool> includeTodaysCashFlows_;
116 };
117
118
119 // helper class to temporarily and safely change the settings
120 class SavedSettings { // NOLINT(cppcoreguidelines-special-member-functions)
121 public:
124 private:
127 ext::optional<bool> includeTodaysCashFlows_;
129 };
130
131
132 // inline
133
134 inline Settings::DateProxy::operator Date() const {
135 if (value() == Date())
136 return Date::todaysDate();
137 else
138 return value();
139 }
140
142 if (value() != d) // avoid notifications if the date doesn't actually change
144 return *this;
145 }
146
148 return evaluationDate_;
149 }
150
152 return evaluationDate_;
153 }
154
157 }
158
161 }
162
163 inline ext::optional<bool>& Settings::includeTodaysCashFlows() {
165 }
166
167 inline ext::optional<bool> Settings::includeTodaysCashFlows() const {
169 }
170
173 }
174
177 }
178
179}
180
181#endif
Concrete date class.
Definition: date.hpp:125
static Date todaysDate()
today's date.
Definition: date.cpp:788
observable and assignable proxy to concrete value
ObservableValue< T > & operator=(T &&)
const Date & value() const
explicit inspector
ext::optional< bool > includeTodaysCashFlows_
Definition: settings.hpp:127
DateProxy & operator=(const Date &)
Definition: settings.hpp:141
global repository for run-time library settings
Definition: settings.hpp:37
void resetEvaluationDate()
Definition: settings.cpp:45
bool & includeReferenceDateEvents()
Definition: settings.hpp:155
bool enforcesTodaysHistoricFixings_
Definition: settings.hpp:115
DateProxy & evaluationDate()
the date at which pricing is to be performed.
Definition: settings.hpp:147
ext::optional< bool > & includeTodaysCashFlows()
Definition: settings.hpp:163
void anchorEvaluationDate()
Definition: settings.cpp:38
ext::optional< bool > includeTodaysCashFlows_
Definition: settings.hpp:114
bool includeReferenceDateEvents_
Definition: settings.hpp:113
DateProxy evaluationDate_
Definition: settings.hpp:112
friend std::ostream & operator<<(std::ostream &, const DateProxy &)
Definition: settings.cpp:29
bool & enforcesTodaysHistoricFixings()
Definition: settings.hpp:171
Basic support for the singleton pattern.
Definition: singleton.hpp:58
Definition: any.hpp:35