Newer
Older
#ifndef MANTID_KERNEL_MULTIFILENAMEPARSER_H_
#define MANTID_KERNEL_MULTIFILENAMEPARSER_H_
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidKernel/DllConfig.h"
#include <set>
#include <vector>
#include <string>
#include <utility>
Copyright © 2010-2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
namespace Mantid {
namespace Kernel {
namespace MultiFileNameParsing {
/// Parses a string consisting of only run number info, into a vector of vector
/// of run numbers.
MANTID_KERNEL_DLL std::vector<std::vector<unsigned int>>
parseMultiRunString(std::string runString);
/// Suggests a workspace name, given a vector of file names. (Which we assume
/// will be added.)
MANTID_KERNEL_DLL std::string
suggestWorkspaceName(const std::vector<std::string> &fileNames);
/// Regexs used to match / parse various strings.
namespace Regexs {
extern const std::string INST, UNDERSCORE, SPACE;
extern const std::string COMMA, PLUS, MINUS, COLON;
extern const std::string SINGLE, RANGE, STEP_RANGE, ADD_LIST, ADD_RANGE,
ADD_STEP_RANGE;
extern const std::string ANY, LIST;
}
/**
* Comparator for set that holds instrument names in Parser.
*/
class MANTID_KERNEL_DLL ReverseCaselessCompare {
public:
bool operator()(const std::string &a, const std::string &b);
};
/**
This class takes a string representing multiple files and parses it into
a vector of vectors of file names. Filenames to be added are placed in the
same sub vectors.
The string to parse should be of the format [dir][inst][under][runs][ext],
where:
[dir] (Optional) = The OS-specific file directory, e.g. "c:\data\"
[inst] (Optional) = The instrument name, e.g. "IRS" or "PG3". If none
provided then use default.
[under] (Optional) = An underscore.
[runs] (Required) = The run numbers, e.g. "0102, 0110-0115, 0120,
0130:0140:2"
[ext] (Optional) = The file extension, e.g. ".raw"
NOTE: This parser does not parse strings of the form:
[dir][inst][under][runs][ext],[dir][inst][under][runs][ext]
*/
class MANTID_KERNEL_DLL Parser {
public:
/// Constructor
Parser();
/// Destructor
~Parser() = default;
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/// Parse the given multiFileNameString.
void parse(const std::string &multiFileName);
/// Return the vector of vectors of parsed file names.
std::vector<std::vector<unsigned int>> runs() const { return m_runs; }
/// Return the vector of vectors of parsed file names.
std::vector<std::vector<std::string>> fileNames() const {
return m_fileNames;
}
/// Return the parsed directory string.
std::string dirString() const { return m_dirString; }
/// Return the parsed instrument string.
std::string instString() const { return m_instString; }
/// Return the parsed underscore string.
std::string underscoreString() const { return m_underscoreString; }
/// Return the parsed run string.
std::string runString() const { return m_runString; }
/// Return the parsed extension string.
std::string extString() const { return m_extString; }
private:
/// Clear all member variables.
void clear();
/// Split the string to parse into its component parts.
void split();
/// A vector of vectors of the parsed runs.
std::vector<std::vector<unsigned int>> m_runs;
/// A vector of vectors of the parsed file names.
std::vector<std::vector<std::string>> m_fileNames;
/// The given string to parse.
std::string m_multiFileName;
/// The various sections of the given string to parse.
std::string m_dirString, m_instString, m_underscoreString, m_runString,
m_extString;
/// The instrument-specific run zero padding value.
// int m_zeroPadding;
/// All the valid instrument names.
std::set<std::string, ReverseCaselessCompare> m_validInstNames;
};
/**
A functor that generates a vector of file names from the given vector of runs,
and other state
passed to it when constructed.
*/
class MANTID_KERNEL_DLL GenerateFileName {
public:
/// Constructor.
GenerateFileName(const std::string &prefix, const std::string &suffix,
const std::string &instString);
/// Overloaded function operator that generates a vector of file names from a
/// vector of runs.
std::vector<std::string> operator()(const std::vector<unsigned int> &runs);
/// Overloaded function operator that generates a file name from a run.
std::string operator()(unsigned int run);
private:
/// String that prefixes any generated file names.
std::string m_prefix;
/// String that suffixes any generated file names.
std::string m_suffix;
/// String that identifies the instrument
std::string m_instString;
};
/**
* A class that holds a list of ranges of runs. Each "range" is just a pair of
* unsigned ints.
* Adding ranges to the list will merge them with what is already there. This
* is essentially
* just a wrapper around a std::set<std::pair<unsigned int,unsigned int>>
* object.
*/
class MANTID_KERNEL_DLL RunRangeList {
public:
/// Constructor
RunRangeList();
// Returns the list of run ranges.
std::set<std::pair<unsigned int, unsigned int>> rangeList() const {
return m_rangeList;
};
/// Add a run to the list of run ranges.
void addRun(unsigned int run);
/// Add a range of runs
void addRunRange(unsigned int from, unsigned int to);
/// Add a range of runs
void addRunRange(std::pair<unsigned int, unsigned int> range);
private:
/// A set of pairs of unsigned ints, where each pair represents a range of
/// runs.
std::set<std::pair<unsigned int, unsigned int>> m_rangeList;
};
} // namespace MultiFileNameParsing
} // namespace Kernel
} // namespace Mantid