Mantid
Loading...
Searching...
No Matches
FunctionDomainMD.cpp
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//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
12
13#include <stdexcept>
14
15namespace Mantid::API {
16
23FunctionDomainMD::FunctionDomainMD(const IMDWorkspace_const_sptr &ws, size_t start, size_t length)
24 : m_iterator(ws->createIterator()), m_startIndex(start), m_currentIndex(0), m_justReset(true), m_workspace(ws) {
25 size_t dataSize = m_iterator->getDataSize();
26 m_size = length == 0 ? dataSize : length;
27 if (start >= dataSize) {
28 throw std::out_of_range("Start point out of range");
29 }
30 if (start + length > dataSize) {
31 throw std::out_of_range("End point out of range");
32 }
33 if (start > 0) {
34 m_iterator->jumpTo(start);
35 }
36}
37
41
44 m_iterator->jumpTo(m_startIndex);
46 m_justReset = true;
47}
48
57 if (m_justReset) {
58 m_justReset = false;
59 return m_iterator.get();
60 }
62 if (!m_iterator->next() || m_currentIndex >= m_size) {
64 return nullptr;
65 }
66 return m_iterator.get();
67}
68
71
72} // namespace Mantid::API
const IMDIterator * getNextIterator() const
Next iterator.
~FunctionDomainMD() override
Destructor.
FunctionDomainMD(const IMDWorkspace_const_sptr &ws, size_t start=0, size_t length=0)
Constructor.
IMDWorkspace_const_sptr getWorkspace() const
Returns the pointer to the original workspace.
std::unique_ptr< IMDIterator > m_iterator
IMDIterator.
size_t m_size
The size of the domain.
size_t m_currentIndex
track the iterator's index, 0 <= m_currentIndex < m_size.
bool m_justReset
Just reset flag.
const size_t m_startIndex
start of the domain, 0 <= m_startIndex < m_iterator->getDataSize()
IMDWorkspace_const_sptr m_workspace
A pointer to the workspace.
void reset() const override
Reset the iterator to point to the start of the domain.
This is an interface to an iterator of an IMDWorkspace.
Definition: IMDIterator.h:39
std::shared_ptr< const IMDWorkspace > IMDWorkspace_const_sptr
Shared pointer to the IMDWorkspace base class (const version)
Definition: IMDWorkspace.h:148