QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
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>
30#include <ql/optional.hpp>
31
32namespace 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 ~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 explicit simple_event(const Date& date) : date_(date) {}
72 Date date() const override { return date_; }
73
74 private:
76 };
77
78 }
79
80}
81
82
83#endif
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Concrete date class.
Definition: date.hpp:125
Base class for event.
Definition: event.hpp:40
virtual void accept(AcyclicVisitor &)
Definition: event.cpp:41
~Event() override=default
virtual Date date() const =0
returns the date at which the event occurs
virtual bool hasOccurred(const Date &refDate=Date(), ext::optional< bool > includeRefDate=ext::nullopt) const
returns true if an event has already occurred before a date
Definition: event.cpp:28
Object that notifies its changes to a set of observers.
Definition: observable.hpp:62
simple_event(const Date &date)
Definition: event.hpp:71
Date date() const override
returns the date at which the event occurs
Definition: event.hpp:72
date- and time-related classes, typedefs and enumerations
const boost::none_t & nullopt
Definition: optional.cpp:27
Definition: any.hpp:35
observer/observable pattern
Maps optional to either the boost or std implementation.