/src/quantlib/ql/event.hpp
Line | Count | Source |
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 | | <http://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 | | /*! \file event.hpp |
22 | | \brief Base class for events associated with a given date |
23 | | */ |
24 | | |
25 | | #ifndef quantlib_event_hpp |
26 | | #define quantlib_event_hpp |
27 | | |
28 | | #include <ql/time/date.hpp> |
29 | | #include <ql/patterns/observable.hpp> |
30 | | #include <ql/optional.hpp> |
31 | | |
32 | | namespace QuantLib { |
33 | | |
34 | | class AcyclicVisitor; |
35 | | |
36 | | //! Base class for event |
37 | | /*! This class acts as a base class for the actual |
38 | | event implementations. |
39 | | */ |
40 | | class Event : public virtual Observable { |
41 | | public: |
42 | 58.1M | ~Event() override = default; |
43 | | //! \name Event interface |
44 | | //@{ |
45 | | //! returns the date at which the event occurs |
46 | | virtual Date date() const = 0; |
47 | | |
48 | | //! returns true if an event has already occurred before a date |
49 | | /*! If includeRefDate is true, then an event has not occurred if its |
50 | | date is the same as the refDate, i.e. this method returns false if |
51 | | the event date is the same as the refDate. |
52 | | */ |
53 | | virtual bool hasOccurred( |
54 | | const Date& refDate = Date(), |
55 | | ext::optional<bool> includeRefDate = ext::nullopt) const; |
56 | | //@} |
57 | | |
58 | | //! \name Visitability |
59 | | //@{ |
60 | | virtual void accept(AcyclicVisitor&); |
61 | | //@} |
62 | | }; |
63 | | |
64 | | |
65 | | namespace detail { |
66 | | |
67 | | // used to create an Event instance. |
68 | | // to be replaced with specific events as soon as we find out which. |
69 | | class simple_event : public Event { |
70 | | public: |
71 | 521k | explicit simple_event(const Date& date) : date_(date) {} |
72 | 521k | Date date() const override { return date_; } |
73 | | |
74 | | private: |
75 | | Date date_; |
76 | | }; |
77 | | |
78 | | } |
79 | | |
80 | | } |
81 | | |
82 | | |
83 | | #endif |