27 bool isRepresentRange(
const std::optional<int>& v0,
const std::optional<int>& v1)
29 if (v0.has_value() && v1.has_value())
30 return v0.value() > 0 && v1.value() > 0 && v0.value() <= v1.value();
35 std::vector<ColumnInfo> columnsForType(
const std::vector<ColumnInfo>& input,
36 const std::string& columnType)
38 std::vector<ColumnInfo> result;
39 std::copy_if(input.begin(), input.end(), std::back_inserter(result),
40 [columnType](
auto x) { return x.type_name == columnType; });
48 std::vector<std::string> result;
50 std::ifstream file(file_name);
52 throw std::ios_base::failure(
"Unable to open file '" + file_name +
"'");
53 for (std::string line; getline(file, line);)
54 result.emplace_back(line);
60 std::vector<std::pair<int, int>> result;
71 if (isRepresentRange(conv0, conv1))
72 result.push_back({conv0.value(), conv1.value()});
82 auto result = [expanded_pattern](
int line_number) {
83 for (
auto pair : expanded_pattern) {
84 if (line_number >= pair.first && line_number <= pair.second)
94 auto result = [prefix_to_exclude](
const std::string& line) {
96 if (line.empty() || line.find_first_not_of(
' ') == std::string::npos)
99 return line.find_first_of(prefix_to_exclude) == 0 ? false :
true;
106 if (separator.empty())
107 throw std::runtime_error(
"Error, empty separator.");
109 bool is_space_only_separator = separator.find_first_not_of(
' ') == std::string::npos;
110 auto result = [separator, is_space_only_separator](
const std::string& line) {
111 std::vector<std::string> values;
113 if (is_space_only_separator)
122 const std::string open_div =
"<div>";
123 const std::string close_div =
"</div>";
125 return open_div + line + close_div;
130 const std::string open_tag =
"<font color=\"" + color +
"\">";
131 const std::string close_tag =
"</font>";
133 return open_tag + line + close_tag;
138 const std::string open_tag =
"<span style=\"background-color:" + color +
"\">";
139 const std::string close_tag =
"</span>";
141 return open_tag + line + close_tag;
145 const std::vector<std::string>& parts,
146 const std::string& color_parts,
147 const std::string& color_rest)
150 std::string_view view(line);
155 for (
auto part : parts) {
156 auto it = view.find_first_of(part);
160 view.remove_prefix(it + part.size());
165 std::pair<std::vector<double>, std::vector<double>>
169 std::vector<double> vec1, vec2;
170 for (
const auto& row : text_data) {
171 if (col1 < row.size() && col2 < row.size()) {
174 if (val1.has_value() && val2.has_value()) {
175 vec1.push_back(val1.value());
176 vec2.push_back(val2.value());
181 return std::make_pair(std::move(vec1), std::move(vec2));
184 std::vector<std::pair<ColumnInfo, ColumnInfo>>
187 std::vector<std::pair<ColumnInfo, ColumnInfo>> result;
192 if (axis_columns.size() != 1)
193 throw std::runtime_error(
"There must be exactly one column with AxisType selected.");
195 for (
const auto& intensity_info : intensity_columns)
196 result.push_back(std::make_pair(axis_columns.back(), intensity_info));
206 auto [axis_values, intensity_values] =
209 std::transform(intensity_values.begin(), intensity_values.end(), intensity_values.begin(),
210 [&intensity](
auto x) { return x * intensity.multiplier; });
MVVM_MODEL_EXPORT std::string RemoveRepeatedSpaces(std::string str)
Removes repeating spaces for a string.
MVVM_MODEL_EXPORT std::string TrimWhitespace(const std::string &str)
Returns string after trimming whitespace surrounding, including tabs and carriage returns.
MVVM_MODEL_EXPORT std::vector< std::string > SplitString(const std::string &str, const std::string &delimeter)
Split string on substring using given delimeter. Reproduces Python's str.split() behavior.
MVVM_MODEL_EXPORT std::optional< int > StringToInteger(const std::string &str)
Converts string to integer.
MVVM_MODEL_EXPORT std::optional< double > StringToDouble(const std::string &str)
Converts string to double value using classc locale and returns it in the form of optional.
const std::string IntensityType
const std::string AxisType
DAREFLCORE_EXPORT std::vector< std::string > LoadASCIIFile(const std::string &file_name)
Loads ASCII file, returns it in the form of vector of strings.
DAREFLCORE_EXPORT accept_int_t CreateLineNumberPatternValidator(const std::string &pattern)
Creates a callback to define if given line number satisfies line number pattern.
DAREFLCORE_EXPORT std::pair< std::vector< double >, std::vector< double > > ExtractTwoColumns(const std::vector< std::vector< std::string >> &text_data, size_t col1, size_t col2)
Extracts double values from two columns of a string array.
DAREFLCORE_EXPORT line_splitter_t CreateSeparatorBasedSplitter(const std::string &separator)
Creates line splitter based on separator.
DAREFLCORE_EXPORT accept_string_t CreateLinePrefixValidator(const std::string &prefix_to_exclude)
Creates a callback to define if given line has a valid content for further parsing.
DAREFLCORE_EXPORT std::string AddHtmlColorTagToParts(const std::string &line, const std::vector< std::string > &parts, const std::string &color_parts, const std::string &color_rest)
Returns string representing original 'line', where 'parts' are surrounded with color tag.
DAREFLCORE_EXPORT std::string AddHtmlDivTag(const std::string &line)
Returns string representing original 'line' wrapped in 'div' tag.
DAREFLCORE_EXPORT std::vector< std::pair< ColumnInfo, ColumnInfo > > CreateGraphInfoPairs(const std::vector< ColumnInfo > &column_info)
Pack ColumnInfo into pairs representing {AxisType, IntensityType}.
DAREFLCORE_EXPORT std::vector< std::pair< int, int > > ExpandLineNumberPattern(const std::string &pattern)
Expands string representing line number pattern to inclusive pairs of line numbers.
DAREFLCORE_EXPORT GraphImportData CreateData(const std::vector< std::vector< std::string >> &text_data, const ColumnInfo &axis, const ColumnInfo &intensity)
Creates structure from text data.
DAREFLCORE_EXPORT std::string AddHtmlColorTag(const std::string &line, const std::string &color)
Returns string representing original 'line' wrapped in html color tag.
DAREFLCORE_EXPORT std::string AddHtmlBackgroundTag(const std::string &line, const std::string &color)
Returns string representing original 'line' wrapped in 'div' tag.
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
std::function< bool(const std::string &line)> accept_string_t
Function to define if given string should be accepted for further consideration.
std::function< bool(int)> accept_int_t
Function to define if given index satisfies criteria.
std::function< std::vector< std::string >(const std::string &line)> line_splitter_t
Function to define line splitter according to some criteria.
Info about the column as defined by the user via ImportTableWidget.
Raw data to construct GraphItem and Data1DItem's.
std::vector< double > bin_centers
std::vector< double > bin_values