Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RBinIndexRange.hxx
Go to the documentation of this file.
1/// \file
2/// \warning This is part of the %ROOT 7 prototype! It will change without notice. It might trigger earthquakes.
3/// Feedback is welcome!
4
5#ifndef ROOT_RBinIndexRange
6#define ROOT_RBinIndexRange
7
8#include "RBinIndex.hxx"
9
10#include <cassert>
11#include <cstddef> // for std::ptrdiff_t
12#include <cstdint>
13#include <iterator>
14
15namespace ROOT {
16namespace Experimental {
17
18// forward declarations for friend declaration
19class RBinIndexRange;
20namespace Internal {
21static RBinIndexRange CreateBinIndexRange(RBinIndex begin, RBinIndex end, std::uint64_t nNormalBins);
22} // namespace Internal
23
24/**
25A range of bin indices \f$[fBegin, fEnd)\f$.
26
27The interface allows convenient iteration over RBinIndex. If included, RBinIndex::Underflow() is encountered before the
28normal bins and RBinIndex::Overflow() is the last value.
29
30\code
31ROOT::Experimental::RRegularAxis axis(10, 0, 1);
32for (auto index : axis.GetNormalRange(2, 5)) {
33 // Will iterate over [2, 3, 4]
34}
35for (auto index : axis.GetFullRange()) {
36 // Will iterate over all bins, starting with the underflow and ending with the overflow bin
37}
38\endcode
39
40\warning This is part of the %ROOT 7 prototype! It will change without notice. It might trigger earthquakes.
41Feedback is welcome!
42*/
45
46 /// The begin of the range (inclusive)
48 /// The end of the range (exclusive)
50 /// The number of normal bins, after which iteration advances to RBinIndex::Overflow()
51 std::uint64_t fNNormalBins = 0;
52
53public:
54 /// Construct an invalid bin index range.
55 RBinIndexRange() = default;
56
57 RBinIndex GetBegin() const { return fBegin; }
58 RBinIndex GetEnd() const { return fEnd; }
59 // fNNormalBins is not exposed because it might be confusing for partial ranges.
60
61 friend bool operator==(const RBinIndexRange &lhs, const RBinIndexRange &rhs)
62 {
63 return lhs.fBegin == rhs.fBegin && lhs.fEnd == rhs.fEnd && lhs.fNNormalBins == rhs.fNNormalBins;
64 }
65
66 friend bool operator!=(const RBinIndexRange &lhs, const RBinIndexRange &rhs) { return !(lhs == rhs); }
67
68 /// Iterator over RBinIndex.
70 /// The current bin index
72 /// The number of normal bins, after which iteration advances to RBinIndex::Overflow()
73 std::uint64_t fNNormalBins = 0;
74
75 public:
76 using difference_type = std::ptrdiff_t;
78 using pointer = const RBinIndex *;
80 using iterator_category = std::input_iterator_tag;
81
82 RIterator() = default;
84
86 {
87 if (fIndex.IsUnderflow()) {
88 fIndex = 0;
89 } else if (fIndex.IsOverflow()) {
90 fIndex = RBinIndex();
91 } else if (fIndex.IsInvalid()) {
92 // This should never happen! In the worst case, when built with NDEBUG, the iterator stays at Invalid.
93 assert(0); // GCOVR_EXCL_LINE
94 } else {
95 fIndex++;
96 if (fIndex.GetIndex() == fNNormalBins) {
98 }
99 }
100 return *this;
101 }
103 {
104 RIterator old = *this;
105 operator++();
106 return old;
107 }
108
109 RBinIndex operator*() const { return fIndex; }
110 const RBinIndex *operator->() const { return &fIndex; }
111
112 friend bool operator==(const RIterator &lhs, const RIterator &rhs)
113 {
114 return lhs.fIndex == rhs.fIndex && lhs.fNNormalBins == rhs.fNNormalBins;
115 }
116 friend bool operator!=(const RIterator &lhs, const RIterator &rhs) { return !(lhs == rhs); }
117 };
118
121};
122
123namespace Internal {
124
125/// %Internal function to create RBinIndexRange.
126///
127/// Users are strongly advised to create bin index ranges via the respective axis types, for example with
128/// \ref RRegularAxis::GetNormalRange(RBinIndex, RBinIndex) const "RRegularAxis::GetNormalRange(RBinIndex, RBinIndex)"
129/// or RRegularAxis::GetFullRange().
130///
131/// \param[in] begin the begin of the bin index range (inclusive)
132/// \param[in] end the end of the bin index range (exclusive)
133/// \param[in] nNormalBins the number of normal bins, after which iteration advances to RBinIndex::Overflow()
135{
137 range.fBegin = begin;
138 range.fEnd = end;
139 range.fNNormalBins = nNormalBins;
140 return range;
141}
142
143} // namespace Internal
144
145} // namespace Experimental
146} // namespace ROOT
147
148#endif
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
std::uint64_t fNNormalBins
The number of normal bins, after which iteration advances to RBinIndex::Overflow()
friend bool operator!=(const RIterator &lhs, const RIterator &rhs)
RIterator(RBinIndex index, std::uint64_t nNormalBins)
friend bool operator==(const RIterator &lhs, const RIterator &rhs)
RBinIndex fBegin
The begin of the range (inclusive)
RBinIndex fEnd
The end of the range (exclusive)
friend bool operator!=(const RBinIndexRange &lhs, const RBinIndexRange &rhs)
friend bool operator==(const RBinIndexRange &lhs, const RBinIndexRange &rhs)
RBinIndexRange()=default
Construct an invalid bin index range.
std::uint64_t fNNormalBins
The number of normal bins, after which iteration advances to RBinIndex::Overflow()
A bin index with special values for underflow and overflow bins.
Definition RBinIndex.hxx:23
static RBinIndex Overflow()
std::uint64_t GetIndex() const
Return the index for a normal bin.
Definition RBinIndex.hxx:42
static RBinIndexRange CreateBinIndexRange(RBinIndex begin, RBinIndex end, std::uint64_t nNormalBins)
Internal function to create RBinIndexRange.