/src/quantlib/ql/event.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2009 Ferdinando Ametrano |
5 | | Copyright (C) 2005 Joseph Wang |
6 | | |
7 | | This file is part of QuantLib, a free-software/open-source library |
8 | | for financial quantitative analysts and developers - http://quantlib.org/ |
9 | | |
10 | | QuantLib is free software: you can redistribute it and/or modify it |
11 | | under the terms of the QuantLib license. You should have received a |
12 | | copy of the license along with this program; if not, please email |
13 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
14 | | <https://www.quantlib.org/license.shtml>. |
15 | | |
16 | | This program is distributed in the hope that it will be useful, but WITHOUT |
17 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
18 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
19 | | */ |
20 | | |
21 | | #include <ql/event.hpp> |
22 | | #include <ql/patterns/visitor.hpp> |
23 | | #include <ql/optional.hpp> |
24 | | #include <ql/settings.hpp> |
25 | | |
26 | | namespace QuantLib { |
27 | | |
28 | | bool Event::hasOccurred(const Date& d, // refDate |
29 | 488k | ext::optional<bool> includeRefDate) const { |
30 | 488k | Date refDate = |
31 | 488k | d != Date() ? d : Settings::instance().evaluationDate(); |
32 | 488k | bool includeRefDateEvent = includeRefDate ? // NOLINT(readability-implicit-bool-conversion) |
33 | 0 | *includeRefDate : |
34 | 488k | Settings::instance().includeReferenceDateEvents(); |
35 | 488k | if (includeRefDateEvent) |
36 | 0 | return date() < refDate; |
37 | 488k | else |
38 | 488k | return date() <= refDate; |
39 | 488k | } |
40 | | |
41 | 0 | void Event::accept(AcyclicVisitor& v) { |
42 | 0 | auto* v1 = dynamic_cast<Visitor<Event>*>(&v); |
43 | 0 | if (v1 != nullptr) |
44 | 0 | v1->visit(*this); |
45 | 0 | else |
46 | 0 | QL_FAIL("not an event visitor"); |
47 | 0 | } |
48 | | |
49 | | } |