forked from viva64/plog-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathioutput.cpp
63 lines (52 loc) · 1.37 KB
/
ioutput.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// 2006-2008 (c) Viva64.com Team
// 2008-2020 (c) OOO "Program Verification Systems"
#include "ioutput.h"
namespace PlogConverter
{
void IOutput::Start() {}
void IOutput::Finish() {}
IOutput::~IOutput() = default;
static std::basic_ostream<char> &OfstreamOrStdOut(std::ofstream &of, bool useStdErr, const std::string &path)
{
if (path.empty())
{
return useStdErr ? std::cerr : std::cout;
}
return of;
}
IOutput::IOutput(const ProgramOptions &options, const std::string &extension) : m_ostream(OfstreamOrStdOut(m_ofstream, options.useStderr, options.output))
{
if (!options.output.empty())
{
std::string output = options.output;
if (IsDirectory(output))
{
output += '/';
output += options.outputName.empty() ? FileStem(FileBaseName(options.inputFiles.at(0))) : options.outputName;
output += '.';
output += extension;
}
m_ofstream.open(output);
if (!m_ofstream.is_open())
{
throw FilesystemException("Can't write to file: " + output);
}
}
m_errorCodeMappings = options.codeMappings;
}
IOutput::IOutput() : m_ostream(std::cout)
{
}
IOutput::IOutput(const std::string &path) : m_ostream(m_ofstream)
{
if (path.empty())
{
throw FilesystemException("Empty filepath");
}
m_ofstream.open(path);
if (!m_ofstream.is_open())
{
throw FilesystemException("Can't write to file: " + path);
}
}
}