Mantid
Loading...
Searching...
No Matches
SpectrumInfoIterator.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
10#include <boost/iterator/iterator_facade.hpp>
11
13
14namespace Mantid {
15namespace API {
16
28template <typename T>
29class SpectrumInfoIterator : public boost::iterator_facade<SpectrumInfoIterator<T>, SpectrumInfoItem<T> &,
30 boost::random_access_traversal_tag> {
31
32public:
33 SpectrumInfoIterator(T &spectrumInfo, const size_t index) : m_item(spectrumInfo, index) {}
34
35private:
36 // Allow boost iterator access
38
39 // Iterator methods
40 void advance(int64_t delta) {
41 m_item.m_index = delta < 0 ? std::max(static_cast<uint64_t>(0), static_cast<uint64_t>(m_item.m_index) + delta)
42 : std::min(m_item.m_spectrumInfo->size(), m_item.m_index + static_cast<size_t>(delta));
43 }
44
45 // This could cause a segmentation fault if a user goes past the end of the
46 // iterator and tries to index into the n+1 th element (which would not
47 // exist). Adding range checks to all the above methods may slow down
48 // performance though.
49 void increment() {
50 if (m_item.m_index < m_item.m_spectrumInfo->size()) {
51 ++m_item.m_index;
52 }
53 }
54
55 void decrement() {
56 if (m_item.m_index > 0) {
57 --m_item.m_index;
58 }
59 }
60
61 size_t getIndex() const { return m_item.m_index; }
62
63 void setIndex(const size_t index) { m_item.m_index = index; }
64
65 uint64_t distance_to(const SpectrumInfoIterator<T> &other) const {
66 return static_cast<uint64_t>(other.getIndex()) - static_cast<uint64_t>(getIndex());
67 }
68
69 bool equal(const SpectrumInfoIterator<T> &other) const { return getIndex() == other.getIndex(); }
70
72
74};
75
76} // namespace API
77} // namespace Mantid
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
uint64_t distance_to(const SpectrumInfoIterator< T > &other) const
SpectrumInfoIterator(T &spectrumInfo, const size_t index)
bool equal(const SpectrumInfoIterator< T > &other) const
SpectrumInfoItem< T > & dereference() const
Helper class which provides the Collimation Length for SANS instruments.