STIR  6.2.0
write_to_file.h
Go to the documentation of this file.
1 //
2 //
3 #ifndef __stir_IO_write_to_file_H__
4 #define __stir_IO_write_to_file_H__
5 /*
6  Copyright (C) 2015, University College London
7  This file is part of STIR.
8 
9  SPDX-License-Identifier: Apache-2.0
10 
11  See STIR/LICENSE.txt for details
12 */
23 #include "stir/Succeeded.h"
24 #include "stir/error.h"
25 #include <boost/format.hpp>
26 
27 START_NAMESPACE_STIR
28 
30 
45 template <class DataT>
46 inline std::string
47 write_to_file(const std::string& filename, const DataT& data)
48 {
49  std::string filename_used(filename);
50 
51  if (OutputFileFormat<typename DataT::hierarchy_base_type>::default_sptr()->write_to_file(filename_used, data) != Succeeded::yes)
52  {
53  error(boost::format("Error writing data to file '%1%'") % filename);
54  }
55  return filename_used;
56 }
57 
58 END_NAMESPACE_STIR
59 
60 #endif
Declaration of class stir::Succeeded.
Declaration of stir::error()
Declaration of class stir::OutputFileFormat.
std::string write_to_file(const std::string &filename, const DataT &data)
Function that writes data to file using the default OutputFileFormat.
Definition: write_to_file.h:47
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition: error.cxx:42
Base class for classes that create output files.
Definition: OutputFileFormat.h:55