-
Notifications
You must be signed in to change notification settings - Fork 2
/
errorstream.cxx
49 lines (41 loc) · 1017 Bytes
/
errorstream.cxx
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
// This class is a replacement for the original erstream.cxx which was too
// dependent on older non-standard C++ features to update
//
// (c) Copyright 2014, Shawn Waldon.
#include "errorstream.hpp"
#include <cstring>
ErrorStream::ErrorStream(std::ostream &s) : prog(NULL), stream(s) {}
ErrorStream::ErrorStream(const char *title, std::ostream &s)
: prog(NULL), stream(s)
{
prog = new char[std::strlen(title) + 1];
std::strcpy(prog, title);
}
ErrorStream::ErrorStream(const ErrorStream &er) : prog(NULL), stream(er.stream)
{
if (er.prog) {
prog = new char[std::strlen(er.prog) + 1];
std::strcpy(prog, er.prog);
}
}
ErrorStream::~ErrorStream()
{
if (prog) {
delete[] prog;
}
}
std::ostream &ErrorStream::fatal()
{
stream << "Fatal erorr in " << prog << ": ";
return stream;
}
std::ostream &ErrorStream::fail()
{
stream << "Failure in " << prog << ": ";
return stream;
}
std::ostream &ErrorStream::warning()
{
stream << "Warning from " << prog << ": ";
return stream;
}