diff --git a/include/rosa/agent/Abstraction.hpp b/include/rosa/agent/Abstraction.hpp index 6337f25..a343ec8 100644 --- a/include/rosa/agent/Abstraction.hpp +++ b/include/rosa/agent/Abstraction.hpp @@ -1,190 +1,190 @@ /***************************************************************************//** * * \file rosa/agent/Abstraction.hpp * * \author David Juhasz (david.juhasz@tuwien.ac.at) * * \date 2017 * * \brief Definition of *abstraction* *functionality*. * ******************************************************************************/ #ifndef ROSA_AGENT_ABSTRACTION_HPP #define ROSA_AGENT_ABSTRACTION_HPP #include "rosa/agent/Module.h" #include "rosa/support/debug.hpp" #include #include namespace rosa { namespace agent { /// Abstracts values from a type to another one. /// /// \tparam T type to abstract from /// \tparam A type to abstract to template class Abstraction : public Module { protected: /// Value to abstract to by default. const A Default; public: /// Creates an instance. /// /// \param Default value to abstract to by default Abstraction(const A Default) noexcept : Default(Default) {} /// Destroys `this` object. ~Abstraction(void) = default; /// Abstracts a value from type `T` to type `A`. /// /// \note The default implementation always returns /// `rosa::agent::Abstraction::Default`, hence the actual argument is ignored. /// /// \return the abstracted value virtual A operator()(const T &) const noexcept { return Default; } }; /// Implements `rosa::agent::Abstraction` as a `std::map` from a type to another /// one. /// /// \note This implementation is supposed to be used to abstract between /// enumeration types, which is statically enforced. /// /// \tparam T type to abstract from /// \tparam A type to abstract to template class MapAbstraction : public Abstraction, private std::map { // Make sure the actual type arguments are enumerations. STATIC_ASSERT((std::is_enum::value && std::is_enum::value), "mapping not enumerations"); // Bringing into scope inherited members. using Abstraction::Default; using std::map::end; using std::map::find; public: /// Creates an instance by initializing the underlying `std::map`. /// /// \param Map the mapping to do abstraction according to /// \param Default value to abstract to by default MapAbstraction(const std::map &Map, const A Default) noexcept : Abstraction(Default), std::map(Map) {} /// Destroys `this` object. ~MapAbstraction(void) = default; /// Abstracts a value from type `T` to type `A` based on the set mapping. /// /// Results in the value associated by the set mapping to the argument, or /// `rosa::agent::MapAbstraction::Default` if the actual argument is not /// associated with anything by the set mapping. /// /// \param V value to abstract /// /// \return the abstracted value based on the set mapping A operator()(const T &V) const noexcept override { const auto I = find(V); return I == end() ? Default : *I; } }; /// Implements `rosa::agent::Abstraction` as a `std::map` from ranges of a type /// to values of another type. /// /// \note This implementation is supposed to be used to abstract ranges of /// arithmetic types into enumerations, which is statically enforced. /// /// \invariant The keys in the underlying `std::map` define valid ranges /// `(first <= second)` and there are no overlapping ranges defined by the keys. /// /// \tparam T type to abstract from /// \tparam A type to abstract to template class RangeAbstraction : public Abstraction, private std::map, A> { // Make sure the actual type arguments are matching our expectations. STATIC_ASSERT((std::is_arithmetic::value), "abstracting not arithmetic"); STATIC_ASSERT((std::is_enum::value), "abstracting not to enumeration"); // Bringing into scope inherited members. using Abstraction::Default; using std::map, A>::begin; using std::map, A>::end; using std::map, A>::find; public: /// Creates an instance by Initializing the unserlying `std::map`. /// /// \param Map the mapping to do abstraction according to /// \param Default value to abstract to by default /// /// \pre Each key defines a valid range `(first <= second)` and there are no /// overlapping ranges defined by the keys. RangeAbstraction(const std::map, A> &Map, const A &Default) : Abstraction(Default), std::map, A>(Map) { // Sanity check. ASSERT(std::all_of( begin(), end(), [this](const std::pair, A> &P) { return P.first.first <= P.first.second && std::all_of(++find(P.first), end(), [&P](const std::pair, A> &R) { // NOTE: Values in Map are sorted. return P.first.first < P.first.second && P.first.second <= R.first.first || P.first.first == P.first.second && P.first.second < R.first.first; }); })); } /// Destroys `this` object. ~RangeAbstraction(void) = default; // Gives a value of type A associated by the underlying map to V of type T, // or Default if no range containing V is defined. /// Abstracts a value from type `T` to type `A` based on the set mapping. /// /// Results in the value associated by the set mapping to the argument, or /// `rosa::agent::RangeAbstraction::Default` if the actual argument is not /// included in any of the ranges in the set mapping. /// /// \param V value to abstract /// /// \return the abstracted value based on the set mapping A operator()(const T &V) const noexcept override { auto I = begin(); - bool found = false; // Indicates if I refers to a matching range. - bool failed = false; // Indicates if it is pointless to continue searching. - while (!found && !failed && I != end()) { + bool Found = false; // Indicates if I refers to a matching range. + bool Failed = false; // Indicates if it is pointless to continue searching. + while (!Found && !Failed && I != end()) { if (V < I->first.first) { // No match so far and V is below the next range, never will match. // \note Keys are sorted in the map. - failed = true; + Failed = true; } else if (I->first.first <= V && V < I->first.second) { // Matching range found. - found = true; + Found = true; } else { // Cannot conclude in this step, move to the next range. ++I; } } - ASSERT(!found || I != end()); - return found ? I->second : Default; + ASSERT(!Found || I != end()); + return Found ? I->second : Default; } }; } // End namespace agent } // End namespace rosa #endif // ROSA_AGENT_ABSTRACTION_HPP diff --git a/include/rosa/config/namespaces.h b/include/rosa/config/namespaces.h index b82066b..9c23e55 100755 --- a/include/rosa/config/namespaces.h +++ b/include/rosa/config/namespaces.h @@ -1,22 +1,27 @@ /***************************************************************************//** * * \file rosa/config/namespaces.h * * \author David Juhasz (david.juhasz@tuwien.ac.at) * * \date 2017 * * \brief Documentation for namespaces that are scattered into more then one * header file. * ******************************************************************************/ +#ifndef ROSA_CONFIG_NAMESPACES_H +#define ROSA_CONFIG_NAMESPACES_H + /// Base namespace used by the RoSA framework. namespace rosa { /// Contains facilities that are supposed to be useful for implementing /// *agents*. namespace agent {} -} +} // End namespace rosa + +#endif // ROSA_CONFIG_NAMESPACES_H diff --git a/include/rosa/config/version.h b/include/rosa/config/version.h index d35e769..0ebfa8b 100644 --- a/include/rosa/config/version.h +++ b/include/rosa/config/version.h @@ -1,34 +1,34 @@ /***************************************************************************//** * * \file rosa/config/version.h * * \author David Juhasz (david.juhasz@tuwien.ac.at) * * \date 2017 * * \brief Version information about the build of the library. * ******************************************************************************/ #ifndef ROSA_CONFIG_VERSION_H #define ROSA_CONFIG_VERSION_H #include "rosa/config/rosa_config.h" -#include +#include // NOLINT namespace rosa { /// Returns a string containing the name of the library followed by its version. std::string library_string(void); /// Returns a string containing the version number of the library. std::string version(void); /// Returns a multi-line string containing verbose information on the library. std::string verbose_version(void); } // End namespace rosa #endif // ROSA_CONFIG_VERSION_H diff --git a/lib/config/version.cpp b/lib/config/version.cpp index 18ccea7..b7e9736 100644 --- a/lib/config/version.cpp +++ b/lib/config/version.cpp @@ -1,42 +1,42 @@ /***************************************************************************//** * * \file config/version.cpp * * \author David Juhasz (david.juhasz@tuwien.ac.at) * * \date 2017 * * \brief Implementation for rosa/config/version.h. * ******************************************************************************/ #include "rosa/config/version.h" #include namespace rosa { std::string library_string(void) { return PACKAGE_STRING; } std::string version(void) { return PACKAGE_VERSION; } std::string verbose_version(void) { - std::stringstream ss; - ss << PACKAGE_STRING << std::endl + std::stringstream SS; + SS << PACKAGE_STRING << std::endl << "Built by " << CMAKE_GENERATOR << " with " << CMAKE_CXX_COMPILER_ID << ' ' << CMAKE_CXX_COMPILER_VERSION << std::endl << "on a(n) " << CMAKE_SYSTEM << " system." << std::endl << "Build date: " << BUILD_DATE << std::endl << "Package name: " << PACKAGE_NAME << std::endl << "Package version: " << PACKAGE_VERSION << std::endl << "Report issues: " << PACKAGE_BUGREPORT << std::endl; - return ss.str(); + return SS.str(); } } // End namespace rosa diff --git a/lib/support/log.cpp b/lib/support/log.cpp index 85aec33..4120bd9 100644 --- a/lib/support/log.cpp +++ b/lib/support/log.cpp @@ -1,59 +1,59 @@ /***************************************************************************//** * * \file support/log.cpp * * \author David Juhasz (david.juhasz@tuwien.ac.at) * * \date 2017 * * \brief Implementation for rosa/support/log.h. * ******************************************************************************/ #include "rosa/support/log.h" -#include "rosa/support/debug.hpp" +#include "rosa/support/debug.hpp" // NOLINT #include "rosa/support/terminal_colors.h" #include namespace rosa { /// Textual representation of `rosa::LogLevel` values. /// \note Do not index with `rosa::LogLevel::NumLogLevels`! constexpr std::array(LogLevel::NumLogLevels)> LogLevelStrings{{"ERROR", "WARNING", "INFO", "DEBUG", "TRACE"}}; /// Terminal colors associated to `rosa::LogLevel` values. /// \note Do not index with `rosa::LogLevel::NumLogLevels`! constexpr std::array(LogLevel::NumLogLevels)> LogLevelColors{{ terminal::Color::Red, ///< color corresponding to /// `rosa::LogLevel::Error` terminal::Color::Yellow, ///< color corresponding to /// `rosa::LogLevel::Warning` terminal::Color::Green, ///< color corresponding to /// `rosa::LogLevel::Info` terminal::Color::Blue, ///< color corresponding to /// `rosa::LogLevel::Debug` terminal::Color::Default, ///< color corresponding to /// `rosa::LogLevel::Trace` }}; std::string logLevelToString(const LogLevel logLevel) { ASSERT(logLevel != LogLevel::NumLogLevels); return LogLevelStrings[static_cast(logLevel)]; } std::ostream &operator<<(std::ostream &os, const LogLevel logLevel) { ASSERT(logLevel != LogLevel::NumLogLevels); os << LogLevelColors[static_cast(logLevel)] << "[" << logLevelToString(logLevel) << "]" << terminal::Color::Default; return os; } std::ostream LogSink(nullptr); } // End namespace rosa