This source file includes following definitions.
- close
- cannot_open_file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #include <sstream>
23 #include "io_errorStream.h"
24 #include "io_parameter.h"
25
26 #ifdef DEBUG
27 #include <iostream>
28 #endif
29
30 void cannot_open_file(const std::string& fname);
31
32 Esfem::Io::Error_stream::Error_stream(const std::string& fname)
33 :ofs {fname, std::ios_base::app}
34 {
35 #ifdef DEBUG
36 std::clog << "Opening " << fname << " for Error_stream" << std::endl;
37 #endif
38 if(!ofs) cannot_open_file(fname);
39 }
40 Esfem::Io::Error_stream::Error_stream(const Parameter& d)
41 :Error_stream {d.error_log()}
42 {}
43 Esfem::Io::Error_stream::Error_stream(const std::string& suffix, const Parameter& d)
44 :Error_stream {d.error_log() + suffix}
45 {}
46 Esfem::Io::Error_stream& Esfem::Io::Error_stream::operator<<(StdManip manip){
47 #if DEBUG > 8
48 std::clog << "Using operator<<(StdManip)." << std::endl;
49 #endif
50 manip(ofs);
51 return *this;
52 }
53 Esfem::Io::Error_stream& Esfem::Io::Error_stream::close(){
54 ofs.close();
55 return *this;
56 }
57
58
59
60
61 void cannot_open_file(const std::string& fname){
62 std::ostringstream err_msg;
63 err_msg << "Error in constructor of Error_stream. "
64 "Could not open file: " << fname;
65 throw std::runtime_error {err_msg.str()};
66 }
67
68
69
70
71