Skip to content

Avoid default no-ops, force derived classes to override [blocks: #2310] #3362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/util/cout_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class cerr_message_handlert:public stream_message_handlert
class console_message_handlert : public message_handlert
{
public:
void print(unsigned, const xmlt &) override
{
}

void print(unsigned, const jsont &) override
{
}

// level 4 and upwards go to cout, level 1-3 to cerr
virtual void print(
unsigned level,
Expand Down Expand Up @@ -57,6 +65,14 @@ class console_message_handlert : public message_handlert
class gcc_message_handlert : public console_message_handlert
{
public:
void print(unsigned, const xmlt &) override
{
}

void print(unsigned, const jsont &) override
{
}

// aims to imitate the messages gcc prints
virtual void print(
unsigned level,
Expand Down
45 changes: 28 additions & 17 deletions src/util/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,16 @@ class message_handlert

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

virtual void print(unsigned level, const xmlt &xml)
{
// no-op by default
}
virtual void print(unsigned level, const xmlt &xml) = 0;

virtual void print(unsigned level, const jsont &json)
{
// no-op by default
}
virtual void print(unsigned level, const jsont &json) = 0;

virtual void print(
unsigned level,
const std::string &message,
const source_locationt &location);

virtual void flush(unsigned level)
{
// no-op by default
}
virtual void flush(unsigned) = 0;

virtual ~message_handlert()
{
Expand Down Expand Up @@ -80,18 +71,30 @@ class message_handlert
class null_message_handlert:public message_handlert
{
public:
virtual void print(unsigned level, const std::string &message)
void print(unsigned level, const std::string &message) override
{
message_handlert::print(level, message);
}

virtual void print(
void print(unsigned, const xmlt &) override
{
}

void print(unsigned, const jsont &) override
{
}

void print(
unsigned level,
const std::string &message,
const source_locationt &)
const source_locationt &) override
{
print(level, message);
}

void flush(unsigned) override
{
}
};

class stream_message_handlert:public message_handlert
Expand All @@ -101,15 +104,23 @@ class stream_message_handlert:public message_handlert
{
}

virtual void print(unsigned level, const std::string &message)
void print(unsigned level, const std::string &message) override
{
message_handlert::print(level, message);

if(verbosity>=level)
out << message << '\n';
}

virtual void flush(unsigned level)
void print(unsigned, const xmlt &) override
{
}

void print(unsigned, const jsont &) override
{
}

void flush(unsigned) override
{
out << std::flush;
}
Expand Down