BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
datahandler.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/dataloader/datahandler.cpp
6 //! @brief Implements 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 
18 #include <iostream>
19 
20 namespace gui2 {
21 
22 //! Load raw data from the list of files, if it was not loaded yet.
23 //! Remove data which is not present.
24 
25 void DataHandler::updateRawData(const std::vector<std::string>& file_names)
26 {
27  for (const auto& file_name : file_names)
28  if (auto it = m_raw_data.find(file_name); it == m_raw_data.end())
29  loadFile(file_name);
30 
31  for (auto it = m_raw_data.begin(); it != m_raw_data.end(); /* no increment */) {
32  if (ModelView::Utils::Contains(file_names, it->first))
33  it++;
34  else
35  m_raw_data.erase(it++);
36  }
37 }
38 
39 //! Returns raw text data representing content of the file with given name.
40 
41 std::vector<std::string> DataHandler::textData(const std::string& file_name)
42 {
43  auto it = m_raw_data.find(file_name);
44  return it != m_raw_data.end() ? it->second : std::vector<std::string>();
45 }
46 
47 //! Load file with given name. File is assumed to be ASCII.
48 
49 void DataHandler::loadFile(const std::string& file_name)
50 {
51  m_raw_data[file_name] = Utils::LoadASCIIFile(file_name);
52 }
53 
54 } // namespace gui2
std::map< std::string, std::vector< std::string > > m_raw_data
Definition: datahandler.h:40
void loadFile(const std::string &file_name)
correspondence of file name to the raw data in the file (i.e. all strings)
Definition: datahandler.cpp:49
void updateRawData(const std::vector< std::string > &file_names)
Load raw data from the list of files, if it was not loaded yet.
Definition: datahandler.cpp:25
std::vector< std::string > textData(const std::string &file_name)
Returns raw text data representing content of the file with given name.
Definition: datahandler.cpp:41
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
bool Contains(const A &container, const B &element)
Returns true if container contains a given element.
DAREFLCORE_EXPORT std::vector< std::string > LoadASCIIFile(const std::string &file_name)
Loads ASCII file, returns it in the form of vector of strings.
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20