BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
OutputDataWriter Class Reference
Collaboration diagram for OutputDataWriter:

Public Member Functions

 OutputDataWriter (const std::string &file_name)
 
void writeOutputData (const OutputData< double > &data)
 
void setStrategy (IOutputDataWriteStrategy *write_strategy)
 

Private Attributes

std::string m_file_name
 
std::unique_ptr< IOutputDataWriteStrategym_write_strategy
 

Detailed Description

Write OutputData to file using different witing strategies.

Definition at line 26 of file OutputDataWriter.h.

Constructor & Destructor Documentation

◆ OutputDataWriter()

OutputDataWriter::OutputDataWriter ( const std::string &  file_name)

Definition at line 29 of file OutputDataWriter.cpp.

29 : m_file_name(file_name) {}
std::string m_file_name

Member Function Documentation

◆ writeOutputData()

void OutputDataWriter::writeOutputData ( const OutputData< double > &  data)

Writes output data to file.

Definition at line 31 of file OutputDataWriter.cpp.

32 {
33  using namespace DataFormatUtils;
34  if (!m_write_strategy)
35  throw Exceptions::NullPointerException("OutputDataWriter::getOutputData() ->"
36  " Error! No read strategy defined");
37 
38  std::ofstream fout;
39  std::ios_base::openmode openmode = std::ios::out;
41  openmode = std::ios::out | std::ios_base::binary;
42 
43 #ifdef _WIN32
45 #else
46  fout.open(m_file_name, openmode);
47 #endif
48 
49  if (!fout.is_open())
50  throw Exceptions::FileNotIsOpenException("OutputDataWriter::writeOutputData() -> Error. "
51  "Can't open file '"
52  + m_file_name + "' for writing.");
53  if (!fout.good())
54  throw Exceptions::FileIsBadException("OutputDataReader::writeOutputData() -> Error! "
55  "File is not good, probably it is a directory.");
56  std::stringstream ss;
57  m_write_strategy->writeOutputData(data, ss);
58 
59  boost::iostreams::filtering_streambuf<boost::iostreams::input> input_filtered;
61  input_filtered.push(boost::iostreams::gzip_compressor());
63  input_filtered.push(boost::iostreams::bzip2_compressor());
64  input_filtered.push(ss);
65 
66  boost::iostreams::copy(input_filtered, fout);
67 
68  fout.close();
69 }
std::unique_ptr< IOutputDataWriteStrategy > m_write_strategy
Utility functions for data input and output.
bool isBZipped(const std::string &name)
Returns true if name contains *.bz2 extension.
bool isCompressed(const std::string &name)
Returns true if name contains *.gz extension.
bool isTiffFile(const std::string &file_name)
returns true if file name corresponds to tiff file (can be also compressed)
bool isGZipped(const std::string &name)
Returns true if name contains *.gz extension.
std::wstring convert_utf8_to_utf16(const std::string &str)
Converts utf8 string represented by std::string to utf16 string represented by std::wstring.

References FileSystemUtils::convert_utf8_to_utf16(), DataFormatUtils::isBZipped(), DataFormatUtils::isCompressed(), DataFormatUtils::isGZipped(), DataFormatUtils::isTiffFile(), m_file_name, and m_write_strategy.

Here is the call graph for this function:

◆ setStrategy()

void OutputDataWriter::setStrategy ( IOutputDataWriteStrategy write_strategy)

Sets concrete writing strategy.

Definition at line 71 of file OutputDataWriter.cpp.

72 {
73  m_write_strategy.reset(write_strategy);
74 }

References m_write_strategy.

Referenced by OutputDataWriteFactory::getWriter().

Member Data Documentation

◆ m_file_name

std::string OutputDataWriter::m_file_name
private

Definition at line 38 of file OutputDataWriter.h.

Referenced by writeOutputData().

◆ m_write_strategy

std::unique_ptr<IOutputDataWriteStrategy> OutputDataWriter::m_write_strategy
private

Definition at line 39 of file OutputDataWriter.h.

Referenced by setStrategy(), and writeOutputData().


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