Rename methods according to code review.

This commit is contained in:
Atgeirr Flø Rasmussen 2016-05-18 22:22:10 +02:00
parent f1a1aa02fb
commit c4c1fe2b30
6 changed files with 34 additions and 34 deletions

View File

@ -31,12 +31,12 @@ namespace Opm {
{ {
} }
void LogBackend::configureDecoration(std::shared_ptr<MessageFormatterInterface> formatter) void LogBackend::setMessageFormatter(std::shared_ptr<MessageFormatterInterface> formatter)
{ {
m_formatter = formatter; m_formatter = formatter;
} }
void LogBackend::configureMessageLimiter(std::shared_ptr<MessageLimiter> limiter) void LogBackend::setMessageLimiter(std::shared_ptr<MessageLimiter> limiter)
{ {
m_limiter = limiter; m_limiter = limiter;
} }
@ -62,7 +62,7 @@ namespace Opm {
// Use the message limiter (if any). // Use the message limiter (if any).
MessageLimiter::Response res = m_limiter MessageLimiter::Response res = m_limiter
? m_limiter->encounteredMessage(messageTag) ? m_limiter->handleMessageTag(messageTag)
: MessageLimiter::Response::PrintMessage; : MessageLimiter::Response::PrintMessage;
if (res == MessageLimiter::Response::JustOverLimit) { if (res == MessageLimiter::Response::JustOverLimit) {
// Special case: add a message to this backend about limit being reached. // Special case: add a message to this backend about limit being reached.
@ -72,7 +72,7 @@ namespace Opm {
return res == MessageLimiter::Response::PrintMessage; return res == MessageLimiter::Response::PrintMessage;
} }
std::string LogBackend::decorateMessage(int64_t messageFlag, const std::string& message) std::string LogBackend::formatMessage(int64_t messageFlag, const std::string& message)
{ {
if (m_formatter) { if (m_formatter) {
return m_formatter->format(messageFlag, message); return m_formatter->format(messageFlag, message);

View File

@ -40,11 +40,11 @@ namespace Opm
/// Virtual destructor to enable inheritance. /// Virtual destructor to enable inheritance.
virtual ~LogBackend(); virtual ~LogBackend();
/// Configure how decorateMessage() will modify message strings. /// Configure how formatMessage() will modify message strings.
void configureDecoration(std::shared_ptr<MessageFormatterInterface> formatter); void setMessageFormatter(std::shared_ptr<MessageFormatterInterface> formatter);
/// Configure how message tags will be used to limit messages. /// Configure how message tags will be used to limit messages.
void configureMessageLimiter(std::shared_ptr<MessageLimiter> limiter); void setMessageLimiter(std::shared_ptr<MessageLimiter> limiter);
/// Add a message to the backend. /// Add a message to the backend.
/// ///
@ -69,7 +69,7 @@ namespace Opm
bool includeMessage(int64_t messageFlag, const std::string& messageTag); bool includeMessage(int64_t messageFlag, const std::string& messageTag);
/// Return decorated version of message depending on configureDecoration() arguments. /// Return decorated version of message depending on configureDecoration() arguments.
std::string decorateMessage(int64_t messageFlag, const std::string& message); std::string formatMessage(int64_t messageFlag, const std::string& message);
private: private:
int64_t m_mask; int64_t m_mask;

View File

@ -57,7 +57,7 @@ namespace Opm
return message_limit_; return message_limit_;
} }
/// Used for encounteredMessage() return type (see that /// Used for handleMessageTag() return type (see that
/// function). /// function).
enum class Response enum class Response
{ {
@ -68,7 +68,7 @@ namespace Opm
/// tag (count <= limit), respond PrintMessage. /// tag (count <= limit), respond PrintMessage.
/// If (count == limit + 1), respond JustOverLimit. /// If (count == limit + 1), respond JustOverLimit.
/// If (count > limit + 1), respond OverLimit. /// If (count > limit + 1), respond OverLimit.
Response encounteredMessage(const std::string& tag) Response handleMessageTag(const std::string& tag)
{ {
if (tag.empty() || message_limit_ == NoLimit) { if (tag.empty() || message_limit_ == NoLimit) {
return Response::PrintMessage; return Response::PrintMessage;

View File

@ -46,7 +46,7 @@ void StreamLog::close() {
void StreamLog::addTaggedMessage(int64_t messageType, const std::string& messageTag, const std::string& message) { void StreamLog::addTaggedMessage(int64_t messageType, const std::string& messageTag, const std::string& message) {
if (includeMessage( messageType, messageTag )) { if (includeMessage( messageType, messageTag )) {
(*m_ostream) << decorateMessage(messageType, message) << std::endl; (*m_ostream) << formatMessage(messageType, message) << std::endl;
if (m_ofstream.is_open()) { if (m_ofstream.is_open()) {
m_ofstream.flush(); m_ofstream.flush();
} }

View File

@ -276,7 +276,7 @@ BOOST_AUTO_TEST_CASE(TestOpmLogWithColors)
BOOST_CHECK_EQUAL( true , OpmLog::hasBackend("COUNTER")); BOOST_CHECK_EQUAL( true , OpmLog::hasBackend("COUNTER"));
BOOST_CHECK_EQUAL( true , OpmLog::hasBackend("STREAM")); BOOST_CHECK_EQUAL( true , OpmLog::hasBackend("STREAM"));
streamLog->configureDecoration(std::make_shared<SimpleMessageFormatter>(false, true)); streamLog->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(false, true));
} }
OpmLog::warning("Warning"); OpmLog::warning("Warning");
@ -322,10 +322,10 @@ BOOST_AUTO_TEST_CASE(TestOpmLogWithLimits)
BOOST_CHECK_EQUAL( true , OpmLog::hasBackend("STREAM1")); BOOST_CHECK_EQUAL( true , OpmLog::hasBackend("STREAM1"));
BOOST_CHECK_EQUAL( true , OpmLog::hasBackend("STREAM2")); BOOST_CHECK_EQUAL( true , OpmLog::hasBackend("STREAM2"));
streamLog1->configureDecoration(std::make_shared<SimpleMessageFormatter>(false, true)); streamLog1->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(false, true));
streamLog1->configureMessageLimiter(std::make_shared<MessageLimiter>(2)); streamLog1->setMessageLimiter(std::make_shared<MessageLimiter>(2));
streamLog2->configureDecoration(std::make_shared<SimpleMessageFormatter>(false, true)); streamLog2->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(false, true));
streamLog2->configureMessageLimiter(std::make_shared<MessageLimiter>()); // no limit streamLog2->setMessageLimiter(std::make_shared<MessageLimiter>()); // no limit
} }
const std::string tag = "ExampleTag"; const std::string tag = "ExampleTag";

View File

@ -47,33 +47,33 @@ BOOST_AUTO_TEST_CASE(Response)
{ {
// No limits. // No limits.
MessageLimiter m; MessageLimiter m;
BOOST_CHECK(m.encounteredMessage("tag1") == MessageLimiter::Response::PrintMessage); BOOST_CHECK(m.handleMessageTag("tag1") == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.encounteredMessage("tag2") == MessageLimiter::Response::PrintMessage); BOOST_CHECK(m.handleMessageTag("tag2") == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.encounteredMessage("tag1") == MessageLimiter::Response::PrintMessage); BOOST_CHECK(m.handleMessageTag("tag1") == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.encounteredMessage("tag2") == MessageLimiter::Response::PrintMessage); BOOST_CHECK(m.handleMessageTag("tag2") == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.encounteredMessage("tag1") == MessageLimiter::Response::PrintMessage); BOOST_CHECK(m.handleMessageTag("tag1") == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.encounteredMessage("tag2") == MessageLimiter::Response::PrintMessage); BOOST_CHECK(m.handleMessageTag("tag2") == MessageLimiter::Response::PrintMessage);
} }
{ {
// Limit == 0. // Limit == 0.
MessageLimiter m(0); MessageLimiter m(0);
BOOST_CHECK(m.encounteredMessage("tag1") == MessageLimiter::Response::JustOverLimit); BOOST_CHECK(m.handleMessageTag("tag1") == MessageLimiter::Response::JustOverLimit);
BOOST_CHECK(m.encounteredMessage("tag2") == MessageLimiter::Response::JustOverLimit); BOOST_CHECK(m.handleMessageTag("tag2") == MessageLimiter::Response::JustOverLimit);
BOOST_CHECK(m.encounteredMessage("tag1") == MessageLimiter::Response::OverLimit); BOOST_CHECK(m.handleMessageTag("tag1") == MessageLimiter::Response::OverLimit);
BOOST_CHECK(m.encounteredMessage("tag2") == MessageLimiter::Response::OverLimit); BOOST_CHECK(m.handleMessageTag("tag2") == MessageLimiter::Response::OverLimit);
BOOST_CHECK(m.encounteredMessage("tag1") == MessageLimiter::Response::OverLimit); BOOST_CHECK(m.handleMessageTag("tag1") == MessageLimiter::Response::OverLimit);
BOOST_CHECK(m.encounteredMessage("tag2") == MessageLimiter::Response::OverLimit); BOOST_CHECK(m.handleMessageTag("tag2") == MessageLimiter::Response::OverLimit);
} }
{ {
// Limit == 1. // Limit == 1.
MessageLimiter m(1); MessageLimiter m(1);
BOOST_CHECK(m.encounteredMessage("tag1") == MessageLimiter::Response::PrintMessage); BOOST_CHECK(m.handleMessageTag("tag1") == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.encounteredMessage("tag2") == MessageLimiter::Response::PrintMessage); BOOST_CHECK(m.handleMessageTag("tag2") == MessageLimiter::Response::PrintMessage);
BOOST_CHECK(m.encounteredMessage("tag1") == MessageLimiter::Response::JustOverLimit); BOOST_CHECK(m.handleMessageTag("tag1") == MessageLimiter::Response::JustOverLimit);
BOOST_CHECK(m.encounteredMessage("tag2") == MessageLimiter::Response::JustOverLimit); BOOST_CHECK(m.handleMessageTag("tag2") == MessageLimiter::Response::JustOverLimit);
BOOST_CHECK(m.encounteredMessage("tag1") == MessageLimiter::Response::OverLimit); BOOST_CHECK(m.handleMessageTag("tag1") == MessageLimiter::Response::OverLimit);
BOOST_CHECK(m.encounteredMessage("tag2") == MessageLimiter::Response::OverLimit); BOOST_CHECK(m.handleMessageTag("tag2") == MessageLimiter::Response::OverLimit);
} }
} }