Commit b6491883 authored by Thomas Moulard's avatar Thomas Moulard
Browse files

Clean code.

parent 99b70dba
/* // -*- mode: c++ -*-
* Copyright 2010, // Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
* François Bleibel, // JRL, CNRS/AIST.
* Olivier Stasse, //
* // This file is part of dynamic-graph.
* CNRS/AIST // dynamic-graph is free software: you can redistribute it and/or
* // modify it under the terms of the GNU Lesser General Public License
* This file is part of dynamic-graph. // as published by the Free Software Foundation, either version 3 of
* dynamic-graph is free software: you can redistribute it and/or // the License, or (at your option) any later version.
* modify it under the terms of the GNU Lesser General Public License //
* as published by the Free Software Foundation, either version 3 of // dynamic-graph is distributed in the hope that it will be useful, but
* the License, or (at your option) any later version. // WITHOUT ANY WARRANTY; without even the implied warranty of
* dynamic-graph is distributed in the hope that it will be // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty // General Lesser Public License for more details. You should have
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // received a copy of the GNU Lesser General Public License along with
* GNU Lesser General Public License for more details. You should // dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
* 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_ #ifndef DYNAMIC_GRAPH_ALL_SIGNALS_H
#define ALLSIGNALS_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.h>
#include <dynamic-graph/signal-ptr.h> # include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h> # include <dynamic-graph/signal-time-dependent.h>
#endif /* ALLSIGNALS_H_ */ #endif //! DYNAMIC_GRAPH_ALL_SIGNALS_H
/* // -*- mode: c++ -*-
* Copyright 2010, // Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
* François Bleibel, // JRL, CNRS/AIST.
* Olivier Stasse, //
* // This file is part of dynamic-graph.
* CNRS/AIST // dynamic-graph is free software: you can redistribute it and/or
* // modify it under the terms of the GNU Lesser General Public License
* This file is part of dynamic-graph. // as published by the Free Software Foundation, either version 3 of
* dynamic-graph is free software: you can redistribute it and/or // the License, or (at your option) any later version.
* modify it under the terms of the GNU Lesser General Public License //
* as published by the Free Software Foundation, either version 3 of // dynamic-graph is distributed in the hope that it will be useful, but
* the License, or (at your option) any later version. // WITHOUT ANY WARRANTY; without even the implied warranty of
* dynamic-graph is distributed in the hope that it will be // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty // General Lesser Public License for more details. You should have
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // received a copy of the GNU Lesser General Public License along with
* GNU Lesser General Public License for more details. You should // dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
* 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>
#ifndef __CONTIIFSTREAM_HH__ # include <iostream>
#define __CONTIIFSTREAM_HH__ # 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 ();
/* --------------------------------------------------------------------- */ inline void open (const std::string& n)
/* --- INCLUDE --------------------------------------------------------- */ {
/* --------------------------------------------------------------------- */ filename=n;
cursor=0;
}
bool loop ();
#include <iostream> inline bool ready ()
#include <fstream> {
#include <sstream> return 0 < reader.size ();
#ifndef WIN32 }
# include <unistd.h>
#endif
#include <list>
#include <dynamic-graph/interpreter.h> std::string next ();
#include <dynamic-graph/config-contiifstream.hh>
#ifndef WIN32
# include <pthread.h>
#endif
namespace dynamicgraph {
/* --------------------------------------------------------------------- */
/* --- CLASS ----------------------------------------------------------- */
/* --------------------------------------------------------------------- */
class DG_CONTIIFSTREAM_DLLAPI Contiifstream
{
protected: protected:
std::string filename; std::string filename;
std::streamoff cursor; std::streamoff cursor;
...@@ -53,25 +61,7 @@ namespace dynamicgraph { ...@@ -53,25 +61,7 @@ namespace dynamicgraph {
char buffer[BUFFER_SIZE]; char buffer[BUFFER_SIZE];
std::list< std::string > reader; std::list< std::string > reader;
bool first; 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 } // end of namespace dynamicgraph.
#endif /* #ifndef __CONTIIFSTREAM_HH__ */
#endif //! DYNAMIC_GRAPH_CONTIIFSTREAM_H
/* // -*- mode: c++ -*-
* Copyright 2010, // Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
* François Bleibel, // JRL, CNRS/AIST.
* Olivier Stasse, //
* // This file is part of dynamic-graph.
* CNRS/AIST // dynamic-graph is free software: you can redistribute it and/or
* // modify it under the terms of the GNU Lesser General Public License
* This file is part of dynamic-graph. // as published by the Free Software Foundation, either version 3 of
* dynamic-graph is free software: you can redistribute it and/or // the License, or (at your option) any later version.
* modify it under the terms of the GNU Lesser General Public License //
* as published by the Free Software Foundation, either version 3 of // dynamic-graph is distributed in the hope that it will be useful, but
* the License, or (at your option) any later version. // WITHOUT ANY WARRANTY; without even the implied warranty of
* dynamic-graph is distributed in the hope that it will be // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty // General Lesser Public License for more details. You should have
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // received a copy of the GNU Lesser General Public License along with
* GNU Lesser General Public License for more details. You should // dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
* 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 * Macro de trace et de debugage
...@@ -36,139 +33,243 @@ ...@@ -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 // TEMPLATE
#define __DEBUG_HH # 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> inline bool dgTDEBUG_ENABLE (const int & level)
#include <iostream> {
#include <fstream> return level<=VP_TEMPLATE_DEBUG_MODE;
#include <sstream> }
#include <stdarg.h>
#include <dynamic-graph/dynamic-graph-api.h>
# else // VP_DEBUG
/* -------------------------------------------------------------------------- */ # define dgPREERROR \
/* -------------------------------------------------------------------------- */ "\t!! "<<__FILE__ << ": " <<__FUNCTION__ << "(#" << __LINE__ << ") :"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ # define dgDEBUG(level) \
if (1) \
; \
else \
std::cout
#ifndef VP_DEBUG_MODE # define dgDEBUGMUTE (level) \
#define VP_DEBUG_MODE 0 if (1) \
#endif ; \
#ifndef VP_TEMPLATE_DEBUG_MODE else \
#define VP_TEMPLATE_DEBUG_MODE 0 std::cout
#endif
#define DG_COMMON_TRACES do { \ # define dgERROR \
va_list arg; \ dgERRORFLOW.outputbuffer << dgPREERROR
va_start(arg,format); \
vsnprintf( charbuffer,SIZE,format,arg ); \
va_end(arg); \
outputbuffer << tmpbuffer.str() << charbuffer <<std::endl; \
} while(0)
namespace dynamicgraph { inline void dgDEBUGF (const int, const char*, ...)
{
return;
}
class DYNAMIC_GRAPH_DLLAPI DebugTrace inline void dgDEBUGF (const char*, ...)
{ {
public: return;
static const int SIZE = 512; }
std::stringstream tmpbuffer; inline void dgERRORF (const int, const char*, ...)
std::ostream& outputbuffer; {
char charbuffer[SIZE+1]; return;
int traceLevel; }
int traceLevelTemplate;
inline void dgERRORF (const char*, ...)
DebugTrace( std::ostream& os ): outputbuffer(os) {} {
return;
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; }
// TEMPLATE // TEMPLATE
# define dgTDEBUG(level) if( 1 ) ; else std::cout # define dgTDEBUG(level) \
inline void dgTDEBUGF( const int, const char*,...) { return; } if (1) \
inline void dgTDEBUGF( const char*,...) { return; } ; \
#define dgDEBUG_ENABLE(level) false else \
#define dgTDEBUG_ENABLE(level) false std::cout
#endif // #ifdef VP_DEBUG inline void dgTDEBUGF (const int, const char*, ...)
/* -------------------------------------------------------------------------- */ {
return;
}
#define dgDEBUGIN(level) dgDEBUG(level) << "# In {" << std::endl inline void dgTDEBUGF (const char*, ...)
#define dgDEBUGOUT(level) dgDEBUG(level) << "# Out }" << std::endl {
#define dgDEBUGINOUT(level) dgDEBUG(level) << "# In/Out { }" << std::endl return;
}
#define dgTDEBUGIN(level) dgTDEBUG(level) << "# In {" << std::endl # define dgDEBUG_ENABLE(level) false
#define dgTDEBUGOUT(level) dgTDEBUG(level) << "# Out }" << std::endl # define dgTDEBUG_ENABLE(level) false
#define dgTDEBUGINOUT(level) dgTDEBUG(level) << "# In/Out { }" << std::endl
# endif //! VP_DEBUG
#endif /* #ifdef __VS_DEBUG_HH */ # define dgDEBUGIN(level) \
dgDEBUG(level) << "# In {" << std::endl
/* # define dgDEBUGOUT(level) \
* Local variables: dgDEBUG(level) << "# Out }" << std::endl
* c-basic-offset: 4
* End: # 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
/* // -*- mode: c++ -*-
* Copyright 2010, // Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
* François Bleibel, // JRL, CNRS/AIST.
* Olivier Stasse, //
* // This file is part of dynamic-graph.
* CNRS/AIST // dynamic-graph is free software: you can redistribute it and/or
* // modify it under the terms of the GNU Lesser General Public License
* This file is part of dynamic-graph. // as published by the Free Software Foundation, either version 3 of
* dynamic-graph is free software: you can redistribute it and/or // the License, or (at your option) any later version.
* modify it under the terms of the GNU Lesser General Public License //
* as published by the Free Software Foundation, either version 3 of // dynamic-graph is distributed in the hope that it will be useful, but
* the License, or (at your option) any later version. // WITHOUT ANY WARRANTY; without even the implied warranty of
* dynamic-graph is distributed in the hope that it will be // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty // General Lesser Public License for more details. You should have
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // received a copy of the GNU Lesser General Public License along with
* GNU Lesser General Public License for more details. You should // dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
* have received a copy of the GNU Lesser General Public License along
* with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
*/