BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
dataloader_utils.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/dataloader/dataloader_utils.h
6 //! @brief Defines class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI2_DATALOADER_DATALOADER_UTILS_H
16 #define BORNAGAIN_GUI2_DATALOADER_DATALOADER_UTILS_H
17 
19 
20 namespace gui2 {
21 
22 struct GraphImportData;
23 
24 namespace Utils {
25 
26 //! Loads ASCII file, returns it in the form of vector of strings.
27 DAREFLCORE_EXPORT std::vector<std::string> LoadASCIIFile(const std::string& file_name);
28 
29 //! Expands string representing line number pattern to inclusive pairs of line numbers.
30 //! "1" will be expanded to { {1, 1} }, "1, 3-5" will be expanded to { {1, 1}, {3, 5} }
31 DAREFLCORE_EXPORT std::vector<std::pair<int, int>>
32 ExpandLineNumberPattern(const std::string& pattern);
33 
34 //! Creates a callback to define if given line number satisfies line number pattern.
35 //! "1, 4-6" will accept numbers {1, 4, 5, 6} and will refuse all others.
36 DAREFLCORE_EXPORT accept_int_t CreateLineNumberPatternValidator(const std::string& pattern);
37 
38 //! Creates a callback to define if given line has a valid content for further parsing.
39 //! Empty lines and lines starting from a given prefix will be excluded.
40 DAREFLCORE_EXPORT accept_string_t CreateLinePrefixValidator(const std::string& prefix_to_exclude);
41 
42 //! Creates line splitter based on separator.
43 DAREFLCORE_EXPORT line_splitter_t CreateSeparatorBasedSplitter(const std::string& separator);
44 
45 //! Returns string representing original 'line' wrapped in 'div' tag.
46 DAREFLCORE_EXPORT std::string AddHtmlDivTag(const std::string& line);
47 
48 //! Returns string representing original 'line' wrapped in html color tag.
49 DAREFLCORE_EXPORT std::string AddHtmlColorTag(const std::string& line, const std::string& color);
50 
51 //! Returns string representing original 'line' wrapped in 'div' tag.
52 DAREFLCORE_EXPORT std::string AddHtmlBackgroundTag(const std::string& line,
53  const std::string& color);
54 
55 //! Returns string representing original 'line', where 'parts' are surrounded with color tag.
56 DAREFLCORE_EXPORT std::string AddHtmlColorTagToParts(const std::string& line,
57  const std::vector<std::string>& parts,
58  const std::string& color_parts,
59  const std::string& color_rest);
60 
61 //! Extracts double values from two columns of a string array.
62 //! The row must be valid: string value must represent single double for both target columns,
63 //! rows should have enough columns. If a row is invalid, it will be skipped, so resulting arrays
64 //! have always the same length.
65 
66 DAREFLCORE_EXPORT std::pair<std::vector<double>, std::vector<double>>
67 ExtractTwoColumns(const std::vector<std::vector<std::string>>& text_data, size_t col1, size_t col2);
68 
69 //! Pack ColumnInfo into pairs representing {AxisType, IntensityType}.
70 //! For the moment we expect that only one column with AxisType exists. Number of intensity columns
71 //! can be arbitrary.
72 
73 DAREFLCORE_EXPORT std::vector<std::pair<ColumnInfo, ColumnInfo>>
74 CreateGraphInfoPairs(const std::vector<ColumnInfo>& column_info);
75 
76 //! Creates structure from text data.
77 
78 DAREFLCORE_EXPORT GraphImportData CreateData(const std::vector<std::vector<std::string>>& text_data,
79  const ColumnInfo& axis, const ColumnInfo& intensity);
80 
81 } // namespace Utils
82 
83 } // namespace gui2
84 
85 #endif // BORNAGAIN_GUI2_DATALOADER_DATALOADER_UTILS_H
Defines class CLASS?
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.
Definition: app_constants.h:20
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.