BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
gui2::DataHandler Class Reference

Handles raw data during the life time of DataHandlerDialog. More...

Public Member Functions

 DataHandler ()=default
 
std::vector< std::string > textData (const std::string &file_name)
 Returns raw text data representing content of the file with given name. More...
 
void updateRawData (const std::vector< std::string > &file_names)
 Load raw data from the list of files, if it was not loaded yet. More...
 

Private Member Functions

void loadFile (const std::string &file_name)
 correspondence of file name to the raw data in the file (i.e. all strings) More...
 

Private Attributes

std::map< std::string, std::vector< std::string > > m_raw_data
 

Detailed Description

Handles raw data during the life time of DataHandlerDialog.

Loads the data from multiple ASCII files and stores in a buffer of strings.

Definition at line 28 of file datahandler.h.

Constructor & Destructor Documentation

◆ DataHandler()

gui2::DataHandler::DataHandler ( )
default

Member Function Documentation

◆ loadFile()

void gui2::DataHandler::loadFile ( const std::string &  file_name)
private

correspondence of file name to the raw data in the file (i.e. all strings)

Load file with given name. File is assumed to be ASCII.

Definition at line 49 of file datahandler.cpp.

50 {
51  m_raw_data[file_name] = Utils::LoadASCIIFile(file_name);
52 }
std::map< std::string, std::vector< std::string > > m_raw_data
Definition: datahandler.h:40
DAREFLCORE_EXPORT std::vector< std::string > LoadASCIIFile(const std::string &file_name)
Loads ASCII file, returns it in the form of vector of strings.

References gui2::Utils::LoadASCIIFile(), and m_raw_data.

Referenced by updateRawData().

Here is the call graph for this function:

◆ textData()

std::vector< std::string > gui2::DataHandler::textData ( const std::string &  file_name)

Returns raw text data representing content of the file with given name.

Definition at line 41 of file datahandler.cpp.

42 {
43  auto it = m_raw_data.find(file_name);
44  return it != m_raw_data.end() ? it->second : std::vector<std::string>();
45 }

References m_raw_data.

◆ updateRawData()

void gui2::DataHandler::updateRawData ( const std::vector< std::string > &  file_names)

Load raw data from the list of files, if it was not loaded yet.

Remove data which is not present.

Definition at line 25 of file datahandler.cpp.

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 }
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
bool Contains(const A &container, const B &element)
Returns true if container contains a given element.

References ModelView::Utils::Contains(), loadFile(), and m_raw_data.

Here is the call graph for this function:

Member Data Documentation

◆ m_raw_data

std::map<std::string, std::vector<std::string> > gui2::DataHandler::m_raw_data
private

Definition at line 40 of file datahandler.h.

Referenced by loadFile(), textData(), and updateRawData().


The documentation for this class was generated from the following files: