Skip to content

Commit ccd11f5

Browse files
committed
Avoid default no-ops, force derived classes to override
1 parent d752b42 commit ccd11f5

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

Diff for: src/util/message.h

+28-17
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,17 @@ class message_handlert
3131

3232
virtual void print(unsigned level, const std::string &message)=0;
3333

34-
virtual void print(unsigned level, const xmlt &xml)
35-
{
36-
// no-op by default
37-
}
34+
virtual void print(unsigned level, const xmlt &xml) = 0;
3835

39-
virtual void print(unsigned level, const jsont &json)
40-
{
41-
// no-op by default
42-
}
36+
virtual void print(unsigned level, const jsont &json) = 0;
4337

4438
virtual void print(
4539
unsigned level,
4640
const std::string &message,
4741
int sequence_number,
4842
const source_locationt &location);
4943

50-
virtual void flush(unsigned level)
51-
{
52-
// no-op by default
53-
}
44+
virtual void flush(unsigned) = 0;
5445

5546
virtual ~message_handlert()
5647
{
@@ -75,19 +66,31 @@ class message_handlert
7566
class null_message_handlert:public message_handlert
7667
{
7768
public:
78-
virtual void print(unsigned level, const std::string &message)
69+
void print(unsigned level, const std::string &message) override
7970
{
8071
message_handlert::print(level, message);
8172
}
8273

83-
virtual void print(
74+
void print(unsigned, const xmlt &) override
75+
{
76+
}
77+
78+
void print(unsigned, const jsont &) override
79+
{
80+
}
81+
82+
void print(
8483
unsigned level,
8584
const std::string &message,
8685
int sequence_number,
87-
const source_locationt &location)
86+
const source_locationt &location) override
8887
{
8988
print(level, message);
9089
}
90+
91+
void flush(unsigned) override
92+
{
93+
}
9194
};
9295

9396
class stream_message_handlert:public message_handlert
@@ -97,15 +100,23 @@ class stream_message_handlert:public message_handlert
97100
{
98101
}
99102

100-
virtual void print(unsigned level, const std::string &message)
103+
void print(unsigned level, const std::string &message) override
101104
{
102105
message_handlert::print(level, message);
103106

104107
if(verbosity>=level)
105108
out << message << '\n';
106109
}
107110

108-
virtual void flush(unsigned level)
111+
void print(unsigned, const xmlt &) override
112+
{
113+
}
114+
115+
void print(unsigned, const jsont &) override
116+
{
117+
}
118+
119+
void flush(unsigned) override
109120
{
110121
out << std::flush;
111122
}

0 commit comments

Comments
 (0)