Mantid
Loading...
Searching...
No Matches
FunctionModelSpectra.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2020 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
9#include "DllOption.h"
10#include "IndexTypes.h"
12
13#include <set>
14#include <stdexcept>
15#include <vector>
16
17#include <QList>
18#include <QString>
19#include <QStringList>
20
21namespace MantidQt {
22namespace MantidWidgets {
23
24/*
25 * Representation of a discontinuous spectra range.
26 * Can be used in a vector-like manner.
27 *
28 * Holds a string and vector representation.
29 */
31public:
32 explicit FunctionModelSpectra(const std::string &str);
38 bool empty() const;
39 FitDomainIndex size() const;
40 std::string getString() const;
41 std::pair<WorkspaceIndex, WorkspaceIndex> getMinMax() const;
42 WorkspaceIndex front() const { return m_vec.front(); }
43 WorkspaceIndex back() const { return m_vec.back(); }
44 std::vector<WorkspaceIndex>::const_iterator begin() const { return m_vec.cbegin(); }
45 std::vector<WorkspaceIndex>::const_iterator end() const { return m_vec.cend(); }
46 const WorkspaceIndex &operator[](FitDomainIndex index) const { return m_vec[index.value]; }
47 bool operator==(FunctionModelSpectra const &spec) const;
48 bool isContinuous() const;
49 FitDomainIndex indexOf(WorkspaceIndex i) const;
50 FunctionModelSpectra combine(const FunctionModelSpectra &other) const;
51 void erase(WorkspaceIndex index);
52
53private:
54 explicit FunctionModelSpectra(const std::set<WorkspaceIndex> &indices);
55 void checkContinuous();
56 std::vector<WorkspaceIndex> m_vec;
58};
59
60template <typename F> struct ApplySpectra {
61 explicit ApplySpectra(F &&functor) : m_functor(std::forward<F>(functor)) {}
62
63 void operator()(const FunctionModelSpectra &spectra) const {
64 for (const auto &spectrum : spectra)
65 m_functor(spectrum);
66 }
67
68private:
70};
71
72template <typename F> struct ApplyEnumeratedSpectra {
74 : m_start(start), m_functor(std::forward<F>(functor)) {}
75
77 auto i = m_start;
78 for (const auto &spectrum : spectra)
79 m_functor(i++, spectrum);
80 return i;
81 }
82
83private:
86};
87
88template <class T> std::vector<T> vectorFromString(const std::string &listString) {
89 try {
90 return Mantid::Kernel::ArrayProperty<T>("vector", listString);
91 } catch (const std::runtime_error &) {
92 return std::vector<T>();
93 }
94}
95
96} // namespace MantidWidgets
97} // namespace MantidQt
#define EXPORT_OPT_MANTIDQT_COMMON
Definition: DllOption.h:15
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
std::vector< WorkspaceIndex >::const_iterator begin() const
FunctionModelSpectra & operator=(const FunctionModelSpectra &vec)
const WorkspaceIndex & operator[](FitDomainIndex index) const
FunctionModelSpectra(const FunctionModelSpectra &vec)
std::vector< WorkspaceIndex >::const_iterator end() const
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
std::vector< T > vectorFromString(const std::string &listString)
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
STL namespace.
ApplyEnumeratedSpectra(F &&functor, WorkspaceIndex start=WorkspaceIndex{0})
WorkspaceIndex operator()(const FunctionModelSpectra &spectra) const
void operator()(const FunctionModelSpectra &spectra) const