diff --git a/include/dynamic-graph/signal-cast-helper.h b/include/dynamic-graph/signal-cast-helper.h index 20cc25e05d8aabe65a97f984eb2afe9db2b0a827..790d5b81e75f0e465973655519d77901678254a6 100644 --- a/include/dynamic-graph/signal-cast-helper.h +++ b/include/dynamic-graph/signal-cast-helper.h @@ -92,6 +92,10 @@ namespace dynamicgraph * SignalCast<TYPE>::disp_, * SignalCast<TYPE>::cast_, * SignalCast<TYPE>::trace_); + + * NMSD: I don't really understand the use of this additional class. IMHO + * (comme on dit), it should be possible to rewrite the same-spec macros + * using specialization of the template class DefaultCastRegisterer. No? */ template< class T > class SignalCast @@ -142,27 +146,27 @@ namespace dynamicgraph /* Standard definition macros: the three functions can be specified * in the macros. To define then in the cpp, just put ';' in the args. */ -#define DG_SIGNAL_CAST_FULL_DEFINITION(TYPE,CAST,DISP,TRACE) \ -template<> \ - class SignalCast<TYPE> \ -{ \ -public: \ - static TYPE cast( std::istringstream& iss ) CAST \ - static void disp( TYPE const& t,std::ostream& os ) DISP \ - static void trace( TYPE const& t,std::ostream& os ) TRACE \ -public: \ - DYNAMIC_GRAPH_DLLEXPORT \ - static boost::any cast_( std::istringstream& stringValue ) { \ - return boost::any_cast<TYPE>(cast(stringValue)); \ - } \ - DYNAMIC_GRAPH_DLLEXPORT \ - static void disp_( const boost::any& t,std::ostream& os ) { \ - disp(boost::any_cast<TYPE>(t), os); \ - } \ - DYNAMIC_GRAPH_DLLEXPORT \ - static void trace_( const boost::any& t,std::ostream& os ) { \ - trace(boost::any_cast<TYPE>(t),os); \ - } \ +#define DG_SIGNAL_CAST_FULL_DEFINITION(TYPE,CAST,DISP,TRACE) \ +template<> \ + class SignalCast<TYPE> \ +{ \ +public: \ + static TYPE cast( std::istringstream& iss ) CAST \ + static void disp( TYPE const& t,std::ostream& os ) DISP \ + static void trace( TYPE const& t,std::ostream& os ) TRACE \ +public: \ + DYNAMIC_GRAPH_DLLEXPORT \ + static boost::any cast_( std::istringstream& stringValue ) { \ + return boost::any_cast<TYPE>(cast(stringValue)); \ + } \ + DYNAMIC_GRAPH_DLLEXPORT \ + static void disp_( const boost::any& t,std::ostream& os ) { \ + disp(boost::any_cast<TYPE>(t), os); \ + } \ + DYNAMIC_GRAPH_DLLEXPORT \ + static void trace_( const boost::any& t,std::ostream& os ) { \ + trace(boost::any_cast<TYPE>(t),os); \ + } \ } /* Standard definition macros: the functions <cast> and <disp> have diff --git a/src/signal/signal-cast-helper.cpp b/src/signal/signal-cast-helper.cpp index 109fc51bc020d75c90afd1d2ab05584228e4ca3c..2c97a4a54d5bae20932acdf12fe6a938f7d3b40d 100644 --- a/src/signal/signal-cast-helper.cpp +++ b/src/signal/signal-cast-helper.cpp @@ -66,14 +66,37 @@ namespace dynamicgraph } } + /* Specialize Matrix and Vector traces. */ + template <> + void + DefaultCastRegisterer<dynamicgraph::Vector>:: + trace(const boost::any& object, std::ostream& os) + { + const dynamicgraph::Vector & v = boost::any_cast<dynamicgraph::Vector> (object); + for( unsigned int i=0;i<v.size();++i ) + { os << "\t" << v(i); } + } + template <> + void + DefaultCastRegisterer<dynamicgraph::Matrix>:: + trace(const boost::any& object, std::ostream& os) + { + const dynamicgraph::Matrix & m = boost::any_cast<dynamicgraph::Matrix> (object); + for( unsigned int i=0;i<m.nbRows();++i ) + for( unsigned int j=0;j<m.nbCols();++j ) + { os << "\t" << m(i,j); } + } + + + /// Registers useful casts namespace { DefaultCastRegisterer<double> double_reg; - // DefaultCastRegisterer<int> int_reg; - // DefaultCastRegisterer<unsigned int> uint_reg; - // DefaultCastRegisterer<dynamicgraph::Vector> vectorCastRegisterer; - // DefaultCastRegisterer<dynamicgraph::Matrix> matrixCastRegisterer; + DefaultCastRegisterer<int> int_reg; + DefaultCastRegisterer<unsigned int> uint_reg; + DefaultCastRegisterer<dynamicgraph::Vector> vectorCastRegisterer; + DefaultCastRegisterer<dynamicgraph::Matrix> matrixCastRegisterer; } // end of anonymous namespace. } // namespace dynamicgraph diff --git a/src/signal/signal-caster.cpp b/src/signal/signal-caster.cpp index 6ab9aacd8d5bee34afd84a7edba656efaba79424..06e0f7880eaab6e2227e790d0b6d75a0e63255c8 100644 --- a/src/signal/signal-caster.cpp +++ b/src/signal/signal-caster.cpp @@ -119,8 +119,6 @@ namespace dynamicgraph return getCast(type.name ()).get<1> () (iss); } - /// The global instance of the caster class. - //SignalCaster g_caster; /// Singleton on the library-wide instance of SignalCaster SignalCaster& g_caster(void) { @@ -129,12 +127,3 @@ namespace dynamicgraph } } // namespace dynamicgraph - - - - -struct sigcastint -{ - sigcastint() { std::cout << "sigcastint!" << std::endl; } -}; -sigcastint sigcastint_init;