From 70864112c87365af645f0404f881edf36c1ec734 Mon Sep 17 00:00:00 2001 From: Olivier Stasse <ostasse@laas.fr> Date: Mon, 3 Feb 2020 07:58:59 +0100 Subject: [PATCH] clang format. --- include/dynamic-graph/command-setter.t.cpp | 1 - include/dynamic-graph/logger.h | 50 +++++++++--------- include/dynamic-graph/value.h | 4 +- src/command/value.cpp | 58 ++++++++++++--------- tests/debug-logger.cpp | 59 ++++++++++++---------- tests/entity.cpp | 12 +++-- tests/signal-all.cpp | 16 +++--- tests/value.cpp | 24 ++++----- 8 files changed, 118 insertions(+), 106 deletions(-) diff --git a/include/dynamic-graph/command-setter.t.cpp b/include/dynamic-graph/command-setter.t.cpp index 0fb8b91..d1972b1 100644 --- a/include/dynamic-graph/command-setter.t.cpp +++ b/include/dynamic-graph/command-setter.t.cpp @@ -9,7 +9,6 @@ #include "dynamic-graph/command-setter.h" #include "dynamic-graph/linear-algebra.h" -#include "dynamic-graph/command-setter.h" #include <boost/assign/list_of.hpp> #include <sstream> diff --git a/include/dynamic-graph/logger.h b/include/dynamic-graph/logger.h index b7552b5..a4d151c 100644 --- a/include/dynamic-graph/logger.h +++ b/include/dynamic-graph/logger.h @@ -27,17 +27,17 @@ namespace dynamicgraph { /** Enum representing the different kind of messages. */ enum MsgType { - MSG_TYPE_TYPE_BITS = 1<<0 | 1<<1 | 1<<2 | 1<<3, // 15 - MSG_TYPE_STREAM_BIT = 1<<4, // 16 - - MSG_TYPE_DEBUG = 1<<3, // 1 - MSG_TYPE_INFO = 1<<2, // 2 - MSG_TYPE_WARNING = 1<<1, // 4 - MSG_TYPE_ERROR = 1<<0, // 8 - MSG_TYPE_DEBUG_STREAM = MSG_TYPE_DEBUG | MSG_TYPE_STREAM_BIT, // 17 - MSG_TYPE_INFO_STREAM = MSG_TYPE_INFO | MSG_TYPE_STREAM_BIT, // 18 - MSG_TYPE_WARNING_STREAM = MSG_TYPE_WARNING | MSG_TYPE_STREAM_BIT, // 20 - MSG_TYPE_ERROR_STREAM = MSG_TYPE_ERROR | MSG_TYPE_STREAM_BIT // 24 + MSG_TYPE_TYPE_BITS = 1 << 0 | 1 << 1 | 1 << 2 | 1 << 3, // 15 + MSG_TYPE_STREAM_BIT = 1 << 4, // 16 + + MSG_TYPE_DEBUG = 1 << 3, // 1 + MSG_TYPE_INFO = 1 << 2, // 2 + MSG_TYPE_WARNING = 1 << 1, // 4 + MSG_TYPE_ERROR = 1 << 0, // 8 + MSG_TYPE_DEBUG_STREAM = MSG_TYPE_DEBUG | MSG_TYPE_STREAM_BIT, // 17 + MSG_TYPE_INFO_STREAM = MSG_TYPE_INFO | MSG_TYPE_STREAM_BIT, // 18 + MSG_TYPE_WARNING_STREAM = MSG_TYPE_WARNING | MSG_TYPE_STREAM_BIT, // 20 + MSG_TYPE_ERROR_STREAM = MSG_TYPE_ERROR | MSG_TYPE_STREAM_BIT // 24 }; } // namespace dynamicgraph @@ -92,7 +92,6 @@ namespace dynamicgraph { #define DYNAMIC_GRAPH_ENTITY_ERROR_STREAM(entity) \ _DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_ERROR_STREAM) - template <typename T> std::string toString(const T &v, const int precision = 3, const int width = -1) { @@ -143,11 +142,11 @@ std::string toString(const Eigen::MatrixBase<T> &v, const int precision = 3, } enum LoggerVerbosity { - VERBOSITY_ALL = MSG_TYPE_DEBUG, + VERBOSITY_ALL = MSG_TYPE_DEBUG, VERBOSITY_INFO_WARNING_ERROR = MSG_TYPE_INFO, - VERBOSITY_WARNING_ERROR = MSG_TYPE_WARNING, - VERBOSITY_ERROR = MSG_TYPE_ERROR, - VERBOSITY_NONE = 0 + VERBOSITY_WARNING_ERROR = MSG_TYPE_WARNING, + VERBOSITY_ERROR = MSG_TYPE_ERROR, + VERBOSITY_NONE = 0 }; /// \ingroup debug @@ -209,7 +208,7 @@ public: * iterations. * \param lineId typically __FILE__ ":" BOOST_PP_STRINGIZE(__LINE__) */ - RTLoggerStream stream(MsgType type, const std::string& lineId = "") { + RTLoggerStream stream(MsgType type, const std::string &lineId = "") { RealTimeLogger &rtlogger = ::dynamicgraph::RealTimeLogger::instance(); if (acceptMsg(type, lineId)) return rtlogger.front(); @@ -221,15 +220,15 @@ public: * stream(type, lineId) << msg << '\n'; * \endcode */ - void sendMsg(std::string msg, MsgType type, const std::string& lineId = ""); + void sendMsg(std::string msg, MsgType type, const std::string &lineId = ""); /** \deprecated instead, use * \code * stream(type, lineId) << msg << '\n'; * \endcode */ - void sendMsg(std::string msg, MsgType type, const std::string& file, - int line) DYNAMIC_GRAPH_DEPRECATED; + void sendMsg(std::string msg, MsgType type, const std::string &file, + int line) DYNAMIC_GRAPH_DEPRECATED; /** Set the sampling time at which the method countdown() * is going to be called. */ @@ -264,28 +263,27 @@ protected: the collection of streaming messages */ StreamCounterMap_t m_stream_msg_counters; - inline bool isStreamMsg(MsgType m) { - return (m & MSG_TYPE_STREAM_BIT); - } + inline bool isStreamMsg(MsgType m) { return (m & MSG_TYPE_STREAM_BIT); } /** Check whether a message of type \m and from \c lineId should be accepted. * \note If \c is a stream type, the internal counter associated to \c lineId * is updated. */ - bool acceptMsg (MsgType m, const std::string& lineId) { + bool acceptMsg(MsgType m, const std::string &lineId) { // If more verbose than the current verbosity level if ((m & MSG_TYPE_TYPE_BITS) > m_lv) return false; // if print is allowed by current verbosity level - if (isStreamMsg(m)) return checkStreamPeriod(lineId); + if (isStreamMsg(m)) + return checkStreamPeriod(lineId); return true; } /** Check whether a message from \c lineId should be accepted. * \note The internal counter associated to \c lineId is updated. */ - bool checkStreamPeriod (const std::string& lineId); + bool checkStreamPeriod(const std::string &lineId); }; } // namespace dynamicgraph diff --git a/include/dynamic-graph/value.h b/include/dynamic-graph/value.h index 0474348..dc70594 100644 --- a/include/dynamic-graph/value.h +++ b/include/dynamic-graph/value.h @@ -107,8 +107,8 @@ public: Vector vectorValue() const; Eigen::MatrixXd matrixXdValue() const; Eigen::Matrix4d matrix4dValue() const; - Values valuesValue () const; - const Values &constValuesValue () const; + Values valuesValue() const; + const Values &constValuesValue() const; Type type_; const void *const value_; }; diff --git a/src/command/value.cpp b/src/command/value.cpp index d950ca2..8455a91 100644 --- a/src/command/value.cpp +++ b/src/command/value.cpp @@ -82,8 +82,7 @@ Value::Value(const Eigen::MatrixXd &value) : type_(MATRIX), value_(new Eigen::MatrixXd(value)) {} Value::Value(const Eigen::Matrix4d &value) : type_(MATRIX4D), value_(new Eigen::Matrix4d(value)) {} -Value::Value(const Values &value) - : type_(VALUES), value_(new Values(value)) {} +Value::Value(const Values &value) : type_(VALUES), value_(new Values(value)) {} Value::Value(const Value &value) : type_(value.type_), value_(copyValue(value)) {} @@ -145,20 +144,33 @@ Value Value::operator=(const Value &value) { } bool Value::operator==(const Value &other) const { - if (type_ != other.type_) return false; + if (type_ != other.type_) + return false; switch (type_) { - case Value::BOOL: return boolValue() == other.boolValue(); - case Value::UNSIGNED: return unsignedValue() == other.unsignedValue(); - case Value::INT: return intValue() == other.intValue(); - case Value::DOUBLE: return doubleValue() == other.doubleValue(); - case Value::FLOAT: return floatValue() == other.floatValue(); - case Value::STRING: return stringValue() == other.stringValue(); - case Value::VECTOR: return vectorValue() == other.vectorValue(); - case Value::MATRIX: return matrixXdValue() == other.matrixXdValue(); - case Value::MATRIX4D: return matrix4dValue() == other.matrix4dValue(); - case Value::VALUES: return constValuesValue() == other.constValuesValue(); - case Value::NONE: break; - default: break; + case Value::BOOL: + return boolValue() == other.boolValue(); + case Value::UNSIGNED: + return unsignedValue() == other.unsignedValue(); + case Value::INT: + return intValue() == other.intValue(); + case Value::DOUBLE: + return doubleValue() == other.doubleValue(); + case Value::FLOAT: + return floatValue() == other.floatValue(); + case Value::STRING: + return stringValue() == other.stringValue(); + case Value::VECTOR: + return vectorValue() == other.vectorValue(); + case Value::MATRIX: + return matrixXdValue() == other.matrixXdValue(); + case Value::MATRIX4D: + return matrix4dValue() == other.matrix4dValue(); + case Value::VALUES: + return constValuesValue() == other.constValuesValue(); + case Value::NONE: + break; + default: + break; } return false; } @@ -299,15 +311,13 @@ std::ostream &operator<<(std::ostream &os, const Value &value) { case Value::MATRIX4D: os << value.matrix4dValue(); break; - case Value::VALUES: - { - const std::vector<Value>& vals = value.constValuesValue(); - os << "[ "; - for (std::size_t i = 0; i < vals.size(); ++i) - os << "Value(" << vals[i] << "), "; - os << "]"; - } - break; + case Value::VALUES: { + const std::vector<Value> &vals = value.constValuesValue(); + os << "[ "; + for (std::size_t i = 0; i < vals.size(); ++i) + os << "Value(" << vals[i] << "), "; + os << "]"; + } break; default: return os; } diff --git a/tests/debug-logger.cpp b/tests/debug-logger.cpp index 296897b..1b9d6e0 100644 --- a/tests/debug-logger.cpp +++ b/tests/debug-logger.cpp @@ -34,65 +34,65 @@ public: logger_.setVerbosity(VERBOSITY_NONE); BOOST_CHECK_EQUAL(logger_.getVerbosity(), VERBOSITY_NONE); - BOOST_CHECK( logger_.stream(MSG_TYPE_DEBUG ).isNull()); - BOOST_CHECK( logger_.stream(MSG_TYPE_INFO ).isNull()); - BOOST_CHECK( logger_.stream(MSG_TYPE_WARNING).isNull()); - BOOST_CHECK( logger_.stream(MSG_TYPE_ERROR ).isNull()); + BOOST_CHECK(logger_.stream(MSG_TYPE_DEBUG).isNull()); + BOOST_CHECK(logger_.stream(MSG_TYPE_INFO).isNull()); + BOOST_CHECK(logger_.stream(MSG_TYPE_WARNING).isNull()); + BOOST_CHECK(logger_.stream(MSG_TYPE_ERROR).isNull()); logger_.setVerbosity(VERBOSITY_ERROR); BOOST_CHECK_EQUAL(logger_.getVerbosity(), VERBOSITY_ERROR); - BOOST_CHECK( logger_.stream(MSG_TYPE_DEBUG ).isNull()); - BOOST_CHECK( logger_.stream(MSG_TYPE_INFO ).isNull()); - BOOST_CHECK( logger_.stream(MSG_TYPE_WARNING).isNull()); - BOOST_CHECK(!logger_.stream(MSG_TYPE_ERROR ).isNull()); + BOOST_CHECK(logger_.stream(MSG_TYPE_DEBUG).isNull()); + BOOST_CHECK(logger_.stream(MSG_TYPE_INFO).isNull()); + BOOST_CHECK(logger_.stream(MSG_TYPE_WARNING).isNull()); + BOOST_CHECK(!logger_.stream(MSG_TYPE_ERROR).isNull()); logger_.setVerbosity(VERBOSITY_WARNING_ERROR); BOOST_CHECK_EQUAL(logger_.getVerbosity(), VERBOSITY_WARNING_ERROR); - BOOST_CHECK( logger_.stream(MSG_TYPE_DEBUG ).isNull()); - BOOST_CHECK( logger_.stream(MSG_TYPE_INFO ).isNull()); + BOOST_CHECK(logger_.stream(MSG_TYPE_DEBUG).isNull()); + BOOST_CHECK(logger_.stream(MSG_TYPE_INFO).isNull()); BOOST_CHECK(!logger_.stream(MSG_TYPE_WARNING).isNull()); - BOOST_CHECK(!logger_.stream(MSG_TYPE_ERROR ).isNull()); + BOOST_CHECK(!logger_.stream(MSG_TYPE_ERROR).isNull()); logger_.setVerbosity(VERBOSITY_INFO_WARNING_ERROR); BOOST_CHECK_EQUAL(logger_.getVerbosity(), VERBOSITY_INFO_WARNING_ERROR); - BOOST_CHECK( logger_.stream(MSG_TYPE_DEBUG ).isNull()); - BOOST_CHECK(!logger_.stream(MSG_TYPE_INFO ).isNull()); + BOOST_CHECK(logger_.stream(MSG_TYPE_DEBUG).isNull()); + BOOST_CHECK(!logger_.stream(MSG_TYPE_INFO).isNull()); BOOST_CHECK(!logger_.stream(MSG_TYPE_WARNING).isNull()); - BOOST_CHECK(!logger_.stream(MSG_TYPE_ERROR ).isNull()); + BOOST_CHECK(!logger_.stream(MSG_TYPE_ERROR).isNull()); logger_.setVerbosity(VERBOSITY_ALL); BOOST_CHECK_EQUAL(logger_.getVerbosity(), VERBOSITY_ALL); - BOOST_CHECK(!logger_.stream(MSG_TYPE_DEBUG ).isNull()); - BOOST_CHECK(!logger_.stream(MSG_TYPE_INFO ).isNull()); + BOOST_CHECK(!logger_.stream(MSG_TYPE_DEBUG).isNull()); + BOOST_CHECK(!logger_.stream(MSG_TYPE_INFO).isNull()); BOOST_CHECK(!logger_.stream(MSG_TYPE_WARNING).isNull()); - BOOST_CHECK(!logger_.stream(MSG_TYPE_ERROR ).isNull()); + BOOST_CHECK(!logger_.stream(MSG_TYPE_ERROR).isNull()); } ~CustomEntity() {} void testDebugTrace() { logger_.stream(MSG_TYPE_DEBUG) - << "This is a message of level MSG_TYPE_DEBUG\n"; + << "This is a message of level MSG_TYPE_DEBUG\n"; dynamicgraph::RealTimeLogger::instance().spinOnce(); logger_.stream(MSG_TYPE_INFO) - << "This is a message of level MSG_TYPE_INFO\n"; + << "This is a message of level MSG_TYPE_INFO\n"; dynamicgraph::RealTimeLogger::instance().spinOnce(); logger_.stream(MSG_TYPE_WARNING) - << "This is a message of level MSG_TYPE_WARNING\n"; + << "This is a message of level MSG_TYPE_WARNING\n"; dynamicgraph::RealTimeLogger::instance().spinOnce(); logger_.stream(MSG_TYPE_ERROR) - << "This is a message of level MSG_TYPE_ERROR\n"; + << "This is a message of level MSG_TYPE_ERROR\n"; dynamicgraph::RealTimeLogger::instance().spinOnce(); logger_.stream(MSG_TYPE_DEBUG_STREAM) - << "This is a message of level MSG_TYPE_DEBUG_STREAM\n"; + << "This is a message of level MSG_TYPE_DEBUG_STREAM\n"; dynamicgraph::RealTimeLogger::instance().spinOnce(); logger_.stream(MSG_TYPE_INFO_STREAM) - << "This is a message of level MSG_TYPE_INFO_STREAM\n"; + << "This is a message of level MSG_TYPE_INFO_STREAM\n"; dynamicgraph::RealTimeLogger::instance().spinOnce(); logger_.stream(MSG_TYPE_WARNING_STREAM) - << "This is a message of level MSG_TYPE_WARNING_STREAM\n"; + << "This is a message of level MSG_TYPE_WARNING_STREAM\n"; dynamicgraph::RealTimeLogger::instance().spinOnce(); logger_.stream(MSG_TYPE_ERROR_STREAM) - << "This is a message of level MSG_TYPE_ERROR_STREAM\n"; + << "This is a message of level MSG_TYPE_ERROR_STREAM\n"; /* Add test toString */ dynamicgraph::RealTimeLogger::instance().spinOnce(); double q = 1.0; @@ -103,13 +103,16 @@ public: vq[0] = 1.0; vq[1] = 2.0; vq[2] = 3.0; - logger_.stream(MSG_TYPE_INFO) << "Value to display: " << toString(vq) << '\n'; + logger_.stream(MSG_TYPE_INFO) + << "Value to display: " << toString(vq) << '\n'; dynamicgraph::RealTimeLogger::instance().spinOnce(); - logger_.stream(MSG_TYPE_INFO) << "Value to display: " << toString(vq, 3, 10) << '\n'; + logger_.stream(MSG_TYPE_INFO) + << "Value to display: " << toString(vq, 3, 10) << '\n'; dynamicgraph::RealTimeLogger::instance().spinOnce(); Eigen::Matrix<double, 3, 3> an_eig_m; an_eig_m.setOnes(); - logger_.stream(MSG_TYPE_INFO) << "Value to display: " << toString(an_eig_m) << '\n'; + logger_.stream(MSG_TYPE_INFO) + << "Value to display: " << toString(an_eig_m) << '\n'; dynamicgraph::RealTimeLogger::instance().spinOnce(); logger_.countdown(); } diff --git a/tests/entity.cpp b/tests/entity.cpp index bfb98cd..8a97d07 100644 --- a/tests/entity.cpp +++ b/tests/entity.cpp @@ -218,13 +218,17 @@ BOOST_AUTO_TEST_CASE(sendMsg) { #define __FILELINE__ __FILE__ BOOST_PP_STRINGIZE(__LINE__) entity.logger().stream(dynamicgraph::MSG_TYPE_DEBUG, __FILELINE__) - << "Auto Test Case" << " DEBUG" << '\n'; + << "Auto Test Case" + << " DEBUG" << '\n'; entity.logger().stream(dynamicgraph::MSG_TYPE_INFO, __FILELINE__) - << "Auto Test Case" << " INFO" << '\n'; + << "Auto Test Case" + << " INFO" << '\n'; entity.logger().stream(dynamicgraph::MSG_TYPE_WARNING, __FILELINE__) - << "Auto Test Case" << " WARNING" << '\n'; + << "Auto Test Case" + << " WARNING" << '\n'; entity.logger().stream(dynamicgraph::MSG_TYPE_ERROR, __FILELINE__) - << "Auto Test Case" << " ERROR" << '\n'; + << "Auto Test Case" + << " ERROR" << '\n'; #undef __FILELINE__ }; }; diff --git a/tests/signal-all.cpp b/tests/signal-all.cpp index ef54a17..925f2f1 100644 --- a/tests/signal-all.cpp +++ b/tests/signal-all.cpp @@ -210,25 +210,23 @@ BOOST_AUTO_TEST_CASE(signal_caster_basics) { /// Unregister a type asig_caster->unregisterCast(typeid(double)); - + /// Unregister the type a second time to generate exception - bool res= false; + bool res = false; try { asig_caster->unregisterCast(typeid(double)); - } catch (ExceptionSignal &aes) - { + } catch (ExceptionSignal &aes) { res = (aes.getCode() == ExceptionSignal::GENERIC); } BOOST_CHECK(res); /// Get the type cast to generate exception - res= false; - double ad=2.0; + res = false; + double ad = 2.0; output_test_stream output; try { - asig_caster->disp(ad,output); - } catch (ExceptionSignal &aes) - { + asig_caster->disp(ad, output); + } catch (ExceptionSignal &aes) { res = (aes.getCode() == ExceptionSignal::BAD_CAST); } BOOST_CHECK(res); diff --git a/tests/value.cpp b/tests/value.cpp index 23de53e..1cde9a4 100644 --- a/tests/value.cpp +++ b/tests/value.cpp @@ -376,26 +376,26 @@ BOOST_AUTO_TEST_CASE(value_values) { Value vd1(d1); Values values; - values.push_back (vs1); - values.push_back (vd1); + values.push_back(vs1); + values.push_back(vd1); - Value vvalues (values); + Value vvalues(values); BOOST_CHECK_EQUAL(vvalues.type(), Value::VALUES); { // Const ref - const Values& vs = vvalues.constValuesValue(); + const Values &vs = vvalues.constValuesValue(); BOOST_CHECK_EQUAL(vs.size(), values.size()); BOOST_CHECK(vs == values); } - { // Cast does not work. - //dg::command::EitherType eitherType (vvalues); - //Values vs = static_cast<Values>(eitherType); - //BOOST_CHECK_EQUAL(vs.size(), values.size()); - //BOOST_CHECK(vs == values); - } - { // Constructor - Value vvs (vvalues); + { + // Cast does not work. + // dg::command::EitherType eitherType (vvalues); + // Values vs = static_cast<Values>(eitherType); + // BOOST_CHECK_EQUAL(vs.size(), values.size()); + // BOOST_CHECK(vs == values); + } { // Constructor + Value vvs(vvalues); BOOST_CHECK(vvs == vvalues); } -- GitLab