diff --git a/include/sot/core/reader.hh b/include/sot/core/reader.hh index b0a6eb280b1494694ca113b7f919231dbd230195..40ba8acd6812f9129bccd698eb8f1bcfebcb229d 100644 --- a/include/sot/core/reader.hh +++ b/include/sot/core/reader.hh @@ -96,13 +96,12 @@ class SOTREADER_EXPORT sotReader ml::Vector& getNextData( ml::Vector& res, const unsigned int time ); ml::Matrix& getNextMatrix( ml::Matrix& res, const unsigned int time ); + void resize(const int & nbRow, const int & nbCol); public: /* --- PARAMS --- */ void display( std::ostream& os ) const; - virtual void commandLine( const std::string& cmdLine - ,std::istringstream& cmdArgs - ,std::ostream& os ); + virtual void initCommands(); }; diff --git a/src/traces/reader.cpp b/src/traces/reader.cpp index ca45850b6553ab4f3439deab4981fae7373fc328..6d134685c1476b5463277a17339a579ec5e16907 100644 --- a/src/traces/reader.cpp +++ b/src/traces/reader.cpp @@ -29,6 +29,7 @@ #include <boost/bind.hpp> #include <sstream> #include <dynamic-graph/factory.h> +#include <dynamic-graph/all-commands.h> using namespace dynamicgraph; using namespace dynamicgraph::sot; @@ -57,6 +58,8 @@ sotReader::sotReader( const std::string n ) signalRegistration( selectionSIN<<vectorSOUT<<matrixSOUT ); selectionSIN = true; vectorSOUT.setNeedUpdateFromAllChildren(true); + + initCommands(); } /* --------------------------------------------------------------------- */ @@ -177,42 +180,26 @@ std::ostream& operator<< ( std::ostream& os,const sotReader& t ) return os; } -void sotReader:: -commandLine( const std::string& cmdLine - ,std::istringstream& cmdArgs - ,std::ostream& os ) +/* --- Command line interface ------------------------------------------------------ */ +void sotReader::initCommands() { - if( cmdLine=="help" ) - { - os << "Reader: "<<endl - << " - load" << endl; - - Entity::commandLine( cmdLine,cmdArgs,os ); - } - else if( cmdLine=="load" ) - { - string filename; - cmdArgs>>ws>>filename; - load(filename); - } - else if( cmdLine=="rewind" ) - { - cmdArgs>>ws; - rewind( ); - } - else if( cmdLine=="clear" ) - { - cmdArgs>>ws; - clear( ); - } - else if( cmdLine=="resize" ) - { - cmdArgs >>ws; - if( cmdArgs.good() ) { cmdArgs >> nbRows >>nbCols; } - else { os << "Matrix size = " << nbRows << " x " <<nbCols <<std::endl; } - } - else { Entity::commandLine( cmdLine,cmdArgs,os ); } - - + namespace dc = ::dynamicgraph::command; + addCommand("clear", + dc::makeCommandVoid0(*this,&sotReader::clear, + "Clear the data loaded")); + addCommand("rewind", + dc::makeCommandVoid0(*this,&sotReader::rewind, + "Reset the iterator to the beginning of the data set")); + addCommand("load", + dc::makeCommandVoid1(*this,&sotReader::load, + "load file")); + addCommand("resize", + dc::makeCommandVoid2(*this,&sotReader::resize, + " ")); +} +void sotReader::resize(const int & nbRow, const int & nbCol) +{ + nbRows = nbRow; + nbCols = nbCol; }