From b6491883f05b38897bee24f9480f40499263502f Mon Sep 17 00:00:00 2001 From: Thomas Moulard <thomas.moulard@gmail.com> Date: Fri, 31 Dec 2010 01:40:44 +0100 Subject: [PATCH] Clean code. --- include/dynamic-graph/all-signals.h | 49 +- include/dynamic-graph/contiifstream.h | 116 ++- include/dynamic-graph/debug.h | 373 +++++---- include/dynamic-graph/dynamic-graph-api.h | 41 +- include/dynamic-graph/entity.h | 213 +++--- include/dynamic-graph/exception-abstract.h | 247 +++--- include/dynamic-graph/exception-factory.h | 112 ++- include/dynamic-graph/exception-signal.h | 108 ++- include/dynamic-graph/exception-traces.h | 114 ++- include/dynamic-graph/factory.h | 10 +- include/dynamic-graph/functions.h | 122 ++- include/dynamic-graph/fwd.hh | 7 + include/dynamic-graph/import.h | 36 +- include/dynamic-graph/interpreter-helper.h | 273 +++---- include/dynamic-graph/interpreter.h | 393 +++++----- include/dynamic-graph/plugin-loader.h | 201 +++-- include/dynamic-graph/pool.h | 245 +++--- include/dynamic-graph/shell-procedure.h | 130 ++-- include/dynamic-graph/signal-array.h | 308 ++++---- include/dynamic-graph/signal-base.h | 476 +++++++----- include/dynamic-graph/signal-caster.h | 24 +- include/dynamic-graph/signal-ptr.h | 193 +++-- include/dynamic-graph/signal-ptr.t.cpp | 555 +++++++------- include/dynamic-graph/signal-time-dependent.h | 213 +++--- include/dynamic-graph/signal.h | 20 +- include/dynamic-graph/signal.t.cpp | 608 +++++++-------- include/dynamic-graph/time-dependency.h | 155 ++-- include/dynamic-graph/time-dependency.t.cpp | 356 ++++----- include/dynamic-graph/tracer-real-time.h | 211 +++--- include/dynamic-graph/tracer.h | 229 +++--- src/debug/contiifstream.cpp | 18 +- src/debug/debug.cpp | 12 +- src/dgraph/entity.cpp | 74 +- src/dgraph/factory.cpp | 26 +- src/dgraph/import.cpp | 54 +- src/dgraph/interpreter-helper.cpp | 304 ++++---- src/dgraph/interpreter.cpp | 60 +- src/dgraph/plugin-loader.cpp | 64 +- src/dgraph/pool.cpp | 52 +- src/exception/exception-abstract.cpp | 183 ++--- src/exception/exception-factory.cpp | 2 +- src/plugins/shell-functions.cpp | 35 +- src/plugins/shell-procedure.cpp | 56 +- src/shell/functions.cpp | 708 ++++++++++-------- src/signal/signal-caster.cpp | 22 +- src/traces/tracer-real-time.cpp | 96 +-- src/traces/tracer.cpp | 90 +-- 47 files changed, 3957 insertions(+), 4037 deletions(-) diff --git a/include/dynamic-graph/all-signals.h b/include/dynamic-graph/all-signals.h index a16398b..33ba7c2 100644 --- a/include/dynamic-graph/all-signals.h +++ b/include/dynamic-graph/all-signals.h @@ -1,30 +1,27 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. -#ifndef ALLSIGNALS_H_ -#define ALLSIGNALS_H_ +#ifndef DYNAMIC_GRAPH_ALL_SIGNALS_H +# define DYNAMIC_GRAPH_ALL_SIGNALS_H -/// Utility header files including all signal headers +// Utility header files including all signal headers -#include <dynamic-graph/signal.h> -#include <dynamic-graph/signal-ptr.h> -#include <dynamic-graph/signal-time-dependent.h> +# include <dynamic-graph/signal.h> +# include <dynamic-graph/signal-ptr.h> +# include <dynamic-graph/signal-time-dependent.h> -#endif /* ALLSIGNALS_H_ */ +#endif //! DYNAMIC_GRAPH_ALL_SIGNALS_H diff --git a/include/dynamic-graph/contiifstream.h b/include/dynamic-graph/contiifstream.h index 8e0f941..6e91d41 100644 --- a/include/dynamic-graph/contiifstream.h +++ b/include/dynamic-graph/contiifstream.h @@ -1,51 +1,59 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __CONTIIFSTREAM_HH__ -#define __CONTIIFSTREAM_HH__ +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_CONTIIFSTREAM_H +# define DYNAMIC_GRAPH_CONTIIFSTREAM_H +# include <fstream> +# include <iostream> +# include <list> +# include <sstream> + +# ifndef WIN32 +# include <unistd.h> +# include <pthread.h> +# endif //! WIN32 + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/interpreter.h> +# include <dynamic-graph/config-contiifstream.hh> + +namespace dynamicgraph +{ + class DG_CONTIIFSTREAM_DLLAPI Contiifstream + { + public: + explicit Contiifstream (const std::string& n=""); + ~Contiifstream (); -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ + inline void open (const std::string& n) + { + filename=n; + cursor=0; + } + bool loop (); -#include <iostream> -#include <fstream> -#include <sstream> -#ifndef WIN32 -# include <unistd.h> -#endif -#include <list> + inline bool ready () + { + return 0 < reader.size (); + } -#include <dynamic-graph/interpreter.h> -#include <dynamic-graph/config-contiifstream.hh> -#ifndef WIN32 -# include <pthread.h> -#endif + std::string next (); -namespace dynamicgraph { - /* --------------------------------------------------------------------- */ - /* --- CLASS ----------------------------------------------------------- */ - /* --------------------------------------------------------------------- */ - class DG_CONTIIFSTREAM_DLLAPI Contiifstream - { protected: std::string filename; std::streamoff cursor; @@ -53,25 +61,7 @@ namespace dynamicgraph { char buffer[BUFFER_SIZE]; std::list< std::string > reader; bool first; - - public: /* --- Constructor --- */ - Contiifstream( const std::string& n="" ); - ~Contiifstream( void ); - void open( const std::string& n ) { filename=n; cursor=0; } - - public: /* --- READ FILE --- */ - bool loop( void ); - - public: /* --- READ LIST --- */ - inline bool ready( void ) { return 0<reader.size();} - std::string next( void ) ; - - }; -} // namespace dynamicgraph - -#endif /* #ifndef __CONTIIFSTREAM_HH__ */ - - - +} // end of namespace dynamicgraph. +#endif //! DYNAMIC_GRAPH_CONTIIFSTREAM_H diff --git a/include/dynamic-graph/debug.h b/include/dynamic-graph/debug.h index 24e2fbf..d1f0d1b 100644 --- a/include/dynamic-graph/debug.h +++ b/include/dynamic-graph/debug.h @@ -1,22 +1,19 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. /* * Macro de trace et de debugage @@ -36,139 +33,243 @@ * * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +#ifndef DYNAMIC_GRAPH_DEBUG_HH +# define DYNAMIC_GRAPH_DEBUG_HH +# include <cstdio> +# include <cstdarg> +# include <iostream> +# include <fstream> +# include <sstream> + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/dynamic-graph-api.h> + + +# ifndef VP_DEBUG_MODE +# define VP_DEBUG_MODE 0 +# endif //! VP_DEBUG_MODE + +# ifndef VP_TEMPLATE_DEBUG_MODE +# define VP_TEMPLATE_DEBUG_MODE 0 +# endif //! VP_TEMPLATE_DEBUG_MODE +#define DG_COMMON_TRACES \ + do { \ + va_list arg; \ + va_start (arg, format); \ + vsnprintf (charbuffer, SIZE, format, arg); \ + va_end (arg); \ + outputbuffer << tmpbuffer.str () << charbuffer << std::endl; \ + } while(0) +namespace dynamicgraph +{ + class DYNAMIC_GRAPH_DLLAPI DebugTrace + { + public: + static const int SIZE = 512; + + std::stringstream tmpbuffer; + std::ostream& outputbuffer; + char charbuffer[SIZE+1]; + int traceLevel; + int traceLevelTemplate; + + DebugTrace (std::ostream& os) + : outputbuffer (os) + {} + + inline void trace (const int level, const char* format, ...) + { + if (level <= traceLevel) + DG_COMMON_TRACES; tmpbuffer.str(""); + } + + inline void trace (const char* format, ...) + { + DG_COMMON_TRACES; + tmpbuffer.str(""); + } + + inline void trace (const int level=-1) + { + if (level <= traceLevel) + outputbuffer << tmpbuffer.str (); tmpbuffer.str(""); + } + + inline void traceTemplate (const int level, const char* format, ...) + { + if (level <= traceLevelTemplate) + DG_COMMON_TRACES; + tmpbuffer.str(""); + } + + inline void traceTemplate (const char* format, ...) + { + DG_COMMON_TRACES; + tmpbuffer.str(""); + } + + inline DebugTrace& pre (const std::ostream&) + { + return *this; + } + + inline DebugTrace& pre (const std::ostream&, int level) + { + traceLevel = level; + return *this; + } + + static const char* DEBUG_FILENAME_DEFAULT; + static void openFile (const char* filename = DEBUG_FILENAME_DEFAULT); + static void closeFile( const char* filename = DEBUG_FILENAME_DEFAULT); + }; + + DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgDEBUGFLOW; + DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgERRORFLOW; +} // end of namespace dynamicgraph + +# ifdef VP_DEBUG + +# define dgPREDEBUG \ + __FILE__ << ": " <<__FUNCTION__ << "(#" << __LINE__ << ") :" +# define dgPREERROR \ + "\t!! "<<__FILE__ << ": " <<__FUNCTION__ << "(#" << __LINE__ << ") :" + +# define dgDEBUG(level) \ + if ((level > VP_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good ())) \ + ; \ + else \ + dgDEBUGFLOW.outputbuffer << dgPREDEBUG + +# define dgDEBUGMUTE(level) \ + if ((level > VP_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good ())) \ + ; \ + else \ + dgDEBUGFLOW.outputbuffer + +# define dgERROR \ + if (!dgDEBUGFLOW.outputbuffer.good ()) \ + ; \ + else \ + dgERRORFLOW.outputbuffer << dgPREERROR + +# define dgDEBUGF \ + if (!dgDEBUGFLOW.outputbuffer.good ()) \ + ; \ + else \ + dgDEBUGFLOW.pre (dgDEBUGFLOW.tmpbuffer << dgPREDEBUG, VP_DEBUG_MODE).trace + +# define dgERRORF \ + if (!dgDEBUGFLOW.outputbuffer.good ()) \ + ; \ + else \ + dgERRORFLOW.pre (dgERRORFLOW.tmpbuffer << dgPREERROR).trace -#ifndef __DEBUG_HH -#define __DEBUG_HH +// TEMPLATE +# define dgTDEBUG(level) \ + if ((level > VP_TEMPLATE_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good ())) \ + ; \ + else \ + dgDEBUGFLOW.outputbuffer << dgPREDEBUG + +# define dgTDEBUGF \ + if (!dgDEBUGFLOW.outputbuffer.good ()) \ + ; \ + else \ + dgDEBUGFLOW.pre \ + (dgDEBUGFLOW.tmpbuffer << dgPREDEBUG, VP_TEMPLATE_DEBUG_MODE).trace + +inline bool dgDEBUG_ENABLE (const int & level) +{ + return level<=VP_DEBUG_MODE; +} -#include <stdio.h> -#include <iostream> -#include <fstream> -#include <sstream> -#include <stdarg.h> -#include <dynamic-graph/dynamic-graph-api.h> +inline bool dgTDEBUG_ENABLE (const int & level) +{ + return level<=VP_TEMPLATE_DEBUG_MODE; +} +# else // VP_DEBUG -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ +# define dgPREERROR \ + "\t!! "<<__FILE__ << ": " <<__FUNCTION__ << "(#" << __LINE__ << ") :" -/* -------------------------------------------------------------------------- */ +# define dgDEBUG(level) \ + if (1) \ + ; \ + else \ + std::cout -#ifndef VP_DEBUG_MODE -#define VP_DEBUG_MODE 0 -#endif -#ifndef VP_TEMPLATE_DEBUG_MODE -#define VP_TEMPLATE_DEBUG_MODE 0 -#endif +# define dgDEBUGMUTE (level) \ + if (1) \ + ; \ + else \ + std::cout -#define DG_COMMON_TRACES do { \ - va_list arg; \ - va_start(arg,format); \ - vsnprintf( charbuffer,SIZE,format,arg ); \ - va_end(arg); \ - outputbuffer << tmpbuffer.str() << charbuffer <<std::endl; \ - } while(0) +# define dgERROR \ + dgERRORFLOW.outputbuffer << dgPREERROR -namespace dynamicgraph { +inline void dgDEBUGF (const int, const char*, ...) +{ + return; +} -class DYNAMIC_GRAPH_DLLAPI DebugTrace +inline void dgDEBUGF (const char*, ...) { - public: - static const int SIZE = 512; - - std::stringstream tmpbuffer; - std::ostream& outputbuffer; - char charbuffer[SIZE+1]; - int traceLevel; - int traceLevelTemplate; - - DebugTrace( std::ostream& os ): outputbuffer(os) {} - - inline void trace( const int level,const char* format,...) - { if( level<=traceLevel ) DG_COMMON_TRACES; tmpbuffer.str(""); } - inline void trace( const char* format,...){ DG_COMMON_TRACES; tmpbuffer.str(""); } - inline void trace( const int level=-1 ) - { if( level<=traceLevel ) outputbuffer << tmpbuffer.str(); tmpbuffer.str(""); } - - inline void traceTemplate( const int level,const char* format,...) - { if( level<=traceLevelTemplate ) DG_COMMON_TRACES; tmpbuffer.str(""); } - inline void traceTemplate( const char* format,...) - { DG_COMMON_TRACES; tmpbuffer.str(""); } - - inline DebugTrace& pre( const std::ostream&) { return *this; } - inline DebugTrace& pre( const std::ostream&, int level) - { traceLevel = level; return *this; } -/* inline DebugTrace& preTemplate( const std::ostream& dummy,int level ) */ -/* { traceLevelTemplate = level; return *this; } */ - - - static const char * DEBUG_FILENAME_DEFAULT; - static void openFile( const char * filename = DEBUG_FILENAME_DEFAULT ); - static void closeFile( const char * filename = DEBUG_FILENAME_DEFAULT ); - -}; - -DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgDEBUGFLOW; -DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgERRORFLOW; - -} // namespace dynamicgraph - -#ifdef VP_DEBUG -#define dgPREDEBUG __FILE__ << ": " <<__FUNCTION__ \ - << "(#" << __LINE__ << ") :" -#define dgPREERROR "\t!! "<<__FILE__ << ": " <<__FUNCTION__ \ - << "(#" << __LINE__ << ") :" - -# define dgDEBUG(level) if( (level>VP_DEBUG_MODE)||(!dgDEBUGFLOW.outputbuffer.good()) ) ;\ - else dgDEBUGFLOW.outputbuffer << dgPREDEBUG -# define dgDEBUGMUTE(level) if( (level>VP_DEBUG_MODE)||(!dgDEBUGFLOW.outputbuffer.good()) ) ;\ - else dgDEBUGFLOW.outputbuffer -# define dgERROR if(!dgDEBUGFLOW.outputbuffer.good()); else dgERRORFLOW.outputbuffer << dgPREERROR -# define dgDEBUGF if(!dgDEBUGFLOW.outputbuffer.good()); else dgDEBUGFLOW.pre(dgDEBUGFLOW.tmpbuffer<<dgPREDEBUG,VP_DEBUG_MODE).trace -# define dgERRORF if(!dgDEBUGFLOW.outputbuffer.good()); else dgERRORFLOW.pre(dgERRORFLOW.tmpbuffer<<dgPREERROR).trace -// TEMPLATE -# define dgTDEBUG(level) if( (level>VP_TEMPLATE_DEBUG_MODE)||(!dgDEBUGFLOW.outputbuffer.good()) ) ;\ - else dgDEBUGFLOW.outputbuffer << dgPREDEBUG -# define dgTDEBUGF if(!dgDEBUGFLOW.outputbuffer.good()); else dgDEBUGFLOW.pre(dgDEBUGFLOW.tmpbuffer<<dgPREDEBUG,VP_TEMPLATE_DEBUG_MODE).trace -inline bool dgDEBUG_ENABLE( const int & level ) { return level<=VP_DEBUG_MODE; } -inline bool dgTDEBUG_ENABLE( const int & level ) { return level<=VP_TEMPLATE_DEBUG_MODE; } - -/* -------------------------------------------------------------------------- */ -#else // #ifdef VP_DEBUG -#define dgPREERROR "\t!! "<<__FILE__ << ": " <<__FUNCTION__ \ - << "(#" << __LINE__ << ") :" -# define dgDEBUG(level) if( 1 ) ; else std::cout -# define dgDEBUGMUTE(level) if( 1 ) ; else std::cout -# define dgERROR dgERRORFLOW.outputbuffer << dgPREERROR -inline void dgDEBUGF( const int, const char*,...) { return; } -inline void dgDEBUGF( const char*, ...) { return; } -inline void dgERRORF( const int, const char*,...) { return; } -inline void dgERRORF( const char*, ...) { return; } + return; +} + +inline void dgERRORF (const int, const char*, ...) +{ + return; +} + +inline void dgERRORF (const char*, ...) +{ + return; +} + // TEMPLATE -# define dgTDEBUG(level) if( 1 ) ; else std::cout -inline void dgTDEBUGF( const int, const char*,...) { return; } -inline void dgTDEBUGF( const char*,...) { return; } -#define dgDEBUG_ENABLE(level) false -#define dgTDEBUG_ENABLE(level) false +# define dgTDEBUG(level) \ + if (1) \ + ; \ + else \ + std::cout -#endif // #ifdef VP_DEBUG -/* -------------------------------------------------------------------------- */ +inline void dgTDEBUGF (const int, const char*, ...) +{ + return; +} -#define dgDEBUGIN(level) dgDEBUG(level) << "# In {" << std::endl -#define dgDEBUGOUT(level) dgDEBUG(level) << "# Out }" << std::endl -#define dgDEBUGINOUT(level) dgDEBUG(level) << "# In/Out { }" << std::endl +inline void dgTDEBUGF (const char*, ...) +{ + return; +} -#define dgTDEBUGIN(level) dgTDEBUG(level) << "# In {" << std::endl -#define dgTDEBUGOUT(level) dgTDEBUG(level) << "# Out }" << std::endl -#define dgTDEBUGINOUT(level) dgTDEBUG(level) << "# In/Out { }" << std::endl +# define dgDEBUG_ENABLE(level) false +# define dgTDEBUG_ENABLE(level) false +# endif //! VP_DEBUG -#endif /* #ifdef __VS_DEBUG_HH */ +# define dgDEBUGIN(level) \ + dgDEBUG(level) << "# In {" << std::endl -/* - * Local variables: - * c-basic-offset: 4 - * End: - */ +# define dgDEBUGOUT(level) \ + dgDEBUG(level) << "# Out }" << std::endl + +# define dgDEBUGINOUT(level) \ + dgDEBUG(level) << "# In/Out { }" << std::endl + + +# define dgTDEBUGIN(level) \ + dgTDEBUG(level) << "# In {" << std::endl + +# define dgTDEBUGOUT(level) \ + dgTDEBUG(level) << "# Out }" << std::endl + +# define dgTDEBUGINOUT(level) \ + dgTDEBUG(level) << "# In/Out { }" << std::endl + +#endif //! DYNAMIC_GRAPH_DEBUG_HH diff --git a/include/dynamic-graph/dynamic-graph-api.h b/include/dynamic-graph/dynamic-graph-api.h index 3d3975c..e1125ee 100644 --- a/include/dynamic-graph/dynamic-graph-api.h +++ b/include/dynamic-graph/dynamic-graph-api.h @@ -1,24 +1,21 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. -#ifndef DYNAMICGRAPH_API_H -# define DYNAMICGRAPH_API_H +#ifndef DYNAMIC_GRAPH_API_H +# define DYNAMIC_GRAPH_API_H # include <dynamic-graph/config.hh> -#endif //! DYNAMICGRAPH_API_H +#endif //! DYNAMIC_GRAPH_API_H diff --git a/include/dynamic-graph/entity.h b/include/dynamic-graph/entity.h index 2a215e0..5f8cfa5 100644 --- a/include/dynamic-graph/entity.h +++ b/include/dynamic-graph/entity.h @@ -1,109 +1,106 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __ENTITY_HH__ -#define __ENTITY_HH__ - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -/* DYNAMIC-GRAPH */ -#include <dynamic-graph/signal-base.h> -#include <dynamic-graph/exception-factory.h> -#include <dynamic-graph/signal-array.h> -#include <dynamic-graph/dynamic-graph-api.h> - -/* --- STD --- */ -#include <string> -#include <map> -#include <sstream> - -/* --- BOOST --- */ -#include <boost/noncopyable.hpp> - -/* NAMESPACE */ -namespace dynamicgraph { - -/* --------------------------------------------------------------------- */ -/* --- CLASS ----------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ -/*! \ingroup dgraph - \brief This class represents an entity, i.e. a generic - computational unit that provides input and output signals. - - These signals link the entities together to form a complete computation graph. - To declare a new entity, please see the DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN macro - in g_factory.h. - A command-line interface provided by the entity can be used by a sot shell to - call methods from entities and display the result of their execution. - Classes that derive from Entity can customize the command-line by overriding commandLine(). - */ -class DYNAMIC_GRAPH_DLLAPI Entity -: private boost::noncopyable +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_ENTITY_H +# define DYNAMIC_GRAPH_ENTITY_H +# include <iosfwd> +# include <map> +# include <sstream> +# include <string> + +# include <boost/noncopyable.hpp> + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/dynamic-graph-api.h> +# include <dynamic-graph/exception-factory.h> +# include <dynamic-graph/signal-array.h> +# include <dynamic-graph/signal-base.h> + +namespace dynamicgraph { - - protected: - std::string name; - - void entityRegistration( void ); - void entityDeregistration( void ); - - public: - Entity( const std::string& name ); - virtual ~Entity( void ); - - static const std::string CLASS_NAME; - const std::string& getName( void ) const { return name; } - virtual const std::string& getClassName( void ) const { return CLASS_NAME; } - - protected: /* --- SIGNALS --- */ - typedef std::map< std::string,SignalBase<int>* > SignalMap; - SignalMap signalMap; - void signalRegistration( const SignalArray<int>& signals ); - void signalDeregistration( const std::string& name ); - public: - SignalBase<int>& getSignal( const std::string & signalName ); - const SignalBase<int>& getSignal( const std::string & signalName ) const; - std::ostream& displaySignalList( std::ostream& os ) const; - virtual std::ostream& writeGraph( std::ostream& os ) const; - virtual std::ostream& writeCompletionList( std::ostream& os ) const; - - public: /* --- DISPLAY --- */ - virtual void display( std::ostream& os ) const; - - public: /* --- PARAMS --- */ - virtual void commandLine( const std::string& cmdLine,std::istringstream& cmdArgs, - std::ostream& os ); - - virtual SignalBase<int>* test(void) { return 0; } - virtual void test2( SignalBase<int>* ) { return ; } - - virtual const std::string& getCommandList( void ) const; -}; - -DYNAMIC_GRAPH_DLLAPI std::ostream& operator<< (std::ostream& os, const dynamicgraph::Entity& ent ); - -} // namespace dynamicgraph -#endif /* #ifndef __ENTITY_HH__ */ - - - - + /*! \ingroup dgraph + \brief This class represents an entity, i.e. a generic + computational unit that provides input and output signals. + + These signals link the entities together to form a complete + computation graph. To declare a new entity, please see the + DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN macro in g_factory.h. A + command-line interface provided by the entity can be used by a sot + shell to call methods from entities and display the result of + their execution. Classes that derive from Entity can customize + the command-line by overriding commandLine (). + */ + class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable + { + public: + static const std::string CLASS_NAME; + + explicit Entity (const std::string& name); + virtual ~Entity (); + + const std::string& getName () const + { + return name; + } + + virtual const std::string& getClassName () const + { + return CLASS_NAME; + } + + SignalBase<int>& getSignal (const std::string& signalName); + const SignalBase<int>& getSignal (const std::string& signalName) const; + std::ostream& displaySignalList(std::ostream& os) const; + virtual std::ostream& writeGraph (std::ostream& os) const; + virtual std::ostream& writeCompletionList (std::ostream& os) const; + + virtual void display (std::ostream& os) const; + + virtual void commandLine (const std::string& cmdLine, + std::istringstream& cmdArgs, + std::ostream& os); + + virtual SignalBase<int>* test () + { + return 0; + } + + virtual void test2 (SignalBase<int>*) + { + return ; + } + + virtual const std::string& getCommandList () const; + + protected: + typedef std::map< std::string,SignalBase<int>* > SignalMap; + + void entityRegistration (); + void entityDeregistration (); + + void signalRegistration (const SignalArray<int>& signals); + void signalDeregistration (const std::string& name); + + std::string name; + SignalMap signalMap; + }; + + DYNAMIC_GRAPH_DLLAPI std::ostream& + operator<< (std::ostream& os, const dynamicgraph::Entity& ent); +} // end of namespace dynamicgraph + +#endif //! DYNAMIC_GRAPH_ENTITY_H diff --git a/include/dynamic-graph/exception-abstract.h b/include/dynamic-graph/exception-abstract.h index 8bf3c2a..64036b4 100644 --- a/include/dynamic-graph/exception-abstract.h +++ b/include/dynamic-graph/exception-abstract.h @@ -1,151 +1,154 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __ABSTRACT_EXCEPTION_H -#define __ABSTRACT_EXCEPTION_H - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - - -/* Classes standards. */ -#include <iostream> /* Classe ostream. */ -#include <string> /* Classe string. */ -#include <dynamic-graph/dynamic-graph-api.h> - +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_EXCEPTION_ABSTRACT_H +# define DYNAMIC_GRAPH_EXCEPTION_ABSTRACT_H +# include <iostream> +# include <string> + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/dynamic-graph-api.h> // Uncomment this macros to have lines parameter on the throw display // #define DYNAMIC-GRAPH_EXCEPTION_PASSING_PARAM -/* --------------------------------------------------------------------- */ -/* --- CLASS ----------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -namespace dynamicgraph { +# define DG_RETHROW \ + (const ::dynamicgraph::ExceptionAbstract& err) \ + { \ + throw err; \ + } -/* \class ExceptionAbstract - */ -class DYNAMIC_GRAPH_DLLAPI ExceptionAbstract : public std::exception -{ +# ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM +# define DG_THROW \ + throw ::dynamicgraph::ExceptionAbstract::Param \ + (__LINE__, __FUNCTION__, __FILE__) + +# else +# define DG_THROW \ + throw +# endif // DYNAMICGRAPH_EXCEPTION_PASSING_PARAM - public: - enum ExceptionEnum +namespace dynamicgraph +{ + class DYNAMIC_GRAPH_DLLAPI ExceptionAbstract : public std::exception + { + public: + class Param { - ABSTRACT = 0 - ,SIGNAL = 100 - ,FACTORY = 200 - ,TRACES = 300 - ,TOOLS = 700 - }; - - static const std::string EXCEPTION_NAME; - virtual const std::string& getExceptionName( void ) const { return EXCEPTION_NAME; } - - protected: - /** Error code. - * \sa ErrorCodeEnum */ - int code; + public: + static const int BUFFER_SIZE = 80; - /** Error message (can be empty). */ - std::string message; + Param (const int& _line, const char* _function, const char* _file); + Param () + : functionPTR (), + function (), + line (), + filePTR (), + file (), + pointersSet (false), + set (false) + {} + Param& initCopy (const Param& p); + + const char* functionPTR; + char function[BUFFER_SIZE]; + int line; + const char* filePTR; + char file[BUFFER_SIZE]; + bool pointersSet; + bool set; + }; -private: - /** forbid the empty constructor (private). */ - ExceptionAbstract( void ); -public: + enum ExceptionEnum + { + ABSTRACT = 0, + SIGNAL = 100, + FACTORY = 200, + TRACES = 300, + TOOLS = 700 + }; - ExceptionAbstract( const int& code, const std::string & msg = "" ); - virtual ~ExceptionAbstract( void ) throw() {} + static const std::string EXCEPTION_NAME; - /** Access to the error code. */ - int getCode () const; + explicit ExceptionAbstract (const int& code, const std::string& msg = ""); + virtual ~ExceptionAbstract () throw () + {} - /** Reference access to the error message (can be empty). */ - const std::string& getStringMessage (void) const; + virtual const std::string& getExceptionName () const + { + return EXCEPTION_NAME; + } - /** Access to the pointer on the array of \e char related to the error string. - * Cannot be \e NULL. - */ - const char *getMessage (void); + /** Access to the error code. */ + int getCode () const; - virtual const char* what() const throw() - { - return getStringMessage().c_str(); - } + /** Reference access to the error message (can be empty). */ + const std::string& getStringMessage () const; - /** Print the error structure. */ - DYNAMIC_GRAPH_DLLAPI friend std::ostream & operator << (std::ostream & os, - const ExceptionAbstract & err); + /** Access to the pointer on the array of \e char related to the + * error string. + * Cannot be \e NULL. + */ + const char* getMessage () const; -#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM - public: - class Param + virtual const char* what () const throw () { - public: - static const int BUFFER_SIZE = 80; + return getStringMessage ().c_str (); + } - const char * functionPTR; - char function[ BUFFER_SIZE ]; - int line; - const char * filePTR; - char file[ BUFFER_SIZE ]; - bool pointersSet,set; - public: - Param( const int& _line, const char * _function, const char * _file ); - Param( void ) : pointersSet(false),set(false) {} - Param& initCopy( const Param& p ); - - }; + /** Print the error structure. */ + DYNAMIC_GRAPH_DLLAPI friend std::ostream & + operator << (std::ostream & os, const ExceptionAbstract & err); - protected: - mutable Param p; - template<class Exc> - friend const Exc& operator+ ( const ExceptionAbstract::Param& p, const Exc& e ) - { e.p.initCopy(p); return e; } - template<class Exc> - friend Exc& operator+ ( const ExceptionAbstract::Param& p, Exc& e ) - { e.p.initCopy(p); return e; } -#endif //#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM -}; + protected: + /** Error code. + * \sa ErrorCodeEnum */ + int code; -} // namespace dynamicgraph - -#define DG_RETHROW ( const ExceptionAbstract& err ) { throw err; } + /** Error message (can be empty). */ + std::string message; +# ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM + mutable Param p; + template<class Exc> + friend const Exc& + operator+ (const ExceptionAbstract::Param& p, const Exc& e) + { + e.p.initCopy(p); + return e; + } -#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM -# define DG_THROW throw ExceptionAbstract::Param(__LINE__,__FUNCTION__,__FILE__) + -#else //#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM -# define DG_THROW throw -#endif //#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM + template<class Exc> + friend Exc& + operator+ (const ExceptionAbstract::Param& p, Exc& e) + { + e.p.initCopy (p); + return e; + } +# endif // DYNAMICGRAPH_EXCEPTION_PASSING_PARAM -#endif /* #ifndef __ABSTRACT_EXCEPTION_H */ + private: + /// forbid the empty constructor (private). + ExceptionAbstract (); + }; +} // end of namespace dynamicgraph -/* - * Local variables: - * c-basic-offset: 2 - * End: - */ +#endif //! DYNAMIC_GRAPH_EXCEPTION_ABSTRACT_H diff --git a/include/dynamic-graph/exception-factory.h b/include/dynamic-graph/exception-factory.h index 19ffec4..55e53e1 100644 --- a/include/dynamic-graph/exception-factory.h +++ b/include/dynamic-graph/exception-factory.h @@ -1,49 +1,34 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __EXCEPTION_FACTORY_H -#define __EXCEPTION_FACTORY_H - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - - -#include <dynamic-graph/exception-abstract.h> -#include <dynamic-graph/dynamic-graph-api.h> - -/* --------------------------------------------------------------------- */ -/* --- CLASS ----------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -namespace dynamicgraph { - -/* \class sotExceptionFactory - */ -class DYNAMIC_GRAPH_DLLAPI ExceptionFactory -:public ExceptionAbstract - +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_EXCEPTION_FACTORY_H +# define DYNAMIC_GRAPH_EXCEPTION_FACTORY_H +# include <string> + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/dynamic-graph-api.h> +# include <dynamic-graph/exception-abstract.h> + +namespace dynamicgraph { -public: - - enum ErrorCodeEnum + class DYNAMIC_GRAPH_DLLAPI ExceptionFactory :public ExceptionAbstract + { + public: + enum ErrorCodeEnum { GENERIC = ExceptionAbstract::FACTORY ,UNREFERED_OBJECT @@ -53,29 +38,26 @@ public: ,SIGNAL_CONFLICT ,FUNCTION_CONFLICT ,OBJECT_CONFLICT - ,SYNTAX_ERROR // j' aime bien FATAL_ERROR aussi faut que je la case qq part... + ,SYNTAX_ERROR ,READ_FILE }; - static const std::string EXCEPTION_NAME; - virtual const std::string& getExceptionName( void )const{ return ExceptionFactory::EXCEPTION_NAME; } - - ExceptionFactory ( const ExceptionFactory::ErrorCodeEnum& errcode, - const std::string & msg = "" ); - ExceptionFactory ( const ExceptionFactory::ErrorCodeEnum& errcode, - const std::string & msg,const char* format, ... ); - virtual ~ExceptionFactory( void ) throw() {} - -}; + static const std::string EXCEPTION_NAME; + explicit ExceptionFactory (const ExceptionFactory::ErrorCodeEnum& errcode, + const std::string & msg = ""); + + ExceptionFactory (const ExceptionFactory::ErrorCodeEnum& errcode, + const std::string& msg, const char* format, ...); + + virtual ~ExceptionFactory () throw () + {} -} // namespace dynamicgraph - - -#endif /* #ifndef __EXCEPTION_FACTORY_H */ + virtual const std::string& getExceptionName () const + { + return ExceptionFactory::EXCEPTION_NAME; + } + }; +} // end of namespace dynamicgraph -/* - * Local variables: - * c-basic-offset: 2 - * End: - */ +#endif //! DYNAMIC_GRAPH_EXCEPTION_FACTORY_H diff --git a/include/dynamic-graph/exception-signal.h b/include/dynamic-graph/exception-signal.h index c9fa1ba..5d25fd2 100644 --- a/include/dynamic-graph/exception-signal.h +++ b/include/dynamic-graph/exception-signal.h @@ -1,48 +1,33 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __SIGNAL_EXCEPTION_H -#define __SIGNAL_EXCEPTION_H - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - - -#include <dynamic-graph/exception-abstract.h> -#include <dynamic-graph/dynamic-graph-api.h> - -/* --------------------------------------------------------------------- */ -/* --- CLASS ----------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -namespace dynamicgraph { - -/* \class sotExceptionSignal - */ -class DYNAMIC_GRAPH_DLLAPI ExceptionSignal -:public ExceptionAbstract - +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_EXCEPTION_SIGNAL_H +# define DYNAMIC_GRAPH_EXCEPTION_SIGNAL_H + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/dynamic-graph-api.h> +# include <dynamic-graph/exception-abstract.h> + +namespace dynamicgraph { - public: - enum ErrorCodeEnum + class DYNAMIC_GRAPH_DLLAPI ExceptionSignal : public ExceptionAbstract + { + public: + enum ErrorCodeEnum { GENERIC = ExceptionAbstract::SIGNAL @@ -54,28 +39,21 @@ class DYNAMIC_GRAPH_DLLAPI ExceptionSignal ,BAD_CAST }; - static const std::string EXCEPTION_NAME; - virtual const std::string& getExceptionName( void ) const { return EXCEPTION_NAME; } - -public: - - ExceptionSignal ( const ExceptionSignal::ErrorCodeEnum& errcode, - const std::string & msg = "" ); - ExceptionSignal( const ExceptionSignal::ErrorCodeEnum& errcode, - const std::string & msg,const char* format, ... ); - virtual ~ExceptionSignal( void ) throw() {} - - -}; - -} // namespace dynamicgraph + static const std::string EXCEPTION_NAME; + explicit ExceptionSignal (const ExceptionSignal::ErrorCodeEnum& errcode, + const std::string & msg = "" ); + ExceptionSignal (const ExceptionSignal::ErrorCodeEnum& errcode, + const std::string & msg, const char* format, ...); + virtual ~ExceptionSignal () throw () + {} + virtual const std::string& getExceptionName () const + { + return EXCEPTION_NAME; + } + }; -#endif /* #ifndef __SIGNAL_EXCEPTION_H */ +} // end of namespace dynamicgraph -/* - * Local variables: - * c-basic-offset: 2 - * End: - */ +#endif //!DYNAMIC_GRAPH_EXCEPTION_SIGNAL_H diff --git a/include/dynamic-graph/exception-traces.h b/include/dynamic-graph/exception-traces.h index 81e8bc1..463447e 100644 --- a/include/dynamic-graph/exception-traces.h +++ b/include/dynamic-graph/exception-traces.h @@ -1,79 +1,53 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __TRACES_EXCEPTION_H -#define __TRACES_EXCEPTION_H - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - - -#include <dynamic-graph/exception-abstract.h> -#include <dynamic-graph/dynamic-graph-api.h> - -/* --------------------------------------------------------------------- */ -/* --- CLASS ----------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -namespace dynamicgraph { - -/* \class ExceptionTraces - */ -class DYNAMIC_GRAPH_DLLAPI ExceptionTraces -:public ExceptionAbstract - +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_EXCEPTION_TRACES_H +# define DYNAMIC_GRAPH_EXCEPTION_TRACES_H +# include <string> + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/dynamic-graph-api.h> +# include <dynamic-graph/exception-abstract.h> + +namespace dynamicgraph { - public: - enum ErrorCodeEnum + class DYNAMIC_GRAPH_DLLAPI ExceptionTraces : public ExceptionAbstract + { + public: + enum ErrorCodeEnum { GENERIC = ExceptionAbstract::TRACES - ,NOT_OPEN }; - static const std::string EXCEPTION_NAME; - virtual const std::string& getExceptionName( void ) const { return EXCEPTION_NAME; } - -public: + static const std::string EXCEPTION_NAME; - ExceptionTraces ( const ExceptionTraces::ErrorCodeEnum& errcode, - const std::string & msg = "" ); - ExceptionTraces( const ExceptionTraces::ErrorCodeEnum& errcode, - const std::string & msg,const char* format, ... ); - virtual ~ExceptionTraces( void ) throw () {} + explicit ExceptionTraces (const ExceptionTraces::ErrorCodeEnum& errcode, + const std::string & msg = ""); + ExceptionTraces (const ExceptionTraces::ErrorCodeEnum& errcode, + const std::string& msg, const char* format, ...); + virtual ~ExceptionTraces () throw () + {} + virtual const std::string& getExceptionName () const + { + return EXCEPTION_NAME; + } + }; +} // end of namespace dynamicgraph. -}; - - - -} //namespace dynamicgraph - - - - -#endif /* #ifndef __TRACES_EXCEPTION_H */ - -/* - * Local variables: - * c-basic-offset: 2 - * End: - */ +#endif //! DYNAMIC_GRAPH_EXCEPTION_TRACES_H diff --git a/include/dynamic-graph/factory.h b/include/dynamic-graph/factory.h index 7d22f26..c62a1fc 100644 --- a/include/dynamic-graph/factory.h +++ b/include/dynamic-graph/factory.h @@ -1,4 +1,4 @@ -// -*- c++-mode -*- +// -*- mode: c++ -*- // Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, // JRL, CNRS/AIST. // @@ -107,9 +107,9 @@ namespace dynamicgraph /// After the initialization, no entities will be available. /// registerEntity has to be used to add new entities to the /// object. - explicit FactoryStorage (); + explicit FactoryStorage (); - ~FactoryStorage (); + ~FactoryStorage (); /// \brief Add a new entity to the factory. /// @@ -223,13 +223,13 @@ namespace dynamicgraph FactoryStorage::EntityConstructor_ptr maker); /// \brief Unregister entity to the global factory. - ~EntityRegisterer (); + ~EntityRegisterer (); private: /// \brief Name of the entity registered when the instance has /// been initialized. const std::string entityName; }; -} // namespace dynamicgraph +} // end of namespace dynamicgraph #endif //! DYNAMIC_GRAPH_FACTORY_HH diff --git a/include/dynamic-graph/functions.h b/include/dynamic-graph/functions.h index 9530a2f..40fc407 100644 --- a/include/dynamic-graph/functions.h +++ b/include/dynamic-graph/functions.h @@ -1,51 +1,32 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __SHELL_FUNCTIONS_HH__ -#define __SHELL_FUNCTIONS_HH__ - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -/* DYNAMIC-GRAPH */ -#include <dynamic-graph/exception-factory.h> -#include <dynamic-graph/interpreter.h> -#include <dynamic-graph/dynamic-graph-api.h> - -/* --- STD --- */ -#include <string> -#include <map> -#include <sstream> - -/* --- BOOST --- */ -#include <boost/function.hpp> -#include <boost/bind.hpp> - -/* --------------------------------------------------------------------- */ -/* --- CLASS ----------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -#define STATIC_SHELL_FUNCTION( name ) \ - static void name( const std::string cmd,std::istringstream& args, \ - std::ostream& os ) +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_FUNCTIONS_H +# define DYNAMIC_GRAPH_FUNCTIONS_H +# include <iosfwd> +# include <string> + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/dynamic-graph-api.h> + +# define STATIC_SHELL_FUNCTION(name) \ + static void name (const std::string cmd, \ + std::istringstream& args, \ + std::ostream& os) /*! @ingroup dgraph \brief This plugin implements a bunch of useful shell commands. @@ -54,30 +35,27 @@ and user interaction commands such as display and beep commands. For more information, load the plugin and type help on a sot shell. */ -class DYNAMIC_GRAPH_DLLAPI ShellFunctions +struct DYNAMIC_GRAPH_DLLAPI ShellFunctions { - public: - - STATIC_SHELL_FUNCTION( cmdLoadPlugins ); - STATIC_SHELL_FUNCTION( cmdTry ); - STATIC_SHELL_FUNCTION( cmdDisplayPlugins ); - STATIC_SHELL_FUNCTION( cmdDisplayFactory ); - STATIC_SHELL_FUNCTION( cmdCommentary ); - STATIC_SHELL_FUNCTION( cmdUnplug ); - STATIC_SHELL_FUNCTION( cmdClearPlugin ); - STATIC_SHELL_FUNCTION( cmdSignalTime ); - STATIC_SHELL_FUNCTION( cmdSynchroSignal ); - STATIC_SHELL_FUNCTION( cmdEcho ); - STATIC_SHELL_FUNCTION( cmdCopy ); - STATIC_SHELL_FUNCTION( cmdFreeze ); - STATIC_SHELL_FUNCTION( cmdSqueeze ); - STATIC_SHELL_FUNCTION( cmdEnableTrace ); - STATIC_SHELL_FUNCTION( cmdSetPrompt ); - STATIC_SHELL_FUNCTION( cmdSleep ); - STATIC_SHELL_FUNCTION( cmdBeep ); - STATIC_SHELL_FUNCTION( cmdFlagSet ); - STATIC_SHELL_FUNCTION( cmdCompletionList ); + STATIC_SHELL_FUNCTION (cmdLoadPlugins); + STATIC_SHELL_FUNCTION (cmdTry); + STATIC_SHELL_FUNCTION (cmdDisplayPlugins); + STATIC_SHELL_FUNCTION (cmdDisplayFactory); + STATIC_SHELL_FUNCTION (cmdCommentary); + STATIC_SHELL_FUNCTION (cmdUnplug); + STATIC_SHELL_FUNCTION (cmdClearPlugin); + STATIC_SHELL_FUNCTION (cmdSignalTime); + STATIC_SHELL_FUNCTION (cmdSynchroSignal); + STATIC_SHELL_FUNCTION (cmdEcho); + STATIC_SHELL_FUNCTION (cmdCopy); + STATIC_SHELL_FUNCTION (cmdFreeze); + STATIC_SHELL_FUNCTION (cmdSqueeze); + STATIC_SHELL_FUNCTION (cmdEnableTrace); + STATIC_SHELL_FUNCTION (cmdSetPrompt); + STATIC_SHELL_FUNCTION (cmdSleep); + STATIC_SHELL_FUNCTION (cmdBeep); + STATIC_SHELL_FUNCTION (cmdFlagSet); + STATIC_SHELL_FUNCTION (cmdCompletionList); }; - -#endif //#ifndef __DYNAMIC-GRAPH_SHELL_FUNCTIONS_HH__ +#endif //! DYNAMIC_GRAPH_FUNCTIONS_H diff --git a/include/dynamic-graph/fwd.hh b/include/dynamic-graph/fwd.hh index de625c2..fe34dc2 100644 --- a/include/dynamic-graph/fwd.hh +++ b/include/dynamic-graph/fwd.hh @@ -30,6 +30,13 @@ namespace dynamicgraph template<typename T> class DefaultCastRegisterer; + class Contiifstream; + + class PluginLoader; + class PluginRefMap; + + template<class Time> + class SignalArray; } // end of namespace dynamicgraph. #endif //! DYNAMIC_GRAPH_FWD_HH diff --git a/include/dynamic-graph/import.h b/include/dynamic-graph/import.h index 3491d00..6a9713c 100644 --- a/include/dynamic-graph/import.h +++ b/include/dynamic-graph/import.h @@ -1,24 +1,20 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of sot-core. - * sot-core is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * sot-core is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with sot-core. If not, see <http://www.gnu.org/licenses/>. - */ +// -*- c++-mode -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. -// -*- c++ -*- #ifndef SOT_FACTORY_COMMAND_IMPORT_H # define SOT_FACTORY_COMMAND_IMPORT_H # include <iosfwd> diff --git a/include/dynamic-graph/interpreter-helper.h b/include/dynamic-graph/interpreter-helper.h index ff2aedf..4b5a412 100644 --- a/include/dynamic-graph/interpreter-helper.h +++ b/include/dynamic-graph/interpreter-helper.h @@ -1,157 +1,124 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __INTERPRETER_HELPER_HH__ -#define __INTERPRETER_HELPER_HH__ - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -/* DYNAMIC-GRAPH */ -#include <dynamic-graph/signal-base.h> -#include <dynamic-graph/exception-factory.h> -#include <dynamic-graph/pool.h> -#include <dynamic-graph/dynamic-graph-api.h> -#include <dynamic-graph/plugin-loader.h> - -/* --- STD --- */ -#include <string> -#include <map> -#include <sstream> - -/* --- BOOST --- */ -#include <boost/function.hpp> -#include <boost/bind.hpp> - -namespace dynamicgraph { -/* --------------------------------------------------------------------- */ -/* --- CLASS ----------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -/*! @ingroup dgraph - \brief This class implements the first level interpretor - to control basic functionnalities of the plugins. - - It provides a shell allowing to : - \li load plugin libraries, - \li create instances of plugin, - \li destroy the plugins, - \li unload the libraries, - \li set a signal, - \li get a signal, - \li compute a signal, -*/ -class DYNAMIC_GRAPH_DLLAPI InterpreterHelper +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_INTERPRETER_HELPER_H +# define DYNAMIC_GRAPH_INTERPRETER_HELPER_H +# include <iosfwd> +# include <string> + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/plugin-loader.h> + +namespace dynamicgraph { - - public: - /*! \brief Default constructor - \par[in] dlPtr: a plugin loader to perform the actions provided by this shell. - */ - InterpreterHelper( ); - - - protected: - - /*! \brief The plugin loader */ - PluginLoader dlPtr; - - public: - - /*! \name Implements the commands. - @{ - */ - /*! \brief Instanciate an object - Extracts the name and the class of the object, verifies it is unique, - and creates the instance if this is the case. - */ - void cmdNew(const std::string& className, - const std::string& objName, - std::ostream& os); - - /*! \brief Destroy the object. - Destroy the object objName. - */ - void cmdDestroy( const std::string& objName, - std::ostream& os ); - - /*! \brief Connect two signals. - Connect the input signal obj1.signame1 to the output signal - obj2.signame2. - \param[in] obj1 The input object. - \param[in] obj2 The output object. - \param[in] signame1 The input object's signal name - \param[in] signame2 The output object's signal name - \param[out] os The output stream for logging and error output - */ - void cmdPlug( const std::string& obj1, const std::string & signame1, - const std::string& obj2, const std::string & signame2, - std::ostream& os ); - - /*! \brief Load a dynamic library which includes a plugin. - Extracts the name first and the directory in second from cmdArg - to load the dynamic library. - */ - void cmdLoadPlugin( const std::string& directory, - const std::string& pluginName, - std::ostream& os ); - - /*! \brief Unload a dynamic library which includes a plugin. - Extracts the name to unload the dynamic library. + /*! @ingroup dgraph + \brief This class implements the first level interpretor + to control basic functionnalities of the plugins. + + It provides a shell allowing to : + \li load plugin libraries, + \li create instances of plugin, + \li destroy the plugins, + \li unload the libraries, + \li set a signal, + \li get a signal, + \li compute a signal, */ - void cmdUnloadPlugin( const std::string& pluginName, - std::ostream& os ); - - /*! \brief Set a signal [obj.signal] to a value [value] - with cmdArg = "[obj.signal] [value]" - */ - void cmdSetSignal( const std::string& objname, - const std::string& signame, - const std::string& cmdArg, - std::ostream& os); - - /*! \brief Display the value of the signal [obj.signal] - with cmdArg = "[obj.signal]" - */ - void cmdGetSignal( const std::string& objname, - const std::string& signame, + class DYNAMIC_GRAPH_DLLAPI InterpreterHelper + { + public: + InterpreterHelper () + {} + + /*! \name Implements the commands. + @{ + */ + /*! \brief Instanciate an object + Extracts the name and the class of the object, verifies it is unique, + and creates the instance if this is the case. + */ + void cmdNew (const std::string& className, + const std::string& objName, + std::ostream& os); + + /*! \brief Destroy the object. + Destroy the object objName. + */ + void cmdDestroy (const std::string& objName, std::ostream& os); - /*! \brief Compute the value of the signal [signame=obj.signal] at time [time] - with cmdArg = "[obj.signal] [time]" - */ - void cmdComputeSignal( const std::string& objname, - const std::string& signame, - const int &time, - std::ostream& os ); - -}; - - -} // namespace dynamicgraph - - - -#endif /* #ifndef */ - - - - + /*! \brief Connect two signals. + Connect the input signal obj1.signame1 to the output signal + obj2.signame2. + \param[in] obj1 The input object. + \param[in] obj2 The output object. + \param[in] signame1 The input object's signal name + \param[in] signame2 The output object's signal name + \param[out] os The output stream for logging and error output + */ + void cmdPlug (const std::string& obj1, const std::string & signame1, + const std::string& obj2, const std::string & signame2, + std::ostream& os); + + /*! \brief Load a dynamic library which includes a plugin. + Extracts the name first and the directory in second from cmdArg + to load the dynamic library. + */ + void cmdLoadPlugin (const std::string& directory, + const std::string& pluginName, + std::ostream& os); + + /*! \brief Unload a dynamic library which includes a plugin. + Extracts the name to unload the dynamic library. + */ + void cmdUnloadPlugin (const std::string& pluginName, + std::ostream& os); + + /*! \brief Set a signal [obj.signal] to a value [value] + with cmdArg = "[obj.signal] [value]" + */ + void cmdSetSignal (const std::string& objname, + const std::string& signame, + const std::string& cmdArg, + std::ostream& os); + + /*! \brief Display the value of the signal [obj.signal] + with cmdArg = "[obj.signal]" + */ + void cmdGetSignal (const std::string& objname, + const std::string& signame, + std::ostream& os); + + /*! \brief Compute the value of the signal [signame=obj.signal] at + time [time] with cmdArg = "[obj.signal] [time]" + */ + void cmdComputeSignal (const std::string& objname, + const std::string& signame, + const int &time, + std::ostream& os); + + protected: + /// \brief The plugin loader. + PluginLoader dlPtr; + }; + + +} // end of namespace dynamicgraph + + + +#endif //! DYNAMIC_GRAPH_INTERPRETER_HELPER_H diff --git a/include/dynamic-graph/interpreter.h b/include/dynamic-graph/interpreter.h index 0439b77..95866c0 100644 --- a/include/dynamic-graph/interpreter.h +++ b/include/dynamic-graph/interpreter.h @@ -1,213 +1,192 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __INTERPRETER_HH__ -#define __INTERPRETER_HH__ - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -/* DYNAMIC-GRAPH */ -#include <dynamic-graph/signal-base.h> -#include <dynamic-graph/exception-factory.h> -#include <dynamic-graph/pool.h> -#include <dynamic-graph/dynamic-graph-api.h> - -/* --- STD --- */ -#include <string> -#include <map> -#include <sstream> - -/* --- BOOST --- */ -#include <boost/function.hpp> -#include <boost/bind.hpp> - -namespace dynamicgraph { -/* --------------------------------------------------------------------- */ -/* --- CLASS ----------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ -class PluginLoader; - -/*! @ingroup dgraph - \brief This class implements the first level interpretor - to control basic functionnalities of the plugins. - - It provides a shell allowing to : - \li load plugin libraries, - \li create instances of plugin, - \li destroy the plugins, - \li unload the libraries, - \li set a signal, - \li get a signal, - \li run scripts, - \li compute a signal, - \li act as a proxy for the commands of the plugins. -*/ -class DYNAMIC_GRAPH_DLLAPI Interpreter -{ - - public: - /*! \brief Type of a basic function for the shell. - Such function returns a void and takes 3 arguments: - \li the functionnality (i.e. the method) it provides to the shell, - \li a stream of input string to pass when called, - \li an output stream for display. - */ - typedef boost::function3<void,const std::string&,std::istringstream&,std::ostream&> ShellBasicFunction; - protected: - /*! \brief This type defines a sorted set of basic functions with a unique key. */ - typedef std::map< std::string,ShellBasicFunction > FunctionMap; - /*! Instance of this type. */ - FunctionMap functionMap; - - public: - /*! \brief Default constructor - \par[in] dlPtr: a plugin loader to perform the actions provided by this shell. - */ - Interpreter( PluginLoader* dlPtr=NULL ); - - typedef PluginLoader * sotPluginLoaderPTR; - /*! \brief The plugin loader */ - sotPluginLoaderPTR dlPtr; - - protected: - bool initDone; // Debug - public: - std::string prompt; - static const std::string PROMPT_DEFAULT; - - public: - /*! \brief Register a function at the upper level of the shell. - \par[in] funname: The function's name, - \par[in] fun: The pointer to the function. - */ - void registerFunction( const std::string& funname, const ShellBasicFunction& fun ); - bool deregisterFunction( const std::string& funname ); - - - /*! \brief Set the reference of the plugin loader. */ - void referencePluginLoader( PluginLoader* dl__ ) - { dlPtr = dl__; } - - public: - - /*! \name Implements the commands. - @{ - */ - /*! \brief Instanciante an object - Extracts the name and the class of the object, verifies it is unique, - and creates the instance if this is the case. - */ - void cmdNew( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - /*! \brief Destroy the object. - Extracts the name for cmdArg and destroy the object. - */ - void cmdDestroy( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - /*! \brief Connect two signals. - Connect an input signal to an output one. - */ - void cmdPlug( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - /*! \brief Load a dynamic library which includes a plugin. - Extracts the name first and the directory in second from cmdArg - to load the dynamic library. - */ - void cmdLoadPlugin( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_INTERPRETER_H +# define DYNAMIC_GRAPH_INTERPRETER_H +# include <string> +# include <map> +# include <sstream> + +# include <boost/function.hpp> +# include <boost/bind.hpp> + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/signal-base.h> +# include <dynamic-graph/exception-factory.h> +# include <dynamic-graph/pool.h> +# include <dynamic-graph/dynamic-graph-api.h> + +# define SHELL_FUNCTION_REGISTERER(name, fun) \ + extern "C" { \ + ::dynamicgraph::ShellFunctionRegisterer \ + reg (name, boost::bind (fun, _1, _2, _3)); \ + } - /*! \brief Unload a dynamic library which includes a plugin. - Extracts the name to unload the dynamic library. +namespace dynamicgraph +{ + /*! @ingroup dgraph + \brief This class implements the first level interpretor + to control basic functionnalities of the plugins. + + It provides a shell allowing to : + \li load plugin libraries, + \li create instances of plugin, + \li destroy the plugins, + \li unload the libraries, + \li set a signal, + \li get a signal, + \li run scripts, + \li compute a signal, + \li act as a proxy for the commands of the plugins. */ - void cmdUnloadPlugin( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Ask to each register function to display its help. */ - void cmdHelp( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Run a script */ - void cmdRun( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Set a signal [obj.signal] to a value [value] - with cmdArg = "[obj.signal] [value]" - */ - void cmdSetSignal( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Display the value of the signal [obj.signal] - with cmdArg = "[obj.signal]" + class DYNAMIC_GRAPH_DLLAPI Interpreter + { + public: + /*! \brief Type of a basic function for the shell. + Such function returns a void and takes 3 arguments: + \li the functionnality (i.e. the method) it provides to the shell, + \li a stream of input string to pass when called, + \li an output stream for display. + */ + typedef boost::function3<void, + const std::string&, + std::istringstream&, + std::ostream&> ShellBasicFunction; + + protected: + /*! \brief This type defines a sorted set of basic functions with a unique key. */ + typedef std::map<std::string, ShellBasicFunction> FunctionMap; + /*! Instance of this type. */ + FunctionMap functionMap; + + public: + /*! \brief Default constructor + \par[in] dlPtr: a plugin loader to perform the actions provided by this shell. + */ + Interpreter( PluginLoader* dlPtr=NULL ); + + typedef PluginLoader * sotPluginLoaderPTR; + /*! \brief The plugin loader */ + sotPluginLoaderPTR dlPtr; + + protected: + bool initDone; // Debug + public: + std::string prompt; + static const std::string PROMPT_DEFAULT; + + public: + /*! \brief Register a function at the upper level of the shell. + \par[in] funname: The function's name, + \par[in] fun: The pointer to the function. + */ + void registerFunction( const std::string& funname, const ShellBasicFunction& fun ); + bool deregisterFunction( const std::string& funname ); + + + /*! \brief Set the reference of the plugin loader. */ + void referencePluginLoader( PluginLoader* dl__ ) + { dlPtr = dl__; } + + public: + + /*! \name Implements the commands. + @{ + */ + /*! \brief Instanciante an object + Extracts the name and the class of the object, verifies it is unique, + and creates the instance if this is the case. + */ + void cmdNew( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); + /*! \brief Destroy the object. + Extracts the name for cmdArg and destroy the object. + */ + void cmdDestroy( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); + /*! \brief Connect two signals. + Connect an input signal to an output one. + */ + void cmdPlug( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); + /*! \brief Load a dynamic library which includes a plugin. + Extracts the name first and the directory in second from cmdArg + to load the dynamic library. + */ + void cmdLoadPlugin( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); + + /*! \brief Unload a dynamic library which includes a plugin. + Extracts the name to unload the dynamic library. + */ + void cmdUnloadPlugin( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); + + /*! \brief Ask to each register function to display its help. */ + void cmdHelp( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); + + /*! \brief Run a script */ + void cmdRun( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); + + /*! \brief Set a signal [obj.signal] to a value [value] + with cmdArg = "[obj.signal] [value]" + */ + void cmdSetSignal( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); + + /*! \brief Display the value of the signal [obj.signal] + with cmdArg = "[obj.signal]" + */ + void cmdGetSignal( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); + + /*! \brief Compute the value of the signal [obj.signal] at time [time] + with cmdArg = "[obj.signal] [time]" + */ + void cmdComputeSignal( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); + + /*! \brief Entry point to treat a command. */ + void cmd( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); + + /*! \brief Extract the object name and the function name from a command. */ + static bool objectNameParser( std::istringstream& cmdparse, + std::string& objName,std::string& funName ); + + /*! @} */ + + public: + /*! \brief Method to start the shell. + \par[in] sin: The input stream from which the command will be extracted. + \par[out] sout: The output stream to which the result will be displayed. + \par[in] prompt: The prompt to be displayed. + + */ + void shell( std::istream& sin, std::ostream& sout, const std::string& prompt="" ); + void writeCompletionList(std::ostream& os); + + + }; + + /*! \brief Class for automatic registration of shell functions. + * Use the macro DYNAMIC-GRAPH_SHELL_FUNCTION_REGISTERER(name, fun) in a .cpp file + * to register functions on plugin load. */ - void cmdGetSignal( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Compute the value of the signal [obj.signal] at time [time] - with cmdArg = "[obj.signal] [time]" - */ - void cmdComputeSignal( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Entry point to treat a command. */ - void cmd( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief Extract the object name and the function name from a command. */ - static bool objectNameParser( std::istringstream& cmdparse, - std::string& objName,std::string& funName ); - - /*! @} */ - - public: - /*! \brief Method to start the shell. - \par[in] sin: The input stream from which the command will be extracted. - \par[out] sout: The output stream to which the result will be displayed. - \par[in] prompt: The prompt to be displayed. - - */ - void shell( std::istream& sin, std::ostream& sout, const std::string& prompt="" ); - void writeCompletionList(std::ostream& os); - - -}; - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -/*! \brief Class for automatic registration of shell functions. - * Use the macro DYNAMIC-GRAPH_SHELL_FUNCTION_REGISTERER(name, fun) in a .cpp file - * to register functions on plugin load. - */ -class DYNAMIC_GRAPH_DLLAPI ShellFunctionRegisterer - -{ -public: - ShellFunctionRegisterer( const std::string& funName, - const Interpreter::ShellBasicFunction& f); -}; - -#define SHELL_FUNCTION_REGISTERER(name,fun) \ - extern "C" { \ - ShellFunctionRegisterer reg( name,boost::bind(fun,_1,_2,_3) );\ - } - -DYNAMIC_GRAPH_DLLAPI extern Interpreter g_shell; - -} // namespace dynamicgraph - - - -#endif /* #ifndef */ - + class DYNAMIC_GRAPH_DLLAPI ShellFunctionRegisterer + { + public: + ShellFunctionRegisterer (const std::string& funName, + const Interpreter::ShellBasicFunction& f); + }; + DYNAMIC_GRAPH_DLLAPI extern Interpreter g_shell; +} // end of namespace dynamicgraph. +#endif //! DYNAMIC_GRAPH_INTERPRETER_H diff --git a/include/dynamic-graph/plugin-loader.h b/include/dynamic-graph/plugin-loader.h index 70e4468..64a0274 100644 --- a/include/dynamic-graph/plugin-loader.h +++ b/include/dynamic-graph/plugin-loader.h @@ -1,118 +1,111 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __PLUGINLOADER_HH__ -#define __PLUGINLOADER_HH__ - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -/* --- STD --- */ -#include <list> -#include <string> -#include <map> - -/* --- DYNAMIC-GRAPH --- */ -#include <dynamic-graph/exception-factory.h> -#include <dynamic-graph/dynamic-graph-api.h> - -namespace dynamicgraph { - -/* --------------------------------------------------------------------- */ -/* --- CLASS ----------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -class PluginRefMap; - -/*! @ingroup dgraph - \brief Loads plugins from dynamic libraries (usually .so or .dll files). - - The sotPluginLoader can be made to load individual plugins by specifying their filenames - to addPlugin() or reading them from a configuration file (loadPluginlist). - Once loaded, the plugins register themselves to the sotFactory and the - related objects can subsequently be instantiated by the sotInterpretor for - example. - - */ -class DYNAMIC_GRAPH_DLLAPI PluginLoader +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_PLUGIN_LOADER_H +# define DYNAMIC_GRAPH_PLUGIN_LOADER_H +# include <list> +# include <string> +# include <map> + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/dynamic-graph-api.h> + +namespace dynamicgraph { - protected: + /*! @ingroup dgraph - /*! \brief Directory from where the dynamic libraries are loaded. */ - std::string pluginDirectory; + \brief Loads plugins from dynamic libraries (usually .so or .dll + files). - /*! \brief List of plugin names given by their name postfixed to the directory. */ - std::list< std::string > pluginNames; + The sotPluginLoader can be made to load individual plugins by + specifying their filenames to addPlugin () or reading them from a + configuration file (loadPluginlist). Once loaded, the plugins + register themselves to the sotFactory and the related objects can + subsequently be instantiated by the sotInterpretor for example. - /*! \brief If a plugin has been loaded then this map contains - the name of the plugin. - \note This field looks useless. */ - std::map< std::string,std::string > loadedPluginNames; - - /*! \brief Keeps a reference to the library according to the name of the - plugin. */ - PluginRefMap* pluginRefs; - - public: - - /*! \brief Default constructor. */ - PluginLoader( void ); - ~PluginLoader( void ); - - /*! \brief Set the directory from which to load the dynamic libraries - containing the plugins. */ - const std::string& setDirectory( const std::string& n ); - /*! \brief Get the directory from which to load the dynamic libraries - containing the plugins. */ - const std::string& getDirectory( void ); - - /*! \brief Adds a list of plugins - It is done by reading the file configFile which contains for each line - a plugin name. - \par[in] configFile: The name of the file which contains the plugins name. - \par[in] dir: The name of the directory which contains the dynamic libraries. - */ - void loadPluginList( const std::string& configFile, const std::string& dir="" ); - /*! \brief Adds a single plugin */ - void addPlugin( const std::string& name, const std::string& dir="" ); - /*! \brief Load the plugins previously added */ - void loadPlugins( void ); - /*! \brief Remove from the user memory the dynamic library related to the plugin. */ - void unloadPlugin( const std::string& plugname ); - /*! \brief Remove all the dynamic libraries related to the plugins. + class DYNAMIC_GRAPH_DLLAPI PluginLoader + { + public: + /*! \brief Default constructor. */ + PluginLoader (); + ~PluginLoader (); + + /*! \brief Set the directory from which to load the dynamic libraries + containing the plugins. */ + const std::string& setDirectory (const std::string& n); + /*! \brief Get the directory from which to load the dynamic libraries + containing the plugins. */ + const std::string& getDirectory () const; + + /*! \brief Adds a list of plugins + + It is done by reading the file configFile which contains for + each line a plugin name. + + \par[in] configFile: The name of the file which contains the + plugins name. + \par[in] dir: The name of the directory which contains the + dynamic libraries. + */ + void loadPluginList (const std::string& configFile, + const std::string& dir = ""); + + /*! \brief Adds a single plugin */ + void addPlugin (const std::string& name, + const std::string& dir = ""); + + /*! \brief Load the plugins previously added */ + void loadPlugins (); + + /*! \brief Remove from the user memory the dynamic library related + to the plugin. */ + void unloadPlugin (const std::string& plugname); + + /*! \brief Remove all the dynamic libraries related to the plugins. For non-re-entrant plugins this method HAS TO be called. */ - void unloadAllPlugins(); - + void unloadAllPlugins (); - const std::map< std::string,std::string > getLoadedPluginNames( void ) - { return loadedPluginNames; } - const std::string& searchPlugin( const std::string& plugname ); + const std::map<std::string, std::string>& getLoadedPluginNames () const + { + return loadedPluginNames; + } -}; + const std::string& searchPlugin (const std::string& plugname); -} // namespace dynamicgraph + protected: + /*! \brief Directory from where the dynamic libraries are loaded. */ + std::string pluginDirectory; -#endif /* #ifndef __PLUGINLOADER_HH__ */ + /*! \brief List of plugin names given by their name postfixed to + the directory. */ + std::list< std::string > pluginNames; + /*! \brief If a plugin has been loaded then this map contains + the name of the plugin. + \note This field looks useless. + */ + std::map<std::string, std::string> loadedPluginNames; + /*! \brief Keeps a reference to the library according to the name of the + plugin. */ + PluginRefMap* pluginRefs; + }; +} // end of namespace dynamicgraph. +#endif //! DYNAMIC_GRAPH_PLUGIN_LOADER_H diff --git a/include/dynamic-graph/pool.h b/include/dynamic-graph/pool.h index a24fbcc..5588843 100644 --- a/include/dynamic-graph/pool.h +++ b/include/dynamic-graph/pool.h @@ -1,138 +1,127 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef POOL_H_ -#define POOL_H_ - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -/* --- STD --- */ -#include <map> -#include <string> -#include <sstream> - -/* --- DYNAMIC-GRAPH --- */ -#include <dynamic-graph/exception-factory.h> -#include <dynamic-graph/signal-base.h> -#include <dynamic-graph/dynamic-graph-api.h> +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_POOL_H +# define DYNAMIC_GRAPH_POOL_H +# include <map> +# include <string> +# include <sstream> + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/exception-factory.h> +# include <dynamic-graph/signal-base.h> +# include <dynamic-graph/dynamic-graph-api.h> namespace dynamicgraph { + /*! @ingroup dgraph + \brief This class keep tracks of all the objects in the stack of Tasks. -class Entity; + This class gives access to and remembers all the entities created + during its life. -/* --------------------------------------------------------------------- */ -/* --- CLASS ----------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ + This class provides the necessary operations to register, unregister each + instance of thoses classes. + As tasks and features derived from Entities, they should be registered + as such. -/*! @ingroup dgraph - \brief This class keep tracks of all the objects in the stack of Tasks. + \note From the code it is not very clear why we should not unregister + from the tasks and the features... - This class gives access to and remembers all the entities created - during its life. + The role of this class is also to look for the object supporting + a command, and to apply this command. - This class provides the necessary operations to register, unregister each - instance of thoses classes. - As tasks and features derived from Entities, they should be registered - as such. + It also returns signal. - \note From the code it is not very clear why we should not unregister - from the tasks and the features... - - The role of this class is also to look for the object supporting - a command, and to apply this command. - - It also returns signal. - - */ -class DYNAMIC_GRAPH_DLLAPI PoolStorage -{ - public: - /*! \name Define types to simplify the writing - @{ - */ - /*! \brief Sorted set of entities with unique key (name). */ - typedef std::map< std::string,Entity* > Entities; - - protected: - /*! \name Fields of the class to manage the three entities. - Also the name is singular, those are true sets. - @{ - */ - /*! \brief Set of basic objects of the SoT */ - Entities entity; - - public: - /*! \brief Default destructor */ - ~PoolStorage( void ); - - /*! \name Method related to the handling of entities. - @{ - */ - /*! \brief Register an entity. - \par[in] entname: The name of the entity, - \par[in] ent: Pointer towards the entity. - */ - void registerEntity( const std::string& entname,Entity* ent ); - - /*! \brief Unregister an entity. - \par[in] entname: The name of the entity, - */ - void deregisterEntity( const std::string& entname ); - - /*! \brief Get an entity. - \par[in] entname: The name of the entity, - \return Pointer towards the entity. - */ - Entity& getEntity( const std::string& name ); - - /*! \brief Disallocate an entity. - \par[in] entname: The name of the entity, - */ - void clearPlugin( const std::string& name ); - /*! @} */ - - - /*! \brief Get a reference to a signal. */ - SignalBase<int>& getSignal( std::istringstream& sigpath ); - - /*! \brief This method looks for the object named objectName, - and ask to provide the function functionName with the arguments cmdArg. - If the method of the object displays some information this will - be done on os. - - The commands specific to the \b g_pool object are: - \li \b list : List all the entities registered in the pool */ - void commandLine( const std::string& objectName,const std::string& functionName, - std::istringstream& cmdArg, std::ostream& os ); - - /*! \brief This method write a graph description on the file named FileName. */ - void writeGraph(const std::string &aFileName); - void writeCompletionList(std::ostream& os); -}; - -DYNAMIC_GRAPH_DLLAPI extern dynamicgraph::PoolStorage g_pool; - -} // namespace dynamicgraph - -#endif /* POOL_H_ */ + class DYNAMIC_GRAPH_DLLAPI PoolStorage + { + public: + /*! \name Define types to simplify the writing + @{ + */ + /*! \brief Sorted set of entities with unique key (name). */ + typedef std::map< std::string,Entity* > Entities; + + /*! @} */ + + /*! \brief Default destructor */ + ~PoolStorage (); + + /*! \name Method related to the handling of entities. + @{ + */ + /*! \brief Register an entity. + \par[in] entname: The name of the entity, + \par[in] ent: Pointer towards the entity. + */ + void registerEntity (const std::string& entname, Entity* ent); + + /*! \brief Unregister an entity. + \par[in] entname: The name of the entity, + */ + void deregisterEntity (const std::string& entname); + + /*! \brief Get an entity. + \par[in] entname: The name of the entity, + \return Pointer towards the entity. + */ + Entity& getEntity (const std::string& name); + + /*! \brief Disallocate an entity. + \par[in] entname: The name of the entity, + */ + void clearPlugin (const std::string& name); + /*! @} */ + + + /*! \brief Get a reference to a signal. */ + SignalBase<int>& getSignal (std::istringstream& sigpath); + + /*! \brief This method looks for the object named objectName, + and ask to provide the function functionName with the arguments cmdArg. + If the method of the object displays some information this will + be done on os. + + The commands specific to the \b g_pool object are: + \li \b list : List all the entities registered in the pool + */ + void commandLine (const std::string& objectName, + const std::string& functionName, + std::istringstream& cmdArg, + std::ostream& os); + + /*! \brief This method write a graph description on the file named + FileName. */ + void writeGraph (const std::string& aFileName); + void writeCompletionList (std::ostream& os); + + protected: + /*! \name Fields of the class to manage the three entities. + Also the name is singular, those are true sets. + @{ + */ + /*! \brief Set of basic objects of the SoT */ + Entities entity; + }; + + + DYNAMIC_GRAPH_DLLAPI extern dynamicgraph::PoolStorage g_pool; + +} // end of namespace dynamicgraph. + +#endif //! DYNAMIC_GRAPH_POOL_H diff --git a/include/dynamic-graph/shell-procedure.h b/include/dynamic-graph/shell-procedure.h index e50d0a9..6a3af44 100644 --- a/include/dynamic-graph/shell-procedure.h +++ b/include/dynamic-graph/shell-procedure.h @@ -1,56 +1,38 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __SHELL_PROCEDURE_HH__ -#define __SHELL_PROCEDURE_HH__ - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -/* DYNAMIC-GRAPH */ -#include <dynamic-graph/exception-factory.h> -#include <dynamic-graph/interpreter.h> -#include <dynamic-graph/config-shell-procedure.hh> - -/* --- STD --- */ -#include <string> -#include <map> -#include <sstream> -#include <list> -#include <vector> - -/* --- BOOST --- */ -#include <boost/function.hpp> -#include <boost/bind.hpp> - -/* --------------------------------------------------------------------- */ -/* --- CLASS ----------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_SHELL_PROCEDURE_H +# define DYNAMIC_GRAPH_SHELL_PROCEDURE_H +# include <string> +# include <map> +# include <sstream> +# include <list> +# include <vector> + +# include <dynamic-graph/exception-factory.h> +# include <dynamic-graph/interpreter.h> +# include <dynamic-graph/config-shell-procedure.hh> /*! @ingroup dgraph \brief This plugin exposes shell commands relative to the script language constructs such as procedures and for loops. For more information, load the plugin and type help on a sot shell. - */ +*/ class DG_SHELLPROCEDURE_DLLAPI ShellProcedure { public: @@ -60,12 +42,20 @@ class DG_SHELLPROCEDURE_DLLAPI ShellProcedure std::vector<std::string> args; std::vector<int> params; }; - struct Procedure { - std::list< Instruction > instructions; - std::vector< std::string > params; - void clear() { instructions.clear(); params.clear(); } + + struct Procedure + { + std::list<Instruction> instructions; + std::vector<std::string> params; + + void clear () + { + instructions.clear (); + params.clear (); + } }; - typedef std::map< std::string,Procedure > ProcedureList; + + typedef std::map<std::string, Procedure> ProcedureList; public: std::string procName; @@ -74,20 +64,26 @@ class DG_SHELLPROCEDURE_DLLAPI ShellProcedure Procedure currentProc; public: - - void cmdStartProcedure( const std::string& cmd,std::istringstream& args,std::ostream& os ); - void cmdContinueProcedure( const std::string& cmd,std::istringstream& args,std::ostream& os ); - void cmdEndProcedure( const std::string& cmd,std::istringstream& args,std::ostream& os ); - - void cmdProcedure( const std::string& procname,const std::string& cmd, - std::istringstream& args,std::ostream& os ); - - static void cmdFor( const std::string& cmd,std::istringstream& args,std::ostream& os ); - - + void cmdStartProcedure (const std::string& cmd, + std::istringstream& args, + std::ostream& os); + + void cmdContinueProcedure (const std::string& cmd, + std::istringstream& args, + std::ostream& os); + + void cmdEndProcedure (const std::string& cmd, + std::istringstream& args, + std::ostream& os); + + void cmdProcedure (const std::string& procname, + const std::string& cmd, + std::istringstream& args, + std::ostream& os); + + static void cmdFor (const std::string& cmd, + std::istringstream& args, + std::ostream& os); }; - - - -#endif //#ifndef __DYNAMIC-GRAPH_SHELL_PROCEDURE_HH__ +#endif //! DYNAMIC_GRAPH_SHELL_PROCEDURE_H diff --git a/include/dynamic-graph/signal-array.h b/include/dynamic-graph/signal-array.h index 3757818..19fad5a 100644 --- a/include/dynamic-graph/signal-array.h +++ b/include/dynamic-graph/signal-array.h @@ -1,176 +1,214 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __SIGNAL_ARRAY_HH -#define __SIGNAL_ARRAY_HH - -#include <dynamic-graph/signal-base.h> -#include <dynamic-graph/dynamic-graph-api.h> - -namespace dynamicgraph { - -template<class Time> -class SignalArray; - -template<class Time> -class SignalArray_const +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_SIGNAL_ARRAY_H +# define DYNAMIC_GRAPH_SIGNAL_ARRAY_H +# include <dynamic-graph/signal-base.h> +# include <dynamic-graph/dynamic-graph-api.h> + +namespace dynamicgraph { - public: - static const int DEFAULT_SIZE = 20; - - protected: - const SignalBase<Time> ** const_array; - unsigned int size,rank; - - public: - SignalArray_const<Time>( const unsigned int& sizeARG=DEFAULT_SIZE ) - : const_array(NULL),size(sizeARG),rank(0) - { createArray(); } - - SignalArray_const<Time>( const SignalBase<Time>& sig) - : const_array(NULL),size(1),rank(0) - { createArray(); addElmt(&sig); } - - SignalArray_const<Time> ( const SignalArray<Time>& siga ) - : const_array(NULL),size(DEFAULT_SIZE),rank(siga.getSize()) + template<class Time> + class SignalArray_const + { + public: + static const int DEFAULT_SIZE = 20; + + protected: + const SignalBase<Time> ** const_array; + unsigned int size,rank; + + public: + SignalArray_const<Time> (const unsigned int& sizeARG = DEFAULT_SIZE) + : const_array (NULL), + size (sizeARG), + rank (0) { - createArray(); - for( unsigned int i=0;i<rank;++i ) const_array[i]=&siga[i]; + createArray (); } - SignalArray_const<Time> ( const SignalArray_const<Time>& siga ) - : const_array(NULL),size(DEFAULT_SIZE),rank(siga.getSize()) + SignalArray_const<Time> (const SignalBase<Time>& sig) + : const_array (NULL), + size (1), + rank (0) { - createArray(); - for( unsigned int i=0;i<rank;++i ) const_array[i]=&siga[i]; + createArray (); + addElmt(&sig); } - virtual ~SignalArray_const<Time>( void ) + SignalArray_const<Time> (const SignalArray<Time>& siga) + : const_array (NULL), + size (DEFAULT_SIZE), + rank (siga.getSize ()) { - if( NULL!=const_array ) delete [] const_array; + createArray (); + for (unsigned int i = 0; i < rank; ++i) + const_array[i] = &siga[i]; } - protected: - void createArray( void ) + SignalArray_const<Time> (const SignalArray_const<Time>& siga) + : const_array(NULL), + size(DEFAULT_SIZE), + rank(siga.getSize ()) { - if(0<size) { const_array = new const SignalBase<Time>* [size]; } + createArray (); + for (unsigned int i = 0; i < rank; ++i) + const_array[i] = &siga[i]; } - void addElmt( const SignalBase<Time>* el ) - { if(rank<size) const_array[rank++] = el; } - - public: - virtual SignalArray_const<Time>& operator<< (const SignalBase<Time>& sig) - { addElmt( &sig ); return *this; } - public: - virtual const SignalBase<Time>& operator[] ( const unsigned int& idx ) const - { return *const_array[idx]; } - virtual unsigned int getSize( void ) const { return rank; } -}; - - -template<class Time> -SignalArray_const<Time> operator<<( const SignalBase<Time>& sig1, - const SignalBase<Time>& sig2 ) -{ SignalArray_const<Time> res(20); res<<sig1; res<<sig2; return res;} + virtual ~SignalArray_const<Time> () + { + if (const_array) + delete[] const_array; + } + protected: + void createArray () + { + if (0 < size) + const_array = new const SignalBase<Time>*[size]; + } -/* ---- */ + void addElmt (const SignalBase<Time>* el) + { + if (rank < size) + const_array[rank++] = el; + } + public: + virtual SignalArray_const<Time>& operator<< (const SignalBase<Time>& sig) + { + addElmt (&sig); + return *this; + } -template<class Time> -class SignalArray -:public SignalArray_const<Time> -{ - public: - using SignalArray_const<Time>::DEFAULT_SIZE; - using SignalArray_const<Time>::size; - using SignalArray_const<Time>::rank; - protected: - mutable SignalBase<Time> ** array; + public: + virtual const SignalBase<Time>& operator[] (const unsigned int& idx) const + { + return *const_array[idx]; + } + virtual unsigned int getSize () const + { + return rank; + } + }; + + + template<class Time> + SignalArray_const<Time> operator<< (const SignalBase<Time>& sig1, + const SignalBase<Time>& sig2) + { + SignalArray_const<Time> res(20); + res<<sig1; + res<<sig2; + return res; + } + + + template<class Time> + class SignalArray : public SignalArray_const<Time> + { + public: + using SignalArray_const<Time>::DEFAULT_SIZE; + using SignalArray_const<Time>::size; + using SignalArray_const<Time>::rank; + protected: + mutable SignalBase<Time>** array; + + public: + SignalArray<Time> (const unsigned int& sizeARG = DEFAULT_SIZE) + : SignalArray_const<Time> (0) + { + size=sizeARG; + createArray (); + } - public: - SignalArray<Time>( const unsigned int& sizeARG=DEFAULT_SIZE ) - :SignalArray_const<Time>(0) - { size=sizeARG; createArray(); } + SignalArray<Time> (SignalBase<Time>& sig) + : SignalArray_const<Time> (0) + { + size=1; + createArray (); + addElmt(&sig); + } - SignalArray<Time>( SignalBase<Time>& sig) - : SignalArray_const<Time>(0) - { size=1; createArray(); addElmt(&sig); } + SignalArray<Time> (const SignalArray<Time>& siga) + : SignalArray_const<Time> (DEFAULT_SIZE), + array (NULL) + { + rank = siga.getSize (); + createArray (); + for (unsigned int i = 0; i < rank; ++i) + array[i]=&siga[i]; + } - SignalArray<Time> ( const SignalArray<Time>& siga ) - :SignalArray_const<Time>( DEFAULT_SIZE ) - ,array(NULL) + virtual ~SignalArray<Time> () { - rank = siga.getSize(); - createArray(); - for( unsigned int i=0;i<rank;++i ) array[i]=&siga[i]; + if (array) + delete[] array; } - virtual ~SignalArray<Time>( void ) + + protected: + void createArray () { - if( NULL!=array ) delete [] array; + if( 0 < size) + array = new SignalBase<Time>*[size]; } - protected: - void createArray( void ) + void addElmt (SignalBase<Time>* el) { - if(0<size) { array = new SignalBase<Time>* [size]; } + if(rank < size) + array[rank++] = el; } - void addElmt( SignalBase<Time>* el ) - { if(rank<size) array[rank++] = el; } - public: //protected: - virtual SignalArray<Time>& operator<< (SignalBase<Time>& sig) - { addElmt( &sig ); return *this; } + public: + virtual SignalArray<Time>& operator<< (SignalBase<Time>& sig) + { + addElmt(&sig); + return *this; + } - virtual SignalArray_const<Time> operator<< (const SignalBase<Time>& sig) const + virtual SignalArray_const<Time> + operator<< (const SignalBase<Time>& sig) const { - SignalArray_const<Time> res(size); - res=*this; - res<<sig; + SignalArray_const<Time> res (size); + res = *this; + res << sig; return res; } - - public: - virtual SignalBase<Time>& operator[] ( const unsigned int& idx ) const + virtual SignalBase<Time>& operator[] (const unsigned int& idx) const { return *array[idx]; } -}; - + }; + template<class Time> + SignalArray<Time> operator<< (SignalBase<Time>& sig1, + SignalBase<Time>& sig2) + { + SignalArray<Time> res (20); + res << sig1; + res << sig2; + return res; + } -template<class Time> -SignalArray<Time> operator<<( SignalBase<Time>& sig1, - SignalBase<Time>& sig2 ) -{ - SignalArray<Time> res(20); - res<<sig1; - res<<sig2; - return res; -} - - DYNAMIC_GRAPH_DLLAPI extern SignalArray<int> sotNOSIGNAL; + DYNAMIC_GRAPH_DLLAPI extern SignalArray<int> sotNOSIGNAL; -} // namespace dynamicgraph +} // end of namespace dynamicgraph. -#endif /* #ifndef __SIGNAL_ARRAY_HH */ +#endif //! DYNAMIC_GRAPH_SIGNAL_ARRAY_H diff --git a/include/dynamic-graph/signal-base.h b/include/dynamic-graph/signal-base.h index de98d58..0f6eb34 100644 --- a/include/dynamic-graph/signal-base.h +++ b/include/dynamic-graph/signal-base.h @@ -1,195 +1,285 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __SIGNAL_ABSTRACT_HH -#define __SIGNAL_ABSTRACT_HH - -#include <string> -#include <sstream> -#include <iostream> - -#include <dynamic-graph/exception-signal.h> -#include <boost/noncopyable.hpp> - -namespace dynamicgraph { - -/** \brief The base class for signals: not to be used as such. - Signal values can be accessed programmatically using the access() or accessCopy() - methods; the former directly accesses the value of the signal, which can involve an - extra computation, while the latter accesses a cached value, or 'copy'. - */ -template< class Time > -class SignalBase : public boost::noncopyable +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_SIGNAL_BASE_H +# define DYNAMIC_GRAPH_SIGNAL_BASE_H +# include <string> +# include <sstream> +# include <iostream> + +# include <boost/noncopyable.hpp> + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/exception-signal.h> + + +namespace dynamicgraph { - protected: - - std::string name; - Time signalTime; - bool ready; - - public: - - virtual const Time& getTime( void ) const { return signalTime; } - virtual void setTime( const Time& t ) { signalTime=t; } - const bool& getReady( void ) const { return ready; } - const std::string& getName( void ) const { return name; } - - virtual void setPeriodTime( const Time& ) {} - virtual Time getPeriodTime( void ) const { return 1; } - - public: - - /* --- CONSTRUCTORS ------------------------------------------------------- */ - - SignalBase( std::string name ="" ) - : name(name),signalTime(0),ready(false) {} - virtual ~SignalBase( void ) {} - - - /* --- DEPENDENCIES ------------------------------------------------------- */ - - virtual void addDependency( const SignalBase<Time>& ) {} - virtual void removeDependency( const SignalBase<Time>& ) {} - virtual void clearDependencies( void ) {} - - virtual bool needUpdate( const Time& ) const {return ready;} - inline void setReady( const bool sready = true ) { ready = sready; } - - virtual std::ostream & - writeGraph (std::ostream & os ) const - { - return os; - } - - virtual std::ostream& - displayDependencies( std::ostream& os,const int=-1, - std::string space="", - std::string next1="",std::string ="" ) const - { - os << space << next1 << "-- "; - display(os); return os; - } - - /* --- PLUG --------------------------------------------------------------- */ - - /* Plug the arg-signal on the <this> object. Plug-in is always - * a descending operation (the actual <this> object will call the arg-signal - * and not the opposite). - */ - virtual void plug( SignalBase<Time>* sigarg ) - { DG_THROW ExceptionSignal( ExceptionSignal::PLUG_IMPOSSIBLE, - "Plug-in operation not possible with this signal. ", - "(while trying to plug %s on %s).",sigarg->getName().c_str(), - this->getName().c_str() ); } - virtual void unplug( void ) - { DG_THROW ExceptionSignal( ExceptionSignal::PLUG_IMPOSSIBLE, - "Plug-in operation not possible with this signal. ", - "(while trying to unplug %s).",this->getName().c_str() ); - } - virtual bool isPluged( void ) const { return false; } - virtual SignalBase<Time>* getPluged( void ) const { return NULL; } - virtual void setConstantDefault( void ) - { DG_THROW ExceptionSignal( ExceptionSignal::PLUG_IMPOSSIBLE, - "Plug-in operation not possible with this signal. ", - "(while trying to save %s).",this->getName().c_str() ); - } - /* --- SET ---------------------------------------------------------------- */ - - /* Generic set function. Should be reimplemented by the specific Signal. - * Sets a signal value - */ - virtual void set( std::istringstream&) - { DG_THROW ExceptionSignal( ExceptionSignal::SET_IMPOSSIBLE, - "Set operation not possible with this signal. ", - "(while trying to set %s).",this->getName().c_str() ); - } - virtual void get(std::ostream&) const - { DG_THROW ExceptionSignal( ExceptionSignal::SET_IMPOSSIBLE, - "Get operation not possible with this signal. ", - "(while trying to get %s).",this->getName().c_str() ); - } - virtual inline void recompute( const Time &) - { DG_THROW ExceptionSignal( ExceptionSignal::SET_IMPOSSIBLE, - "Recompute operation not possible with this signal. ", - "(while trying to recompute %s).",this->getName().c_str() ); - } - virtual void trace( std::ostream& ) const - { DG_THROW ExceptionSignal( ExceptionSignal::SET_IMPOSSIBLE, - "Trace operation not possible with this signal. ", - "(while trying to trace %s).",this->getName().c_str() ); - } - - /* --- DISPLAY ------------------------------------------------------------ */ - - virtual std::ostream& display( std::ostream& os ) const - { os<<"Sig:"<<name; return os;} - - std::string shortName( void ) const - { - std::istringstream iss( name ); - const int SIZE = 128; - char buffer[SIZE]; - while( iss.good() ) - { iss.getline(buffer,SIZE,':'); } - const std::string res( buffer ); - return res; - } - /* --- Information providers --- */ - virtual void ExtractNodeAndLocalNames(std::string & LocalName, std::string & NodeName) const - { - std::string fullname = this->getName(); - - size_t IdxPosLocalName = fullname.rfind(":"); - LocalName = fullname.substr(IdxPosLocalName+1,fullname.length()-IdxPosLocalName+1); - size_t IdxPosNodeNameStart = fullname.find("("); - size_t IdxPosNodeNameEnd = fullname.find(")"); - NodeName = fullname.substr(IdxPosNodeNameStart+1,IdxPosNodeNameEnd-IdxPosNodeNameStart-1); - /* std::cout << "Finally " << std:: endl - << "\tLocalName: " << LocalName << std::endl - << "\tNodeName: " << NodeName << std::endl; */ - - } - - /* --- TEST TEST TEST TEST TEST TEST --- */ - public: - virtual void checkCompatibility( void ) - { DG_THROW ExceptionSignal( ExceptionSignal::PLUG_IMPOSSIBLE, - "Abstract signal not compatible with anything.", - "(while trying to plug <%s>).", - this->getName().c_str() ); } - -}; - -/** Forward to a virtual fonction. - */ -template< class Time > -std::ostream& operator<< (std::ostream& os,const SignalBase<Time>& sig ) -{ return sig.display(os); } - -} // namespace dynamicgraph - -#endif // #ifndef __SIGNAL_ABSTRACT_HH - -/* - * Local variables: - * c-basic-offset: 4 - * End: - */ + /** \brief The base class for signals: not to be used as such. + + Signal values can be accessed programmatically using the access + () or accessCopy () methods; the former directly accesses the + value of the signal, which can involve an extra computation, + while the latter accesses a cached value, or 'copy'. + */ + template<class Time> + class SignalBase : public boost::noncopyable + { + public: + explicit SignalBase(std::string name = "") + : name (name), + signalTime (0), + ready (false) + {} + + virtual ~SignalBase () + {} + + /// \name Time + /// \{ + virtual const Time& getTime () const + { + return signalTime; + } + + virtual void setTime (const Time& t) + { + signalTime = t; + } + + const bool& getReady () const + { + return ready; + } + + const std::string& getName () const + { + return name; + } + + virtual void setPeriodTime (const Time&) + {} + + virtual Time getPeriodTime () const + { + return 1; + } + + /// \} + + /// \name Dependencies + /// \{ + + virtual void addDependency (const SignalBase<Time>&) + {} + + virtual void removeDependency (const SignalBase<Time>&) + {} + + virtual void clearDependencies () + {} + + virtual bool needUpdate (const Time&) const + { + return ready; + } + + inline void setReady (const bool sready = true) + { + ready = sready; + } + + virtual std::ostream& + writeGraph (std::ostream& os ) const + { + return os; + } + + virtual std::ostream& + displayDependencies (std::ostream& os, + const int = -1, + std::string space = "", + std::string next1 = "", + std::string = "" ) const + { + os << space << next1 << "-- "; + display(os); + return os; + } + + /// \} + + /// \name Plug + /// \{ + + /* Plug the arg-signal on the <this> object. Plug-in is always + * a descending operation (the actual <this> object will call the arg-signal + * and not the opposite). + */ + virtual void plug (SignalBase<Time>* sigarg) + { + DG_THROW ExceptionSignal + (ExceptionSignal::PLUG_IMPOSSIBLE, + "Plug-in operation not possible with this signal. ", + "(while trying to plug %s on %s).", + sigarg->getName ().c_str (), + this->getName ().c_str () ); + } + + virtual void unplug () + { + DG_THROW ExceptionSignal + (ExceptionSignal::PLUG_IMPOSSIBLE, + "Plug-in operation not possible with this signal. ", + "(while trying to unplug %s).",this->getName ().c_str ()); + } + + virtual bool isPluged () const + { + return false; + } + + virtual SignalBase<Time>* getPluged () const + { + return NULL; + } + + virtual void setConstantDefault () + { + DG_THROW ExceptionSignal + (ExceptionSignal::PLUG_IMPOSSIBLE, + "Plug-in operation not possible with this signal. ", + "(while trying to save %s).", + this->getName ().c_str ()); + } + + /// \} + + /// \name Set + /// \{ + + /* Generic set function. Should be reimplemented by the specific + * Signal. Sets a signal value + */ + virtual void set (std::istringstream&) + { + DG_THROW ExceptionSignal + (ExceptionSignal::SET_IMPOSSIBLE, + "Set operation not possible with this signal. ", + "(while trying to set %s).", + this->getName ().c_str () ); + } + + virtual void get (std::ostream&) const + { + DG_THROW ExceptionSignal + (ExceptionSignal::SET_IMPOSSIBLE, + "Get operation not possible with this signal. ", + "(while trying to get %s).", + this->getName ().c_str ()); + } + + virtual inline void recompute (const Time &) + { + DG_THROW ExceptionSignal + (ExceptionSignal::SET_IMPOSSIBLE, + "Recompute operation not possible with this signal. ", + "(while trying to recompute %s).", + this->getName ().c_str ()); + } + + virtual void trace (std::ostream&) const + { + DG_THROW ExceptionSignal + (ExceptionSignal::SET_IMPOSSIBLE, + "Trace operation not possible with this signal. ", + "(while trying to trace %s).", + this->getName ().c_str () ); + } + + /// \} + + /// \name Display + /// \{ + + virtual std::ostream& display (std::ostream& os) const + { + os << "Sig:" << name; + return os; + } + + std::string shortName () const + { + std::istringstream iss (name); + const int SIZE = 128; + char buffer[SIZE]; + while (iss.good ()) + { + iss.getline(buffer,SIZE,':'); + } + const std::string res (buffer); + return res; + } + /// \} + + /// \name Information providers + /// \{ + + virtual void ExtractNodeAndLocalNames (std::string& LocalName, + std::string & NodeName) const + { + std::string fullname = this->getName (); + + size_t IdxPosLocalName = fullname.rfind (":"); + LocalName = fullname.substr (IdxPosLocalName + 1, + fullname.length () - IdxPosLocalName + 1); + size_t IdxPosNodeNameStart = fullname.find ("("); + size_t IdxPosNodeNameEnd = fullname.find (")"); + NodeName = fullname.substr (IdxPosNodeNameStart + 1, + IdxPosNodeNameEnd - IdxPosNodeNameStart - 1); + } + + /// \} + + /// \name Test + /// \{ + virtual void checkCompatibility () + { + DG_THROW ExceptionSignal + (ExceptionSignal::PLUG_IMPOSSIBLE, + "Abstract signal not compatible with anything.", + "(while trying to plug <%s>).", + this->getName ().c_str ()); + } + /// \} + + protected: + std::string name; + Time signalTime; + bool ready; + }; + + /// Forward to a virtual fonction. + template<class Time> + std::ostream& operator<< (std::ostream& os, const SignalBase<Time>& sig) + { + return sig.display(os); + } +} // end of namespace dynamicgraph. + +#endif //! DYNAMIC_GRAPH_SIGNAL_BASE_H diff --git a/include/dynamic-graph/signal-caster.h b/include/dynamic-graph/signal-caster.h index 37b99b9..0526725 100644 --- a/include/dynamic-graph/signal-caster.h +++ b/include/dynamic-graph/signal-caster.h @@ -46,8 +46,8 @@ namespace dynamicgraph class DYNAMIC_GRAPH_DLLAPI SignalCaster { public: - explicit SignalCaster (); - virtual ~SignalCaster (); + explicit SignalCaster (); + virtual ~SignalCaster (); /// Typedef of displayer functions that take an encapsulated 'any' /// object and displays, cast, or trace it on an output stream @@ -90,7 +90,7 @@ namespace dynamicgraph ///The SignalCast registerer class. Can be used to automatically /// register a cast when instanced somewhere in a cpp file. Pass the - /// typeid() of the type you want to register a cast to as the first + /// typeid () of the type you want to register a cast to as the first /// argument. The code is provided here so the class does not need /// to be exported. class DYNAMIC_GRAPH_DLLAPI SignalCastRegisterer @@ -112,7 +112,7 @@ namespace dynamicgraph class DefaultCastRegisterer : public SignalCastRegisterer { public: - DefaultCastRegisterer () + DefaultCastRegisterer () : SignalCastRegisterer (typeid(T), disp, cast, trace) {} @@ -149,11 +149,11 @@ namespace dynamicgraph iss >> tmp; if (tmp == "nan") - return std::numeric_limits<double>::quiet_NaN (); + return std::numeric_limits<double>::quiet_NaN (); else if (tmp == "inf" || tmp == "+inf") - return std::numeric_limits<double>::infinity (); + return std::numeric_limits<double>::infinity (); else if (tmp == "-inf") - return -1. * std::numeric_limits<double>::infinity (); + return -1. * std::numeric_limits<double>::infinity (); try { @@ -163,7 +163,7 @@ namespace dynamicgraph { boost::format fmt ("failed to serialize %s (to double)"); fmt % tmp; - throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str ()); + throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str ()); } } @@ -173,11 +173,11 @@ namespace dynamicgraph { T inst; iss >> inst; - if (iss.fail ()) + if (iss.fail ()) { boost::format fmt ("failed to serialize %s "); - fmt % iss.str (); - throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str ()); + fmt % iss.str (); + throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str ()); } return inst; } @@ -186,7 +186,7 @@ namespace dynamicgraph /// Global signal cast template (helper) functions /// - /// Using these avoid using the typeid() operator and keeps the + /// Using these avoid using the typeid () operator and keeps the /// implementation details hidden. template<typename T> void signal_disp (const T& value, std::ostream& os) diff --git a/include/dynamic-graph/signal-ptr.h b/include/dynamic-graph/signal-ptr.h index 9e7634f..6d1ad06 100644 --- a/include/dynamic-graph/signal-ptr.h +++ b/include/dynamic-graph/signal-ptr.h @@ -1,125 +1,133 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __SIGNAL_PTR_HH -#define __SIGNAL_PTR_HH - -#include <iostream> - -#include <dynamic-graph/exception-signal.h> -#include <dynamic-graph/signal.h> - -namespace dynamicgraph { - -/** \brief This is the only type of signal that can be plugged to, using the plug() command. - In that sense, when plugged into, it acts as a "pointer" to the input signal, hence - the name. Operator -> is also overloaded and can be used to access the pointed signal. - */ -template< class T,class Time > -class SignalPtr -: public virtual Signal<T,Time> +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_SIGNAL_PTR_H +#define DYNAMIC_GRAPH_SIGNAL_PTR_H +# include <iostream> + +# include <dynamic-graph/exception-signal.h> +# include <dynamic-graph/signal.h> + +namespace dynamicgraph { - public: + + /** \brief This is the only type of signal that can be plugged to, + using the plug () command. + + In that sense, when plugged into, it acts as a "pointer" to the + input signal, hence the name. Operator -> is also overloaded and + can be used to access the pointed signal. + */ + template<class T, class Time> + class SignalPtr : public virtual Signal<T,Time> + { + public: using SignalBase<Time>::getName; - protected: + protected: Signal<T,Time>* signalPtr; bool modeNoThrow; bool transmitAbstract; SignalBase<Time> * abstractTransmitter; T* transmitAbstractData; - inline bool autoref( void ) const { return(signalPtr==this); } + inline bool autoref () const + { + return signalPtr == this; + } + + public: /* --- CONSTRUCTORS --- */ - public: /* --- CONSTRUCTORS --- */ + SignalPtr (Signal<T,Time>* ptr, std::string name="") + : Signal<T,Time> (name), + signalPtr (ptr), + modeNoThrow (false), + transmitAbstract (false), + abstractTransmitter (NULL) + {} - SignalPtr( Signal<T,Time>* ptr,std::string name="" ) - : Signal<T,Time>(name) - ,signalPtr(ptr),modeNoThrow(false) - ,transmitAbstract(false) - ,abstractTransmitter(NULL) {} - virtual ~SignalPtr( void ) { signalPtr = NULL; } + virtual ~SignalPtr () + { + signalPtr = NULL; + } - public: /* --- PLUG-IN OPERATION --- */ + public: /* --- PLUG-IN OPERATION --- */ - Signal<T,Time>* getPtr ( void ); // throw - const Signal<T,Time>* getPtr ( void ) const; // throw - SignalBase<Time>* getAbstractPtr ( void ); // throw - const SignalBase<Time>* getAbstractPtr ( void ) const; // throw + Signal<T,Time>* getPtr (); // throw + const Signal<T,Time>* getPtr () const; // throw + SignalBase<Time>* getAbstractPtr (); // throw + const SignalBase<Time>* getAbstractPtr () const; // throw virtual void plug( SignalBase<Time>* ref ); - virtual void unplug( void ) { plug(NULL); } - virtual bool isPluged( void ) const { return (NULL!=signalPtr); } - virtual SignalBase<Time>* getPluged( void ) const { return signalPtr; } - virtual bool isAbstractPluged( void ) const; - virtual const Time& getTime( void ) const; + virtual void unplug () { plug(NULL); } + virtual bool isPluged () const { return (NULL!=signalPtr); } + virtual SignalBase<Time>* getPluged () const { return signalPtr; } + virtual bool isAbstractPluged () const; + virtual const Time& getTime () const; /* Equivalent operator-like definitions. */ - inline Signal<T,Time>* operator->() { return getPtr(); } - inline const Signal<T,Time>* operator->() const { return getPtr(); } - inline Signal<T,Time>& operator*( void ) { return *getPtr(); } - inline const Signal<T,Time>& operator*( void ) const { return *getPtr(); } - inline operator bool ( void ) const { return isPluged(); } + inline Signal<T,Time>* operator-> () { return getPtr (); } + inline const Signal<T,Time>* operator-> () const { return getPtr (); } + inline Signal<T,Time>& operator* () { return *getPtr (); } + inline const Signal<T,Time>& operator* () const { return *getPtr (); } + inline operator bool () const { return isPluged (); } - public: /* --- INHERITANCE --- */ + public: /* --- INHERITANCE --- */ virtual bool needUpdate( const Time& t ) const ; virtual std::ostream& writeGraph(std::ostream& os) const; virtual std::ostream& display( std::ostream& os ) const; - /* For compatibility, .access() is equivalent to ->access(). For explicit + /* For compatibility, .access () is equivalent to ->access (). For explicit * pointer dereference : - * Prefere ->() to () + * Prefere -> () to () */ - virtual const T& operator()( const Time & t ); + virtual const T& operator ()( const Time & t ); /* Similarly, Prefere ->access to .access */ virtual const T& access( const Time & t ); - virtual const T& accessCopy( void ) const; + virtual const T& accessCopy () const; inline void setConstantDefault( const T& t ) - { Signal<T,Time>::setConstant(t); modeNoThrow = true; } - virtual inline void setConstantDefault( void ) - { setConstantDefault( accessCopy() ); } - inline void unsetConstantDefault( void ){ modeNoThrow = false; } + { Signal<T,Time>::setConstant(t); modeNoThrow = true; } + virtual inline void setConstantDefault () + { setConstantDefault( accessCopy () ); } + inline void unsetConstantDefault (){ modeNoThrow = false; } - public: /* --- INHERITANCE --- */ + public: /* --- INHERITANCE --- */ /* SignalPtr could be used as a classical signal, through the normal * setting functions. The behavior is to plugged the signalPtr on * the classical mother Signal layer of the object. */ virtual void setConstant( const T& t ) - { plug(this); Signal<T,Time>::setConstant(t); } + { plug(this); Signal<T,Time>::setConstant(t); } virtual void setReference( const T* t,typename Signal<T,Time>::Mutex *m=NULL ) - { plug(this); Signal<T,Time>::setReference(t,m); } + { plug(this); Signal<T,Time>::setReference(t,m); } virtual void setFunction( boost::function2<T&,T&,Time> t,typename Signal<T,Time>::Mutex *m=NULL ) - { plug(this); Signal<T,Time>::setFunction(t,m); } + { plug(this); Signal<T,Time>::setFunction(t,m); } -/* template< class Provider > */ -/* void setFunction( T& (Provider::*fun)(Time,T&),Provider& obj, */ -/* boost::try_mutex *mutexref=NULL ) */ -/* { plug(this); Signal<T,Time>::setFunction(fun,obj,mutexref); } */ + /* template< class Provider > */ + /* void setFunction( T& (Provider::*fun)(Time,T&),Provider& obj, */ + /* boost::try_mutex *mutexref=NULL ) */ + /* { plug(this); Signal<T,Time>::setFunction(fun,obj,mutexref); } */ virtual inline Signal<T,Time>& operator= ( const T& t ) - { setConstant( t ); return *this; } + { setConstant( t ); return *this; } virtual std::ostream& displayDependencies( std::ostream& os,const int depth=-1, @@ -127,24 +135,15 @@ class SignalPtr std::string next1="", std::string next2="" ) const; - protected: // Interdiction of the rest of the heritage - - virtual void addDependency() {} - virtual void removeDependency() {} - virtual void clearDependencies() {} - -}; - -} // namespace dynamicgraph - -#include <dynamic-graph/signal-ptr.t.cpp> + protected: // Interdiction of the rest of the heritage + virtual void addDependency () {} + virtual void removeDependency () {} + virtual void clearDependencies () {} -#endif // #ifndef __SIGNAL_PTR_HH + }; -/* - * Local variables: - * c-basic-offset: 4 - * End: - */ +} // end of namespace dynamicgraph +# include <dynamic-graph/signal-ptr.t.cpp> +#endif //! DYNAMIC_GRAPH_SIGNAL_PTR_H diff --git a/include/dynamic-graph/signal-ptr.t.cpp b/include/dynamic-graph/signal-ptr.t.cpp index 74bbd9f..1d32bfa 100644 --- a/include/dynamic-graph/signal-ptr.t.cpp +++ b/include/dynamic-graph/signal-ptr.t.cpp @@ -1,314 +1,261 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - * Copyright Projet JRL-Japan, 2007 - *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - * - * File: SignalPtr.t.cpp - * Project: DYNAMIC-GRAPH - * Author: Nicolas Mansard - * - * Version control - * =============== - * - * $Id$ - * - * Description - * ============ - * - * - * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ - - - - -#ifndef __SIGNAL_PTR_TCPP -#define __SIGNAL_PTR_TCPP - -#include <dynamic-graph/signal-ptr.h> - -#undef VP_TEMPLATE_DEBUG_MODE -#define VP_TEMPLATE_DEBUG_MODE 0 -#include <dynamic-graph/debug.h> - -namespace dynamicgraph { - -template< class T,class Time > -bool SignalPtr<T,Time>:: -isAbstractPluged( void ) const +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_SIGNAL_PTR_T_CPP +# define DYNAMIC_GRAPH_SIGNAL_PTR_T_CPP +# include <dynamic-graph/signal-ptr.h> + +# undef VP_TEMPLATE_DEBUG_MODE +# define VP_TEMPLATE_DEBUG_MODE 0 +# include <dynamic-graph/debug.h> + +namespace dynamicgraph { - return ( (NULL!=signalPtr)||(abstractTransmitter) ); -} - - -template< class T,class Time > -Signal<T,Time>* SignalPtr<T,Time>:: -getPtr ( void ) -{ - dgTDEBUGIN(25); - if(! isPluged() ) - DG_THROW ExceptionSignal( ExceptionSignal::NOT_INITIALIZED, + template< class T,class Time > + bool SignalPtr<T,Time>:: + isAbstractPluged () const + { + return ( (NULL!=signalPtr)||(abstractTransmitter) ); + } + + + template< class T,class Time > + Signal<T,Time>* SignalPtr<T,Time>:: + getPtr () + { + dgTDEBUGIN(25); + if(! isPluged () ) + DG_THROW ExceptionSignal( ExceptionSignal::NOT_INITIALIZED, + "In SignalPtr: SIN ptr not set.", + " (in signal <%s>)",getName ().c_str ()); + dgTDEBUGOUT(25); + return signalPtr; + } + + template< class T,class Time > + const Signal<T,Time>* SignalPtr<T,Time>:: + getPtr () const + { + dgTDEBUGIN(25) << SignalBase<Time>::name <<"("<< isPluged () <<")" + << this << "->"<<signalPtr <<std::endl; + dgTDEBUGIN(25); + if(! isPluged () ) + { DG_THROW ExceptionSignal( ExceptionSignal::NOT_INITIALIZED, "In SignalPtr: SIN ptr not set.", - " (in signal <%s>)",getName().c_str()); - dgTDEBUGOUT(25); - return signalPtr; -} - -template< class T,class Time > -const Signal<T,Time>* SignalPtr<T,Time>:: -getPtr ( void ) const -{ - dgTDEBUGIN(25) << SignalBase<Time>::name <<"("<< isPluged() <<")" - << this << "->"<<signalPtr <<std::endl; - dgTDEBUGIN(25); - if(! isPluged() ) - { DG_THROW ExceptionSignal( ExceptionSignal::NOT_INITIALIZED, - "In SignalPtr: SIN ptr not set.", - " (in signal <%s>)",getName().c_str()); } - dgTDEBUGOUT(25); - return signalPtr; -} - -template< class T,class Time > -SignalBase<Time>* SignalPtr<T,Time>:: -getAbstractPtr ( void ) -{ - if(! isAbstractPluged() ) - { DG_THROW ExceptionSignal( ExceptionSignal::NOT_INITIALIZED, - "In SignalPtr: SIN ptr not set.", - " (in signal <%s>)",getName().c_str()); } - if( NULL!=signalPtr ) return signalPtr; - else return abstractTransmitter; -} - -template< class T,class Time > -const SignalBase<Time>* SignalPtr<T,Time>:: -getAbstractPtr ( void ) const -{ - if(! isAbstractPluged() ) - { DG_THROW ExceptionSignal( ExceptionSignal::NOT_INITIALIZED, - "In SignalPtr: SIN ptr not set.", - " (in signal <%s>)",getName().c_str()); } - if( NULL!=signalPtr ) return signalPtr; - else return abstractTransmitter; -} - -template< class T,class Time > -void SignalPtr<T,Time>:: -plug( SignalBase<Time>* unknown_ref ) -{ - dgTDEBUGIN(5); - if(! unknown_ref ) - { - signalPtr = NULL; - transmitAbstract = false; - dgTDEBUGOUT(5); - return; - } - - dgTDEBUG(5) << "# In T = "<< getName() <<" =" - <<typeid( Signal<T,Time>::Tcopy1 ) .name() << "{ "<<std::endl; - - - Signal<T,Time> * ref = dynamic_cast< Signal<T,Time>* > (unknown_ref); - if( NULL==ref ) - { - try { - unknown_ref->checkCompatibility(); + " (in signal <%s>)",getName ().c_str ()); } + dgTDEBUGOUT(25); + return signalPtr; + } + + template< class T,class Time > + SignalBase<Time>* SignalPtr<T,Time>:: + getAbstractPtr () + { + if(! isAbstractPluged () ) + { DG_THROW ExceptionSignal( ExceptionSignal::NOT_INITIALIZED, + "In SignalPtr: SIN ptr not set.", + " (in signal <%s>)",getName ().c_str ()); } + if( NULL!=signalPtr ) return signalPtr; + else return abstractTransmitter; + } + + template< class T,class Time > + const SignalBase<Time>* SignalPtr<T,Time>:: + getAbstractPtr () const + { + if(! isAbstractPluged () ) + { DG_THROW ExceptionSignal( ExceptionSignal::NOT_INITIALIZED, + "In SignalPtr: SIN ptr not set.", + " (in signal <%s>)",getName ().c_str ()); } + if( NULL!=signalPtr ) return signalPtr; + else return abstractTransmitter; + } + + template< class T,class Time > + void SignalPtr<T,Time>:: + plug( SignalBase<Time>* unknown_ref ) + { + dgTDEBUGIN(5); + if(! unknown_ref ) + { + signalPtr = NULL; + transmitAbstract = false; + dgTDEBUGOUT(5); + return; } - catch( T* t ) - { - dgTDEBUG(25) << "Cast THROW ok."<< std::endl; - Signal<T,Time>::setReference( t ); - transmitAbstract = true; abstractTransmitter = unknown_ref; - transmitAbstractData = t; - } - catch(...) - { - dgTDEBUG(25) << "Fatal error."<< std::endl; - transmitAbstract = false; - DG_THROW ExceptionSignal( ExceptionSignal::PLUG_IMPOSSIBLE, - "Compl. Uncompatible types for plugin.", - "(while trying to plug <%s> on <%s>).", - unknown_ref->getName().c_str(), - this->getName().c_str()); - } - } - else - { - dgTDEBUG(25) << "Cast ok."<< std::endl; - transmitAbstract = false; - signalPtr = ref; - } - dgTDEBUGOUT(5); -} - -template< class T,class Time > -bool SignalPtr<T,Time>:: -needUpdate( const Time& t ) const -{ - if( (isAbstractPluged())&&(!autoref()) ){ return getAbstractPtr()->needUpdate(t);} - else return Signal<T,Time>::needUpdate(t); -} - -template< class T,class Time > -const Time& SignalPtr<T,Time>::getTime( void ) const -{ - if( (isAbstractPluged())&&(!autoref()) ){ return getAbstractPtr()->getTime();} - return Signal<T,Time>::getTime(); -} - - -template< class T,class Time > -const T& SignalPtr<T,Time>:: -operator()( const Time & t ) -{ - return access(t); -} -template< class T,class Time > -const T& SignalPtr<T,Time>:: -access( const Time & t ) -{ - dgTDEBUGIN(15); - if( modeNoThrow&&(! isPluged())&&Signal<T,Time>::copyInit ) - { - dgTDEBUGOUT(15); - return Signal<T,Time>::accessCopy(); - } - else if( autoref() ) - { - dgTDEBUGOUT(15); - return Signal<T,Time>::access(t); - } - else if( transmitAbstract ) - { - abstractTransmitter->recompute(t); - dgTDEBUGOUT(15); - return *transmitAbstractData; - } - else - { - dgTDEBUGOUT(15); - return getPtr()->access(t); - } -} -template< class T,class Time > -const T& SignalPtr<T,Time>:: -accessCopy( void ) const -{ - if( modeNoThrow&&(! isPluged())&&Signal<T,Time>::copyInit ) - return Signal<T,Time>::accessCopy(); - else if( autoref() ) return Signal<T,Time>::accessCopy(); - else if( transmitAbstract ) return *transmitAbstractData; - else return getPtr()->accessCopy(); -} -template< class T, class Time> -std::ostream & SignalPtr<T,Time>:: -writeGraph(std::ostream &os) const -{ - std::string LeaderLocalName; - std::string LeaderNodeName; - Signal<T,Time>::ExtractNodeAndLocalNames(LeaderLocalName,LeaderNodeName); - if ( isAbstractPluged() && !autoref()) - { - std::string itLocalName,itNodeName; - getAbstractPtr()->ExtractNodeAndLocalNames(itLocalName,itNodeName); - os << "\t\"" << itNodeName << "\" -> \"" << LeaderNodeName << "\"" << std::endl - << "\t [ headlabel = \"" << LeaderLocalName - << "\" , taillabel = \"" << itLocalName - << "\", fontsize=7, fontcolor=red ]" << std::endl; - - } - return os; -} - -template< class T,class Time > -std::ostream& SignalPtr<T,Time>:: -display( std::ostream& os ) const -{ - dgTDEBUGIN(25) << SignalBase<Time>::name << this << "||" << isPluged() << "||"<<signalPtr; - { Signal<T,Time>::display(os); } + dgTDEBUG(5) << "# In T = "<< getName () <<" =" + <<typeid( Signal<T,Time>::Tcopy1 ) .name () << "{ "<<std::endl; - if( (isAbstractPluged())&&(!autoref()) ) - { - // dgTDEBUG(25) << "Display pointed."<<std::endl; - // getPtr()->display(os<<"PTR->"); - os << " -->-- PLUGGED"; - } - else - { - if(! isAbstractPluged()) os << " UNPLUGGED"; - else if(autoref()) os << " AUTOPLUGGED"; - } - dgTDEBUGOUT(25); - return os; -} - -template< class T,class Time > -std::ostream& SignalPtr<T,Time>:: -displayDependencies( std::ostream& os,const int depth, - std::string space, - std::string next1,std::string next2 ) const -{ - dgTDEBUGIN(25); - if( (isAbstractPluged())&&(!autoref()) ) - { getAbstractPtr()->displayDependencies(os,depth,space,next1+"-- " - +SignalBase<Time>::name+" -->",next2); } - else - { - SignalBase<Time>::displayDependencies(os,depth,space,next1,next2); - } - dgTDEBUGOUT(25); - return os; -} + Signal<T,Time> * ref = dynamic_cast< Signal<T,Time>* > (unknown_ref); + if( NULL==ref ) + { + try { + unknown_ref->checkCompatibility (); + } + catch( T* t ) + { + dgTDEBUG(25) << "Cast THROW ok."<< std::endl; + Signal<T,Time>::setReference( t ); + transmitAbstract = true; abstractTransmitter = unknown_ref; + transmitAbstractData = t; + } + catch(...) + { + dgTDEBUG(25) << "Fatal error."<< std::endl; + transmitAbstract = false; + DG_THROW ExceptionSignal( ExceptionSignal::PLUG_IMPOSSIBLE, + "Compl. Uncompatible types for plugin.", + "(while trying to plug <%s> on <%s>).", + unknown_ref->getName ().c_str (), + this->getName ().c_str ()); + } + } + else + { + dgTDEBUG(25) << "Cast ok."<< std::endl; + transmitAbstract = false; + signalPtr = ref; + } + dgTDEBUGOUT(5); + } + + template< class T,class Time > + bool SignalPtr<T,Time>:: + needUpdate( const Time& t ) const + { + if( (isAbstractPluged ())&&(!autoref ()) ){ return getAbstractPtr ()->needUpdate(t);} + else return Signal<T,Time>::needUpdate(t); + } + + template< class T,class Time > + const Time& SignalPtr<T,Time>::getTime () const + { + if( (isAbstractPluged ())&&(!autoref ()) ){ return getAbstractPtr ()->getTime ();} + return Signal<T,Time>::getTime (); + } + + + template< class T,class Time > + const T& SignalPtr<T,Time>:: + operator ()( const Time & t ) + { + return access(t); + } + + template< class T,class Time > + const T& SignalPtr<T,Time>:: + access( const Time & t ) + { + dgTDEBUGIN(15); + if( modeNoThrow&&(! isPluged ())&&Signal<T,Time>::copyInit ) + { + dgTDEBUGOUT(15); + return Signal<T,Time>::accessCopy (); + } + else if( autoref () ) + { + dgTDEBUGOUT(15); + return Signal<T,Time>::access(t); + } + else if( transmitAbstract ) + { + abstractTransmitter->recompute(t); + dgTDEBUGOUT(15); + return *transmitAbstractData; + } + else + { + dgTDEBUGOUT(15); + return getPtr ()->access(t); + } + } + template< class T,class Time > + const T& SignalPtr<T,Time>:: + accessCopy () const + { + if( modeNoThrow&&(! isPluged ())&&Signal<T,Time>::copyInit ) + return Signal<T,Time>::accessCopy (); + else if( autoref () ) return Signal<T,Time>::accessCopy (); + else if( transmitAbstract ) return *transmitAbstractData; + else return getPtr ()->accessCopy (); + } + template< class T, class Time> + std::ostream & SignalPtr<T,Time>:: + writeGraph(std::ostream &os) const + { + std::string LeaderLocalName; + std::string LeaderNodeName; + Signal<T,Time>::ExtractNodeAndLocalNames(LeaderLocalName,LeaderNodeName); + if ( isAbstractPluged () && !autoref ()) + { + std::string itLocalName,itNodeName; + getAbstractPtr ()->ExtractNodeAndLocalNames(itLocalName,itNodeName); + os << "\t\"" << itNodeName << "\" -> \"" << LeaderNodeName << "\"" << std::endl + << "\t [ headlabel = \"" << LeaderLocalName + << "\" , taillabel = \"" << itLocalName + << "\", fontsize=7, fontcolor=red ]" << std::endl; -} // namespace dynamicgraph + } + return os; + } + + template< class T,class Time > + std::ostream& SignalPtr<T,Time>:: + display( std::ostream& os ) const + { + dgTDEBUGIN(25) << SignalBase<Time>::name << this << "||" << isPluged () << "||"<<signalPtr; + { Signal<T,Time>::display(os); } + + if( (isAbstractPluged ())&&(!autoref ()) ) + { + // dgTDEBUG(25) << "Display pointed."<<std::endl; + // getPtr ()->display(os<<"PTR->"); + os << " -->-- PLUGGED"; + } + else + { + if(! isAbstractPluged ()) os << " UNPLUGGED"; + else if(autoref ()) os << " AUTOPLUGGED"; + } -#endif // #ifndef __SIGNAL_PTR_TCPP + dgTDEBUGOUT(25); + return os; + } + + template< class T,class Time > + std::ostream& SignalPtr<T,Time>:: + displayDependencies( std::ostream& os,const int depth, + std::string space, + std::string next1,std::string next2 ) const + { + dgTDEBUGIN(25); + if( (isAbstractPluged ())&&(!autoref ()) ) + { getAbstractPtr ()->displayDependencies(os,depth,space,next1+"-- " + +SignalBase<Time>::name+" -->",next2); } + else + { + SignalBase<Time>::displayDependencies(os,depth,space,next1,next2); + } + dgTDEBUGOUT(25); + return os; + } -/* - * Local variables: - * c-basic-offset: 2 - * End: - */ +} // end of namespace dynamicgraph. +#endif //! DYNAMIC_GRAPH_SIGNAL_PTR_T_CPP diff --git a/include/dynamic-graph/signal-time-dependent.h b/include/dynamic-graph/signal-time-dependent.h index f17337b..ad71f81 100644 --- a/include/dynamic-graph/signal-time-dependent.h +++ b/include/dynamic-graph/signal-time-dependent.h @@ -1,117 +1,112 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __DEPENDENT_SIGNAL_HH -#define __DEPENDENT_SIGNAL_HH - -#include <dynamic-graph/signal.h> - -#include <dynamic-graph/time-dependency.h> - -namespace dynamicgraph { - -/*! \brief A type of signal that enforces a time dependency between other signals, -making sure its inputs are up to date on access, using a incrementing time tick as reference. -It works this way: for a given SignalTimeDependent S, the user manually adds dependent signals through the -use of the addDependency function. On access (calling the signal S operator () or access(Time) function), -if the dependent signals are not up-to-date, i.e. if their [last update] time is less than the -current time, their value will be access()'ed to bring them up-to-date. Thus, the value of dependent -signals can be accessed \b quickly and \b repeatedly through the accessCopy() function. - */ -template< class T,class Time > -class SignalTimeDependent -: public virtual Signal<T,Time> -, public TimeDependency<Time> +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_SIGNAL_TIME_DEPENDENT_H +# define DYNAMIC_GRAPH_SIGNAL_TIME_DEPENDENT_H +# include <dynamic-graph/signal.h> +# include <dynamic-graph/time-dependency.h> + +namespace dynamicgraph { + /*! \brief A type of signal that enforces a time dependency between other signals, + making sure its inputs are up to date on access, using a incrementing time tick as reference. + It works this way: for a given SignalTimeDependent S, the user manually adds dependent signals through the + use of the addDependency function. On access (calling the signal S operator () or access(Time) function), + if the dependent signals are not up-to-date, i.e. if their [last update] time is less than the + current time, their value will be access ()'ed to bring them up-to-date. Thus, the value of dependent + signals can be accessed \b quickly and \b repeatedly through the accessCopy () function. + */ + template< class T,class Time > + class SignalTimeDependent + : public virtual Signal<T,Time> + , public TimeDependency<Time> + { - //TimeDependency<Time> timeDependency; + //TimeDependency<Time> timeDependency; - public: - SignalTimeDependent( std::string name = "" ); - SignalTimeDependent( const SignalArray_const<Time> & arr - ,std::string name = "" ); - SignalTimeDependent( boost::function2<T&,T&,Time> t - ,const SignalArray_const<Time> & sig - ,std::string name = "" ); + public: + SignalTimeDependent( std::string name = "" ); + SignalTimeDependent( const SignalArray_const<Time> & arr + ,std::string name = "" ); + SignalTimeDependent( boost::function2<T&,T&,Time> t + ,const SignalArray_const<Time> & sig + ,std::string name = "" ); - virtual ~SignalTimeDependent( void ) {} + virtual ~SignalTimeDependent () {} - inline const T& operator() ( const Time& t1 ){ return access(t1); } - const T& access( const Time& t1 ); + inline const T& operator () ( const Time& t1 ){ return access(t1); } + const T& access( const Time& t1 ); - virtual void addDependency( const SignalBase<Time>& signal ) ; - virtual void removeDependency( const SignalBase<Time>& signal ) ; - virtual void clearDependencies( void ); + virtual void addDependency( const SignalBase<Time>& signal ) ; + virtual void removeDependency( const SignalBase<Time>& signal ) ; + virtual void clearDependencies (); - std::ostream& writeGraph(std::ostream &os) const - { return os;} + std::ostream& writeGraph(std::ostream &os) const + { return os;} - std::ostream& displayDependencies( std::ostream& os,const int depth=-1, - std::string space="", - std::string next1="",std::string next2="" ) const - { return TimeDependency<Time>::displayDependencies( os,depth,space,next1,next2 ); } + std::ostream& displayDependencies( std::ostream& os,const int depth=-1, + std::string space="", + std::string next1="",std::string next2="" ) const + { return TimeDependency<Time>::displayDependencies( os,depth,space,next1,next2 ); } - virtual bool needUpdate( const Time& t ) const; - virtual void setPeriodTime( const Time& p ) ; - virtual Time getPeriodTime( void ) const; + virtual bool needUpdate( const Time& t ) const; + virtual void setPeriodTime( const Time& p ) ; + virtual Time getPeriodTime () const; -}; + }; -/* -------------------------------------------- */ + /* -------------------------------------------- */ -template < class T,class Time > -SignalTimeDependent<T,Time>:: -SignalTimeDependent( std::string name ) + template < class T,class Time > + SignalTimeDependent<T,Time>:: + SignalTimeDependent( std::string name ) :Signal<T,Time>(name) - ,TimeDependency<Time>(this) + ,TimeDependency<Time>(this) {} -template< class T,class Time> -SignalTimeDependent<T,Time>:: -SignalTimeDependent( const SignalArray_const<Time> & arr - ,std::string name ) + template< class T,class Time> + SignalTimeDependent<T,Time>:: + SignalTimeDependent( const SignalArray_const<Time> & arr + ,std::string name ) :Signal<T,Time>(name) ,TimeDependency<Time>(this,arr) {} -template< class T,class Time> -SignalTimeDependent<T,Time>:: - SignalTimeDependent( boost::function2<T&,T&,Time> t - ,const SignalArray_const<Time> & sig - ,std::string name ) + template< class T,class Time> + SignalTimeDependent<T,Time>:: + SignalTimeDependent( boost::function2<T&,T&,Time> t + ,const SignalArray_const<Time> & sig + ,std::string name ) :Signal<T,Time>(name) ,TimeDependency<Time>(this,sig) { setFunction(t); } -template< class T,class Time> - const T& SignalTimeDependent<T,Time>:: -access( const Time& t1 ) + template< class T,class Time> + const T& SignalTimeDependent<T,Time>:: + access( const Time& t1 ) { const bool up = TimeDependency<Time>::needUpdate(t1); //SignalBase<Time>::setReady(false); -/* std::cout << "Time before: "<< signalTime << " -- " */ -/* << t1<< " -> Up: "<<up <<std::endl ; */ + /* std::cout << "Time before: "<< signalTime << " -- " */ + /* << t1<< " -> Up: "<<up <<std::endl ; */ if( up ) { TimeDependency<Time>::lastAskForUpdate = false; @@ -119,41 +114,41 @@ access( const Time& t1 ) SignalBase<Time>::setReady(false); return Tres; } - else { return Signal<T,Time>::accessCopy(); } + else { return Signal<T,Time>::accessCopy (); } } -template< class T,class Time> - void SignalTimeDependent<T,Time>:: -addDependency( const SignalBase<Time>& signal ) + template< class T,class Time> + void SignalTimeDependent<T,Time>:: + addDependency( const SignalBase<Time>& signal ) { TimeDependency<Time>::addDependency(signal); } -template< class T,class Time> - void SignalTimeDependent<T,Time>:: -removeDependency( const SignalBase<Time>& signal ) + template< class T,class Time> + void SignalTimeDependent<T,Time>:: + removeDependency( const SignalBase<Time>& signal ) { TimeDependency<Time>::removeDependency(signal); } -template< class T,class Time> - void SignalTimeDependent<T,Time>:: -clearDependencies( void ) - { TimeDependency<Time>::clearDependency(); } + template< class T,class Time> + void SignalTimeDependent<T,Time>:: + clearDependencies () + { TimeDependency<Time>::clearDependency (); } -template< class T,class Time> - bool SignalTimeDependent<T,Time>:: -needUpdate( const Time& t ) const -{ - return TimeDependency<Time>::needUpdate(t); -} + template< class T,class Time> + bool SignalTimeDependent<T,Time>:: + needUpdate( const Time& t ) const + { + return TimeDependency<Time>::needUpdate(t); + } -template< class T,class Time> + template< class T,class Time> void SignalTimeDependent<T,Time>:: -setPeriodTime( const Time& p ) + setPeriodTime( const Time& p ) { TimeDependency<Time>::setPeriodTime( p ); } -template< class T,class Time> - Time SignalTimeDependent<T,Time>:: -getPeriodTime( void ) const - { return TimeDependency<Time>::getPeriodTime(); } + template< class T,class Time> + Time SignalTimeDependent<T,Time>:: + getPeriodTime () const + { return TimeDependency<Time>::getPeriodTime (); } -} // namespace dynamicgraph +} // end of namespace dynamicgraph -#endif /* #ifndef __DEPENDENT_SIGNAL_HH */ +#endif //! DYNAMIC_GRAPH_SIGNAL_TIME_DEPENDENT_H diff --git a/include/dynamic-graph/signal.h b/include/dynamic-graph/signal.h index 07ed582..e06aa88 100644 --- a/include/dynamic-graph/signal.h +++ b/include/dynamic-graph/signal.h @@ -98,7 +98,7 @@ protected: /* --- Constructor/destrusctor --- */ Signal( std::string name ); - virtual ~Signal( void ) {} + virtual ~Signal () {} /* --- Generic In/Out function --- */ virtual void get( std::ostream& value ) const; @@ -112,34 +112,34 @@ protected: virtual void setFunction( boost::function2<T&,T&,Time> t, Mutex *mutexref=NULL); - inline bool getKeepReference( void ){ return keepReference; } + inline bool getKeepReference (){ return keepReference; } inline void setKeepReference( const bool& b ){ keepReference=b; } /* --- Signal computation --- */ virtual const T& access( const Time & t ); virtual inline void recompute( const Time & t ) { access(t); } - virtual const T& accessCopy( void ) const; + virtual const T& accessCopy () const; virtual std::ostream& display( std::ostream& os ) const; /* --- Operators --- */ - virtual inline const T& operator()( const Time & t ){ return access(t); } + virtual inline const T& operator ()( const Time & t ){ return access(t); } virtual Signal<T,Time>& operator= ( const T& t ); - inline operator const T& ( void ) const { return accessCopy(); } + inline operator const T& () const { return accessCopy (); } public: - virtual void checkCompatibility( void ) { throw Tcopy; } + virtual void checkCompatibility () { throw Tcopy; } private: const T& setTcopy( const T& t ); - T& getTwork( void ); - const T& getTwork( void ) const ; - const T& switchTcopy( void ); + T& getTwork (); + const T& getTwork () const ; + const T& switchTcopy (); }; -} // namespace dynamicgraph +} // end of namespace dynamicgraph #include <dynamic-graph/signal.t.cpp> diff --git a/include/dynamic-graph/signal.t.cpp b/include/dynamic-graph/signal.t.cpp index be66f94..edda08a 100644 --- a/include/dynamic-graph/signal.t.cpp +++ b/include/dynamic-graph/signal.t.cpp @@ -1,278 +1,274 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - * Copyright Projet JRL-Japan, 2007 - *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - * - * File: Signal.t.cpp - * Project: DYNAMIC-GRAPH - * Author: Nicolas Mansard - * - * Version control - * =============== - * - * $Id$ - * - * Description - * ============ - * - * - * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ - - - -#ifndef __SIGNAL_TEMPLATE -#define __SIGNAL_TEMPLATE - - -#include <dynamic-graph/signal.h> -#include <dynamic-graph/signal-caster.h> - -#undef VP_TEMPLATE_DEBUG_MODE -#define VP_TEMPLATE_DEBUG_MODE 0 -#include <dynamic-graph/debug.h> - -namespace dynamicgraph { - -#define __SIGNAL_INIT(name,Tcpy,Tref,TrefNC,mutex) \ - SignalBase<Time>(name) \ - ,signalType(SIGNAL_TYPE_DEFAULT) \ - ,Tcopy1(Tcpy) \ - ,Tcopy2(Tcpy) \ - ,Tcopy(&Tcopy1) \ - ,Treference(Tref) \ - ,TreferenceNonConst(TrefNC) \ - ,Tfunction() \ - ,keepReference( KEEP_REFERENCE_DEFAULT ) \ - ,providerMutex(mutex) - -template< class T,class Time > -Signal<T,Time>:: -Signal( std::string name ) - :__SIGNAL_INIT(name,T(),NULL,NULL,NULL) +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_SIGNAL_T_CPP +# define DYNAMIC_GRAPH_SIGNAL_T_CPP +# include <dynamic-graph/signal.h> +# include <dynamic-graph/signal-caster.h> + +# undef VP_TEMPLATE_DEBUG_MODE +# define VP_TEMPLATE_DEBUG_MODE 0 +# include <dynamic-graph/debug.h> + +# define __SIGNAL_INIT(name,Tcpy,Tref,TrefNC,mutex) \ + SignalBase<Time>(name) \ + ,signalType (SIGNAL_TYPE_DEFAULT) \ + ,Tcopy1 (Tcpy) \ + ,Tcopy2 (Tcpy) \ + ,Tcopy (&Tcopy1) \ + ,Treference (Tref) \ + ,TreferenceNonConst (TrefNC) \ + ,Tfunction () \ + ,keepReference (KEEP_REFERENCE_DEFAULT) \ + ,providerMutex (mutex) + +namespace dynamicgraph { - return; -} -/* -------------------------------------------------------------------------- */ + template< class T,class Time > + Signal<T,Time>:: + Signal( std::string name ) + :__SIGNAL_INIT(name,T (),NULL,NULL,NULL) + { + return; + } + + /* -------------------------------------------------------------------------- */ + + + template< class T,class Time > + void Signal<T,Time>:: + set( std::istringstream& stringValue ) + { + (*this) = signal_cast<T>( stringValue ); + } + + template< class T,class Time > + void Signal<T,Time>:: + get( std::ostream& os ) const + { + signal_disp<T>( this->accessCopy (),os ); + } + + template< class T,class Time > + void Signal<T,Time>:: + trace( std::ostream& os ) const + { + try { signal_trace<T>( this->accessCopy (),os ); } + catch DG_RETHROW + catch (...) + { DG_THROW ExceptionSignal( ExceptionSignal::SET_IMPOSSIBLE, + "TRACE operation not possible with this signal. ", + "(bad cast while getting value from %s).", + SignalBase<Time>::getName ().c_str ()); + } -template< class T,class Time > -void Signal<T,Time>:: -set( std::istringstream& stringValue ) -{ - (*this) = signal_cast<T>( stringValue ); -} - -template< class T,class Time > -void Signal<T,Time>:: -get( std::ostream& os ) const -{ - signal_disp<T>( this->accessCopy(),os ); -} - -template< class T,class Time > -void Signal<T,Time>:: -trace( std::ostream& os ) const -{ - try { signal_trace<T>( this->accessCopy(),os ); } - catch DG_RETHROW - catch (...) - { DG_THROW ExceptionSignal( ExceptionSignal::SET_IMPOSSIBLE, - "TRACE operation not possible with this signal. ", - "(bad cast while getting value from %s).", - SignalBase<Time>::getName().c_str()); - } - -} - + } -/* -------------------------------------------------------------------------- */ -template< class T,class Time > -const T& Signal<T,Time>:: -setTcopy( const T& t ) -{ - if( Tcopy==&Tcopy1 ) - { - Tcopy2 = t; - copyInit = true; - Tcopy = &Tcopy2; - return Tcopy2; - } - else - { - Tcopy1 = t; - copyInit = true; - Tcopy = &Tcopy1; - return Tcopy1; - } -} - -template< class T,class Time > -T& Signal<T,Time>:: -getTwork( void ) -{ - if( Tcopy==&Tcopy1 ) return Tcopy2; else return Tcopy1; -} + /* -------------------------------------------------------------------------- */ -template< class T,class Time > -const T& Signal<T,Time>:: -getTwork( void ) const -{ - if( Tcopy==&Tcopy1 ) return Tcopy2; else return Tcopy1; -} - - -template< class T,class Time > -const T& Signal<T,Time>:: -switchTcopy( void ) -{ - if( Tcopy==&Tcopy1 ) - { - Tcopy = &Tcopy2; - return Tcopy2; + template< class T,class Time > + const T& Signal<T,Time>:: + setTcopy( const T& t ) + { + if( Tcopy==&Tcopy1 ) + { + Tcopy2 = t; + copyInit = true; + Tcopy = &Tcopy2; + return Tcopy2; } - else - { - Tcopy = &Tcopy1; - return Tcopy1; - } -} - - - -template< class T,class Time > -void Signal<T,Time>:: -setConstant( const T& t ) -{ - signalType = CONSTANT; setTcopy(t); - setReady(); -} - - -template< class T,class Time > -void Signal<T,Time>:: -setReference( const T* t,Mutex *mutexref ) -{ - signalType = REFERENCE; Treference = t; - providerMutex = mutexref; - copyInit = false; - setReady(); -} - -template< class T,class Time > -void Signal<T,Time>:: -setReferenceNonConstant( T* t,Mutex *mutexref ) -{ - signalType = REFERENCE_NON_CONST; - Treference = t; - TreferenceNonConst = t; - providerMutex = mutexref; - copyInit = false; - setReady(); -} - -template< class T,class Time > -void Signal<T,Time>:: -setFunction( boost::function2<T&,T&,Time> t,Mutex *mutexref ) -{ - signalType = FUNCTION; - Tfunction = t; - providerMutex = mutexref; - copyInit = false; - setReady(); -} - -template< class T,class Time > -const T& Signal<T,Time>:: -accessCopy( void ) const -{ - return *Tcopy; -} - + else + { + Tcopy1 = t; + copyInit = true; + Tcopy = &Tcopy1; + return Tcopy1; + } + } + + template< class T,class Time > + T& Signal<T,Time>:: + getTwork () + { + if( Tcopy==&Tcopy1 ) return Tcopy2; else return Tcopy1; + } + + template< class T,class Time > + const T& Signal<T,Time>:: + getTwork () const + { + if( Tcopy==&Tcopy1 ) return Tcopy2; else return Tcopy1; + } + + + template< class T,class Time > + const T& Signal<T,Time>:: + switchTcopy () + { + if( Tcopy==&Tcopy1 ) + { + Tcopy = &Tcopy2; + return Tcopy2; + } + else + { + Tcopy = &Tcopy1; + return Tcopy1; + } + } + + + + template< class T,class Time > + void Signal<T,Time>:: + setConstant( const T& t ) + { + signalType = CONSTANT; setTcopy(t); + setReady (); + } + + + template< class T,class Time > + void Signal<T,Time>:: + setReference( const T* t,Mutex *mutexref ) + { + signalType = REFERENCE; Treference = t; + providerMutex = mutexref; + copyInit = false; + setReady (); + } + + template< class T,class Time > + void Signal<T,Time>:: + setReferenceNonConstant( T* t,Mutex *mutexref ) + { + signalType = REFERENCE_NON_CONST; + Treference = t; + TreferenceNonConst = t; + providerMutex = mutexref; + copyInit = false; + setReady (); + } + + template< class T,class Time > + void Signal<T,Time>:: + setFunction( boost::function2<T&,T&,Time> t,Mutex *mutexref ) + { + signalType = FUNCTION; + Tfunction = t; + providerMutex = mutexref; + copyInit = false; + setReady (); + } + + template< class T,class Time > + const T& Signal<T,Time>:: + accessCopy () const + { + return *Tcopy; + } + + + + template< class T,class Time > + const T& Signal<T,Time>:: + access(const Time& t) + { + //dgTDEBUG(20) << "# In (" << SignalBase<Time>::name <<")"<<std::endl; + switch( signalType ) + { + case REFERENCE: + case REFERENCE_NON_CONST: + { + if( NULL==providerMutex ) + { + copyInit=true; + signalTime = t; + return setTcopy( *Treference ); + } + else + { + try + { +#ifdef HAVE_LIBBOOST_THREAD + boost::try_mutex::scoped_try_lock lock(*providerMutex); +#endif + copyInit = true; + signalTime = t; + return setTcopy(*Treference); + } + catch( MutexError le ) + { return accessCopy (); } + } + break; + } -template< class T,class Time > -const T& Signal<T,Time>:: -access(const Time& t) -{ - //dgTDEBUG(20) << "# In (" << SignalBase<Time>::name <<")"<<std::endl; - switch( signalType ) - { - case REFERENCE: - case REFERENCE_NON_CONST: - { - if( NULL==providerMutex ) - { - copyInit=true; - signalTime = t; - return setTcopy( *Treference ); - } - else - { - try - { + case FUNCTION: + { + if( NULL==providerMutex ) + { + signalTime = t; + Tfunction(getTwork (),t); + copyInit=true; + return switchTcopy (); + } + else + { + try + { #ifdef HAVE_LIBBOOST_THREAD - boost::try_mutex::scoped_try_lock lock(*providerMutex); + boost::try_mutex::scoped_try_lock lock(*providerMutex); #endif - copyInit = true; - signalTime = t; - return setTcopy(*Treference); - } - catch( MutexError le ) - { return accessCopy(); } + signalTime = t; + Tfunction(getTwork (),t); + copyInit = true; + return switchTcopy (); + } + catch( MutexError le ) + { return accessCopy (); } + } + break; + } + case CONSTANT: + default: + if( this->getReady () ) + { + setReady(false); + setTime(t); } + return accessCopy (); + }; + } + - break; - } - case FUNCTION: + template< class T,class Time > + Signal<T,Time>& Signal<T,Time>::operator= ( const T& t ) + { + if( keepReference&&(REFERENCE_NON_CONST==signalType)&&(NULL!=TreferenceNonConst) ) { if( NULL==providerMutex ) { - signalTime = t; - Tfunction(getTwork(),t); - copyInit=true; - return switchTcopy(); + setTcopy( t ); + (*TreferenceNonConst)=t; } else { @@ -281,81 +277,35 @@ access(const Time& t) #ifdef HAVE_LIBBOOST_THREAD boost::try_mutex::scoped_try_lock lock(*providerMutex); #endif - signalTime = t; - Tfunction(getTwork(),t); - copyInit = true; - return switchTcopy(); + setTcopy(t); + (*TreferenceNonConst)=t; } catch( MutexError le ) - { return accessCopy(); } + { /* TODO ERROR */ } } - break; } - case CONSTANT: - default: - if( this->getReady() ) - { - setReady(false); - setTime(t); - } - return accessCopy(); - }; -} - - - -template< class T,class Time > -Signal<T,Time>& Signal<T,Time>::operator= ( const T& t ) -{ - if( keepReference&&(REFERENCE_NON_CONST==signalType)&&(NULL!=TreferenceNonConst) ) - { - if( NULL==providerMutex ) - { - setTcopy( t ); - (*TreferenceNonConst)=t; - } - else - { - try - { -#ifdef HAVE_LIBBOOST_THREAD - boost::try_mutex::scoped_try_lock lock(*providerMutex); -#endif - setTcopy(t); - (*TreferenceNonConst)=t; - } - catch( MutexError le ) - { /* TODO ERROR */ } - } - } - else - { setConstant( t ); } - return *this; -} - + else + { setConstant( t ); } + return *this; + } + + + template< class T,class Time > + std::ostream& Signal<T,Time>:: + display (std::ostream& os) const + { + os<<"Sig:"<<this->name<<" (Type "; + switch( this->signalType ) + { + case Signal<T,Time>::CONSTANT: os<< "Cst";break; + case Signal<T,Time>::REFERENCE: os<<"Ref"; break; + case Signal<T,Time>::REFERENCE_NON_CONST: os<<"RefNonCst"; break; + case Signal<T,Time>::FUNCTION: os<<"Fun"; break; + } + return os<<")"; + } -template< class T,class Time > -std::ostream& Signal<T,Time>:: -display (std::ostream& os) const -{ - os<<"Sig:"<<this->name<<" (Type "; - switch( this->signalType ) - { - case Signal<T,Time>::CONSTANT: os<< "Cst";break; - case Signal<T,Time>::REFERENCE: os<<"Ref"; break; - case Signal<T,Time>::REFERENCE_NON_CONST: os<<"RefNonCst"; break; - case Signal<T,Time>::FUNCTION: os<<"Fun"; break; - } - return os<<")"; -} - -} // namespace dynamicgraph - -#endif // #ifndef __SIGNAL_TEMPLATE - -/* - * Local variables: - * c-basic-offset: 2 - * End: - */ +} // end of namespace dynamicgraph. +# undef __SIGNAL_INIT +#endif //! DYNAMIC_GRAPH_SIGNAL_T_CPP diff --git a/include/dynamic-graph/time-dependency.h b/include/dynamic-graph/time-dependency.h index 2369cbd..836643a 100644 --- a/include/dynamic-graph/time-dependency.h +++ b/include/dynamic-graph/time-dependency.h @@ -1,100 +1,95 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __TIME_DEPENDENCY_HH -#define __TIME_DEPENDENCY_HH - -#include <list> -#include <iostream> - -#include <dynamic-graph/signal-base.h> -#include <dynamic-graph/signal-array.h> - -namespace dynamicgraph { - -/** \brief A helper class for setting and specifying dependencies between signals. - */ -template< class Time > -class TimeDependency +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_TIME_DEPENDENCY_H +# define DYNAMIC_GRAPH_TIME_DEPENDENCY_H +# include <list> +# include <iostream> + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/signal-base.h> +# include <dynamic-graph/signal-array.h> + +namespace dynamicgraph { - public: - enum DependencyType - { - TIME_DEPENDENT, - BOOL_DEPENDENT, - ALWAYS_READY - }; + /** \brief A helper class for setting and specifying dependencies + between signals. + */ + template<class Time> + class TimeDependency + { + public: + enum DependencyType + { + TIME_DEPENDENT, + BOOL_DEPENDENT, + ALWAYS_READY + }; - mutable Time lastAskForUpdate; + mutable Time lastAskForUpdate; - // protected: - public: + public: - SignalBase< Time >& leader; + SignalBase< Time >& leader; - typedef std::list< const SignalBase<Time> * > Dependencies; - static const DependencyType DEPENDENCY_TYPE_DEFAULT = TIME_DEPENDENT; + typedef std::list< const SignalBase<Time> * > Dependencies; + static const DependencyType DEPENDENCY_TYPE_DEFAULT = TIME_DEPENDENT; - Dependencies dependencies; - bool updateFromAllChildren; - static const bool ALL_READY_DEFAULT = false; + Dependencies dependencies; + bool updateFromAllChildren; + static const bool ALL_READY_DEFAULT = false; - DependencyType dependencyType; + DependencyType dependencyType; - Time periodTime; - static const Time PERIOD_TIME_DEFAULT = 1; + Time periodTime; + static const Time PERIOD_TIME_DEFAULT = 1; - public: + public: - TimeDependency( SignalBase<Time>* sig, - const DependencyType dep = DEPENDENCY_TYPE_DEFAULT ); - TimeDependency( SignalBase<Time>* sig, - const SignalArray_const<Time>& arr, - const DependencyType dep = DEPENDENCY_TYPE_DEFAULT ); - ~TimeDependency( void ) {} + TimeDependency( SignalBase<Time>* sig, + const DependencyType dep = DEPENDENCY_TYPE_DEFAULT ); + TimeDependency( SignalBase<Time>* sig, + const SignalArray_const<Time>& arr, + const DependencyType dep = DEPENDENCY_TYPE_DEFAULT ); + ~TimeDependency () {} - void addDependency( const SignalBase<Time>& sig ); - void removeDependency( const SignalBase<Time>& sig ); - void clearDependency( void ); + void addDependency( const SignalBase<Time>& sig ); + void removeDependency( const SignalBase<Time>& sig ); + void clearDependency (); - virtual std::ostream & writeGraph(std::ostream &os) const; - std::ostream& displayDependencies( std::ostream& os,const int depth=-1, - std::string space="", - std::string next1="",std::string next2="" ) const; + virtual std::ostream & writeGraph(std::ostream &os) const; + std::ostream& displayDependencies( std::ostream& os,const int depth=-1, + std::string space="", + std::string next1="",std::string next2="" ) const; - bool needUpdate( const Time& t1 ) const; + bool needUpdate( const Time& t1 ) const; - void setDependencyType( DependencyType dep ) { dependencyType = dep; } + void setDependencyType( DependencyType dep ) { dependencyType = dep; } - void setNeedUpdateFromAllChildren( const bool b = true ){ updateFromAllChildren=b; } - bool getNeedUpdateFromAllChildren( void ) const { return updateFromAllChildren; } + void setNeedUpdateFromAllChildren( const bool b = true ){ updateFromAllChildren=b; } + bool getNeedUpdateFromAllChildren () const { return updateFromAllChildren; } - void setPeriodTime( const Time& p ) { periodTime = p; } - Time getPeriodTime( void ) const { return periodTime; } + void setPeriodTime( const Time& p ) { periodTime = p; } + Time getPeriodTime () const { return periodTime; } -}; + }; -} // namespace dynamicgraph +} // end of namespace dynamicgraph - -#include <dynamic-graph/time-dependency.t.cpp> - -#endif /* #ifndef __TIME_DEPENDENCY_HH */ +# include <dynamic-graph/time-dependency.t.cpp> +#endif //! DYNAMIC_GRAPH_TIME_DEPENDENCY_H diff --git a/include/dynamic-graph/time-dependency.t.cpp b/include/dynamic-graph/time-dependency.t.cpp index 0e9cbae..6199bb1 100644 --- a/include/dynamic-graph/time-dependency.t.cpp +++ b/include/dynamic-graph/time-dependency.t.cpp @@ -1,223 +1,177 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - - /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - * Copyright Projet JRL-Japan, 2007 - *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - * - * File: TimeDependency.t.cpp - * Project: DYNAMIC-GRAPH - * Author: Nicolas Mansard - * - * Version control - * =============== - * - * $Id$ - * - * Description - * ============ - * - * - * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ - - - - -#ifndef __TIME_DEPENDENCY_TCPP -#define __TIME_DEPENDENCY_TCPP - -#include <dynamic-graph/time-dependency.h> - -namespace dynamicgraph { - -#undef VP_TEMPLATE_DEBUG_MODE -#define VP_TEMPLATE_DEBUG_MODE 0 -#include <dynamic-graph/debug.h> - -#define __TIME_DEPENDENCY_INIT(sig,dep) \ - leader(*sig) \ - ,dependencies() \ - ,updateFromAllChildren(ALL_READY_DEFAULT) \ - ,dependencyType(dep) \ - ,periodTime(PERIOD_TIME_DEFAULT) - - -template< class Time > -TimeDependency<Time>:: -TimeDependency( SignalBase<Time> *sig - ,const DependencyType dep ) - :__TIME_DEPENDENCY_INIT(sig,dep) -{} - -template< class Time > -TimeDependency<Time>:: -TimeDependency( SignalBase<Time> * sig - ,const SignalArray_const<Time>& ar - ,const DependencyType dep ) - :__TIME_DEPENDENCY_INIT(sig,dep) +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_TIME_DEPENDENCY_T_CPP +# define DYNAMIC_GRAPH_TIME_DEPENDENCY_T_CPP +# include <dynamic-graph/time-dependency.h> + +# undef VP_TEMPLATE_DEBUG_MODE +# define VP_TEMPLATE_DEBUG_MODE 0 +# include <dynamic-graph/debug.h> + +# define __TIME_DEPENDENCY_INIT(sig,dep) \ + leader(*sig) \ + ,dependencies () \ + ,updateFromAllChildren (ALL_READY_DEFAULT) \ + ,dependencyType (dep) \ + ,periodTime (PERIOD_TIME_DEFAULT) + + + +namespace dynamicgraph { - for( unsigned int i=0;i<ar.getSize();++i ) - {addDependency( ar[i] ); } - - return ; -} + template<class Time> + TimeDependency<Time>:: + TimeDependency( SignalBase<Time> *sig + ,const DependencyType dep ) + :__TIME_DEPENDENCY_INIT(sig,dep) + {} + + template<class Time> + TimeDependency<Time>:: + TimeDependency( SignalBase<Time> * sig + ,const SignalArray_const<Time>& ar + ,const DependencyType dep ) + :__TIME_DEPENDENCY_INIT(sig,dep) + { + for( unsigned int i=0;i<ar.getSize ();++i ) + {addDependency( ar[i] ); } + + return ; + } + + /* -------------------------------------------------------------------------- */ + template<class Time> + void TimeDependency<Time>:: + addDependency( const SignalBase<Time>& sig ) + { + dependencies.push_front(&sig); + } + + template<class Time> + void TimeDependency<Time>:: + removeDependency( const SignalBase<Time>& sig ) + { + dependencies.remove(&sig); + } + template<class Time> + void TimeDependency<Time>:: + clearDependency () + { + dependencies.clear (); + } + + template<class Time> + bool TimeDependency<Time>:: + needUpdate( const Time& t1 ) const + { + dgTDEBUG(15) << "# In {" << leader.getName () << " : ("<< leader.getReady ()<<") " + << t1 << " >? " << leader.getTime () << std::endl; + + if( leader.getReady () ) { dgTDEBUGOUT(15);return true; } + if( lastAskForUpdate ) { dgTDEBUGOUT(15);return true; } + + switch( dependencyType ) + { + case ALWAYS_READY: + { dgTDEBUGOUT(15);return true; } + case BOOL_DEPENDENT: break; + case TIME_DEPENDENT: + { + if( t1<leader.getTime ()+periodTime ) + { dgTDEBUGOUT(15);return false; } + break; + } + }; -/* -------------------------------------------------------------------------- */ -template< class Time > -void TimeDependency<Time>:: -addDependency( const SignalBase<Time>& sig ) -{ - dependencies.push_front(&sig); -} + bool res = updateFromAllChildren; + const typename Dependencies::const_iterator itend=dependencies.end (); + for( typename Dependencies::const_iterator it=dependencies.begin ();it!=itend;++it ) + { + const SignalBase<Time> &sig = **it; + dgTDEBUG(15)<< "Ask update for "<< sig <<std::endl; -template< class Time > -void TimeDependency<Time>:: -removeDependency( const SignalBase<Time>& sig ) -{ - dependencies.remove(&sig); -} -template< class Time > -void TimeDependency<Time>:: -clearDependency( void ) -{ - dependencies.clear(); -} + if( (sig.getTime ()>leader.getTime ()) || (sig.needUpdate(t1)) ) + { if(updateFromAllChildren) continue; else {res=true; break;} } + else { if(updateFromAllChildren) {res=false; break;} else continue; } + } + lastAskForUpdate = res; -template< class Time > -bool TimeDependency<Time>:: -needUpdate( const Time& t1 ) const -{ - dgTDEBUG(15) << "# In {" << leader.getName() << " : ("<< leader.getReady()<<") " - << t1 << " >? " << leader.getTime() << std::endl; + dgTDEBUGOUT(15); + return res; + } - if( leader.getReady() ) { dgTDEBUGOUT(15);return true; } - if( lastAskForUpdate ) { dgTDEBUGOUT(15);return true; } - switch( dependencyType ) - { - case ALWAYS_READY: - { dgTDEBUGOUT(15);return true; } - case BOOL_DEPENDENT: break; - case TIME_DEPENDENT: + template<class Time> + std::ostream& TimeDependency<Time>:: + writeGraph( std::ostream & os) const + { + std::string LeaderLocalName; + std::string LeaderNodeName; + leader.ExtractNodeAndLocalNames(LeaderLocalName,LeaderNodeName); + if (dependencies.size ()!=0) { - if( t1<leader.getTime()+periodTime ) - { dgTDEBUGOUT(15);return false; } - break; + const typename Dependencies::const_iterator itend=dependencies.end (); + for( typename Dependencies::const_iterator it=dependencies.begin ();it!=itend;++it ) + { + std::string itLocalName,itNodeName; + (*it)->ExtractNodeAndLocalNames(itLocalName,itNodeName); + os << "\"" << itNodeName << "\" -> \"" << LeaderNodeName << "\"" << std::endl + << " [ headlabel = \"" << LeaderLocalName << "\" , taillabel = \"" << itLocalName << "\" ]" << std::endl; + } } - }; - - bool res = updateFromAllChildren; - const typename Dependencies::const_iterator itend=dependencies.end(); - for( typename Dependencies::const_iterator it=dependencies.begin();it!=itend;++it ) - { - const SignalBase<Time> &sig = **it; - dgTDEBUG(15)<< "Ask update for "<< sig <<std::endl; - - if( (sig.getTime()>leader.getTime()) || (sig.needUpdate(t1)) ) - { if(updateFromAllChildren) continue; else {res=true; break;} } - else { if(updateFromAllChildren) {res=false; break;} else continue; } - } - lastAskForUpdate = res; - - dgTDEBUGOUT(15); - return res; -} - - -template< class Time > -std::ostream& TimeDependency<Time>:: -writeGraph( std::ostream & os) const -{ - std::string LeaderLocalName; - std::string LeaderNodeName; - leader.ExtractNodeAndLocalNames(LeaderLocalName,LeaderNodeName); - if (dependencies.size()!=0) - { - const typename Dependencies::const_iterator itend=dependencies.end(); - for( typename Dependencies::const_iterator it=dependencies.begin();it!=itend;++it ) - { - std::string itLocalName,itNodeName; - (*it)->ExtractNodeAndLocalNames(itLocalName,itNodeName); - os << "\"" << itNodeName << "\" -> \"" << LeaderNodeName << "\"" << std::endl - << " [ headlabel = \"" << LeaderLocalName << "\" , taillabel = \"" << itLocalName << "\" ]" << std::endl; - } - } - return os; -} - -template< class Time > -std::ostream& TimeDependency<Time>:: -displayDependencies( std::ostream& os,const int depth, - std::string space, - std::string next1,std::string next2 ) const -{ - leader.SignalBase<Time>::displayDependencies(os,depth,space,next1,next2)<<" ("; - switch( dependencyType ) - { - case ALWAYS_READY: os<<"A"; break; - case BOOL_DEPENDENT: os << "ready=" << ((leader.getReady())?"TRUE":"FALSE"); break; - case TIME_DEPENDENT: - os <<"t="<<leader.getTime() <<" (/"<<periodTime<<") " ; - break; - }; - os<<")"; //<<std::endl; + return os; + } + + template<class Time> + std::ostream& TimeDependency<Time>:: + displayDependencies( std::ostream& os,const int depth, + std::string space, + std::string next1,std::string next2 ) const + { + leader.SignalBase<Time>::displayDependencies(os,depth,space,next1,next2)<<" ("; + switch( dependencyType ) + { + case ALWAYS_READY: os<<"A"; break; + case BOOL_DEPENDENT: os << "ready=" << ((leader.getReady ())?"TRUE":"FALSE"); break; + case TIME_DEPENDENT: + os <<"t="<<leader.getTime () <<" (/"<<periodTime<<") " ; + break; + }; + os<<")"; //<<std::endl; { - const typename Dependencies::const_iterator itend=dependencies.end(); - for( typename Dependencies::const_iterator it=dependencies.begin();it!=itend;++it ) + const typename Dependencies::const_iterator itend=dependencies.end (); + for( typename Dependencies::const_iterator it=dependencies.begin ();it!=itend;++it ) if( depth!=0 ) { os<<std::endl; std::string ajout = "|"; std::string ajout2 = "|"; typename Dependencies::const_iterator it2=it; it2++; - if( it2==dependencies.end() ) { ajout = "`"; ajout2= " "; } + if( it2==dependencies.end () ) { ajout = "`"; ajout2= " "; } (*it)->displayDependencies( os,depth-1,space+next2+" ",ajout,ajout2 ); } else { os<<std::endl<<space<<" `-- ..."; break; } } - return os; -} - -} // namespace dynamicgraph - -#endif /* #ifndef __TIME_DEPENDENCY_TCPP */ + return os; + } +} // end of namespace dynamicgraph +# undef __TIME_DEPENDENCY_INIT +#endif //! DYNAMIC_GRAPH_TIME_DEPENDENCY_T_CPP diff --git a/include/dynamic-graph/tracer-real-time.h b/include/dynamic-graph/tracer-real-time.h index ca24598..4fb91bb 100644 --- a/include/dynamic-graph/tracer-real-time.h +++ b/include/dynamic-graph/tracer-real-time.h @@ -1,111 +1,102 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __TRACER_RT_H__ -#define __TRACER_RT_H__ - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -/* STD */ -#include <sstream> - -/* DG */ -#include <dynamic-graph/tracer.h> -#include <dynamic-graph/config-tracer-real-time.hh> - -/* --------------------------------------------------------------------- */ -/* --- TRACER ---------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -namespace dynamicgraph { - -class DG_TRACERREALTIME_DLLAPI OutStringStream - : public std::ostringstream -{ -public: - char * buffer; - size_t index; - size_t bufferSize; - bool full; - std::string givenname; - -public: - - OutStringStream( void ); - ~OutStringStream( void ); - - void resize( const unsigned int & size ); - bool addData( const char * data, const std::streamoff& size ); - void dump( std::ostream& os ); - void empty( void ); - -}; - -class DG_TRACERREALTIME_DLLAPI TracerRealTime -: public Tracer +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_TRACER_REAL_TIME_H +# define DYNAMIC_GRAPH_TRACER_REAL_TIME_H +# include <sstream> + +# include <dynamic-graph/fwd.hh> +# include <dynamic-graph/tracer.h> +# include <dynamic-graph/config-tracer-real-time.hh> + +namespace dynamicgraph { - public: - static const std::string CLASS_NAME; - virtual const std::string& getClassName( void ) { return CLASS_NAME; } - - protected: - int bufferSize; - static const int BUFFER_SIZE_DEFAULT = 1048576; // 1Mo - typedef std::list< std::ofstream* > HardFileList; - HardFileList hardFiles; - - public: - TracerRealTime( const std::string n ); - virtual ~TracerRealTime( void ){ } - - public: - virtual void closeFiles( void ); - virtual void trace( void ); - protected: - virtual void openFile( const SignalBase<int> & sig, - const std::string& filename ); - virtual void recordSignal( std::ostream& os, - const SignalBase<int>& sig ); - void emptyBuffers( void ); - - public: - void setBufferSize( const int & SIZE ) { bufferSize=SIZE; } - const int & getBufferSize( void ) { return bufferSize; } - - public: - - /* --- DISPLAY ------------------------------------------------------------ */ - void display( std::ostream& os ) const; - DG_TRACERREALTIME_DLLAPI friend std::ostream& operator<< - (std::ostream& os, const TracerRealTime& t); - - /* --- PARAMS --- */ - virtual void commandLine( const std::string& cmdLine - ,std::istringstream& cmdArgs - ,std::ostream& os ); -}; - - -} // namespace dynamicgraph - - -#endif /* #ifndef __TRACER_RT_H__ */ + class DG_TRACERREALTIME_DLLAPI OutStringStream : public std::ostringstream + { + public: + char* buffer; + size_t index; + size_t bufferSize; + bool full; + std::string givenname; + + public: + OutStringStream (); + ~OutStringStream (); + + void resize (const unsigned int & size); + bool addData (const char * data, const std::streamoff& size); + void dump (std::ostream& os); + void empty (); + }; + + class DG_TRACERREALTIME_DLLAPI TracerRealTime : public Tracer + { + public: + static const std::string CLASS_NAME; + virtual const std::string& getClassName () + { + return CLASS_NAME; + } + + protected: + int bufferSize; + static const int BUFFER_SIZE_DEFAULT = 1048576; // 1Mo + typedef std::list<std::ofstream*> HardFileList; + HardFileList hardFiles; + + public: + TracerRealTime (const std::string n); + virtual ~TracerRealTime () + {} + + public: + virtual void closeFiles (); + virtual void trace (); + protected: + virtual void openFile (const SignalBase<int>& sig, + const std::string& filename); + + virtual void recordSignal (std::ostream& os, + const SignalBase<int>& sig); + void emptyBuffers (); + + public: + void setBufferSize (const int& SIZE) + { + bufferSize=SIZE; + } + + const int& getBufferSize () + { + return bufferSize; + } + + public: + /* --- DISPLAY ---------------------------------------------------------- */ + void display (std::ostream& os) const; + DG_TRACERREALTIME_DLLAPI friend std::ostream& operator<< + (std::ostream& os, const TracerRealTime& t); + + /* --- PARAMS --- */ + virtual void commandLine (const std::string& cmdLine + ,std::istringstream& cmdArgs + ,std::ostream& os); + }; +} // end of namespace dynamicgraph + +#endif //! DYNAMIC_GRAPH_TRACER_REAL_TIME_H diff --git a/include/dynamic-graph/tracer.h b/include/dynamic-graph/tracer.h index 7d5f323..24044dd 100644 --- a/include/dynamic-graph/tracer.h +++ b/include/dynamic-graph/tracer.h @@ -1,130 +1,115 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __TRACER_H__ -#define __TRACER_H__ - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -/* STD */ -#include <string> -#include <list> -#include <boost/function.hpp> - -/* DG */ -#include <dynamic-graph/signal-base.h> -#include <dynamic-graph/signal-time-dependent.h> -#include <dynamic-graph/time-dependency.h> -#include <dynamic-graph/entity.h> -#include <dynamic-graph/exception-traces.h> - -#include <dynamic-graph/config-tracer.hh> - -/* --------------------------------------------------------------------- */ -/* --- TRACER ---------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -namespace dynamicgraph { - -class DG_TRACER_DLLAPI Tracer : public Entity +// -*- mode: c++ -*- +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#ifndef DYNAMIC_GRAPH_TRACER_H +# define DYNAMIC_GRAPH_TRACER_H +# include <string> +# include <list> +# include <boost/function.hpp> + +# include <dynamic-graph/signal-base.h> +# include <dynamic-graph/signal-time-dependent.h> +# include <dynamic-graph/time-dependency.h> +# include <dynamic-graph/entity.h> +# include <dynamic-graph/exception-traces.h> + +# include <dynamic-graph/config-tracer.hh> + +namespace dynamicgraph { - protected: - typedef std::list< const SignalBase<int>* > SignalList; - SignalList toTraceSignals; + class DG_TRACER_DLLAPI Tracer : public Entity + { + protected: + typedef std::list< const SignalBase<int>* > SignalList; + SignalList toTraceSignals; - public: - static const std::string CLASS_NAME; - virtual const std::string& getClassName( void ) { return CLASS_NAME; } + public: + static const std::string CLASS_NAME; + virtual const std::string& getClassName () { return CLASS_NAME; } - public: - enum TraceStyle + public: + enum TraceStyle { WHEN_SAID /// Record, then trace to file only when said to. ,EACH_TIME /// Record and trace to file immediately. - ,FREQUENTLY /// Record X time then trace (X is tuned by setFrenquence() ). + ,FREQUENTLY /// Record X time then trace (X is tuned by setFrenquence () ). }; - TraceStyle traceStyle; - static const TraceStyle TRACE_STYLE_DEFAULT = EACH_TIME; - double frequency; - - std::string basename; - std::string suffix; - std::string rootdir; - bool namesSet; - typedef std::list< std::ostream* > FileList; - FileList files; - typedef std::list< std::string > NameList; - NameList names; - bool play; - int timeStart; - - public: - Tracer( const std::string n ); - virtual ~Tracer( void ){ closeFiles(); } - - void addSignalToTrace( const SignalBase<int>& sig, - const std::string& filename="" ); - void clearSignalToTrace( void ); - //void parasite( SignalBase<int>& sig ); - void openFiles( const std::string& rootdir, const std::string& basename, - const std::string& suffix ); - virtual void closeFiles( void ); - - protected: - virtual void openFile( const SignalBase<int> & sig, - const std::string& filename ); - - public: - void setTraceStyle( const TraceStyle& style ){ traceStyle = style; } - TraceStyle getTraceStyle( void ){ return traceStyle; } - - void setFrenquency( const double& frqu ){ frequency = frqu; } - double getFrequency( void ){ return frequency; } - - void record( void ); - virtual void recordSignal( std::ostream& os, - const SignalBase<int>& sig ); - int& recordTrigger( int& dummy, const int& time ); - - virtual void trace( void ); - - public: - //SignalTrigerer<int> triger; - SignalTimeDependent<int,int> triger; - - /* --- DISPLAY ------------------------------------------------------------ */ - DG_TRACER_DLLAPI friend std::ostream& operator<< - (std::ostream& os,const Tracer& t); - - /* --- PARAMS --- */ - void display( std::ostream& os ) const; - virtual void commandLine( const std::string& cmdLine - ,std::istringstream& cmdArgs - ,std::ostream& os ); -}; - - -} // namespace dynamicgraph - - -#endif /* #ifndef __TRACER_H__ */ + TraceStyle traceStyle; + static const TraceStyle TRACE_STYLE_DEFAULT = EACH_TIME; + double frequency; + + std::string basename; + std::string suffix; + std::string rootdir; + bool namesSet; + typedef std::list< std::ostream* > FileList; + FileList files; + typedef std::list< std::string > NameList; + NameList names; + bool play; + int timeStart; + + public: + Tracer( const std::string n ); + virtual ~Tracer (){ closeFiles (); } + + void addSignalToTrace( const SignalBase<int>& sig, + const std::string& filename="" ); + void clearSignalToTrace (); + //void parasite( SignalBase<int>& sig ); + void openFiles( const std::string& rootdir, const std::string& basename, + const std::string& suffix ); + virtual void closeFiles (); + + protected: + virtual void openFile( const SignalBase<int> & sig, + const std::string& filename ); + + public: + void setTraceStyle( const TraceStyle& style ){ traceStyle = style; } + TraceStyle getTraceStyle (){ return traceStyle; } + + void setFrenquency( const double& frqu ){ frequency = frqu; } + double getFrequency (){ return frequency; } + + void record (); + virtual void recordSignal( std::ostream& os, + const SignalBase<int>& sig ); + int& recordTrigger( int& dummy, const int& time ); + + virtual void trace (); + + public: + //SignalTrigerer<int> triger; + SignalTimeDependent<int,int> triger; + + /* --- DISPLAY ------------------------------------------------------------ */ + DG_TRACER_DLLAPI friend std::ostream& operator<< + (std::ostream& os,const Tracer& t); + + /* --- PARAMS --- */ + void display( std::ostream& os ) const; + virtual void commandLine( const std::string& cmdLine + ,std::istringstream& cmdArgs + ,std::ostream& os ); + }; + + +} // end of namespace dynamicgraph + +#endif //! DYNAMIC_GRAPH_TRACER_H diff --git a/src/debug/contiifstream.cpp b/src/debug/contiifstream.cpp index 3e3d8ea..b4cd34c 100644 --- a/src/debug/contiifstream.cpp +++ b/src/debug/contiifstream.cpp @@ -29,32 +29,32 @@ Contiifstream( const std::string& n ) Contiifstream:: -~Contiifstream( void ) +~Contiifstream () { dgDEBUGINOUT(5); } bool Contiifstream:: -loop( void ) +loop () { dgDEBUGIN(25); bool res=false; - std::fstream file( filename.c_str() ); + std::fstream file( filename.c_str () ); file.seekg(cursor); - file.sync(); + file.sync (); while(1) { file.get(buffer,BUFFER_SIZE); - if( file.gcount() ) + if( file.gcount () ) { res=true; std::string line(buffer); if(! first) reader.push_back(line); - cursor=file.tellg(); cursor++; + cursor=file.tellg (); cursor++; file.get(*buffer); // get the last char ( = '\n') dgDEBUG(15) << "line: "<< line<<std::endl; } @@ -67,10 +67,10 @@ loop( void ) } std::string -Contiifstream::next( void ) +Contiifstream::next () { - std::string res = *reader.begin(); - reader.pop_front(); + std::string res = *reader.begin (); + reader.pop_front (); return res; } diff --git a/src/debug/debug.cpp b/src/debug/debug.cpp index 39bfb4e..8899dca 100644 --- a/src/debug/debug.cpp +++ b/src/debug/debug.cpp @@ -43,8 +43,8 @@ std::ofstream dg_debugfile; //( "/dev/null", std::ios::trunc&std::ios::out ); class dgDebug_init { public: - dgDebug_init( void ) - { dg_debugfile.setstate( std::ios::failbit ) ; /* dg_debugfile.close(); */ } + dgDebug_init () + { dg_debugfile.setstate( std::ios::failbit ) ; /* dg_debugfile.close (); */ } }; dgDebug_init dgDebug_initialisator; @@ -57,15 +57,15 @@ namespace dynamicgraph { void DebugTrace::openFile( const char * filename ) { - if( dg_debugfile.good()&&dg_debugfile.is_open() ) dg_debugfile.close(); - dg_debugfile.clear(); + if( dg_debugfile.good ()&&dg_debugfile.is_open () ) dg_debugfile.close (); + dg_debugfile.clear (); dg_debugfile.open( filename, std::ios::trunc&std::ios::out ); - //std::cout << filename << dg_debugfile.good() << dg_debugfile.is_open() << std::endl; + //std::cout << filename << dg_debugfile.good () << dg_debugfile.is_open () << std::endl; } void DebugTrace::closeFile(const char *) { - if( dg_debugfile.good()&&dg_debugfile.is_open() ) { dg_debugfile.close(); } + if( dg_debugfile.good ()&&dg_debugfile.is_open () ) { dg_debugfile.close (); } dg_debugfile.setstate( std::ios::failbit ) ; } diff --git a/src/dgraph/entity.cpp b/src/dgraph/entity.cpp index 02764fa..37b2079 100644 --- a/src/dgraph/entity.cpp +++ b/src/dgraph/entity.cpp @@ -36,7 +36,7 @@ const std::string Entity::CLASS_NAME = "Entity"; void Entity:: -entityRegistration( void ) +entityRegistration () { //sotPool.entity[name] = this; @@ -44,7 +44,7 @@ entityRegistration( void ) } void Entity:: -entityDeregistration( void ) +entityDeregistration () { g_pool.deregisterEntity(name); } @@ -54,22 +54,22 @@ Entity( const string& name__ ) : name(name__) { dgDEBUG(15) << "New entity <"<<name__<<">"<<endl; - if( name.length()==0 ) + if( name.length ()==0 ) { - stringstream oss; oss << rand(); + stringstream oss; oss << rand (); name = CLASS_NAME; name+="::"; - name+=oss.str(); + name+=oss.str (); } - entityRegistration(); + entityRegistration (); } Entity:: -~Entity( void ) +~Entity () { dgDEBUG(25) << "# In (" << name << " { " << endl; - entityDeregistration(); + entityDeregistration (); dgDEBUGOUT(25); } @@ -79,32 +79,32 @@ Entity:: void Entity:: signalRegistration( const SignalArray<int>& signals ) { - for( unsigned int i=0;i<signals.getSize();++i ) + for( unsigned int i=0;i<signals.getSize ();++i ) { SignalBase<int>& sig = signals[i]; - //const string& signame = sig.getName(); - istringstream iss( sig.getName() ); + //const string& signame = sig.getName (); + istringstream iss( sig.getName () ); const int SIZE = 128; char buffer[SIZE]; - while( iss.good() ) + while( iss.good () ) { iss.getline(buffer,SIZE,':'); } const string& signame( buffer ); SignalMap::iterator sigkey = signalMap.find(signame); - if( sigkey != signalMap.end() ) // key does exist + if( sigkey != signalMap.end () ) // key does exist { - dgERRORF( "Key %s already exist in the signalMap.",signame.c_str() ); + dgERRORF( "Key %s already exist in the signalMap.",signame.c_str () ); if( sigkey->second!=&sig ) { throw ExceptionFactory( ExceptionFactory::SIGNAL_CONFLICT, "Another signal already defined with the same name. ", - "Signame is <%s>.",signame.c_str() ); + "Signame is <%s>.",signame.c_str () ); } } else { dgDEBUG(10) << "Register signal <"<< signame << "> for entity <" - << getName() << "> ."<<endl; + << getName () << "> ."<<endl; signalMap[signame] = &sig; } } @@ -115,17 +115,17 @@ void Entity:: signalDeregistration( const std::string& signame ) { SignalMap::iterator sigkey = signalMap.find(signame); - if( sigkey == signalMap.end() ) // key does not exist + if( sigkey == signalMap.end () ) // key does not exist { - dgERRORF( "Key %s does not exist in the signalMap.",signame.c_str() ); + dgERRORF( "Key %s does not exist in the signalMap.",signame.c_str () ); throw ExceptionFactory( ExceptionFactory::UNREFERED_SIGNAL, "No signal defined with the given name. ", - " (while erasing <%s>).",signame.c_str() ); + " (while erasing <%s>).",signame.c_str () ); } else { dgDEBUG(10) << "Deregister signal <"<< signame << "> for entity <" - << getName() << "> ."<<endl; + << getName () << "> ."<<endl; signalMap.erase(signame); } } @@ -133,11 +133,11 @@ signalDeregistration( const std::string& signame ) #define __DG_ENTITY_GET_SIGNAL__(ITER_TYPE) \ SignalMap::ITER_TYPE sigkey = signalMap.find(signame); \ - if( sigkey == signalMap.end() ) /* key does NOT exist */ \ + if( sigkey == signalMap.end () ) /* key does NOT exist */ \ { \ throw ExceptionFactory( ExceptionFactory::UNREFERED_SIGNAL,\ "The requested signal is not registered",\ - ": %s",signame.c_str() );\ + ": %s",signame.c_str () );\ }\ return *(sigkey ->second) ; @@ -159,9 +159,9 @@ getSignal( const string & signame ) const std::ostream& Entity:: displaySignalList( std::ostream& os ) const { - os << "--- <" << getName() << "> signal list: "<<endl; - const SignalMap::const_iterator iterend=signalMap.end(); - for( SignalMap::const_iterator iter = signalMap.begin();iterend!=iter;++iter ) + os << "--- <" << getName () << "> signal list: "<<endl; + const SignalMap::const_iterator iterend=signalMap.end (); + for( SignalMap::const_iterator iter = signalMap.begin ();iterend!=iter;++iter ) { os << " "; if( (++iter)--==iterend ) os << "`"; else os <<"|"; os << "-- <" << *(iter->second) << endl; @@ -172,8 +172,8 @@ displaySignalList( std::ostream& os ) const std::ostream& Entity:: writeGraph( std::ostream& os ) const { - const SignalMap::const_iterator iterend=signalMap.end(); - for( SignalMap::const_iterator iter = signalMap.begin();iterend!=iter;++iter ) + const SignalMap::const_iterator iterend=signalMap.end (); + for( SignalMap::const_iterator iter = signalMap.begin ();iterend!=iter;++iter ) { (*(iter->second)).writeGraph(os); @@ -184,21 +184,21 @@ writeGraph( std::ostream& os ) const std::ostream& Entity:: writeCompletionList( std::ostream& os ) const { - const SignalMap::const_iterator iterend=signalMap.end(); - for( SignalMap::const_iterator iter = signalMap.begin();iterend!=iter;++iter ) + const SignalMap::const_iterator iterend=signalMap.end (); + for( SignalMap::const_iterator iter = signalMap.begin ();iterend!=iter;++iter ) { - os << getName() << "." << (*(iter->second)).shortName() << std::endl; + os << getName () << "." << (*(iter->second)).shortName () << std::endl; } - os << getCommandList() << std::endl; + os << getCommandList () << std::endl; return os; } void Entity:: display( std::ostream& os ) const { - os<<this->getClassName()<<": "<<name; + os<<this->getClassName ()<<": "<<name; } std::ostream& dynamicgraph::operator<< (std::ostream& os, const Entity& ent ) @@ -213,7 +213,7 @@ std::ostream& dynamicgraph::operator<< (std::ostream& os, const Entity& ent ) static std::string Entity_COMMAND_LIST = "print\nsignals\nsignalDep"; const std::string& Entity:: -getCommandList( void ) const +getCommandList () const { return Entity_COMMAND_LIST; } @@ -238,7 +238,7 @@ commandLine( const std::string& cmdLine,std::istringstream& cmdArgs,std::ostream { string sig; cmdArgs>>sig; cmdArgs >> ws; int depth=-1; - if( cmdArgs.good() ) { cmdArgs >> depth; } + if( cmdArgs.good () ) { cmdArgs >> depth; } getSignal(sig) .displayDependencies( os,depth ); os<<endl; } else @@ -247,18 +247,18 @@ commandLine( const std::string& cmdLine,std::istringstream& cmdArgs,std::ostream SignalBase<int> & sig = getSignal( cmdLine ); int time; cmdArgs>>ws; - if( cmdArgs.good() ) + if( cmdArgs.good () ) {cmdArgs >> time;} else {time=0;} sig.recompute( time ); os << cmdLine << " = "; sig.get( os ); } catch( ExceptionFactory& e ) { - switch( e.getCode() ) + switch( e.getCode () ) { case ExceptionFactory::UNREFERED_SIGNAL: DG_THROW ExceptionFactory( ExceptionFactory::UNREFERED_FUNCTION, "The requested function/signal :","<%s> is " - "not registered.",cmdLine.c_str() ); + "not registered.",cmdLine.c_str () ); break; default: throw; diff --git a/src/dgraph/factory.cpp b/src/dgraph/factory.cpp index cb8ca88..341c103 100644 --- a/src/dgraph/factory.cpp +++ b/src/dgraph/factory.cpp @@ -24,11 +24,11 @@ using namespace dynamicgraph; namespace dynamicgraph { - FactoryStorage::FactoryStorage () - : entityMap () + FactoryStorage::FactoryStorage () + : entityMap () {} - FactoryStorage::~FactoryStorage () + FactoryStorage::~FactoryStorage () { dgDEBUGINOUT (25); } @@ -44,10 +44,10 @@ namespace dynamicgraph (ExceptionFactory::OBJECT_CONFLICT, "Another entity class already defined with the same name. ", "(while adding entity class <%s> inside the g_factory).", - entname.c_str ()); + entname.c_str ()); dgERRORF ("Another entity class already defined with the same name. " "(while adding entity class <%s> inside the factory).", - entname.c_str ()); + entname.c_str ()); } else { @@ -75,11 +75,11 @@ namespace dynamicgraph DG_THROW ExceptionFactory( ExceptionFactory::OBJECT_CONFLICT, "Entity class not defined yet. ", "(while removing entity class <%s>).", - entname.c_str() ); + entname.c_str () ); dgERRORF(ExceptionFactory::OBJECT_CONFLICT, "Entity class not defined yet. " "(while removing entity class <%s>).", - entname.c_str() ); + entname.c_str () ); } else { @@ -98,13 +98,13 @@ namespace dynamicgraph << objname << ">" << std::endl; EntityMap::const_iterator entPtr = entityMap.find (classname); - if (entPtr == entityMap.end ()) + if (entPtr == entityMap.end ()) { DG_THROW ExceptionFactory (ExceptionFactory::UNREFERED_OBJECT, "Unknown entity.", " (while calling new_entity <%s>)", - classname.c_str ()); + classname.c_str ()); } return entPtr->second (objname); } @@ -116,8 +116,8 @@ namespace dynamicgraph FactoryStorage::existEntity (const std::string& name) const { EntityMap::const_iterator lb = entityMap.lower_bound (name); - return lb != entityMap.end () - && !(entityMap.key_comp () (name, lb->first)); + return lb != entityMap.end () + && !(entityMap.key_comp () (name, lb->first)); } //FIXME: this should be removed at some point. @@ -141,7 +141,7 @@ namespace dynamicgraph std::string cmd2; cmdArgs >> cmd2; - if (!cmdArgs.good ()) + if (!cmdArgs.good ()) os << " <arg>\t\t\t\taccess to the factory (help <arg> for more detail)" << std::endl; @@ -177,7 +177,7 @@ namespace dynamicgraph dgDEBUGOUT (15); } - EntityRegisterer::~EntityRegisterer() + EntityRegisterer::~EntityRegisterer () { dgDEBUGIN(15); g_factory.deregisterEntity (entityName); diff --git a/src/dgraph/import.cpp b/src/dgraph/import.cpp index 058a2e1..d2e3f91 100644 --- a/src/dgraph/import.cpp +++ b/src/dgraph/import.cpp @@ -54,7 +54,7 @@ namespace dynamicgraph namespace { /// Initialize import paths list (called during static initialization). - std::vector<std::string> initializePaths (); + std::vector<std::string> initializePaths (); /// \brief Import paths list. /// @@ -68,7 +68,7 @@ namespace dynamicgraph /// /// When typing ``import foo'', C will be searched first then B /// and A. The search stops when the file is found. - std::vector<std::string> importPaths = initializePaths (); + std::vector<std::string> importPaths = initializePaths (); /// Search for a module. /// @@ -81,7 +81,7 @@ namespace dynamicgraph /// Transform strings such as "foo" or 'foo' into foo. void removeQuotes (std::string& msg); - std::vector<std::string> initializePaths () + std::vector<std::string> initializePaths () { std::vector<std::string> importPaths; importPaths.push_back (DG_IMPORT_DEFAULT_PATHS); @@ -108,8 +108,8 @@ namespace dynamicgraph // Insert it back. std::back_insert_iterator<std::vector<std::string> > bi (importPaths); - std::copy (splittedEnvironmentVariable.begin (), - splittedEnvironmentVariable.end (), bi); + std::copy (splittedEnvironmentVariable.begin (), + splittedEnvironmentVariable.end (), bi); return importPaths; } @@ -118,29 +118,29 @@ namespace dynamicgraph // Make sure the traversal is right to left to enforce // correct priorities. typedef std::vector<std::string>::const_reverse_iterator citer_t; - for (citer_t it = importPaths.rbegin (); - it != importPaths.rend (); ++it) + for (citer_t it = importPaths.rbegin (); + it != importPaths.rend (); ++it) { const std::string& path = *it; - assert (!path.empty ()); + assert (!path.empty ()); std::string filename (path); - if (filename[filename.length () - 1] != '/') + if (filename[filename.length () - 1] != '/') filename += "/"; filename += module; - std::ifstream file (filename.c_str ()); - if (file.is_open () && file.good ()) + std::ifstream file (filename.c_str ()); + if (file.is_open () && file.good ()) return filename; } - return std::string (); + return std::string (); } void removeQuotes (std::string& msg) { - if ((msg[0] == '"' && msg[msg.length () - 1] == '"') - || (msg[0] == '\'' && msg[msg.length () - 1] == '\'')) - msg = msg.substr (1, msg.length () - 2); + if ((msg[0] == '"' && msg[msg.length () - 1] == '"') + || (msg[0] == '\'' && msg[msg.length () - 1] == '\'')) + msg = msg.substr (1, msg.length () - 2); } } // end of anonymous namespace. @@ -168,12 +168,12 @@ namespace dynamicgraph removeQuotes (module); std::string filename = searchModule (module); - std::ifstream file (filename.c_str ()); - if (filename.empty () || !file.is_open () || !file.good ()) + std::ifstream file (filename.c_str ()); + if (filename.empty () || !file.is_open () || !file.good ()) { std::string scriptDirectories; - if (importPaths.empty ()) + if (importPaths.empty ()) scriptDirectories = "empty"; else { @@ -183,7 +183,7 @@ namespace dynamicgraph scriptDirectories += ", "; } scriptDirectories = scriptDirectories.substr - (0, scriptDirectories.length () - 2); + (0, scriptDirectories.length () - 2); } boost::format fmt @@ -191,21 +191,21 @@ namespace dynamicgraph fmt % module; fmt % scriptDirectories; DG_THROW ExceptionFactory - (ExceptionFactory::READ_FILE, fmt.str ()); + (ExceptionFactory::READ_FILE, fmt.str ()); return; } int lineIdx = 0; try { - while (file.good ()) + while (file.good ()) { ++lineIdx; dgDEBUGIN (15); std::string line; std::getline (file, line); - if (line.empty ()) + if (line.empty ()) continue; std::istringstream iss (line); @@ -216,7 +216,7 @@ namespace dynamicgraph std::getline (iss, currentCmdArgs); boost::format fmt ("Run ``%1%'' with args ``%2%''"); fmt % currentCmdName % currentCmdArgs; - dgDEBUG(25) << fmt.str () << std::endl; + dgDEBUG(25) << fmt.str () << std::endl; std::istringstream issArgs (currentCmdArgs); interpreter.cmd (currentCmdName, issArgs, os); } @@ -226,10 +226,10 @@ namespace dynamicgraph catch (ExceptionAbstract& exc) { // FIXME: come on... - std::string& msg = const_cast<std::string&> (exc.getStringMessage ()); + std::string& msg = const_cast<std::string&> (exc.getStringMessage ()); boost::format fmt (" (in line %1% of file ``%2%'')"); fmt % lineIdx % filename; - msg = msg + fmt.str(); + msg = msg + fmt.str (); std::cout << msg << std::endl; throw; } @@ -266,8 +266,8 @@ namespace dynamicgraph << std::endl; return; } - if (!importPaths.empty ()) - importPaths.pop_back (); + if (!importPaths.empty ()) + importPaths.pop_back (); } } // end of namespace command. diff --git a/src/dgraph/interpreter-helper.cpp b/src/dgraph/interpreter-helper.cpp index 6483594..bc459c4 100644 --- a/src/dgraph/interpreter-helper.cpp +++ b/src/dgraph/interpreter-helper.cpp @@ -1,187 +1,161 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - -/* --------------------------------------------------------------------- */ -/* --- INCLUDE --------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -/* DYNAMIC-GRAPH */ -#include <dynamic-graph/interpreter-helper.h> -#include <dynamic-graph/plugin-loader.h> -#include <dynamic-graph/debug.h> - -/* --- STD --- */ -using namespace std; -using namespace dynamicgraph; - -/* --------------------------------------------------------------------- */ -/* --- CLASS ----------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - - -InterpreterHelper::InterpreterHelper() -{ -} - +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. -/* --------------------------------------------------------------------- */ -/* --- NEW ------------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ -#include <dynamic-graph/factory.h> -using namespace std; +#include <dynamic-graph/debug.h> #include <dynamic-graph/entity.h> +#include <dynamic-graph/factory.h> +#include <dynamic-graph/interpreter-helper.h> +#include <dynamic-graph/plugin-loader.h> +#include <dynamic-graph/pool.h> #include <dynamic-graph/signal-base.h> -void InterpreterHelper:: -cmdPlug( const std::string& obj1, const std::string & signame1, - const std::string& obj2, const std::string & signame2, - std::ostream& ) -{ - dgDEBUG(20) << "Get Ent1 <"<<obj1<<"> ."<<endl; - Entity& ent1 = g_pool.getEntity(obj1); - dgDEBUG(20) << "Get Sig1 <"<<signame1<<"> ."<<endl; - SignalBase<int> &sig1 = ent1.getSignal(signame1); - - dgDEBUG(20) << "Get Ent2 <"<<obj2<<"> ."<<endl; - Entity& ent2 = g_pool.getEntity(obj2); - dgDEBUG(20) << "Get Sig2 <"<<signame2<<"> ."<<endl; - SignalBase<int> &sig2 = ent2.getSignal(signame2); - - dgDEBUG(25) << "Plug..."<<endl; - sig2.plug(&sig1); -} - -void InterpreterHelper:: -cmdNew( const std::string& className, - const std::string& objName, - std::ostream& os ) -{ - dgDEBUG(15) << "New <" << className<<"> requested."<<endl; - if( g_factory.existEntity( className ) ) - { - dgDEBUG(15) << "New entity<"<<className<<"> " <<objName<<std::endl; - g_factory.newEntity(className,objName); - } - else os << " !! Class <" << className << "> does not exist."<<endl; -} - - -void InterpreterHelper:: -cmdDestroy( const std::string& objName, - std::ostream& ) -{ - - dgDEBUG(15) << "Destroy <" << objName <<"> requested."<<endl; - delete &( g_pool.getEntity( objName ) ); - -} - -void InterpreterHelper:: -cmdLoadPlugin( const std::string& directory, - const std::string& pluginName, - std::ostream& ) +namespace dynamicgraph { - - if( directory.length() != 0 ) dlPtr.setDirectory( directory ); - dlPtr.addPlugin( pluginName ); - - try{ - dgDEBUG(15) << "Try to load " << pluginName<< endl; - dlPtr.loadPlugins(); - }catch( ExceptionAbstract& e ) { dgDEBUG(5) << e << endl; throw e; } -} - -void InterpreterHelper:: -cmdUnloadPlugin( const std::string& pluginName, - std::ostream& ) -{ - - dgDEBUGIN(15); - try{ - dgDEBUG(25) << "Try short name " << pluginName << endl; - const std::string& fullname = dlPtr.searchPlugin(pluginName); - dgDEBUG(25) << "Full name " << fullname << endl; - dlPtr.unloadPlugin(fullname); + void + InterpreterHelper::cmdPlug (const std::string& obj1, + const std::string& signame1, + const std::string& obj2, + const std::string& signame2, + std::ostream&) + { + dgDEBUG (20) << "Get Ent1 <" << obj1 << "> ." << std::endl; + Entity& ent1 = g_pool.getEntity (obj1); + dgDEBUG (20) << "Get Sig1 <" << signame1 << "> ." << std::endl; + SignalBase<int>& sig1 = ent1.getSignal (signame1); + + dgDEBUG (20) << "Get Ent2 <" << obj2 << "> ." << std::endl; + Entity& ent2 = g_pool.getEntity (obj2); + dgDEBUG (20) << "Get Sig2 <" << signame2 << "> ." << std::endl; + SignalBase<int>& sig2 = ent2.getSignal (signame2); + + dgDEBUG (25) << "Plug..." << std::endl; + sig2.plug (&sig1); } - catch(...) - { - dgDEBUG(25) << "Full name " << pluginName << endl; - dlPtr.unloadPlugin(pluginName); - } - - dgDEBUGOUT(15); -} - -void InterpreterHelper:: -cmdSetSignal( const std::string& objname, - const std::string& signame, - const std::string& value, - std::ostream& ) -{ - dgDEBUGIN(15); - - Entity& obj = g_pool.getEntity(objname); - SignalBase<int>& sig = obj.getSignal( signame ); - istringstream cmdArg(value); - sig.set( cmdArg ); + void + InterpreterHelper::cmdNew (const std::string& className, + const std::string& objName, + std::ostream& os) + { + dgDEBUG(15) << "New <" << className << "> requested." << std::endl; + if (g_factory.existEntity (className)) + { + dgDEBUG(15) << "New entity<" << className << "> " + << objName << std::endl; + g_factory.newEntity (className, objName); + } + else + os << " !! Class <" << className << "> does not exist." << std::endl; + } - dgDEBUGOUT(15); -} + void + InterpreterHelper::cmdDestroy (const std::string& objName, std::ostream&) + { + dgDEBUG(15) << "Destroy <" << objName << "> requested." << std::endl; + delete &(g_pool.getEntity (objName)); + } -void InterpreterHelper:: -cmdGetSignal( const std::string& objname, - const std::string& signame, - std::ostream& os ) -{ - dgDEBUGIN(15); + void + InterpreterHelper::cmdLoadPlugin (const std::string& directory, + const std::string& pluginName, + std::ostream&) + { + if (directory.length () != 0) + dlPtr.setDirectory (directory); + dlPtr.addPlugin (pluginName); + + try + { + dgDEBUG(15) << "Try to load " << pluginName<< std::endl; + dlPtr.loadPlugins (); + } + catch (const ExceptionAbstract& e) + { + dgDEBUG(5) << e << std::endl; + throw; + } + } - Entity& obj = g_pool.getEntity(objname); - SignalBase<int>& sig = obj.getSignal( signame ); + void + InterpreterHelper::cmdUnloadPlugin (const std::string& pluginName, + std::ostream&) + { + dgDEBUGIN (15); + try + { + dgDEBUG (25) << "Try short name " << pluginName << std::endl; + const std::string& fullname = dlPtr.searchPlugin (pluginName); + dgDEBUG(25) << "Full name " << fullname << std::endl; + dlPtr.unloadPlugin (fullname); + } + catch (...) + { + dgDEBUG(25) << "Full name " << pluginName << std::endl; + dlPtr.unloadPlugin (pluginName); + } + + dgDEBUGOUT (15); + } - os << signame << " = "; sig.get( os ); + void + InterpreterHelper::cmdSetSignal (const std::string& objname, + const std::string& signame, + const std::string& value, + std::ostream&) + { + dgDEBUGIN (15); - dgDEBUGOUT(15); + Entity& obj = g_pool.getEntity (objname); + SignalBase<int>& sig = obj.getSignal (signame); -} + std::istringstream cmdArg (value); + sig.set (cmdArg); -void InterpreterHelper:: -cmdComputeSignal( const std::string& objname, - const std::string& signame, - const int &time, - std::ostream& ) -{ - dgDEBUGIN(15); + dgDEBUGOUT (15); + } - Entity& obj = g_pool.getEntity(objname); - SignalBase<int>& sig = obj.getSignal( signame ); + void + InterpreterHelper::cmdGetSignal (const std::string& objname, + const std::string& signame, + std::ostream& os) + { + dgDEBUGIN (15); - sig.recompute( time ); + Entity& obj = g_pool.getEntity (objname); + SignalBase<int>& sig = obj.getSignal (signame); - dgDEBUGOUT(15); + os << signame << " = "; + sig.get (os); -} + dgDEBUGOUT (15); + } + void + InterpreterHelper::cmdComputeSignal (const std::string& objname, + const std::string& signame, + const int& time, + std::ostream&) + { + dgDEBUGIN (15); + Entity& obj = g_pool.getEntity (objname); + SignalBase<int>& sig = obj.getSignal (signame); -/* --------------------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ -/* --------------------------------------------------------------------- */ + sig.recompute (time); + dgDEBUGOUT (15); + } +} // end of namespace dynamicgraph. diff --git a/src/dgraph/interpreter.cpp b/src/dgraph/interpreter.cpp index d4ab490..64a7ee0 100644 --- a/src/dgraph/interpreter.cpp +++ b/src/dgraph/interpreter.cpp @@ -67,15 +67,15 @@ registerFunction( const string& funname, { if( initDone ) {dgDEBUG(15) << "Register " << funname << std::endl;} FunctionMap::iterator funkey = functionMap.find(funname); - if( funkey != functionMap.end() ) // key does exist + if( funkey != functionMap.end () ) // key does exist { if( initDone ) { dgDEBUG(15) << "!! Another function already defined with the same name. Overloading " - << "Funname is" <<funname.c_str() << endl; + << "Funname is" <<funname.c_str () << endl; throw ExceptionFactory( ExceptionFactory::FUNCTION_CONFLICT, "Another function already defined with the same name. ", - "Funname is <%s>.",funname.c_str() ); + "Funname is <%s>.",funname.c_str () ); } } @@ -123,8 +123,8 @@ cmdPlug( const std::string& cmdLine, istringstream& cmdArg, std::ostream& os ) { DG_THROW ExceptionFactory( ExceptionFactory::SYNTAX_ERROR, "Plug function: syntax is plug OBJ1.SIG1 OBJ2.SIG2.", - "(while calling plug %s %s).",ssig1.c_str(), - ssig2.c_str() ); + "(while calling plug %s %s).",ssig1.c_str (), + ssig2.c_str () ); } dgDEBUG(20) << "Get Ent1 <"<<obj1<<"> ."<<endl; @@ -193,14 +193,14 @@ cmdLoadPlugin( const std::string& cmdLine, std::istringstream& cmdArg, std::ostr string pluginName,directory; cmdArg >> pluginName; cmdArg >> directory; - if( directory.length() != 0 ) dlPtr->setDirectory( directory ); + if( directory.length () != 0 ) dlPtr->setDirectory( directory ); dlPtr ->addPlugin( pluginName ); try { dgDEBUG(15) << "Try to load " << pluginName<< endl; dgDEBUG(25)<<"sotShell.dlPtr ="<< this->dlPtr <<endl; - dlPtr->loadPlugins(); + dlPtr->loadPlugins (); dgDEBUG(25)<<"sotShell.dlPtr ="<< this->dlPtr <<endl; } catch (const ExceptionAbstract& e) @@ -254,18 +254,18 @@ cmdHelp( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& o std::string procname; bool personalizedHelp = false; cmdArg >> ws; - if( cmdArg.good() ) + if( cmdArg.good () ) { - const std::streamoff gc = cmdArg.tellg(); + const std::streamoff gc = cmdArg.tellg (); cmdArg >> procname; - cmdArg.seekg(gc); cmdArg.clear(); + cmdArg.seekg(gc); cmdArg.clear (); personalizedHelp = true; dgDEBUG(15)<< "Personalized help on <"<< procname<<">"<<gc<<endl; } bool procfund = !personalizedHelp; - for( FunctionMap::const_iterator iter=functionMap.begin(); - iter!=functionMap.end();++iter ) + for( FunctionMap::const_iterator iter=functionMap.begin (); + iter!=functionMap.end ();++iter ) { if( iter->first!="help" ) if( (! personalizedHelp) || ( procname==iter->first ) ) @@ -290,13 +290,13 @@ cmdRun( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os string filename; cmdArg>>filename; dgDEBUG(25) << "Script <" <<filename<<">"<<endl; - ifstream script( filename.c_str(),ios::in ); - if(! script.is_open() ) + ifstream script( filename.c_str (),ios::in ); + if(! script.is_open () ) { boost::format fmt ("failed to run file ``%1%'' (file does not exist or is not readable)."); fmt % filename; - DG_THROW ExceptionFactory (ExceptionFactory::READ_FILE, fmt.str ()); + DG_THROW ExceptionFactory (ExceptionFactory::READ_FILE, fmt.str ()); } const int SIZE = 16384; @@ -309,7 +309,7 @@ cmdRun( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os dgDEBUGIN(15); script.getline (line, SIZE); - if (!script.good ()) + if (!script.good ()) break; std::string name; @@ -331,10 +331,10 @@ cmdRun( const std::string& cmdLine, std::istringstream& cmdArg, std::ostream& os catch (ExceptionAbstract& exc) { //FIXME: exception should be changed instead. - std::string& msg = const_cast<std::string&>(exc.getStringMessage()); + std::string& msg = const_cast<std::string&>(exc.getStringMessage ()); std::stringstream oss; oss << " (in line " << lineIdx <<" of file <" << filename << ">)"; - msg = msg + oss.str(); + msg = msg + oss.str (); throw exc; } @@ -405,7 +405,7 @@ cmdComputeSignal( const std::string& cmdLine, std::istringstream& cmdArg, std::o SignalBase<int>& sig = obj.getSignal( signame ); int time; cmdArg >> std::ws; - if( cmdArg.good() ) + if( cmdArg.good () ) {cmdArg >> time;} else {time=0;} sig.recompute( time ); @@ -422,7 +422,7 @@ cmdComputeSignal( const std::string& cmdLine, std::istringstream& cmdArg, std::o void Interpreter:: cmd( const std::string& cmdLine, istringstream& cmdArg, std::ostream& os ) { - istringstream cmdparse(cmdLine.c_str()); + istringstream cmdparse(cmdLine.c_str ()); string obj,fun; if (cmdLine.find_first_not_of(" ") == string::npos) {} @@ -435,11 +435,11 @@ cmd( const std::string& cmdLine, istringstream& cmdArg, std::ostream& os ) { dgDEBUG(15) << "Function <" << cmdLine <<">"<< endl; FunctionMap::iterator funPtr = functionMap .find( cmdLine ); - if( funPtr == functionMap.end() ) + if( funPtr == functionMap.end () ) { DG_THROW ExceptionFactory( ExceptionFactory::UNREFERED_FUNCTION, "Unknown function."," (while calling <%s>)", - cmdLine.c_str() ); + cmdLine.c_str () ); } funPtr->second(cmdLine,cmdArg,os); } @@ -455,7 +455,7 @@ objectNameParser( istringstream& cmdparse,std::string& objName,std::string& funN char buffer[SIZE]; cmdparse >> ws; cmdparse.getline( buffer,SIZE,'.' ); - if(! cmdparse.good() ) // The callback is not an object method + if(! cmdparse.good () ) // The callback is not an object method return false; objName = buffer; @@ -473,21 +473,21 @@ shell( std::istream& sin, std::ostream& sout, const std::string& promptUser ) { while( 1 ) { - if( promptUser.length() ) sout << promptUser; else sout << prompt; + if( promptUser.length () ) sout << promptUser; else sout << prompt; string cmdLine; const int SIZE = 16384; char cmdArgs[SIZE]; sin >>skipws>> cmdLine ; dgDEBUG(15) << "Cmd <" <<cmdLine<<">"<<endl; if( cmdLine == "exit" ) break; - if( sin.eof() ) break; + if( sin.eof () ) break; sin.getline( cmdArgs,SIZE-1 ); - if( sin.gcount() >= SIZE-2 ) + if( sin.gcount () >= SIZE-2 ) { sout << "!! Line size exceeded" << endl; - do{ sin.getline( cmdArgs,SIZE-1 ); } while ( sin.gcount() >= SIZE-2 ); + do{ sin.getline( cmdArgs,SIZE-1 ); } while ( sin.gcount () >= SIZE-2 ); sout << cmdArgs << endl; } else @@ -497,7 +497,7 @@ shell( std::istream& sin, std::ostream& sout, const std::string& promptUser ) istringstream args (cmdArgs); try{ cmd(cmdLine,args,sout); } - catch( exception& e ) { dgDEBUG(1) << e.what(); throw; } + catch( exception& e ) { dgDEBUG(1) << e.what (); throw; } catch(...) { dgDEBUG(1) << "!! unknow!." <<endl; throw; } } } @@ -515,8 +515,8 @@ ShellFunctionRegisterer( const std::string& funName, void Interpreter::writeCompletionList(std::ostream& os) { - for (FunctionMap::iterator iter=functionMap.begin (); - iter != functionMap.end (); ++iter) + for (FunctionMap::iterator iter=functionMap.begin (); + iter != functionMap.end (); ++iter) { const std::string & name = iter->first; os << name << std::endl; diff --git a/src/dgraph/plugin-loader.cpp b/src/dgraph/plugin-loader.cpp index 27869e9..d5cd531 100644 --- a/src/dgraph/plugin-loader.cpp +++ b/src/dgraph/plugin-loader.cpp @@ -29,9 +29,11 @@ #endif /* --- DYNAMIC-GRAPH --- */ +#include <dynamic-graph/exception-factory.h> #include <dynamic-graph/plugin-loader.h> #include <dynamic-graph/debug.h> + /* --- STD --- */ #include <fstream> #include <sstream> @@ -57,13 +59,13 @@ public: PluginLoader:: -PluginLoader( void ) +PluginLoader () { - pluginRefs = new PluginRefMap(); + pluginRefs = new PluginRefMap (); } PluginLoader:: -~PluginLoader( void ) +~PluginLoader () { delete pluginRefs; } @@ -74,7 +76,7 @@ setDirectory( const std::string& n ) return pluginDirectory = n; } const std::string& PluginLoader:: -getDirectory( void ) +getDirectory () const { return pluginDirectory; } @@ -87,18 +89,18 @@ loadPluginList( const std::string& configFileName, const std::string& dir ) string name; //while (1) - ifstream configFile( configFileName.c_str(),ios::in ); - if(! configFile.is_open()) + ifstream configFile( configFileName.c_str (),ios::in ); + if(! configFile.is_open ()) { DG_THROW ExceptionFactory( ExceptionFactory::READ_FILE, "File is not open."," (while reading <%s>).", - configFileName.c_str() ); + configFileName.c_str () ); } for(;;) { configFile>>name; - if(configFile.eof()) break; + if(configFile.eof ()) break; dgDEBUG(9)<<"Add <"<< name << "> to the list"<<endl; addPlugin( name,dir); } @@ -110,7 +112,7 @@ void PluginLoader:: addPlugin( const std::string& name, const std::string& dir ) { dgDEBUGIN(15); - if( dir.length() ) + if( dir.length () ) pluginNames.push_back( dir +"/"+name ); else { pluginNames.push_back( pluginDirectory +"/"+name ); } @@ -125,18 +127,18 @@ addPlugin( const std::string& name, const std::string& dir ) /* --- DYNAMIC LOADER LIB --------------------------------------------------- */ /* -------------------------------------------------------------------------- */ void PluginLoader:: -loadPlugins( void ) +loadPlugins () { dgDEBUGIN(15); - for( list<string>::iterator iter = pluginNames.begin(); - iter!=pluginNames.end();++iter ) + for( list<string>::iterator iter = pluginNames.begin (); + iter!=pluginNames.end ();++iter ) { dgDEBUG(9)<<"Load <"<< *iter << "> plugin"<<endl; #ifndef WIN32 - PluginRefMap::plugin_key_type dlib = dlopen( iter->c_str(),RTLD_NOW|RTLD_GLOBAL); + PluginRefMap::plugin_key_type dlib = dlopen( iter->c_str (),RTLD_NOW|RTLD_GLOBAL); #else - PluginRefMap::plugin_key_type dlib = LoadLibrary ( iter->c_str()); + PluginRefMap::plugin_key_type dlib = LoadLibrary ( iter->c_str ()); #endif dgDEBUG(19)<<"Plugin <"<< *iter << "> loaded "<<endl; @@ -156,15 +158,15 @@ loadPlugins( void ) // exception is thrown just after. MS Windows do not raise // an exception here and must have an incoherent behavior // anyway... - iter = pluginNames.begin(); + iter = pluginNames.begin (); #ifndef WIN32 - dgDEBUG(5) << "Failure while loading: " <<dlerror() <<endl; + dgDEBUG(5) << "Failure while loading: " <<dlerror () <<endl; DG_THROW ExceptionFactory( ExceptionFactory::DYNAMIC_LOADING, - "Error while dlopen. ","<%s>",dlerror() ); + "Error while dlopen. ","<%s>",dlerror () ); #else // Retrieve the system error message for the last-error code LPTSTR pszMessage; - DWORD dwLastError = GetLastError(); + DWORD dwLastError = GetLastError (); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | @@ -182,7 +184,7 @@ loadPlugins( void ) error_of << "Error while LoadLibrary (" << wrongLib << ") "; DG_THROW ExceptionFactory( ExceptionFactory::DYNAMIC_LOADING, - error_of.str().c_str(), pszMessage ); + error_of.str ().c_str (), pszMessage ); LocalFree(pszMessage); @@ -192,7 +194,7 @@ loadPlugins( void ) loadedPluginNames[*iter] = (*iter); pluginRefs->keyMap[*iter] = dlib; } - pluginNames.clear(); + pluginNames.clear (); dgDEBUGOUT(15); } @@ -208,10 +210,10 @@ unloadPlugin( const std::string& plugname ) dgDEBUGIN( 15 ); PluginRefMap::KeyMap::iterator plugkey = pluginRefs->keyMap.find(plugname); - if( plugkey==pluginRefs->keyMap.end() ) // key does exist + if( plugkey==pluginRefs->keyMap.end () ) // key does exist { throw ExceptionFactory( ExceptionFactory::OBJECT_CONFLICT, - "Plugin not loaded",": <%s>.",plugname.c_str() ); + "Plugin not loaded",": <%s>.",plugname.c_str () ); } #ifndef WIN32 @@ -223,11 +225,11 @@ unloadPlugin( const std::string& plugname ) { #ifndef WIN32 dgDEBUG(1) << "Error while unloading <" << plugname <<"> : " - << dlerror() <<endl; + << dlerror () <<endl; #else // Retrieve the system error message for the last-error code LPTSTR pszMessage; - DWORD dwLastError = GetLastError(); + DWORD dwLastError = GetLastError (); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | @@ -255,8 +257,8 @@ searchPlugin( const std::string& plugname ) { unsigned int refFound = 0; const std::string *plugFullName =0; - for( PluginRefMap::KeyMap::iterator iter = pluginRefs->keyMap.begin(); - iter!=pluginRefs->keyMap.end();++iter ) + for( PluginRefMap::KeyMap::iterator iter = pluginRefs->keyMap.begin (); + iter!=pluginRefs->keyMap.end ();++iter ) { const std::string &str = iter->first; size_t found = str.find_last_of("/\\"); @@ -276,13 +278,13 @@ searchPlugin( const std::string& plugname ) void PluginLoader:: -unloadAllPlugins() +unloadAllPlugins () { dgDEBUGIN( 15 ); - PluginRefMap::KeyMap::iterator plugkey = pluginRefs->keyMap.begin(); + PluginRefMap::KeyMap::iterator plugkey = pluginRefs->keyMap.begin (); - while( plugkey!=pluginRefs->keyMap.end() ) + while( plugkey!=pluginRefs->keyMap.end () ) { #ifndef WIN32 const int errCode = dlclose(plugkey->second); @@ -293,11 +295,11 @@ unloadAllPlugins() { #ifndef WIN32 dgDEBUG(1) << "Error while unloading <" << plugkey->first <<"> : " - << dlerror() <<endl; + << dlerror () <<endl; #else // Retrieve the system error message for the last-error code LPTSTR pszMessage; - DWORD dwLastError = GetLastError(); + DWORD dwLastError = GetLastError (); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | diff --git a/src/dgraph/pool.cpp b/src/dgraph/pool.cpp index 66a311d..5cf7d30 100644 --- a/src/dgraph/pool.cpp +++ b/src/dgraph/pool.cpp @@ -36,11 +36,11 @@ using namespace dynamicgraph; /* --------------------------------------------------------------------- */ PoolStorage:: -~PoolStorage( void ) +~PoolStorage () { dgDEBUGIN(15); - for( Entities::iterator iter=entity.begin();iter!=entity.end(); iter=entity.begin()) + for( Entities::iterator iter=entity.begin ();iter!=entity.end (); iter=entity.begin ()) { dgDEBUG(15) << "Delete \"" << (iter->first) <<"\""<<std::endl; @@ -58,11 +58,11 @@ void PoolStorage:: registerEntity( const std::string& entname,Entity* ent ) { Entities::iterator entkey = entity.find(entname); - if( entkey != entity.end() ) // key does exist + if( entkey != entity.end () ) // key does exist { throw ExceptionFactory( ExceptionFactory::OBJECT_CONFLICT, "Another entity already defined with the same name. ", - "Entity name is <%s>.",entname.c_str() ); + "Entity name is <%s>.",entname.c_str () ); } else { @@ -76,11 +76,11 @@ void PoolStorage:: deregisterEntity( const std::string& entname ) { Entities::iterator entkey = entity.find(entname); - if( entkey == entity.end() ) // key doesnot exist + if( entkey == entity.end () ) // key doesnot exist { throw ExceptionFactory( ExceptionFactory::OBJECT_CONFLICT, "Entity not defined yet. ", - "Entity name is <%s>.",entname.c_str() ); + "Entity name is <%s>.",entname.c_str () ); } else { @@ -95,11 +95,11 @@ getEntity( const std::string& name ) { dgDEBUG(25) << "Get <" << name << ">"<<std::endl; Entities::iterator entPtr = entity .find( name ); - if( entPtr == entity.end() ) + if( entPtr == entity.end () ) { DG_THROW ExceptionFactory( ExceptionFactory::UNREFERED_OBJECT, "Unknown entity."," (while calling <%s>)", - name.c_str() ); + name.c_str () ); } else return *entPtr->second; } @@ -110,13 +110,13 @@ clearPlugin( const std::string& name ) dgDEBUGIN(5); std::list<Entity*> toDelete; - for (Entities::iterator entPtr = entity.begin (); - entPtr != entity.end (); ++entPtr) - if (entPtr->second->getClassName() == name) + for (Entities::iterator entPtr = entity.begin (); + entPtr != entity.end (); ++entPtr) + if (entPtr->second->getClassName () == name) toDelete.push_back (entPtr->second); - for (std::list< Entity* >::iterator iter = toDelete.begin (); - iter != toDelete.end (); ++iter) + for (std::list< Entity* >::iterator iter = toDelete.begin (); + iter != toDelete.end (); ++iter) delete (Entity*) *iter; dgDEBUGOUT(5); } @@ -139,7 +139,7 @@ writeGraph(const std::string &aFileName) size_t IdxSeparatorFound = aFileName.rfind("/"); std::string GenericName; if (IdxSeparatorFound!=std::string::npos) - GenericName = tmp1.substr(IdxSeparatorFound,tmp1.length()); + GenericName = tmp1.substr(IdxSeparatorFound,tmp1.length ()); else GenericName = tmp1; @@ -154,7 +154,7 @@ writeGraph(const std::string &aFileName) #endif /*WIN32*/ /* Opening the file and writing the first comment. */ - std::ofstream GraphFile (aFileName.c_str(),std::ofstream::out); + std::ofstream GraphFile (aFileName.c_str (),std::ofstream::out); GraphFile << "/* This graph has been automatically generated. " << std::endl; GraphFile << " " << 1900+ltimeformatted.tm_year << " Month: " << 1+ltimeformatted.tm_mon @@ -169,12 +169,12 @@ writeGraph(const std::string &aFileName) GraphFile << "\t} " << std::endl; - for( Entities::iterator iter=entity.begin(); - iter!=entity.end(); ++iter) + for( Entities::iterator iter=entity.begin (); + iter!=entity.end (); ++iter) { Entity* ent = iter->second; - GraphFile << ent->getName() - <<" [ label = \"" << ent->getName() << "\" ," << std::endl + GraphFile << ent->getName () + <<" [ label = \"" << ent->getName () << "\" ," << std::endl <<" fontcolor = black, color = black, fillcolor=cyan, style=filled, shape=box ]" << std::endl; ent->writeGraph(GraphFile); } @@ -182,14 +182,14 @@ writeGraph(const std::string &aFileName) GraphFile << "}"<< std::endl; - GraphFile.close(); + GraphFile.close (); } void PoolStorage:: writeCompletionList(std::ostream& os) { - for( Entities::iterator iter=entity.begin(); - iter!=entity.end(); ++iter) + for( Entities::iterator iter=entity.begin (); + iter!=entity.end (); ++iter) { Entity* ent = iter->second; ent->writeCompletionList(os); @@ -216,12 +216,12 @@ commandLine( const std::string& objectName,const std::string& functionName, } else if( functionName=="list" ) { - for( Entities::iterator iter=entity.begin(); - iter!=entity.end(); ++iter) + for( Entities::iterator iter=entity.begin (); + iter!=entity.end (); ++iter) { Entity* ent = iter->second; - os << ent->getName() - <<" (" << ent->getClassName() << ")" << std::endl; + os << ent->getName () + <<" (" << ent->getClassName () << ")" << std::endl; } } diff --git a/src/exception/exception-abstract.cpp b/src/exception/exception-abstract.cpp index f37ef50..2143a21 100644 --- a/src/exception/exception-abstract.cpp +++ b/src/exception/exception-abstract.cpp @@ -1,130 +1,97 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ - +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#include <cstring> #include <dynamic-graph/exception-abstract.h> #include <dynamic-graph/debug.h> -using namespace std; -using namespace dynamicgraph; - -/* ------------------------------------------------------------------------- */ -/* --- CONSTRUCTORS -------------------------------------------------------- */ -/* ------------------------------------------------------------------------- */ - -const std::string ExceptionAbstract::EXCEPTION_NAME = "Abstract"; - - -ExceptionAbstract:: -ExceptionAbstract (const int& _code, - const string & _msg) - : - code (_code), - message (_msg) - -{ - return ; +namespace dynamicgraph { + const std::string ExceptionAbstract::EXCEPTION_NAME = "Abstract"; -} -/* ------------------------------------------------------------------------ */ -/* --- ACCESSORS ---------------------------------------------------------- */ -/* ------------------------------------------------------------------------ */ + ExceptionAbstract::ExceptionAbstract (const int& _code, + const std::string& _msg) + : code (_code), + message (_msg) + {} -const char *ExceptionAbstract:: -getMessage (void) -{ - return (this->message) .c_str(); -} + const char* + ExceptionAbstract::getMessage () const + { + return (this->message) .c_str (); + } -const string& ExceptionAbstract:: -getStringMessage (void) const -{ + const std::string& + ExceptionAbstract::getStringMessage () const + { return this->message; -} + } -int -ExceptionAbstract::getCode () const -{ + int + ExceptionAbstract::getCode () const + { return this->code; -} + } + ExceptionAbstract::Param& + ExceptionAbstract::Param::initCopy (const Param& p) + { + if (&p == this) + return *this; -/* ------------------------------------------------------------------------- */ -/* --- MODIFIORS ----------------------------------------------------------- */ -/* ------------------------------------------------------------------------- */ -#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM - - -ExceptionAbstract::Param& ExceptionAbstract::Param:: -initCopy( const Param& p ) -{ dgDEBUGIN(25); - if( p.pointersSet ) - { - strncpy( function,p.functionPTR,BUFFER_SIZE); - strncpy( file,p.filePTR,BUFFER_SIZE); - line = p.line; - pointersSet=false; - set=true; - } else set=false; + if (p.pointersSet) + { + strncpy (function,p.functionPTR, BUFFER_SIZE); + strncpy (file,p.filePTR, BUFFER_SIZE); + line = p.line; + pointersSet = false; + set = true; + } + else + set = false; dgDEBUGOUT(25); return *this; -} -ExceptionAbstract::Param:: -Param( const int& _line, const char * _function, const char * _file ) - : functionPTR(_function),line(_line),filePTR(_file),pointersSet(true) -{ + } + + ExceptionAbstract::Param::Param (const int& _line, + const char* _function, + const char* _file) + : functionPTR (_function), + line (_line), + filePTR (_file), + pointersSet (true) + { dgDEBUGINOUT(25); -} -#endif //#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM - -/* ------------------------------------------------------------------------- */ -/* --- OP << --------------------------------------------------------------- */ -/* ------------------------------------------------------------------------- */ - -namespace dynamicgraph { + } -ostream & -operator << (ostream & os, - const ExceptionAbstract & error) -{ - os << error.getExceptionName()<<"Error [#" << error.code << "]: " << error.message << endl; + std::ostream& + operator << (std::ostream& os, + const ExceptionAbstract& error) + { + os << error.getExceptionName () + << "Error [#" << error.code << "]: " << error.message << std::endl; #ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM - if( error.p.set ) - os << "Thrown from "<<error.p.file << ": "<<error.p.function - <<" (#"<<error.p.line << ")"<<endl; -#endif //#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM + if (error.p.set) + os << "Thrown from " << error.p.file << ": " << error.p.function + <<" (#" << error.p.line << ")"<< std::endl; +#endif // DYNAMICGRAPH_EXCEPTION_PASSING_PARAM return os; -} - -} // namespace dynamicgraph - - - -/** \file $Source$ - */ + } -/* - * Local variables: - * c-basic-offset: 4 - * End: - */ +} // end of namespace dynamicgraph. diff --git a/src/exception/exception-factory.cpp b/src/exception/exception-factory.cpp index 7e46722..d6c5e57 100644 --- a/src/exception/exception-factory.cpp +++ b/src/exception/exception-factory.cpp @@ -36,7 +36,7 @@ ExceptionFactory ( const ExceptionFactory::ErrorCodeEnum& errcode, const std::string & msg ) :ExceptionAbstract(errcode,msg) { - dgDEBUGF( 15,"Created with message <%s>.",msg.c_str()); + dgDEBUGF( 15,"Created with message <%s>.",msg.c_str ()); dgDEBUG( 1) <<"Created with message <%s>."<<msg<<std::endl; } diff --git a/src/plugins/shell-functions.cpp b/src/plugins/shell-functions.cpp index caee428..49b1870 100644 --- a/src/plugins/shell-functions.cpp +++ b/src/plugins/shell-functions.cpp @@ -1,23 +1,20 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. +#include <dynamic-graph/interpreter.h> #include <dynamic-graph/functions.h> #include <dynamic-graph/plugin-loader.h> #include <dynamic-graph/factory.h> diff --git a/src/plugins/shell-procedure.cpp b/src/plugins/shell-procedure.cpp index 973966b..5c9a47c 100644 --- a/src/plugins/shell-procedure.cpp +++ b/src/plugins/shell-procedure.cpp @@ -41,9 +41,9 @@ cmdStartProcedure( const std::string& cmdLine,std::istringstream& args,std::ostr args>>procName; dgDEBUG(5)<<"Proc <" <<procName<<">"<<endl; - currentProc.clear(); + currentProc.clear (); args >> ws; - while( args.good() ) + while( args.good () ) { std::string next; args>>next>>ws; @@ -67,11 +67,11 @@ cmdContinueProcedure( const std::string& cmdLine,std::istringstream& args,std::o Instruction ins; ins.cmd=cmd2; args >> ws; - while( args.good() ) + while( args.good () ) { std::string next; int param=-1; args>>next>>ws; - for( unsigned int i=0;i<currentProc.params.size();++i ) + for( unsigned int i=0;i<currentProc.params.size ();++i ) { if( next==currentProc.params[i] ) { param=i; break; } } ins.args.push_back(next); ins.params.push_back( param ); @@ -94,20 +94,20 @@ cmdEndProcedure( const std::string& cmdLine,std::istringstream&, std::ostream& o procedureList[ procName ] = currentProc; // std::string toto="toto"; -// for( Procedure::iterator ins=procedureList[ toto ].begin(); -// ins!=procedureList[ toto ].end(); ++ins ) +// for( Procedure::iterator ins=procedureList[ toto ].begin (); +// ins!=procedureList[ toto ].end (); ++ins ) // { // dgDEBUG(15) << "Proc <" << procName << "> : " // << ins->cmd << " -> " << ins->args <<endl; // } - currentProc.clear(); + currentProc.clear (); if( g_shell.deregisterFunction( procName )) { os<< "Redefining proc <"<<procName<<">: procedure already defined. " << "Overwrite it."<<endl; } ShellFunctionRegisterer registration - ( procName.c_str(),boost::bind(&ShellProcedure::cmdProcedure, + ( procName.c_str (),boost::bind(&ShellProcedure::cmdProcedure, this,procName,_1,_2,_3) ); } @@ -120,32 +120,32 @@ cmdProcedure( const std::string& procname, { os<<" - "<<procname<<"\t\t\t\t\tUser-defined procedure"<<endl; args >> ws; - if( args.good() ) + if( args.good () ) { std::string argname; - const std::streamoff gc = args.tellg(); + const std::streamoff gc = args.tellg (); args >> argname; - args.seekg(gc); args.clear(); + args.seekg(gc); args.clear (); if( procname==argname ) { /* if cmdline = "Help <procname>", then display * the proc instruction. */ ProcedureList::iterator pair = procedureList.find( argname ); - if( pair==procedureList.end() ) + if( pair==procedureList.end () ) { DG_THROW ExceptionFactory( ExceptionFactory::UNREFERED_FUNCTION, "Undefined procedure", ": procedure <%s> not defined.", - argname.c_str() ); + argname.c_str () ); } Procedure & proc = pair->second; unsigned int cmdnum=1; - for( std::list<Instruction>::iterator ins=proc.instructions.begin(); - ins!=proc.instructions.end(); ++ins ) + for( std::list<Instruction>::iterator ins=proc.instructions.begin (); + ins!=proc.instructions.end (); ++ins ) { os<<"\t#" <<cmdnum++<<" "<<ins->cmd; // <<" "<<ins->args <<endl; - for( unsigned int i=0;i<ins->args.size();++i ) + for( unsigned int i=0;i<ins->args.size ();++i ) { os << " " << ins->args[i]; } os << endl; } @@ -158,11 +158,11 @@ cmdProcedure( const std::string& procname, dgDEBUG(15) << " Calling procedure <" <<cmdLine<<"> " <<endl; ProcedureList::iterator pair = procedureList.find( cmdLine ); - if( pair==procedureList.end() ) + if( pair==procedureList.end () ) { DG_THROW ExceptionFactory( ExceptionFactory::UNREFERED_FUNCTION, "Undefined procedure", - ": procedure <%s> not defined.",cmdLine.c_str() ); + ": procedure <%s> not defined.",cmdLine.c_str () ); } /* You need a copy here, in case the proc is removed from the @@ -176,10 +176,10 @@ cmdProcedure( const std::string& procname, Procedure proc = pair->second; std::vector< std::string > paramValue; - for( unsigned int i=0;i<proc.params.size();++i ) + for( unsigned int i=0;i<proc.params.size ();++i ) { args>>ws; - if( args.good() ) + if( args.good () ) { std::string next; args>>next>>ws; paramValue.push_back( next ); @@ -189,20 +189,20 @@ cmdProcedure( const std::string& procname, } istringstream iss; ostringstream oss; - for( std::list<Instruction>::iterator ins=proc.instructions.begin(); - ins!=proc.instructions.end(); ++ins ) + for( std::list<Instruction>::iterator ins=proc.instructions.begin (); + ins!=proc.instructions.end (); ++ins ) { dgDEBUG(15) << "Proc <" << cmdLine << "> : " << ins->cmd << endl; - oss.clear(); oss.str(""); - for( unsigned int i=0;i<ins->params.size();++i ) + oss.clear (); oss.str(""); + for( unsigned int i=0;i<ins->params.size ();++i ) { int paramArg = ins->params[i]; if( paramArg==-1 ) oss << ins->args[i] << " "; else oss << paramValue[paramArg] << " "; } - dgDEBUG(15) << " Args = " << oss.str() << endl; - iss.str(oss.str()); iss.clear(); + dgDEBUG(15) << " Args = " << oss.str () << endl; + iss.str(oss.str ()); iss.clear (); g_shell.cmd(ins->cmd,iss,os); } } @@ -248,12 +248,12 @@ cmdFor( const std::string& cmdLine,std::istringstream& args,std::ostream& os ) std::string insp; istringstream issargs( argsstr ); - while( issargs.good() ) + while( issargs.good () ) { issargs >> insp; if( insp == idx ) { oss << i << " "; } else { oss<<insp<< " "; } } - iss.str( oss.str() ); + iss.str( oss.str () ); g_shell.cmd(cmd2,iss,os); } } diff --git a/src/shell/functions.cpp b/src/shell/functions.cpp index 36f6e90..8e0b3e1 100644 --- a/src/shell/functions.cpp +++ b/src/shell/functions.cpp @@ -1,480 +1,592 @@ -/* - * Copyright 2010, - * François Bleibel, - * Olivier Stasse, - * - * CNRS/AIST - * - * This file is part of dynamic-graph. - * dynamic-graph is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * dynamic-graph is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. You should - * have received a copy of the GNU Lesser General Public License along - * with dynamic-graph. If not, see <http://www.gnu.org/licenses/>. - */ +// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, +// JRL, CNRS/AIST. +// +// This file is part of dynamic-graph. +// dynamic-graph is free software: you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// dynamic-graph is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// dynamic-graph. If not, see <http://www.gnu.org/licenses/>. + +#include <fstream> + +#ifdef WIN32 +# include <Windows.h> +#endif // WIN32 + +#include <boost/foreach.hpp> +#include <boost/format.hpp> -#include <dynamic-graph/functions.h> -#include <dynamic-graph/plugin-loader.h> -#include <dynamic-graph/factory.h> #include <dynamic-graph/debug.h> #include <dynamic-graph/entity.h> -#include <dynamic-graph/signal.h> #include <dynamic-graph/exception-signal.h> +#include <dynamic-graph/factory.h> +#include <dynamic-graph/functions.h> +#include <dynamic-graph/interpreter.h> +#include <dynamic-graph/plugin-loader.h> +#include <dynamic-graph/signal.h> -#ifdef WIN32 -#include <Windows.h> -#endif - -#include <fstream> -using namespace std; using namespace dynamicgraph; -void ShellFunctions:: -cmdTry( const std::string cmdLine, istringstream& cmdArg, std::ostream& os ) +static const char* NO_PLUGINLOADER_ERROR_MSG = + "!! Dynamic loading functionalities not accessible through the shell."; + +static void sleep (int secs) { - if( cmdLine == "help" ) +#ifndef WIN32 + usleep(secs * 1000000); +#else + Sleep (secs * 1000); +#endif //! WIN32 +} + + + +void +ShellFunctions::cmdTry (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) +{ + if (cmdLine == "help") { os << " - try <cmd...>" - << "\t\t\t\tTry <cmd> and display the caught exception." <<endl; + << "\t\t\t\tTry <cmd> and display the caught exception." << std::endl; return; } - string cmdLine2; - cmdArg>>cmdLine2; - dgDEBUG(5)<<"Try <" <<cmdLine2<<">"<<endl; - try{ - g_shell.cmd(cmdLine2,cmdArg,os); - } catch ( const ExceptionAbstract& e ) { os << "dgERROR catch: " <<endl<< e<<endl; } - catch( ... ) { os<<"Unknown error catch." <<endl; } + std::string cmdLine2; + cmdArg >> cmdLine2; + dgDEBUG(5) << "Try <" << cmdLine2 << ">" << std::endl; + + try + { + g_shell.cmd (cmdLine2,cmdArg,os); + } + catch (const ExceptionAbstract& e) + { + os << "dgERROR catch: " <<std::endl + << e << std::endl; + } + catch(...) + { + os << "Unknown error caught." << std::endl; + } } -void ShellFunctions:: -cmdLoadPlugins( const std::string cmdLine, std::istringstream& cmdArg, std::ostream& os ) +void +ShellFunctions::cmdLoadPlugins (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { os << " - loadPlugins <file.txt> <directory>" - << "\t\tLoad the plugins listed in the file." <<endl; + << "\t\tLoad the plugins listed in the file." << std::endl; return; } - if( NULL!=g_shell.dlPtr ) + + if (!g_shell.dlPtr) { - string pluginName,directory; - cmdArg >> pluginName; - cmdArg >> directory; - dgDEBUG(15) << "Load plugin list <" <<pluginName<<"> from dir <" << directory<<">."<<endl; - if( directory.length() != 0 ) g_shell.dlPtr->setDirectory( directory ); - g_shell.dlPtr ->loadPluginList( pluginName ); - g_shell.dlPtr->loadPlugins(); + os << NO_PLUGINLOADER_ERROR_MSG << std::endl; + return; } - else { os << "!! Dynamic loading functionalities not accessible through the shell." <<endl; } + + std::string pluginName, directory; + cmdArg >> pluginName; + cmdArg >> directory; + + dgDEBUG(15) << "Load plugin list <" + << pluginName << "> from dir <" << directory + << ">." << std::endl; + + if (directory.length () != 0) + g_shell.dlPtr->setDirectory (directory); + + g_shell.dlPtr->loadPluginList (pluginName); + g_shell.dlPtr->loadPlugins (); } -void ShellFunctions:: -cmdClearPlugin( const std::string cmdLine, std::istringstream& cmdArg, std::ostream& os ) +void +ShellFunctions::cmdClearPlugin (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { os << " - clearPlugin <className>" - << "\t\tDestroy all the objects of type <className>." <<endl; + << "\t\tDestroy all the objects of type <className>." <<std::endl; return; } - string pluginName; + std::string pluginName; cmdArg >> pluginName; - g_pool.clearPlugin( pluginName ); - + g_pool.clearPlugin (pluginName); } -void ShellFunctions:: -cmdDisplayPlugins( const std::string cmdLine, std::istringstream&, std::ostream& os ) +void +ShellFunctions::cmdDisplayPlugins (const std::string cmdLine, + std::istringstream&, + std::ostream& os) { - if( cmdLine == "help" ) + typedef std::pair< std::string,std::string > plugin_t; + + if (cmdLine == "help") { os << " - displayPlugins " - << "\t\t\t\tDisplay the name of the loaded plugins." <<endl; + << "\t\t\t\tDisplay the name of the loaded plugins." <<std::endl; return; } - if( NULL!=g_shell.dlPtr ) - { - std::map< std::string,std::string > m = g_shell.dlPtr->getLoadedPluginNames(); - for( std::map< std::string,std::string >::const_iterator iter = m.begin(); - iter!=m.end(); ++iter ) - { - os << " - <"<<iter->first<<">:\t"<<iter->second<<endl; - } + if (!g_shell.dlPtr) + { + os << NO_PLUGINLOADER_ERROR_MSG << std::endl; + return; } - else { os << "!! Dynamic loading functionalities not accessible through the shell." <<endl; } - + boost::format fmt ("- <%s>:\t %s"); + BOOST_FOREACH(plugin_t plugin, g_shell.dlPtr->getLoadedPluginNames ()) + { + fmt % plugin.first % plugin.second; + os << fmt.str () << std::endl; + } } - -void ShellFunctions:: -cmdDisplayFactory( const std::string cmdLine, std::istringstream& cmdArg, - std::ostream& os ) +void +ShellFunctions::cmdDisplayFactory (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { - os << " - "; g_factory.commandLine(cmdLine,cmdArg,os); + os << " - "; + g_factory.commandLine(cmdLine,cmdArg,os); return; } - string cmd2; cmdArg >> cmd2; - g_factory.commandLine( cmd2,cmdArg,os ); + std::string cmd2; + cmdArg >> cmd2; + g_factory.commandLine (cmd2, cmdArg, os); } -void ShellFunctions:: -cmdCommentary( const std::string cmdLine, std::istringstream&, std::ostream& os ) +void +ShellFunctions::cmdCommentary (const std::string cmdLine, + std::istringstream&, + std::ostream& os) { - if( cmdLine == "help" ) - { os << " # comment with '#': ignore the end of the line." <<endl; } + if (cmdLine == "help") + os << " # comment with '#': ignore the end of the line." << std::endl; return; } -void ShellFunctions:: -cmdUnplug( const std::string cmdLine, istringstream& cmdArg, std::ostream& os ) +void +ShellFunctions::cmdUnplug (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { os << " - unplug <obj2.sig2>" - << "\t\t\t\tPlug on sig2 (consumer) in sig1->sig2." <<endl; + << "\t\t\t\tPlug on sig2 (consumer) in sig1->sig2." << std::endl; return; } - string ssig; + + std::string ssig; cmdArg>>ssig; - string obj2,fun2; - istringstream str2(ssig); - if( !Interpreter::objectNameParser(str2,obj2,fun2) ) + std::string obj2, fun2; + std::istringstream str2 (ssig); + + if (!Interpreter::objectNameParser(str2, obj2, fun2)) { - DG_THROW ExceptionFactory( ExceptionFactory::SYNTAX_ERROR, - "Plug function: syntax is unplug OBJ2.SIG2.", - "(while calling plug %s %s).",ssig.c_str() ); + DG_THROW ExceptionFactory + (ExceptionFactory::SYNTAX_ERROR, + "Plug function: syntax is unplug OBJ2.SIG2.", + "(while calling plug %s %s).",ssig.c_str ()); } - dgDEBUG(20) << "Get Ent2 <"<<obj2<<"> ."<<endl; - Entity& ent2 = g_pool.getEntity(obj2); - dgDEBUG(20) << "Get Sig2 <"<<fun2<<"> ."<<endl; - SignalBase<int> &sig2 = ent2.getSignal(fun2); - + dgDEBUG(20) << "Get Ent2 <" << obj2 << "> ." << std::endl; + Entity& ent2 = g_pool.getEntity (obj2); + dgDEBUG(20) << "Get Sig2 <" << fun2 << "> ." << std::endl; + SignalBase<int>& sig2 = ent2.getSignal (fun2); - dgDEBUG(25) << "Unplug..."<<endl; - sig2.unplug(); + dgDEBUG(25) << "Unplug..." << std::endl; + sig2.unplug (); } -void ShellFunctions:: -cmdSignalTime( const std::string cmdLine, istringstream& cmdArg, std::ostream& os ) +void +ShellFunctions::cmdSignalTime (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { os << " - signalTime <obj.sig>" - << "\t\t\t\tDisplay the time of sig." <<endl; + << "\t\t\t\tDisplay the time of sig." << std::endl; return; } - string ssig; - cmdArg>>ssig; + std::string ssig; + cmdArg >> ssig; - string obj2,fun2; - istringstream str2(ssig); - if( !Interpreter::objectNameParser(str2,obj2,fun2) ) + std::string obj2,fun2; + std::istringstream str2 (ssig); + if (!Interpreter::objectNameParser(str2,obj2,fun2)) { - DG_THROW ExceptionFactory( ExceptionFactory::SYNTAX_ERROR, - "signalTime function: syntax is signalTime OBJ2.SIG2.", - "(while calling signalTime %s).",ssig.c_str() ); + DG_THROW ExceptionFactory + (ExceptionFactory::SYNTAX_ERROR, + "signalTime function: syntax is signalTime OBJ2.SIG2.", + "(while calling signalTime %s).",ssig.c_str ()); } - dgDEBUG(20) << "Get Ent2 <"<<obj2<<"> ."<<endl; - Entity& ent2 = g_pool.getEntity(obj2); - dgDEBUG(20) << "Get Sig2 <"<<fun2<<"> ."<<endl; - SignalBase<int> &sig2 = ent2.getSignal(fun2); + dgDEBUG(20) << "Get Ent2 <" << obj2 << "> ." << std::endl; + Entity& ent2 = g_pool.getEntity (obj2); + dgDEBUG(20) << "Get Sig2 <" << fun2 << "> ." << std::endl; + SignalBase<int>& sig2 = ent2.getSignal (fun2); - os << sig2.getTime() << endl; + os << sig2.getTime () << std::endl; } -void ShellFunctions:: -cmdSynchroSignal( const std::string cmdLine, std::istringstream& cmdArg, std::ostream& os ) +void +ShellFunctions::cmdSynchroSignal (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { os << " - synchro <obj.sig> [<period>]" - << "\t\t\t\tGet/Set the syncho of a signal <sig>." <<endl; + << "\t\t\t\tGet/Set the syncho of a signal <sig>." << std::endl; return; } - SignalBase<int> & sig = g_pool.getSignal( cmdArg ); - cmdArg >>ws; - if( cmdArg.good() ) + std::string ws; + + SignalBase<int>& sig = g_pool.getSignal (cmdArg); + cmdArg >> ws; + + if (!cmdArg.good ()) { - int period; cmdArg>>period; - sig.setPeriodTime( period ); - cmdArg >>ws; - if( cmdArg.good() ) - { - /* The sig is recomputed at the given period from the - * current time, at any time T so that T%p==0, p the period. - * By modifying the current time, the sig reomputation is done - * at T s.t. T%p=d, d the desynchro. */ - int currTime = sig.getTime (); - int desynchro; cmdArg>>desynchro; - sig.setTime( currTime+desynchro ); - } + os << "period = " << sig.getPeriodTime () << std::endl; + return; } - else + + int period = 0; + cmdArg >> period; + sig.setPeriodTime (period); + cmdArg >> ws; + if (cmdArg.good ()) { - os << "period = " << sig.getPeriodTime() << std::endl; + /* The sig is recomputed at the given period from the + * current time, at any time T so that T%p==0, p the period. + * By modifying the current time, the sig reomputation is done + * at T s.t. T%p=d, d the desynchro. */ + int currTime = sig.getTime (); + int desynchro; + cmdArg>>desynchro; + sig.setTime (currTime + desynchro); } } -void ShellFunctions:: -cmdEcho( const std::string cmdLine, std::istringstream& cmdArg, std::ostream& os ) +void +ShellFunctions::cmdEcho (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { os << " - echo <string>" - << "\t\t\t\tPrint <string. on the standard output." <<endl; + << "\t\t\t\tPrint <string. on the standard output." << std::endl; return; } - cmdArg >>ws; - while( cmdArg.good() ) + std::string ws; + cmdArg >> ws; + while (cmdArg.good ()) { - std::string toPrint; cmdArg>>toPrint; - os<<toPrint<<" "; + std::string toPrint; + cmdArg >> toPrint; + os << toPrint << " "; } - os<<std::endl; + os << std::endl; } -void ShellFunctions:: -cmdCopy( const std::string cmdLine, istringstream& cmdArg, std::ostream& os ) +void +ShellFunctions::cmdCopy (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { os << " - copy <obj1.sig1> <obj2.sig2>" - << "\t\tCopy the value of sig1 to constant value in sig2." <<endl; + << "\t\tCopy the value of sig1 to constant value in sig2." + << std::endl; return; } - string ssig1,ssig2; - cmdArg>>ssig1>>ssig2; - istringstream str1(ssig1),str2(ssig2); - - try { - SignalBase<int> &sig1 = g_pool.getSignal( str1 ); - SignalBase<int> &sig2 = g_pool.getSignal( str2 ); - - dgDEBUG(25) << "Copy..."<<endl; - sig2.plug(&sig1); - sig2.setConstantDefault(); - sig2.plug(&sig2); - } catch( ExceptionAbstract & err ) { throw; } - catch( ... ) { - DG_THROW ExceptionFactory( ExceptionFactory::SYNTAX_ERROR, - "Copy: syntax is copy OBJ1.SIG1 OBJ2.SIG2.", - "(while calling copy %s %s).",ssig1.c_str(), - ssig2.c_str() ); - } + std::string ssig1, ssig2; + cmdArg >> ssig1 >> ssig2; + + std::istringstream str1 (ssig1), str2 (ssig2); + + try + { + SignalBase<int>& sig1 = g_pool.getSignal (str1); + SignalBase<int>& sig2 = g_pool.getSignal (str2); + + dgDEBUG(25) << "Copy..."<< std::endl; + sig2.plug (&sig1); + sig2.setConstantDefault (); + sig2.plug (&sig2); + } + catch (ExceptionAbstract& err) + { + throw; + } + catch (...) + { + DG_THROW ExceptionFactory + (ExceptionFactory::SYNTAX_ERROR, + "Copy: syntax is copy OBJ1.SIG1 OBJ2.SIG2.", + "(while calling copy %s %s).",ssig1.c_str (), + ssig2.c_str ()); + } } -void ShellFunctions:: -cmdFreeze( const std::string cmdLine, istringstream& cmdArg, std::ostream& os ) +void +ShellFunctions::cmdFreeze (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { os << " - freeze <obj.sig> " << "\t\tOn a ptr-sig: save the current value from the source " - << "and unplug the signal." <<endl; + << "and unplug the signal." << std::endl; return; } - string ssig1; - cmdArg>>ssig1; - istringstream str1(ssig1); - - try { - SignalBase<int> &sig1 = g_pool.getSignal( str1 ); + std::string ssig1; + cmdArg >> ssig1; + std::istringstream str1 (ssig1); - dgDEBUG(25) << "Unplug..."<<endl; - sig1.setConstantDefault(); - sig1.plug(&sig1); - } catch( ... ) { - DG_THROW ExceptionFactory( ExceptionFactory::SYNTAX_ERROR, - "Freeze: syntax is freeze OBJ.SIG.", - "(while calling freeze %s ).",ssig1.c_str()); - } + try + { + SignalBase<int>& sig1 = g_pool.getSignal (str1); + dgDEBUG(25) << "Unplug..."<< std::endl; + sig1.setConstantDefault (); + sig1.plug(&sig1); + } + catch (...) + { + DG_THROW ExceptionFactory + (ExceptionFactory::SYNTAX_ERROR, + "Freeze: syntax is freeze OBJ.SIG.", + "(while calling freeze %s ).", ssig1.c_str ()); + } } -void ShellFunctions:: -cmdSqueeze( const std::string cmdLine, istringstream& cmdArg, std::ostream& os ) +void +ShellFunctions::cmdSqueeze (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { - os << " - squeeze <mainObj.mainSig> <squeezeObj.sigIn> <squeezeObj.sigOut>" - << "\t\tIntercalate squeezeObj between mainObj and its source." <<endl; + os << + " - squeeze <mainObj.mainSig> <squeezeObj.sigIn> <squeezeObj.sigOut>" + << "\t\tIntercalate squeezeObj between mainObj and its source." + << std::endl; return; } - string ssigMain,ssigIn,ssigOut; - cmdArg>>ssigMain>>ssigIn>>ssigOut; - istringstream strMain(ssigMain); - istringstream strIn(ssigIn); - istringstream strOut(ssigOut); - - try { - SignalBase<int> &sigMain = g_pool.getSignal(strMain ); - SignalBase<int> &sigIn = g_pool.getSignal( strIn ); - SignalBase<int> &sigOut = g_pool.getSignal( strOut ); + std::string ssigMain, ssigIn, ssigOut; + cmdArg >> ssigMain >> ssigIn >> ssigOut; + std::istringstream strMain(ssigMain); + std::istringstream strIn(ssigIn); + std::istringstream strOut(ssigOut); - SignalBase<int> *sigMainSource = sigMain.getPluged(); - if( sigMainSource==&sigMain ) - { - DG_THROW ExceptionFactory( ExceptionFactory::SYNTAX_ERROR, - "The main signal is autopluged (or set constant). ", - "(while calling freeze %s ).",ssigMain.c_str()); - } + try + { + SignalBase<int>& sigMain = g_pool.getSignal (strMain); + SignalBase<int>& sigIn = g_pool.getSignal (strIn); + SignalBase<int>& sigOut = g_pool.getSignal (strOut); - sigMain.plug( &sigOut ); - sigIn.plug( sigMainSource ); - } - catch( ExceptionFactory& exc ) { - switch( exc.getCode() ) - { - case ExceptionFactory::UNREFERED_SIGNAL: - DG_THROW ExceptionFactory( ExceptionFactory::SYNTAX_ERROR, - "Sqeeze: unknown signal. ", - "(error while searching signal: %s ).", - exc.getMessage() ); - break; - default: - throw; - } - } + SignalBase<int>* sigMainSource = sigMain.getPluged (); + if(sigMainSource == &sigMain) + { + DG_THROW ExceptionFactory + (ExceptionFactory::SYNTAX_ERROR, + "The main signal is autopluged (or set constant). ", + "(while calling freeze %s ).",ssigMain.c_str ()); + } + sigMain.plug (&sigOut); + sigIn.plug(sigMainSource); + } + catch (const ExceptionFactory& exc) + { + switch (exc.getCode ()) + { + case ExceptionFactory::UNREFERED_SIGNAL: + DG_THROW ExceptionFactory + (ExceptionFactory::SYNTAX_ERROR, + "Sqeeze: unknown signal. ", + "(error while searching signal: %s ).", + exc.getMessage ()); + break; + default: + throw; + } + } } -void ShellFunctions:: -cmdEnableTrace( const std::string cmdLine, istringstream& cmdArg, std::ostream& os ) +void +ShellFunctions::cmdEnableTrace (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { os << " - debugtrace [{true|false}] [<filename>=" << DebugTrace::DEBUG_FILENAME_DEFAULT <<"]" - << "\t\tOpen/close the file <filename> for debug tracing." <<endl; + << "\t\tOpen/close the file <filename> for debug tracing." + << std::endl; return; } + std::string ws; cmdArg >> ws; - if( cmdArg.good() ) - { - std::string opt; - std::string filename; - - cmdArg>>opt>>ws; - if( opt=="true" ) - if( cmdArg.good() ) - { - cmdArg>>filename; - DebugTrace::openFile( filename.c_str() ); - } - else { DebugTrace::openFile(); } - else DebugTrace::closeFile(); - } - else + if (!cmdArg.good ()) { - if( dgDEBUGFLOW.outputbuffer.good() ) os << "true" <<endl; - else os << "false" <<endl; + if (dgDEBUGFLOW.outputbuffer.good ()) + os << "true" << std::endl; + else + os << "false" << std::endl; + return; } + std::string opt; + std::string filename; + + cmdArg >> opt >> ws; + if (opt == "true") + if (cmdArg.good ()) + { + cmdArg >> filename; + DebugTrace::openFile (filename.c_str ()); + } + else + DebugTrace::openFile (); + else + DebugTrace::closeFile (); } -void ShellFunctions:: -cmdSetPrompt( const std::string cmdLine, istringstream& cmdArg, std::ostream& os ) +void +ShellFunctions::cmdSetPrompt (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { os << " - prompt [<string>] " - << "\t\tSet/get the default prompt." <<endl; + << "\t\tSet/get the default prompt." << std::endl; return; } - string opt; + std::string opt; + std::string ws; cmdArg >> ws; - if( cmdArg. good() ) + + if (!cmdArg. good ()) { - char buffer [80]; cmdArg .getline(buffer,80); - g_shell .prompt = buffer; - } else { os << "Current prompt is <" << g_shell. prompt << ">." << endl; } + os << "Current prompt is <" << g_shell. prompt << ">." << std::endl; + return; + } + + char buffer [80]; + cmdArg.getline (buffer, 80); + g_shell.prompt = buffer; } -void ShellFunctions:: -cmdSleep( const std::string cmdLine, istringstream& cmdArg, std::ostream& os ) +void +ShellFunctions::cmdSleep (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { os << " - sleep [<float> secs] " - << "\t\tSleep (time in secs)." <<endl; + << "\t\tSleep (time in secs)." << std::endl; return; } - string opt; + std::string opt; + std::string ws; cmdArg >> ws; - if( cmdArg. good() ) + if (!cmdArg. good ()) { - double secs; cmdArg >> secs; - if( secs > 0 ) -#ifndef WIN32 - usleep( int(secs*1000000) ); -#else - Sleep( int(secs*1000) ); -#endif - } else { /* TODO ERROR */ } + //FIXME: handle error here. + return; + } + + double secs = 0.; + cmdArg >> secs; + if (secs > 0) + sleep (int (secs)); } -void ShellFunctions:: -cmdBeep( const std::string cmdLine, std::istringstream&, std::ostream& os ) +void +ShellFunctions::cmdBeep (const std::string cmdLine, + std::istringstream&, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { os << " - beep [<float> secs] " - << "\t\tSend a bip to the std::cout." <<endl; + << "\t\tSend a bip to the std::cout." << std::endl; return; } - os << char(7) << "Beep!" << std::endl; + os << char (7) << "Beep!" << std::endl; } -void ShellFunctions:: -cmdCompletionList( const std::string cmdLine, istringstream& cmdArg, std::ostream& os ) +void +ShellFunctions::cmdCompletionList (const std::string cmdLine, + std::istringstream& cmdArg, + std::ostream& os) { - if( cmdLine == "help" ) + if (cmdLine == "help") { os << " - completion <filename>" - << "\t\tGenerate the completion list for current graph." <<endl; + << "\t\tGenerate the completion list for current graph." << std::endl; return; } - try { - - std::string aFileName; cmdArg >> aFileName; - std::ofstream completionFile(aFileName.c_str()); - g_pool.writeCompletionList( completionFile ); - - - } catch( ExceptionAbstract & err ) { throw; } - catch( ... ) { - DG_THROW ExceptionFactory( ExceptionFactory::SYNTAX_ERROR, - "setflag: sig should be of flag type. ", - "(while calling setflag)."); - } + try + { + std::string aFileName; + cmdArg >> aFileName; + std::ofstream completionFile (aFileName.c_str ()); + g_pool.writeCompletionList (completionFile); + } + catch (const ExceptionAbstract & err) + { + throw; + } + catch (...) + { + DG_THROW ExceptionFactory + (ExceptionFactory::SYNTAX_ERROR, + "setflag: sig should be of flag type. ", + "(while calling setflag)."); + } } diff --git a/src/signal/signal-caster.cpp b/src/signal/signal-caster.cpp index 109c6a8..1f41874 100644 --- a/src/signal/signal-caster.cpp +++ b/src/signal/signal-caster.cpp @@ -26,10 +26,10 @@ namespace dynamicgraph { - SignalCaster::SignalCaster () + SignalCaster::SignalCaster () {} - SignalCaster::~SignalCaster () + SignalCaster::~SignalCaster () {} void @@ -40,20 +40,20 @@ namespace dynamicgraph { if (existsCast(type)) { - std::string typeName (type.name ()); + std::string typeName (type.name ()); std::ostringstream os; os << "cast already registered for type " << typeName << "."; //TODO: throw "cast already registered for type" exception throw ExceptionSignal - (ExceptionSignal::GENERIC, os.str()); + (ExceptionSignal::GENERIC, os.str ()); } - functions_[type.name()] = cast_functions_type(displayer,caster, tracer); + functions_[type.name ()] = cast_functions_type(displayer,caster, tracer); } void SignalCaster::unregisterCast (const std::type_info& type) { - size_t n = functions_.erase(type.name()); + size_t n = functions_.erase(type.name ()); if (0 == n) // erase did not find element // TODO: throw Cast not registered exception throw ExceptionSignal(ExceptionSignal::GENERIC); @@ -62,7 +62,7 @@ namespace dynamicgraph bool SignalCaster::existsCast (const std::type_info& type) const { - return functions_.find (type.name ()) != functions_.end (); + return functions_.find (type.name ()) != functions_.end (); } SignalCaster::cast_functions_type& @@ -71,7 +71,7 @@ namespace dynamicgraph std::map<std::string, cast_functions_type>::iterator it = functions_.find(type_name); - if (it == functions_.end ()) + if (it == functions_.end ()) //TODO: throw "cast not registered" exception throw ExceptionSignal(ExceptionSignal::BAD_CAST, "bad cast"); return it->second; @@ -80,19 +80,19 @@ namespace dynamicgraph void SignalCaster::disp (const boost::any& object, std::ostream& os) { - getCast(object.type ().name ()).get<0> () (object, os); + getCast(object.type ().name ()).get<0> () (object, os); } void SignalCaster::trace(const boost::any& object, std::ostream& os) { - getCast(object.type ().name ()).get<2> () (object, os); + getCast(object.type ().name ()).get<2> () (object, os); } boost::any SignalCaster::cast (const std::type_info& type, std::istringstream& iss) { - return getCast(type.name ()).get<1> () (iss); + return getCast(type.name ()).get<1> () (iss); } diff --git a/src/traces/tracer-real-time.cpp b/src/traces/tracer-real-time.cpp index f441057..94beb98 100644 --- a/src/traces/tracer-real-time.cpp +++ b/src/traces/tracer-real-time.cpp @@ -41,15 +41,15 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(TracerRealTime,"TracerRealTime"); /* --------------------------------------------------------------------- */ OutStringStream:: -OutStringStream( void ) - : std::ostringstream() +OutStringStream () + : std::ostringstream () ,buffer( 0 ),index(0),bufferSize(0),full(false) { dgDEBUGINOUT(15); } OutStringStream:: -~OutStringStream( void ) +~OutStringStream () { dgDEBUGIN(15); delete[] buffer; @@ -97,7 +97,7 @@ dump( std::ostream& os ) } void OutStringStream:: -empty( void ) +empty () { dgDEBUGIN(15); index=0; full=false; @@ -129,19 +129,19 @@ openFile( const SignalBase<int> & sig, { dgDEBUGIN(15); string signame; - if( givenname.length() ) - { signame = givenname; } else { signame = sig.shortName(); } + if( givenname.length () ) + { signame = givenname; } else { signame = sig.shortName (); } string filename = rootdir + basename + signame + suffix; - dgDEBUG(5) << "Sig <"<<sig.getName() + dgDEBUG(5) << "Sig <"<<sig.getName () << ">: new file "<< filename << endl; - std::ofstream * newfile = new std::ofstream( filename.c_str() ); + std::ofstream * newfile = new std::ofstream( filename.c_str () ); dgDEBUG(5) << "Newfile:" << (void*) newfile << endl; hardFiles.push_back( newfile ); dgDEBUG(5) << "Creating Outstringstream" << endl; - //std::stringstream * newbuffer = new std::stringstream(); - OutStringStream * newbuffer = new OutStringStream(); // std::stringstream(); + //std::stringstream * newbuffer = new std::stringstream (); + OutStringStream * newbuffer = new OutStringStream (); // std::stringstream (); newbuffer->resize( bufferSize ); newbuffer->givenname = givenname; files.push_back( newbuffer ); @@ -151,21 +151,21 @@ openFile( const SignalBase<int> & sig, void TracerRealTime:: -closeFiles( void ) +closeFiles () { dgDEBUGIN(15); - FileList::iterator iter = files.begin(); - HardFileList::iterator hardIter = hardFiles.begin(); + FileList::iterator iter = files.begin (); + HardFileList::iterator hardIter = hardFiles.begin (); - while( files.end()!=iter ) + while( files.end ()!=iter ) { dgDEBUG(25) << "Close the files." << endl; std::stringstream * file = dynamic_cast< stringstream* >(*iter); std::ofstream * hardFile = *hardIter; - (*hardFile) <<flush; hardFile->close(); + (*hardFile) <<flush; hardFile->close (); delete file; delete hardFile; @@ -173,21 +173,21 @@ closeFiles( void ) } dgDEBUG(25) << "Clear the lists." << endl; - files.clear(); - hardFiles.clear(); + files.clear (); + hardFiles.clear (); dgDEBUGOUT(15); } void TracerRealTime:: -trace( void ) +trace () { dgDEBUGIN(15); - FileList::iterator iter = files.begin(); - HardFileList::iterator hardIter = hardFiles.begin(); + FileList::iterator iter = files.begin (); + HardFileList::iterator hardIter = hardFiles.begin (); - while( files.end()!=iter ) + while( files.end ()!=iter ) { dgDEBUG(35) << "Next" << endl; std::ostream * os = *iter; @@ -201,20 +201,20 @@ trace( void ) "The buffer is not open",""); } std::ofstream & hardFile = **hardIter; - if(! hardFile.good() ) + if(! hardFile.good () ) { DG_THROW ExceptionTraces( ExceptionTraces::NOT_OPEN, "The file is not open",""); } - if( (hardFile.good())&&(NULL!=file) ) + if( (hardFile.good ())&&(NULL!=file) ) { // const unsigned int SIZE = 1024*8; // char buffer[SIZE]; -// streambuf * pbuf = file.rdbuf(); +// streambuf * pbuf = file.rdbuf (); // pbuf->pubseekpos(0); -// const unsigned int NB_BYTE = pbuf->in_avail(); +// const unsigned int NB_BYTE = pbuf->in_avail (); // dgDEBUG(35) << "Bytes in buffer: " << NB_BYTE << endl; -// //dgDEBUG(35) << "Copie" <<endl<<file.str()<< endl; +// //dgDEBUG(35) << "Copie" <<endl<<file.str ()<< endl; // for( unsigned int index=0;index<NB_BYTE;index+=SIZE ) // { @@ -223,12 +223,12 @@ trace( void ) // dgDEBUG(35) << "Copie ["<<nget<<"] " <<buffer<<endl; // hardFile.write( buffer,nget ); // } - //hardFile << file.str() << flush; + //hardFile << file.str () << flush; //file.seekp(0); file->dump( hardFile ); - file->empty(); - hardFile.flush(); + file->empty (); + hardFile.flush (); //file.str(""); } @@ -240,15 +240,15 @@ trace( void ) } void TracerRealTime:: -emptyBuffers( void ) +emptyBuffers () { dgDEBUGIN(15); - for( FileList::iterator iter = files.begin();files.end()!=iter;++iter ) + for( FileList::iterator iter = files.begin ();files.end ()!=iter;++iter ) { //std::stringstream & file = * dynamic_cast< stringstream* >(*iter); try { OutStringStream & file = * dynamic_cast< OutStringStream* >(*iter); - file.empty(); + file.empty (); //file.str(""); } catch( ... ) { DG_THROW ExceptionTraces( ExceptionTraces::NOT_OPEN, @@ -261,8 +261,8 @@ emptyBuffers( void ) // void TracerRealTime:: // emptyBuffer( std::stringstream & file ) // { -// streambuf * pbuf = file.rdbuf(); -// pbuf->file.rdbuf() ->pubsetbuf( fileBuffer,10 ); +// streambuf * pbuf = file.rdbuf (); +// pbuf->file.rdbuf () ->pubsetbuf( fileBuffer,10 ); @@ -277,13 +277,13 @@ recordSignal( std::ostream& os, OutStringStream & file = dynamic_cast< OutStringStream& >(os); file.str(""); - dgDEBUG(45) << "Empty file [" << file.tellp() - << "] <" << file.str().c_str() <<"> " <<endl; + dgDEBUG(45) << "Empty file [" << file.tellp () + << "] <" << file.str ().c_str () <<"> " <<endl; Tracer::recordSignal( file,sig ); - file.addData( file.str().c_str(),file.tellp() ); - dgDEBUG(35) << "Write data [" << file.tellp() - << "] <" << file.str().c_str() <<"> " <<endl; + file.addData( file.str ().c_str (),file.tellp () ); + dgDEBUG(35) << "Write data [" << file.tellp () + << "] <" << file.str ().c_str () <<"> " <<endl; } catch( ExceptionAbstract & exc ) { throw exc; } catch( ... ) { @@ -309,18 +309,18 @@ display( std::ostream& os ) const << "] : "<< endl << " - Dep list: "<<endl; - FileList::const_iterator iterFile = files.begin(); - for( SignalList::const_iterator iter = toTraceSignals.begin(); - toTraceSignals.end()!=iter;++iter ) + FileList::const_iterator iterFile = files.begin (); + for( SignalList::const_iterator iter = toTraceSignals.begin (); + toTraceSignals.end ()!=iter;++iter ) { dgDEBUG(35) << "Next" << endl; const OutStringStream * file = dynamic_cast< OutStringStream* >(*iterFile); - os << " -> "<<(*iter)->getName(); - if( file->givenname.length() ) os << " (in " << file->givenname << ")" ; + os << " -> "<<(*iter)->getName (); + if( file->givenname.length () ) os << " (in " << file->givenname << ")" ; os << "\t"; if( file ) { - const std::streamsize PRECISION = os.precision(); + const std::streamsize PRECISION = os.precision (); const unsigned int SIZE = file->index; const unsigned int MSIZE = file->bufferSize; unsigned int dec=0; std::string unit =""; @@ -363,17 +363,17 @@ commandLine( const std::string& cmdLine } else if( cmdLine=="empty" ) { - emptyBuffers(); + emptyBuffers (); } else if( cmdLine=="bufferSize" ) { cmdArgs>>ws; - if( cmdArgs.good() ) + if( cmdArgs.good () ) { int s; cmdArgs>>s; setBufferSize( s ); } - else os << getBufferSize() << endl; + else os << getBufferSize () << endl; } diff --git a/src/traces/tracer.cpp b/src/traces/tracer.cpp index b44b41a..dc01df8 100644 --- a/src/traces/tracer.cpp +++ b/src/traces/tracer.cpp @@ -40,15 +40,15 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(Tracer,"Tracer"); Tracer::Tracer( const std::string n ) :Entity(n) - ,toTraceSignals() + ,toTraceSignals () ,traceStyle(TRACE_STYLE_DEFAULT) ,frequency(1) - ,basename() + ,basename () ,suffix(".dat") - ,rootdir() + ,rootdir () ,namesSet( false ) - ,files() - ,names() + ,files () + ,names () ,play(false) ,timeStart(0) ,triger( boost::bind(&Tracer::recordTrigger,this,_1,_2), @@ -80,10 +80,10 @@ addSignalToTrace( const SignalBase<int>& sig, * the files in particular. */ void Tracer:: -clearSignalToTrace( void ) +clearSignalToTrace () { - toTraceSignals.clear(); - triger.clearDependencies(); + toTraceSignals.clear (); + triger.clearDependencies (); } @@ -98,20 +98,20 @@ openFiles( const std::string& rootdir_, const std::string& basename_, const std::string& suffix_ ) { dgDEBUGIN(15); - int n = rootdir_.length(); + int n = rootdir_.length (); rootdir=rootdir_; if( (0<n)&('/'!=rootdir[n-1]) ) rootdir+='/'; basename=basename_; suffix=suffix_; - if( files.size() ) closeFiles(); + if( files.size () ) closeFiles (); - SignalList::const_iterator iter = toTraceSignals.begin(); - NameList::const_iterator iterName = names.begin(); - while( toTraceSignals.end()!=iter ) + SignalList::const_iterator iter = toTraceSignals.begin (); + NameList::const_iterator iterName = names.begin (); + while( toTraceSignals.end ()!=iter ) { - dgDEBUG(15) << "Open <" << (*iter)->getName() + dgDEBUG(15) << "Open <" << (*iter)->getName () << "> in <" << *iterName << ">." << std::endl; openFile( **iter,*iterName ); ++iter; ++iterName; @@ -127,29 +127,29 @@ openFile( const SignalBase<int> & sig, { dgDEBUGIN(15); string signame; - if( givenname.length() ) - { signame = givenname; } else { signame = sig.shortName(); } + if( givenname.length () ) + { signame = givenname; } else { signame = sig.shortName (); } string filename = rootdir + basename + signame + suffix; - dgDEBUG(5) << "Sig <"<< sig.getName() << ">: new file "<< filename << endl; - std::ofstream * newfile = new std::ofstream( filename.c_str() ); + dgDEBUG(5) << "Sig <"<< sig.getName () << ">: new file "<< filename << endl; + std::ofstream * newfile = new std::ofstream( filename.c_str () ); files.push_back( newfile ); dgDEBUGOUT(15); } void Tracer:: -closeFiles( void ) +closeFiles () { dgDEBUGIN(15); - for( FileList::iterator iter = files.begin();files.end()!=iter;++iter ) + for( FileList::iterator iter = files.begin ();files.end ()!=iter;++iter ) { std::ostream * filePtr = *iter; delete filePtr; } - files.clear(); + files.clear (); dgDEBUGOUT(15); } @@ -159,21 +159,21 @@ closeFiles( void ) /* --------------------------------------------------------------------- */ void Tracer:: -record( void ) +record () { if(! play) { dgDEBUGINOUT(15); return;} dgDEBUGIN(15); - if( files.size()!=toTraceSignals.size() ) + if( files.size ()!=toTraceSignals.size () ) { DG_THROW ExceptionTraces( ExceptionTraces::NOT_OPEN, "No files open for tracing"," (file=%d != %d=sig).", - files.size(),toTraceSignals.size()); } + files.size (),toTraceSignals.size ()); } - FileList::iterator iterFile = files.begin(); - SignalList::iterator iterSig = toTraceSignals.begin(); + FileList::iterator iterFile = files.begin (); + SignalList::iterator iterSig = toTraceSignals.begin (); - while( toTraceSignals.end()!=iterSig ) + while( toTraceSignals.end ()!=iterSig ) { dgDEBUG(45) << "Try..." <<endl; recordSignal( **iterFile,**iterSig ); @@ -189,9 +189,9 @@ recordSignal( std::ostream& os, dgDEBUGIN(15); try { - if( sig.getTime()>timeStart ) + if( sig.getTime ()>timeStart ) { - os<< sig.getTime() << "\t"; + os<< sig.getTime () << "\t"; sig.trace(os); os<<endl; } } @@ -207,14 +207,14 @@ int& Tracer:: recordTrigger( int& dummy, const int& time ) { dgDEBUGIN(15) << " time="<<time <<endl; - record(); + record (); dgDEBUGOUT(15); return dummy; } void Tracer:: -trace( void ) +trace () { } @@ -229,9 +229,9 @@ display( std::ostream& os ) const os << CLASS_NAME << " " << name << " [mode=" << (play?"play":"pause") << "] : "<< endl << " - Dep list: "<<endl; - for( SignalList::const_iterator iter = toTraceSignals.begin(); - toTraceSignals.end()!=iter;++iter ) - { os << " -> "<<(*iter)->getName()<<endl; } + for( SignalList::const_iterator iter = toTraceSignals.begin (); + toTraceSignals.end ()!=iter;++iter ) + { os << " -> "<<(*iter)->getName ()<<endl; } } @@ -266,18 +266,18 @@ commandLine( const std::string& cmdLine SignalBase<int> &sig = g_pool.getSignal(cmdArgs); string r; cmdArgs>>ws>>r; addSignalToTrace(sig,r); - dgDEBUG(14)<<"Add <" <<sig.getName()<<"> with nick \""<<r<<"\""<<endl; + dgDEBUG(14)<<"Add <" <<sig.getName ()<<"> with nick \""<<r<<"\""<<endl; } else if( cmdLine=="clear" ) - { closeFiles(); toTraceSignals.clear(); } + { closeFiles (); toTraceSignals.clear (); } else if( cmdLine=="open" ) { string n,r="",s=".dat"; cmdArgs>>ws>>r; - if( cmdArgs.good() ) + if( cmdArgs.good () ) { cmdArgs>>ws>>n; - if( cmdArgs.good() ) + if( cmdArgs.good () ) { cmdArgs>>ws>>s; } @@ -285,18 +285,18 @@ commandLine( const std::string& cmdLine //>>r>>s; dgDEBUGF( 15,"Close files."); - closeFiles(); + closeFiles (); dgDEBUGF( 15,"Open files \"%s\" \"%s\" \"%s\".", - r.c_str(),n.c_str(),s.c_str()); + r.c_str (),n.c_str (),s.c_str ()); openFiles(r,n,s); } - else if( cmdLine=="close" ) { closeFiles(); } - else if( cmdLine=="trace" ) { trace(); } + else if( cmdLine=="close" ) { closeFiles (); } + else if( cmdLine=="trace" ) { trace (); } else if( cmdLine=="record" ) { //unsigned int t; - //cmdArgs >> ws>>t; if(! cmdArgs.good() ) t=0; - record(); + //cmdArgs >> ws>>t; if(! cmdArgs.good () ) t=0; + record (); } // else if( cmdLine=="parasite" ) // { @@ -307,7 +307,7 @@ commandLine( const std::string& cmdLine else if( cmdLine == "stop" ) { play=false; } else if( cmdLine == "timeStart" ) { - cmdArgs >> std::ws; if(! cmdArgs.good() ) + cmdArgs >> std::ws; if(! cmdArgs.good () ) { os << "timeStart = " << timeStart << std::endl; } else { cmdArgs >> timeStart; } } -- GitLab