]>
Commit | Line | Data |
---|---|---|
92f5a8d4 TL |
1 | // Copyright 2015-2019 Hans Dembinski |
2 | // | |
3 | // Distributed under the Boost Software License, Version 1.0. | |
4 | // (See accompanying file LICENSE_1_0.txt | |
5 | // or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | #ifndef BOOST_HISTOGRAM_AXIS_INTERVAL_VIEW_HPP | |
8 | #define BOOST_HISTOGRAM_AXIS_INTERVAL_VIEW_HPP | |
9 | ||
f67539c2 TL |
10 | #include <boost/histogram/fwd.hpp> |
11 | ||
92f5a8d4 TL |
12 | namespace boost { |
13 | namespace histogram { | |
14 | namespace axis { | |
15 | ||
16 | /** | |
17 | Lightweight bin view. | |
18 | ||
19 | Represents the current bin interval. | |
20 | */ | |
f67539c2 | 21 | template <class Axis> |
92f5a8d4 TL |
22 | class interval_view { |
23 | public: | |
f67539c2 | 24 | interval_view(const Axis& axis, index_type idx) : axis_(axis), idx_(idx) {} |
92f5a8d4 | 25 | // avoid viewing a temporary that goes out of scope |
f67539c2 | 26 | interval_view(Axis&& axis, index_type idx) = delete; |
92f5a8d4 TL |
27 | |
28 | /// Return lower edge of bin. | |
29 | decltype(auto) lower() const noexcept { return axis_.value(idx_); } | |
30 | /// Return upper edge of bin. | |
31 | decltype(auto) upper() const noexcept { return axis_.value(idx_ + 1); } | |
32 | /// Return center of bin. | |
33 | decltype(auto) center() const noexcept { return axis_.value(idx_ + 0.5); } | |
34 | /// Return width of bin. | |
35 | decltype(auto) width() const noexcept { return upper() - lower(); } | |
36 | ||
f67539c2 | 37 | template <class BinType> |
92f5a8d4 TL |
38 | bool operator==(const BinType& rhs) const noexcept { |
39 | return lower() == rhs.lower() && upper() == rhs.upper(); | |
40 | } | |
41 | ||
f67539c2 | 42 | template <class BinType> |
92f5a8d4 TL |
43 | bool operator!=(const BinType& rhs) const noexcept { |
44 | return !operator==(rhs); | |
45 | } | |
46 | ||
47 | private: | |
48 | const Axis& axis_; | |
f67539c2 | 49 | const index_type idx_; |
92f5a8d4 TL |
50 | }; |
51 | ||
52 | } // namespace axis | |
53 | } // namespace histogram | |
54 | } // namespace boost | |
55 | ||
56 | #endif |