CBMC
Loading...
Searching...
No Matches
output_file.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Output File Container
4
5Author: Daniel Kroening, dkr@amazon.com
6
7\*******************************************************************/
8
11
12#include "output_file.h"
13
14#include "exception_utils.h"
15#include "unicode.h"
16
17#include <fstream>
18#include <iostream>
19
20output_filet::output_filet(std::string file_name) : _name(std::move(file_name))
21{
22 if(_name == "-")
23 {
24 _stream = &std::cout;
25 _name = "stdout";
26 }
27 else
28 {
29 _ofstream = std::make_unique<std::ofstream>(widen_if_needed(_name));
30 if(!*_ofstream)
31 throw system_exceptiont("failed to open " + _name);
32 _stream = _ofstream.get();
33 }
34}
35
output_filet(std::string file_name)
Create a stream to the given file name, or stdout if "-".
std::unique_ptr< std::ofstream > _ofstream
Definition output_file.h:48
std::string _name
Definition output_file.h:47
std::ostream * _stream
Definition output_file.h:49
Thrown when some external system fails unexpectedly.
STL namespace.
Output file container that handles stdout ("-") and regular files.
#define widen_if_needed(s)
Definition unicode.h:28