Skip to content

Commit 873dafc

Browse files
[debug] Add toString logger tests + uncomment line used for scalar types.
1 parent df48199 commit 873dafc

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

include/dynamic-graph/logger.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace dynamicgraph {
6161
#define SEND_WARNING_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_WARNING_STREAM)
6262
#define SEND_ERROR_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_ERROR_STREAM)
6363

64-
/*template<typename T>
64+
template<typename T>
6565
std::string toString(const T& v, const int precision=3, const int width=-1)
6666
{
6767
std::stringstream ss;
@@ -70,20 +70,20 @@ std::string toString(const T& v, const int precision=3, const int width=-1)
7070
else
7171
ss<<std::fixed<<std::setprecision(precision)<<v;
7272
return ss.str();
73-
}*/
73+
}
7474

7575
template <typename T>
7676
std::string toString(const std::vector<T> &v, const int precision = 3,
7777
const int width = -1, const std::string separator = ", ") {
7878
std::stringstream ss;
7979
if (width > precision) {
80-
for (int i = 0; i < v.size() - 1; i++)
80+
for (unsigned int i = 0; i < v.size() - 1; i++)
8181
ss << std::fixed << std::setw(width) << std::setprecision(precision)
8282
<< v[i] << separator;
8383
ss << std::fixed << std::setw(width) << std::setprecision(precision)
8484
<< v[v.size() - 1];
8585
} else {
86-
for (int i = 0; i < v.size() - 1; i++)
86+
for (unsigned int i = 0; i < v.size() - 1; i++)
8787
ss << std::fixed << std::setprecision(precision) << v[i] << separator;
8888
ss << std::fixed << std::setprecision(precision) << v[v.size() - 1];
8989
}
@@ -96,13 +96,13 @@ std::string toString(const Eigen::MatrixBase<T> &v, const int precision = 3,
9696
const int width = -1, const std::string separator = ", ") {
9797
std::stringstream ss;
9898
if (width > precision) {
99-
for (int i = 0; i < v.size() - 1; i++)
99+
for (unsigned int i = 0; i < v.size() - 1; i++)
100100
ss << std::fixed << std::setw(width) << std::setprecision(precision)
101101
<< v[i] << separator;
102102
ss << std::fixed << std::setw(width) << std::setprecision(precision)
103103
<< v[v.size() - 1];
104104
} else {
105-
for (int i = 0; i < v.size() - 1; i++)
105+
for (unsigned int i = 0; i < v.size() - 1; i++)
106106
ss << std::fixed << std::setprecision(precision) << v[i] << separator;
107107
ss << std::setprecision(precision) << v[v.size() - 1];
108108
}

tests/debug-logger.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ class CustomEntity : public Entity {
5050
MSG_TYPE_WARNING_STREAM);
5151
sendMsg("This is a message of level MSG_TYPE_ERROR_STREAM",
5252
MSG_TYPE_ERROR_STREAM);
53-
53+
/* Add test toString */
54+
double q=1.0;
55+
sendMsg("Value to display: "+toString(q));
56+
std::vector<double> vq;
57+
vq.resize(3);
58+
vq[0] = 1.0; vq[1] = 2.0; vq[2] = 3.0;
59+
sendMsg("Value to display: "+toString(vq));
60+
Eigen::Matrix<double,3,3> an_eig_m;
61+
an_eig_m.Ones();
62+
sendMsg("Value to display: "+toString(an_eig_m));
5463
logger_.countdown();
5564
}
5665
};

0 commit comments

Comments
 (0)