Skip to content

Commit 0131dbd

Browse files
committed
Replace signal_trace.
1 parent d0431fb commit 0131dbd

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

include/dynamic-graph/signal-caster.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "dynamic-graph/exception-signal.h"
1919
#include <dynamic-graph/dynamic-graph-api.h>
20+
#include <dynamic-graph/linear-algebra.h>
2021

2122
namespace dynamicgraph {
2223
/// This singleton class allows serialization of a number of objects into
@@ -109,9 +110,20 @@ template <typename T> T signal_cast(std::istringstream &iss) {
109110
return boost::any_cast<T>(SignalCaster::getInstance()->cast(typeid(T), iss));
110111
}
111112

112-
template <typename T> void signal_trace(const T &value, std::ostream &os) {
113-
SignalCaster::getInstance()->trace(value, os);
113+
/// Template class used to display a signal value.
114+
template <typename T> struct signal_trace {
115+
inline static void run(const T &value, std::ostream &os) { os << value << '\n'; }
116+
};
117+
118+
/// Template specialization of signal_trace for Eigen objects
119+
template <typename Derived> struct signal_trace<Eigen::DenseBase<Derived> > {
120+
inline static void run(const Eigen::DenseBase<Derived> &value, std::ostream &os) {
121+
static const Eigen::IOFormat row_format (Eigen::StreamPrecision,
122+
Eigen::DontAlignCols, ", ", ", ", "", "", "", "\n");
123+
os << value.format(row_format);
114124
}
125+
};
126+
115127
} // end of namespace dynamicgraph.
116128

117129
#endif //! DYNAMIC_GRAPH_SIGNAL_CASTER_HH

include/dynamic-graph/signal.t.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void Signal<T, Time>::get(std::ostream &os) const {
4141
template <class T, class Time>
4242
void Signal<T, Time>::trace(std::ostream &os) const {
4343
try {
44-
signal_trace<T>(this->accessCopy(), os);
44+
signal_trace<T>::run(this->accessCopy(), os);
4545
} catch DG_RETHROW catch (...) {
4646
DG_THROW ExceptionSignal(ExceptionSignal::SET_IMPOSSIBLE,
4747
"TRACE operation not possible with this signal. ",

tests/signal-all.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,14 @@ BOOST_AUTO_TEST_CASE(test_cast_helper) {
159159
/// Test cast register with Vector
160160
output_test_stream output;
161161
dynamicgraph::Vector avec;
162-
DefaultCastRegisterer<dynamicgraph::Vector> defaultVR;
163162
avec.resize(4);
164163
avec[0] = 1.0;
165164
avec[1] = 2.0;
166165
avec[2] = 3.0;
167166
avec[3] = 4.0;
168167
res = true;
169168
try {
170-
defaultVR.trace(avec, output);
169+
signal_trace<Vector>::run(avec, output);
171170
} catch (ExceptionSignal &e) {
172171
/// Exception in case of wrong cast.
173172
/// This should not happen.
@@ -177,15 +176,14 @@ BOOST_AUTO_TEST_CASE(test_cast_helper) {
177176

178177
/// Test cast register with Matrix
179178
dynamicgraph::Matrix amatrix;
180-
DefaultCastRegisterer<dynamicgraph::Matrix> defaultMR;
181179
amatrix.resize(2, 2);
182180
amatrix(0, 0) = 0.0;
183181
amatrix(0, 1) = 1.0;
184182
amatrix(1, 0) = 2.0;
185183
amatrix(1, 1) = 3.0;
186184
res = true;
187185
try {
188-
defaultMR.trace(amatrix, output);
186+
signal_trace<Matrix>::run(amatrix, output);
189187
} catch (ExceptionSignal &e) {
190188
/// Exception in case of wrong cast.
191189
/// This should happen

tests/signal-cast-registerer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,11 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
140140
dynamicgraph::Signal<dynamicgraph::Vector, int> myVectorSignal("vector");
141141

142142
/// Create a second local vector registerer to generate an exception.
143-
bool res = false;
144143
try {
145144
EigenCastRegisterer_V myVectorCast2;
146145
} catch (const ExceptionSignal &aes) {
147-
res = (aes.getCode() == ExceptionSignal::GENERIC);
146+
// BOOST_CHECK(aes.getCode() == ExceptionSignal::GENERIC);
148147
}
149-
// BOOST_CHECK(res);
150148

151149
// Print the signal name.
152150
{

0 commit comments

Comments
 (0)