| 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 | |
| 22 | #include <ql/settings.hpp> |
| 23 | |
| 24 | namespace QuantLib { |
| 25 | |
| 26 | Settings::DateProxy::DateProxy() |
| 27 | : ObservableValue<Date>(Date()) {} |
| 28 | |
| 29 | std::ostream& operator<<(std::ostream& out, |
| 30 | const Settings::DateProxy& p) { |
| 31 | return out << Date(p); |
| 32 | } |
| 33 | |
| 34 | Settings::Settings() |
| 35 | |
| 36 | = default; |
| 37 | |
| 38 | void Settings::anchorEvaluationDate() { |
| 39 | // set to today's date if not already set. |
| 40 | if (evaluationDate_.value() == Date()) |
| 41 | evaluationDate_ = Date::todaysDate(); |
| 42 | // If set, no-op since the date is already anchored. |
| 43 | } |
| 44 | |
| 45 | void Settings::resetEvaluationDate() { |
| 46 | evaluationDate_ = Date(); |
| 47 | } |
| 48 | |
| 49 | SavedSettings::SavedSettings() |
| 50 | : evaluationDate_(Settings::instance().evaluationDate()), |
| 51 | includeReferenceDateEvents_(Settings::instance().includeReferenceDateEvents()), |
| 52 | includeTodaysCashFlows_(Settings::instance().includeTodaysCashFlows()), |
| 53 | enforcesTodaysHistoricFixings_(Settings::instance().enforcesTodaysHistoricFixings()) {} |
| 54 | |
| 55 | SavedSettings::~SavedSettings() { |
| 56 | try { |
| 57 | if (Settings::instance().evaluationDate() != evaluationDate_) |
| 58 | Settings::instance().evaluationDate() = evaluationDate_; |
| 59 | Settings::instance().includeReferenceDateEvents() = |
| 60 | includeReferenceDateEvents_; |
| 61 | Settings::instance().includeTodaysCashFlows() = |
| 62 | includeTodaysCashFlows_; |
| 63 | Settings::instance().enforcesTodaysHistoricFixings() = |
| 64 | enforcesTodaysHistoricFixings_; |
| 65 | } catch (...) { |
| 66 | // nothing we can do except bailing out. |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | } |
| 71 | |