Mantid
Loading...
Searching...
No Matches
IndexSet.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#include <set>
8
11
12using namespace Mantid;
13using namespace Kernel;
14
16IndexSet::IndexSet(size_t fullRange) : m_size(fullRange) {}
17
20IndexSet::IndexSet(int64_t min, int64_t max, size_t fullRange) {
21 if (min < 0 || min > max)
22 throw Exception::IndexError(min, max, "IndexSet - min");
23 if (max >= static_cast<int64_t>(fullRange))
24 throw Exception::IndexError(max, fullRange - 1, "IndexSet - max");
25
26 // Bounds checked, cast should be fine in all cases.
27 m_min = static_cast<size_t>(min);
28 m_size = static_cast<size_t>(max - min + 1);
29}
30
33IndexSet::IndexSet(const std::vector<size_t> &indices, size_t fullRange) : m_isRange(false) {
34 // We use a set to create unique and ordered indices.
35 std::set<size_t> index_set;
36 for (const auto &index : indices) {
37 if (index >= fullRange)
38 throw Exception::IndexError(index, fullRange - 1, "IndexSet - index vector entry");
39 index_set.insert(index);
40 }
41 m_indices = std::vector<size_t>(begin(index_set), end(index_set));
42 m_size = m_indices.size();
43}
size_t m_size
Maximum size of the store.
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
Exception for index errors.
Definition: Exception.h:284
IndexSet(size_t fullRange)
Constructor for a set covering the full range from 0 to fullRange-1.
Definition: IndexSet.cpp:16
std::vector< size_t > m_indices
Definition: IndexSet.h:48
Helper class which provides the Collimation Length for SANS instruments.