Coverage Report

Created: 2025-12-08 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/cashflows/timebasket.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2003 Decillion Pty(Ltd)
5
 Copyright (C) 2003 StatPro Italia srl
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
/*! \file timebasket.hpp
22
    \brief distribution over a number of date ranges
23
*/
24
25
#ifndef quantlib_time_basket_hpp
26
#define quantlib_time_basket_hpp
27
28
#include <ql/time/date.hpp>
29
#include <ql/utilities/null.hpp>
30
#include <vector>
31
#include <map>
32
33
namespace QuantLib {
34
35
    //! Distribution over a number of dates
36
    class TimeBasket : private std::map<Date,Real> {
37
        // this is needed for Visual C++ 6
38
        typedef std::map<Date,Real> super;
39
      public:
40
0
        TimeBasket() = default;
41
        TimeBasket(const std::vector<Date>& dates,
42
                   const std::vector<Real>& values);
43
        //! \name Map interface
44
        //@{
45
        //! returns the number of entries
46
        using super::size;
47
        //! element access
48
        using super::operator[];
49
        // iterators
50
        typedef super::iterator iterator;
51
        typedef super::const_iterator const_iterator;
52
        typedef super::reverse_iterator reverse_iterator;
53
        typedef super::const_reverse_iterator const_reverse_iterator;
54
        using super::begin;
55
        using super::end;
56
        using super::rbegin;
57
        using super::rend;
58
        //! membership
59
        bool hasDate(const Date&) const;
60
        //@}
61
        //! \name Algebra
62
        //@{
63
        TimeBasket& operator+=(const TimeBasket& other);
64
        TimeBasket& operator-=(const TimeBasket& other);
65
        //@}
66
        //! \name Other methods
67
        //@{
68
        //! redistribute the entries over the given dates
69
        TimeBasket rebin(const std::vector<Date>& buckets) const;
70
        //@}
71
    };
72
73
74
    // inline definitions
75
76
0
    inline bool TimeBasket::hasDate(const Date& d) const {
77
0
        auto i = find(d);
78
0
        return i != end();
79
0
    }
80
81
0
    inline TimeBasket& TimeBasket::operator+=(const TimeBasket& other) {
82
0
        super& self = *this;
83
0
        for (auto j : other)
84
0
            self[j.first] += j.second;
85
0
        return *this;
86
0
    }
87
88
0
    inline TimeBasket& TimeBasket::operator-=(const TimeBasket& other) {
89
0
        super& self = *this;
90
0
        for (auto j : other)
91
0
            self[j.first] -= j.second;
92
0
        return *this;
93
0
    }
94
95
}
96
97
98
#endif