Mantid
Loading...
Searching...
No Matches
TSVSerialiser.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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"
11
12#include <map>
13#include <sstream>
14#include <string>
15#include <vector>
16
17#include <QColor>
18#include <QPoint>
19#include <QRect>
20#include <QString>
21
28namespace MantidQt {
29namespace API {
30
32public:
34
35 explicit TSVSerialiser(const std::string &lines);
36
37 void parseLines(const std::string &lines);
38 std::string outputLines() const;
39 void clear();
40
41 bool hasLine(const std::string &name) const;
42 bool hasSection(const std::string &name) const;
43
44 std::vector<std::string> values(const std::string &name, const size_t i = 0) const;
45
46 template <typename T> TSVSerialiser &operator>>(std::vector<T> &val) {
47 val.reserve(m_curValues.size() - m_curIndex);
48
49 for (size_t i = m_curIndex; i < m_curValues.size(); ++i) {
50 auto valStr = m_curValues.at(i);
51 std::stringstream valSS(valStr);
52 T ret;
53 valSS >> ret;
54 val.emplace_back(ret);
55 }
56 return *this;
57 }
58
69 template <typename T> void parseLines(const std::string &name, std::vector<T> &container) {
70
71 auto extractor = [](TSVSerialiser &tsv) {
72 T value;
73 tsv >> value;
74 return value;
75 };
76
77 parseLines(name, container, extractor);
78 }
79
90 template <typename T, typename Extractor>
91 void parseLines(const std::string &name, std::vector<T> &container, Extractor &&extractor) {
92 size_t index = 0;
93 while (selectLine(name, index)) {
94 auto value = std::forward<Extractor>(extractor)(*this);
95 container.emplace_back(value);
96 ++index;
97 }
98 }
99
100 std::vector<std::string> sections(const std::string &name) const;
101
102 std::string lineAsString(const std::string &name, const size_t i = 0) const;
103 QString lineAsQString(const std::string &name, const size_t i = 0) const;
104
105 bool selectLine(const std::string &name, const size_t i = 0);
106 bool selectSection(const std::string &name, const size_t i = 0);
107
108 void storeDouble(const double val);
109 void storeInt(const int val);
110 void storeString(const std::string &val);
111 void storeBool(const bool val);
112
113 double readDouble();
114 int readInt();
115 std::string readString();
116 bool readBool();
117
118 int asInt(const size_t i) const;
119 size_t asSize_t(const size_t i) const;
120 double asDouble(const size_t i) const;
121 float asFloat(const size_t i) const;
122 std::string asString(const size_t i) const;
123 QString asQString(const size_t i) const;
124 bool asBool(const size_t i) const;
125 QRect asQRect(const size_t i);
126 QColor asQColor(const size_t i);
127 QPoint asQPoint(const size_t i);
128 QPointF asQPointF(const size_t i);
129
130 TSVSerialiser &operator>>(int &val);
131 TSVSerialiser &operator>>(size_t &val);
132 TSVSerialiser &operator>>(double &val);
133 TSVSerialiser &operator>>(float &val);
134 TSVSerialiser &operator>>(std::string &val);
135 TSVSerialiser &operator>>(QString &val);
136 TSVSerialiser &operator>>(bool &val);
137 TSVSerialiser &operator>>(QRect &val);
138 TSVSerialiser &operator>>(QColor &val);
139 TSVSerialiser &operator>>(QPoint &val);
140 TSVSerialiser &operator>>(QPointF &val);
141
142 TSVSerialiser &writeLine(const std::string &name);
143
144 TSVSerialiser &operator<<(const std::string &val);
145 TSVSerialiser &operator<<(const char *val);
146 TSVSerialiser &operator<<(const QString &val);
147 TSVSerialiser &operator<<(const double &val);
148 TSVSerialiser &operator<<(const int &val);
149 TSVSerialiser &operator<<(const size_t &val);
150 TSVSerialiser &operator<<(const bool &val);
151 TSVSerialiser &operator<<(const QRect &val);
152 TSVSerialiser &operator<<(const QColor &val);
153 TSVSerialiser &operator<<(const QPoint &val);
154 TSVSerialiser &operator<<(const QPointF &val);
155
156 void writeRaw(const std::string &raw);
157 void writeSection(const std::string &name, const std::string &body);
158 void writeInlineSection(const std::string &name, const std::string &body);
159
160private:
163
164 std::vector<std::string> m_curValues;
166
167 std::stringstream m_output;
169};
170} // namespace API
171} // namespace MantidQt
#define EXPORT_OPT_MANTIDQT_COMMON
Definition: DllOption.h:15
double value
The value of the point.
Definition: FitMW.cpp:51
std::ostream & operator<<(std::ostream &out, const MantidQt::MantidWidgets::IndexType< i > &index)
Definition: IndexTypes.h:103
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
Mantid::Kernel::CaseInsensitiveMap< std::vector< std::string > > m_sections
std::vector< std::string > m_curValues
void parseLines(const std::string &name, std::vector< T > &container, Extractor &&extractor)
Parse all lines matching a name and extract the values to a vector.
Definition: TSVSerialiser.h:91
TSVSerialiser & operator>>(std::vector< T > &val)
Definition: TSVSerialiser.h:46
Mantid::Kernel::CaseInsensitiveMap< std::vector< std::string > > m_lines
void parseLines(const std::string &name, std::vector< T > &container)
Parse all lines matching a name and extract the values to a vector.
Definition: TSVSerialiser.h:69
std::stringstream m_output
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
std::map< std::string, T, CaseInsensitiveStringComparator > CaseInsensitiveMap
Alias template for a map data structure that has case insensitive string comparision with a variable ...