Commit 0131dbda authored by Joseph Mirabel's avatar Joseph Mirabel
Browse files

Replace signal_trace.

parent d0431fb8
......@@ -17,6 +17,7 @@
#include "dynamic-graph/exception-signal.h"
#include <dynamic-graph/dynamic-graph-api.h>
#include <dynamic-graph/linear-algebra.h>
namespace dynamicgraph {
/// This singleton class allows serialization of a number of objects into
......@@ -109,9 +110,20 @@ template <typename T> T signal_cast(std::istringstream &iss) {
return boost::any_cast<T>(SignalCaster::getInstance()->cast(typeid(T), iss));
}
template <typename T> void signal_trace(const T &value, std::ostream &os) {
SignalCaster::getInstance()->trace(value, os);
/// Template class used to display a signal value.
template <typename T> struct signal_trace {
inline static void run(const T &value, std::ostream &os) { os << value << '\n'; }
};
/// Template specialization of signal_trace for Eigen objects
template <typename Derived> struct signal_trace<Eigen::DenseBase<Derived> > {
inline static void run(const Eigen::DenseBase<Derived> &value, std::ostream &os) {
static const Eigen::IOFormat row_format (Eigen::StreamPrecision,
Eigen::DontAlignCols, ", ", ", ", "", "", "", "\n");
os << value.format(row_format);
}
};
} // end of namespace dynamicgraph.
#endif //! DYNAMIC_GRAPH_SIGNAL_CASTER_HH
......@@ -41,7 +41,7 @@ void Signal<T, Time>::get(std::ostream &os) const {
template <class T, class Time>
void Signal<T, Time>::trace(std::ostream &os) const {
try {
signal_trace<T>(this->accessCopy(), os);
signal_trace<T>::run(this->accessCopy(), os);
} catch DG_RETHROW catch (...) {
DG_THROW ExceptionSignal(ExceptionSignal::SET_IMPOSSIBLE,
"TRACE operation not possible with this signal. ",
......
......@@ -159,7 +159,6 @@ BOOST_AUTO_TEST_CASE(test_cast_helper) {
/// Test cast register with Vector
output_test_stream output;
dynamicgraph::Vector avec;
DefaultCastRegisterer<dynamicgraph::Vector> defaultVR;
avec.resize(4);
avec[0] = 1.0;
avec[1] = 2.0;
......@@ -167,7 +166,7 @@ BOOST_AUTO_TEST_CASE(test_cast_helper) {
avec[3] = 4.0;
res = true;
try {
defaultVR.trace(avec, output);
signal_trace<Vector>::run(avec, output);
} catch (ExceptionSignal &e) {
/// Exception in case of wrong cast.
/// This should not happen.
......@@ -177,7 +176,6 @@ BOOST_AUTO_TEST_CASE(test_cast_helper) {
/// Test cast register with Matrix
dynamicgraph::Matrix amatrix;
DefaultCastRegisterer<dynamicgraph::Matrix> defaultMR;
amatrix.resize(2, 2);
amatrix(0, 0) = 0.0;
amatrix(0, 1) = 1.0;
......@@ -185,7 +183,7 @@ BOOST_AUTO_TEST_CASE(test_cast_helper) {
amatrix(1, 1) = 3.0;
res = true;
try {
defaultMR.trace(amatrix, output);
signal_trace<Matrix>::run(amatrix, output);
} catch (ExceptionSignal &e) {
/// Exception in case of wrong cast.
/// This should happen
......
......@@ -140,13 +140,11 @@ BOOST_AUTO_TEST_CASE(custom_vector_registerer) {
dynamicgraph::Signal<dynamicgraph::Vector, int> myVectorSignal("vector");
/// Create a second local vector registerer to generate an exception.
bool res = false;
try {
EigenCastRegisterer_V myVectorCast2;
} catch (const ExceptionSignal &aes) {
res = (aes.getCode() == ExceptionSignal::GENERIC);
// BOOST_CHECK(aes.getCode() == ExceptionSignal::GENERIC);
}
// BOOST_CHECK(res);
// Print the signal name.
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment