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

Clean code.

parent 99b70dba
/*
* 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
/*
* 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
/*
* 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
/*
* 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