Skip to content
Snippets Groups Projects
Commit 873dafcc authored by Olivier Stasse's avatar Olivier Stasse
Browse files

[debug] Add toString logger tests + uncomment line used for scalar types.

parent df48199d
No related branches found
No related tags found
No related merge requests found
...@@ -61,7 +61,7 @@ namespace dynamicgraph { ...@@ -61,7 +61,7 @@ namespace dynamicgraph {
#define SEND_WARNING_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_WARNING_STREAM) #define SEND_WARNING_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_WARNING_STREAM)
#define SEND_ERROR_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_ERROR_STREAM) #define SEND_ERROR_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_ERROR_STREAM)
/*template<typename T> template<typename T>
std::string toString(const T& v, const int precision=3, const int width=-1) std::string toString(const T& v, const int precision=3, const int width=-1)
{ {
std::stringstream ss; std::stringstream ss;
...@@ -70,20 +70,20 @@ std::string toString(const T& v, const int precision=3, const int width=-1) ...@@ -70,20 +70,20 @@ std::string toString(const T& v, const int precision=3, const int width=-1)
else else
ss<<std::fixed<<std::setprecision(precision)<<v; ss<<std::fixed<<std::setprecision(precision)<<v;
return ss.str(); return ss.str();
}*/ }
template <typename T> template <typename T>
std::string toString(const std::vector<T> &v, const int precision = 3, std::string toString(const std::vector<T> &v, const int precision = 3,
const int width = -1, const std::string separator = ", ") { const int width = -1, const std::string separator = ", ") {
std::stringstream ss; std::stringstream ss;
if (width > precision) { if (width > precision) {
for (int i = 0; i < v.size() - 1; i++) for (unsigned int i = 0; i < v.size() - 1; i++)
ss << std::fixed << std::setw(width) << std::setprecision(precision) ss << std::fixed << std::setw(width) << std::setprecision(precision)
<< v[i] << separator; << v[i] << separator;
ss << std::fixed << std::setw(width) << std::setprecision(precision) ss << std::fixed << std::setw(width) << std::setprecision(precision)
<< v[v.size() - 1]; << v[v.size() - 1];
} else { } else {
for (int i = 0; i < v.size() - 1; i++) for (unsigned int i = 0; i < v.size() - 1; i++)
ss << std::fixed << std::setprecision(precision) << v[i] << separator; ss << std::fixed << std::setprecision(precision) << v[i] << separator;
ss << std::fixed << std::setprecision(precision) << v[v.size() - 1]; ss << std::fixed << std::setprecision(precision) << v[v.size() - 1];
} }
...@@ -96,13 +96,13 @@ std::string toString(const Eigen::MatrixBase<T> &v, const int precision = 3, ...@@ -96,13 +96,13 @@ std::string toString(const Eigen::MatrixBase<T> &v, const int precision = 3,
const int width = -1, const std::string separator = ", ") { const int width = -1, const std::string separator = ", ") {
std::stringstream ss; std::stringstream ss;
if (width > precision) { if (width > precision) {
for (int i = 0; i < v.size() - 1; i++) for (unsigned int i = 0; i < v.size() - 1; i++)
ss << std::fixed << std::setw(width) << std::setprecision(precision) ss << std::fixed << std::setw(width) << std::setprecision(precision)
<< v[i] << separator; << v[i] << separator;
ss << std::fixed << std::setw(width) << std::setprecision(precision) ss << std::fixed << std::setw(width) << std::setprecision(precision)
<< v[v.size() - 1]; << v[v.size() - 1];
} else { } else {
for (int i = 0; i < v.size() - 1; i++) for (unsigned int i = 0; i < v.size() - 1; i++)
ss << std::fixed << std::setprecision(precision) << v[i] << separator; ss << std::fixed << std::setprecision(precision) << v[i] << separator;
ss << std::setprecision(precision) << v[v.size() - 1]; ss << std::setprecision(precision) << v[v.size() - 1];
} }
......
...@@ -50,7 +50,16 @@ public: ...@@ -50,7 +50,16 @@ public:
MSG_TYPE_WARNING_STREAM); MSG_TYPE_WARNING_STREAM);
sendMsg("This is a message of level MSG_TYPE_ERROR_STREAM", sendMsg("This is a message of level MSG_TYPE_ERROR_STREAM",
MSG_TYPE_ERROR_STREAM); MSG_TYPE_ERROR_STREAM);
/* Add test toString */
double q=1.0;
sendMsg("Value to display: "+toString(q));
std::vector<double> vq;
vq.resize(3);
vq[0] = 1.0; vq[1] = 2.0; vq[2] = 3.0;
sendMsg("Value to display: "+toString(vq));
Eigen::Matrix<double,3,3> an_eig_m;
an_eig_m.Ones();
sendMsg("Value to display: "+toString(an_eig_m));
logger_.countdown(); logger_.countdown();
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment