Skip to content
Snippets Groups Projects
Commit eb68f2e9 authored by Nicolas Mansard's avatar Nicolas Mansard
Browse files

Code cleaning after rewriting (marginal) of sig-cast. Introduction of a...

Code cleaning after rewriting (marginal) of sig-cast. Introduction of a specific tracer behaviour for matrix and vector.
parent b4189986
No related branches found
No related tags found
No related merge requests found
...@@ -92,6 +92,10 @@ namespace dynamicgraph ...@@ -92,6 +92,10 @@ namespace dynamicgraph
* SignalCast<TYPE>::disp_, * SignalCast<TYPE>::disp_,
* SignalCast<TYPE>::cast_, * SignalCast<TYPE>::cast_,
* SignalCast<TYPE>::trace_); * 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 > template< class T >
class SignalCast class SignalCast
...@@ -142,27 +146,27 @@ namespace dynamicgraph ...@@ -142,27 +146,27 @@ namespace dynamicgraph
/* Standard definition macros: the three functions can be specified /* Standard definition macros: the three functions can be specified
* in the macros. To define then in the cpp, just put ';' in the args. * in the macros. To define then in the cpp, just put ';' in the args.
*/ */
#define DG_SIGNAL_CAST_FULL_DEFINITION(TYPE,CAST,DISP,TRACE) \ #define DG_SIGNAL_CAST_FULL_DEFINITION(TYPE,CAST,DISP,TRACE) \
template<> \ template<> \
class SignalCast<TYPE> \ class SignalCast<TYPE> \
{ \ { \
public: \ public: \
static TYPE cast( std::istringstream& iss ) CAST \ static TYPE cast( std::istringstream& iss ) CAST \
static void disp( TYPE const& t,std::ostream& os ) DISP \ static void disp( TYPE const& t,std::ostream& os ) DISP \
static void trace( TYPE const& t,std::ostream& os ) TRACE \ static void trace( TYPE const& t,std::ostream& os ) TRACE \
public: \ public: \
DYNAMIC_GRAPH_DLLEXPORT \ DYNAMIC_GRAPH_DLLEXPORT \
static boost::any cast_( std::istringstream& stringValue ) { \ static boost::any cast_( std::istringstream& stringValue ) { \
return boost::any_cast<TYPE>(cast(stringValue)); \ return boost::any_cast<TYPE>(cast(stringValue)); \
} \ } \
DYNAMIC_GRAPH_DLLEXPORT \ DYNAMIC_GRAPH_DLLEXPORT \
static void disp_( const boost::any& t,std::ostream& os ) { \ static void disp_( const boost::any& t,std::ostream& os ) { \
disp(boost::any_cast<TYPE>(t), os); \ disp(boost::any_cast<TYPE>(t), os); \
} \ } \
DYNAMIC_GRAPH_DLLEXPORT \ DYNAMIC_GRAPH_DLLEXPORT \
static void trace_( const boost::any& t,std::ostream& os ) { \ static void trace_( const boost::any& t,std::ostream& os ) { \
trace(boost::any_cast<TYPE>(t),os); \ trace(boost::any_cast<TYPE>(t),os); \
} \ } \
} }
/* Standard definition macros: the functions <cast> and <disp> have /* Standard definition macros: the functions <cast> and <disp> have
......
...@@ -66,14 +66,37 @@ namespace dynamicgraph ...@@ -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 /// Registers useful casts
namespace namespace
{ {
DefaultCastRegisterer<double> double_reg; DefaultCastRegisterer<double> double_reg;
// DefaultCastRegisterer<int> int_reg; DefaultCastRegisterer<int> int_reg;
// DefaultCastRegisterer<unsigned int> uint_reg; DefaultCastRegisterer<unsigned int> uint_reg;
// DefaultCastRegisterer<dynamicgraph::Vector> vectorCastRegisterer; DefaultCastRegisterer<dynamicgraph::Vector> vectorCastRegisterer;
// DefaultCastRegisterer<dynamicgraph::Matrix> matrixCastRegisterer; DefaultCastRegisterer<dynamicgraph::Matrix> matrixCastRegisterer;
} // end of anonymous namespace. } // end of anonymous namespace.
} // namespace dynamicgraph } // namespace dynamicgraph
...@@ -119,8 +119,6 @@ namespace dynamicgraph ...@@ -119,8 +119,6 @@ namespace dynamicgraph
return getCast(type.name ()).get<1> () (iss); 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 /// Singleton on the library-wide instance of SignalCaster
SignalCaster& g_caster(void) SignalCaster& g_caster(void)
{ {
...@@ -129,12 +127,3 @@ namespace dynamicgraph ...@@ -129,12 +127,3 @@ namespace dynamicgraph
} }
} // namespace dynamicgraph } // namespace dynamicgraph
struct sigcastint
{
sigcastint() { std::cout << "sigcastint!" << std::endl; }
};
sigcastint sigcastint_init;
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