Skip to content

Commit 07c7eeb

Browse files
committed
Report::warn etc virtuals
Signed-off-by: James Cherry <cherry@parallaxsw.com>
1 parent 73c2cca commit 07c7eeb

1 file changed

Lines changed: 53 additions & 13 deletions

File tree

include/sta/Report.hh

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ public:
6161
void report(std::string_view fmt,
6262
Args &&...args)
6363
{
64-
reportLine(sta::vformat(fmt, sta::make_format_args(args...)));
64+
report(sta::vformat(fmt, sta::make_format_args(args...)));
65+
}
66+
virtual void report(const std::string &formatted_msg)
67+
{
68+
reportLine(formatted_msg);
6569
}
6670

6771
////////////////////////////////////////////////////////////////
@@ -73,10 +77,14 @@ public:
7377
Args &&...args)
7478
{
7579
if (!isSuppressed(id)) {
76-
reportLine(sta::format(
77-
"Warning {}: {}", id, sta::vformat(fmt, sta::make_format_args(args...))));
80+
warn(id, sta::vformat(fmt, sta::make_format_args(args...)));
7881
}
7982
}
83+
virtual void warn(int id,
84+
const std::string &formatted_msg) {
85+
reportLine(sta::format("Warning {}: {}", id, formatted_msg));
86+
}
87+
8088
// Report warning in a file.
8189
template <typename... Args>
8290
void fileWarn(int id,
@@ -86,19 +94,30 @@ public:
8694
Args &&...args)
8795
{
8896
if (!isSuppressed(id)) {
89-
reportLine(
90-
sta::format("Warning {}: {} line {}, {}", id, filename, line,
91-
sta::vformat(fmt, sta::make_format_args(args...))));
97+
fileWarn(id, filename, line,
98+
sta::vformat(fmt, sta::make_format_args(args...)));
9299
}
93100
}
101+
virtual void
102+
fileWarn(int id,
103+
std::string_view filename,
104+
int line,
105+
const std::string &formatted_msg) {
106+
reportLine(sta::format("Warning {}: {} line {}, {}",
107+
id, filename, line, formatted_msg));
108+
}
94109

95110
template <typename... Args>
96111
void error(int id,
97112
std::string_view fmt,
98113
Args &&...args)
99114
{
100-
std::string msg = sta::vformat(fmt, sta::make_format_args(args...));
101-
reportThrowExceptionMsg(sta::format("{} {}", id, msg), isSuppressed(id));
115+
error(id, sta::vformat(fmt, sta::make_format_args(args...)));
116+
}
117+
virtual void error(int id,
118+
const std::string &formatted_msg)
119+
{
120+
reportThrowExceptionMsg(sta::format("{} {}", id, formatted_msg), isSuppressed(id));
102121
}
103122
// Report error in a file.
104123
template <typename... Args>
@@ -108,8 +127,16 @@ public:
108127
std::string_view fmt,
109128
Args &&...args)
110129
{
111-
const std::string msg = sta::vformat(fmt, sta::make_format_args(args...));
112-
reportThrowExceptionMsg(sta::format("{} {} line {}, {}", id, filename, line, msg),
130+
fileError(id, filename, line,
131+
sta::vformat(fmt, sta::make_format_args(args...)));
132+
}
133+
virtual void fileError(int id,
134+
std::string_view filename,
135+
int line,
136+
const std::string &formatted_msg)
137+
{
138+
reportThrowExceptionMsg(sta::format("{} {} line {}, {}",
139+
id, filename, line, formatted_msg),
113140
isSuppressed(id));
114141
}
115142

@@ -121,19 +148,32 @@ public:
121148
std::string_view fmt,
122149
Args &&...args)
123150
{
124-
reportLine(sta::format("Critical {}: {}", id,
125-
sta::vformat(fmt, sta::make_format_args(args...))));
151+
critical(id, sta::vformat(fmt, sta::make_format_args(args...)));
152+
}
153+
virtual void critical(int id,
154+
const std::string &formatted_msg)
155+
{
156+
reportLine(sta::format("Critical {}: {}", id, formatted_msg));
126157
exit(1);
127158
}
159+
128160
template <typename... Args>
129161
void fileCritical(int id,
130162
std::string_view filename,
131163
int line,
132164
std::string_view fmt,
133165
Args &&...args)
166+
{
167+
fileCritical(id, filename, line,
168+
sta::vformat(fmt, sta::make_format_args(args...)));
169+
}
170+
virtual void fileCritical(int id,
171+
std::string_view filename,
172+
int line,
173+
const std::string &formatted_msg)
134174
{
135175
reportLine(sta::format("Critical {}: {} line {}, {}", id, filename, line,
136-
sta::vformat(fmt, sta::make_format_args(args...))));
176+
formatted_msg));
137177
exit(1);
138178
}
139179

0 commit comments

Comments
 (0)