From 1e21457efbf41981723d89c186930200b83e8f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Tue, 14 Jun 2016 17:11:45 +0200 Subject: [PATCH] Refactored color output of headings. --- include/plasp/pddl/TranslatorASP.h | 3 -- include/plasp/utils/Formatting.h | 64 +++++++++++++++++++++++++++--- src/plasp/pddl/TranslatorASP.cpp | 39 ++++-------------- 3 files changed, 66 insertions(+), 40 deletions(-) diff --git a/include/plasp/pddl/TranslatorASP.h b/include/plasp/pddl/TranslatorASP.h index b066147..d572feb 100644 --- a/include/plasp/pddl/TranslatorASP.h +++ b/include/plasp/pddl/TranslatorASP.h @@ -39,9 +39,6 @@ class TranslatorASP void translateLiteral(const Expression &literal) const; void translatePredicate(const expressions::Predicate &predicate) const; - void printHeading1(const std::string &heading) const; - void printHeading2(const std::string &heading) const; - const Description &m_description; utils::LogStream &m_outputStream; }; diff --git a/include/plasp/utils/Formatting.h b/include/plasp/utils/Formatting.h index 0e2b1bd..b0a69e1 100644 --- a/include/plasp/utils/Formatting.h +++ b/include/plasp/utils/Formatting.h @@ -81,9 +81,9 @@ inline LogStream &operator<<(LogStream &stream, const ResetFormat &) //////////////////////////////////////////////////////////////////////////////////////////////////// -struct Keyword +struct Token { - Keyword(const std::string &name) + Token(const std::string &name) : name(name) { } @@ -93,6 +93,16 @@ struct Keyword //////////////////////////////////////////////////////////////////////////////////////////////////// +struct Keyword: public Token +{ + Keyword(const std::string &name) + : Token(name) + { + } +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + inline LogStream &operator<<(LogStream &stream, const Keyword &keyword) { return (stream @@ -103,14 +113,12 @@ inline LogStream &operator<<(LogStream &stream, const Keyword &keyword) //////////////////////////////////////////////////////////////////////////////////////////////////// -struct Variable +struct Variable: public Token { Variable(const std::string &name) - : name(name) + : Token(name) { } - - const std::string &name; }; //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -123,6 +131,50 @@ inline LogStream &operator<<(LogStream &stream, const Variable &variable) << utils::ResetFormat()); } +//////////////////////////////////////////////////////////////////////////////////////////////////// + +struct Heading1: public Token +{ + Heading1(const std::string &name) + : Token(name) + { + } +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline LogStream &operator<<(LogStream &stream, const Heading1 &heading1) +{ + return (stream + << utils::Format(utils::Color::Blue, utils::FontWeight::Bold) + << "%---------------------------------------" << std::endl + << "% " << heading1.name << std::endl + << "%---------------------------------------" + << utils::ResetFormat() + << std::endl); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +struct Heading2: public Token +{ + Heading2(const std::string &name) + : Token(name) + { + } +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +inline LogStream &operator<<(LogStream &stream, const Heading2 &heading2) +{ + return (stream + << utils::Format(utils::Color::Blue, utils::FontWeight::Bold) + << "% " << heading2.name + << utils::ResetFormat()); +} + + //////////////////////////////////////////////////////////////////////////////////////////////////// } diff --git a/src/plasp/pddl/TranslatorASP.cpp b/src/plasp/pddl/TranslatorASP.cpp index 04c677a..4ee5c70 100644 --- a/src/plasp/pddl/TranslatorASP.cpp +++ b/src/plasp/pddl/TranslatorASP.cpp @@ -43,7 +43,7 @@ void TranslatorASP::translate() const void TranslatorASP::translateDomain() const { - printHeading1("domain"); + m_outputStream << utils::Heading1("domain"); const auto &domain = m_description.domain(); @@ -77,7 +77,7 @@ void TranslatorASP::translateDomain() const void TranslatorASP::translateTypes() const { - printHeading2("types"); + m_outputStream << utils::Heading2("types"); m_outputStream << std::endl; @@ -120,7 +120,7 @@ void TranslatorASP::translateTypes() const void TranslatorASP::translatePredicates() const { - printHeading2("predicates"); + m_outputStream << utils::Heading2("predicates"); const auto &predicates = m_description.domain().predicates(); @@ -147,7 +147,7 @@ void TranslatorASP::translatePredicates() const void TranslatorASP::translateActions() const { - printHeading2("actions"); + m_outputStream << utils::Heading2("actions"); const auto &actions = m_description.domain().actions(); @@ -251,7 +251,7 @@ void TranslatorASP::translateActions() const void TranslatorASP::translateConstants(const std::string &heading, const expressions::Constants &constants) const { - printHeading2(heading); + m_outputStream << utils::Heading2(heading); std::for_each(constants.cbegin(), constants.cend(), [&](const auto &constant) @@ -405,7 +405,7 @@ void TranslatorASP::translateProblem() const { BOOST_ASSERT(m_description.containsProblem()); - printHeading1("problem"); + m_outputStream << utils::Heading1("problem"); const auto &problem = m_description.problem(); @@ -431,7 +431,7 @@ void TranslatorASP::translateInitialState() const { BOOST_ASSERT(m_description.containsProblem()); - printHeading2("initial state"); + m_outputStream << utils::Heading2("initial state"); const auto &initialStateFacts = m_description.problem().initialState().facts(); @@ -466,7 +466,7 @@ void TranslatorASP::translateGoal() const { BOOST_ASSERT(m_description.containsProblem()); - printHeading2("goal"); + m_outputStream << utils::Heading2("goal"); const auto &goal = m_description.problem().goal(); @@ -501,28 +501,5 @@ void TranslatorASP::translateGoal() const //////////////////////////////////////////////////////////////////////////////////////////////////// -void TranslatorASP::printHeading1(const std::string &heading) const -{ - m_outputStream - << utils::Format(utils::Color::Blue, utils::FontWeight::Bold) - << "%---------------------------------------" << std::endl - << "% " << heading << std::endl - << "%---------------------------------------" - << utils::ResetFormat() - << std::endl; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -void TranslatorASP::printHeading2(const std::string &heading) const -{ - m_outputStream - << utils::Format(utils::Color::Blue, utils::FontWeight::Bold) - << "% " << heading - << utils::ResetFormat(); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - } }