From d324d68aee4e079bcd7ea54ef226db8948ecaeba Mon Sep 17 00:00:00 2001 From: Thomas Moulard <thomas.moulard@gmail.com> Date: Sat, 1 Jan 2011 19:39:10 +0100 Subject: [PATCH] Comment classes. --- include/dynamic-graph/#shell-procedure.h# | 97 ++++++++++++++++ include/dynamic-graph/.#shell-procedure.h | 1 + include/dynamic-graph/debug.h | 124 +++++++++++---------- include/dynamic-graph/entity.h | 24 ++-- include/dynamic-graph/exception-abstract.h | 42 ++++--- include/dynamic-graph/exception-factory.h | 9 +- include/dynamic-graph/exception-signal.h | 4 + include/dynamic-graph/exception-traces.h | 3 + include/dynamic-graph/factory.h | 7 +- include/dynamic-graph/shell-procedure.h | 22 ++-- include/dynamic-graph/signal-array.h | 7 +- include/dynamic-graph/signal-ptr.h | 16 +-- include/dynamic-graph/tracer-real-time.h | 37 +++--- include/dynamic-graph/tracer.h | 3 + src/plugins/shell-procedure.cpp | 9 -- 15 files changed, 274 insertions(+), 131 deletions(-) create mode 100644 include/dynamic-graph/#shell-procedure.h# create mode 120000 include/dynamic-graph/.#shell-procedure.h diff --git a/include/dynamic-graph/#shell-procedure.h# b/include/dynamic-graph/#shell-procedure.h# new file mode 100644 index 00000000..3f80f010 --- /dev/null +++ b/include/dynamic-graph/#shell-procedure.h# @@ -0,0 +1,97 @@ +// -*- 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 +# incxlude <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 in a shell. +class DG_SHELLPROCEDURE_DLLAPI ShellProcedure +{ + public: + /// \brief Symbolizes a function call in the dynamic-graph language. + struct Instruction + { + /// \brief Command name. + std::string cmd; + /// \brief Arguments lists. + std::vector<std::string> args; + + std::vector<int> params; + }; + + /// \brief Symbolizes a procedure in the dynamic-graph language. + struct Procedure + { + /// \brief Store the procedure body. + std::list<Instruction> instructions; + /// \brief Store the procedure arguments. + std::vector<std::string> params; + + /// \brief Reset the procedure. + void clear () + { + instructions.clear (); + params.clear (); + } + }; + + /// \brief Map procedure name to their body. + typedef std::map<std::string, Procedure> ProcedureList; + + public: + std::string procName; + ProcedureList procedureList; + 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); +}; + +#endif //! DYNAMIC_GRAPH_SHELL_PROCEDURE_H diff --git a/include/dynamic-graph/.#shell-procedure.h b/include/dynamic-graph/.#shell-procedure.h new file mode 120000 index 00000000..0287ba36 --- /dev/null +++ b/include/dynamic-graph/.#shell-procedure.h @@ -0,0 +1 @@ +thomas@cleo.16209:1293725997 \ No newline at end of file diff --git a/include/dynamic-graph/debug.h b/include/dynamic-graph/debug.h index e55a2508..cef0eed9 100644 --- a/include/dynamic-graph/debug.h +++ b/include/dynamic-graph/debug.h @@ -46,67 +46,73 @@ namespace dynamicgraph { - class DYNAMIC_GRAPH_DLLAPI DebugTrace + /// \ingroup debug + /// + /// \brief Logging class. + /// + /// This class should never be used directly, please use the + /// debugging macro instead. + 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, ...) { - 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, ...) - { + 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 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); - }; + 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; diff --git a/include/dynamic-graph/entity.h b/include/dynamic-graph/entity.h index 5f8cfa54..921bcad6 100644 --- a/include/dynamic-graph/entity.h +++ b/include/dynamic-graph/entity.h @@ -32,18 +32,18 @@ namespace dynamicgraph { - /*! \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 (). - */ + /// \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: diff --git a/include/dynamic-graph/exception-abstract.h b/include/dynamic-graph/exception-abstract.h index 64036b40..155f6b8e 100644 --- a/include/dynamic-graph/exception-abstract.h +++ b/include/dynamic-graph/exception-abstract.h @@ -44,9 +44,15 @@ namespace dynamicgraph { + /// \ingroup error + /// + /// \brief Abstract root class for all dynamic-graph exceptions. class DYNAMIC_GRAPH_DLLAPI ExceptionAbstract : public std::exception { public: + /// \ingroup error + /// + /// \brief Class owned by exceptions to store error locations. class Param { public: @@ -73,7 +79,13 @@ namespace dynamicgraph bool set; }; - + /// \brief Categories error code. + /// + /// Each value matches categories used by a subclass of + /// ExceptionAbstract. + /// + /// This is the programmer responsibility to make sure there is + /// enough room between two categories error code. enum ExceptionEnum { ABSTRACT = 0, @@ -94,16 +106,16 @@ namespace dynamicgraph return EXCEPTION_NAME; } - /** Access to the error code. */ + /// \brief Access to the error code. int getCode () const; - /** Reference access to the error message (can be empty). */ + /// \brief Reference access to the error message (can be empty). const std::string& getStringMessage () const; - /** Access to the pointer on the array of \e char related to the - * error string. - * Cannot be \e NULL. - */ + /// \brief Access to the pointer on the array of \e char related + /// to the error string. + /// + /// Cannot be \e NULL. const char* getMessage () const; virtual const char* what () const throw () @@ -111,20 +123,24 @@ namespace dynamicgraph return getStringMessage ().c_str (); } - /** Print the error structure. */ - DYNAMIC_GRAPH_DLLAPI friend std::ostream & + /// \brief Print the error structure. + DYNAMIC_GRAPH_DLLAPI friend std::ostream& operator << (std::ostream & os, const ExceptionAbstract & err); protected: - /** Error code. - * \sa ErrorCodeEnum */ + /// \brief Error code. + /// \sa ErrorCodeEnum int code; - /** Error message (can be empty). */ + /// \brief Error message (can be empty). std::string message; # ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM + /// \brief Optional mutable attribute to store exception location. + /// + /// Only present if DYNAMICGRAPH_EXCEPTION_PASSING_PARAM + /// preprocessor symbol exists. mutable Param p; template<class Exc> @@ -146,7 +162,7 @@ namespace dynamicgraph # endif // DYNAMICGRAPH_EXCEPTION_PASSING_PARAM private: - /// forbid the empty constructor (private). + /// \brief Forbid the empty constructor (private). ExceptionAbstract (); }; } // end of namespace dynamicgraph diff --git a/include/dynamic-graph/exception-factory.h b/include/dynamic-graph/exception-factory.h index 55e53e1a..214c8e28 100644 --- a/include/dynamic-graph/exception-factory.h +++ b/include/dynamic-graph/exception-factory.h @@ -25,7 +25,10 @@ namespace dynamicgraph { - class DYNAMIC_GRAPH_DLLAPI ExceptionFactory :public ExceptionAbstract + /// \ingroup error + /// + /// \brief Generic error class. + class DYNAMIC_GRAPH_DLLAPI ExceptionFactory : public ExceptionAbstract { public: enum ErrorCodeEnum @@ -46,10 +49,10 @@ namespace dynamicgraph 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 () {} diff --git a/include/dynamic-graph/exception-signal.h b/include/dynamic-graph/exception-signal.h index 5d25fd21..fcf379cc 100644 --- a/include/dynamic-graph/exception-signal.h +++ b/include/dynamic-graph/exception-signal.h @@ -24,6 +24,10 @@ namespace dynamicgraph { + /// \ingroup error + /// + /// \brief Exceptions raised when an error related to signals + /// happen. class DYNAMIC_GRAPH_DLLAPI ExceptionSignal : public ExceptionAbstract { public: diff --git a/include/dynamic-graph/exception-traces.h b/include/dynamic-graph/exception-traces.h index 463447eb..81ab6767 100644 --- a/include/dynamic-graph/exception-traces.h +++ b/include/dynamic-graph/exception-traces.h @@ -25,6 +25,9 @@ namespace dynamicgraph { + /// \ingroup error + /// + /// \brief Exceptions raised when an error related to traces happen. class DYNAMIC_GRAPH_DLLAPI ExceptionTraces : public ExceptionAbstract { public: diff --git a/include/dynamic-graph/factory.h b/include/dynamic-graph/factory.h index c62a1fc6..b51b11b0 100644 --- a/include/dynamic-graph/factory.h +++ b/include/dynamic-graph/factory.h @@ -27,7 +27,8 @@ # include <dynamic-graph/exception-factory.h> # include <dynamic-graph/dynamic-graph-api.h> - +/// \ingroup dgraph +/// /// \brief Automatically register a class to the global factory /// by relying on the static initialization. /// @@ -192,6 +193,8 @@ namespace dynamicgraph EntityMap entityMap; }; + /// \ingroup dgraph + /// /// \brief Global factory. /// /// This global variable is the only valid instance of the @@ -208,6 +211,8 @@ namespace dynamicgraph DYNAMIC_GRAPH_DLLAPI extern FactoryStorage g_factory; + /// \ingroup dgraph + /// /// \brief This class automatically register an Entity to the /// global factory at initialization and unregister it during /// instance destruction. diff --git a/include/dynamic-graph/shell-procedure.h b/include/dynamic-graph/shell-procedure.h index 6a3af44d..8b865087 100644 --- a/include/dynamic-graph/shell-procedure.h +++ b/include/dynamic-graph/shell-procedure.h @@ -27,27 +27,35 @@ # 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. -*/ +/// \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 in a shell. class DG_SHELLPROCEDURE_DLLAPI ShellProcedure { public: + /// \brief Symbolizes a function call in the dynamic-graph language. struct Instruction { + /// \brief Command name. std::string cmd; + /// \brief Arguments lists. std::vector<std::string> args; + std::vector<int> params; }; + /// \brief Symbolizes a procedure in the dynamic-graph language. struct Procedure { + /// \brief Store the procedure body. std::list<Instruction> instructions; + /// \brief Store the procedure arguments. std::vector<std::string> params; + /// \brief Reset the procedure. void clear () { instructions.clear (); @@ -55,12 +63,12 @@ class DG_SHELLPROCEDURE_DLLAPI ShellProcedure } }; + /// \brief Map procedure name to their body. typedef std::map<std::string, Procedure> ProcedureList; public: std::string procName; ProcedureList procedureList; - Procedure currentProc; public: diff --git a/include/dynamic-graph/signal-array.h b/include/dynamic-graph/signal-array.h index 19fad5a8..fe12d09a 100644 --- a/include/dynamic-graph/signal-array.h +++ b/include/dynamic-graph/signal-array.h @@ -22,6 +22,9 @@ namespace dynamicgraph { + /// \ingroup dgraph + /// + /// \brief TODO template<class Time> class SignalArray_const { @@ -118,7 +121,9 @@ namespace dynamicgraph return res; } - + /// \ingroup dgraph + /// + /// \brief TODO template<class Time> class SignalArray : public SignalArray_const<Time> { diff --git a/include/dynamic-graph/signal-ptr.h b/include/dynamic-graph/signal-ptr.h index 6d1ad06d..f048f8e8 100644 --- a/include/dynamic-graph/signal-ptr.h +++ b/include/dynamic-graph/signal-ptr.h @@ -24,14 +24,14 @@ 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. - */ + /// \ingroup dgraph + /// + /// \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> { diff --git a/include/dynamic-graph/tracer-real-time.h b/include/dynamic-graph/tracer-real-time.h index 64f553f7..2a4939ba 100644 --- a/include/dynamic-graph/tracer-real-time.h +++ b/include/dynamic-graph/tracer-real-time.h @@ -25,6 +25,9 @@ namespace dynamicgraph { + /// \ingroup plugin + /// + /// \brief Stream for the tracer real-time. class DG_TRACERREALTIME_DLLAPI OutStringStream : public std::ostringstream { public: @@ -44,6 +47,9 @@ namespace dynamicgraph void empty (); }; + /// \ingroup plugin + /// + /// \brief Main class of the tracer real-time plug-in. class DG_TRACERREALTIME_DLLAPI TracerRealTime : public Tracer { public: @@ -53,20 +59,21 @@ namespace dynamicgraph 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 (); + + void display (std::ostream& os) const; + DG_TRACERREALTIME_DLLAPI friend std::ostream& operator<< + (std::ostream& os, const TracerRealTime& t); + + virtual void commandLine (const std::string& cmdLine, + std::istringstream& cmdArgs, + std::ostream& os); + protected: virtual void openFile (const SignalBase<int>& sig, const std::string& filename); @@ -75,7 +82,6 @@ namespace dynamicgraph const SignalBase<int>& sig); void emptyBuffers (); - public: void setBufferSize (const int& SIZE) { bufferSize=SIZE; @@ -86,16 +92,11 @@ namespace dynamicgraph return bufferSize; } - public: - /* --- DISPLAY ---------------------------------------------------------- */ - void display (std::ostream& os) const; - DG_TRACERREALTIME_DLLAPI friend std::ostream& operator<< - (std::ostream& os, const TracerRealTime& t); + typedef std::list<std::ofstream*> HardFileList; + static const int BUFFER_SIZE_DEFAULT = 1048576; // 1Mo - /* --- PARAMS --- */ - virtual void commandLine (const std::string& cmdLine - ,std::istringstream& cmdArgs - ,std::ostream& os); + int bufferSize; + HardFileList hardFiles; }; } // end of namespace dynamicgraph diff --git a/include/dynamic-graph/tracer.h b/include/dynamic-graph/tracer.h index 24044ddf..c335820a 100644 --- a/include/dynamic-graph/tracer.h +++ b/include/dynamic-graph/tracer.h @@ -31,6 +31,9 @@ namespace dynamicgraph { + /// \ingroup plugin + /// + /// \brief Tracer plug-in main class. class DG_TRACER_DLLAPI Tracer : public Entity { protected: diff --git a/src/plugins/shell-procedure.cpp b/src/plugins/shell-procedure.cpp index 38f00a11..772583ca 100644 --- a/src/plugins/shell-procedure.cpp +++ b/src/plugins/shell-procedure.cpp @@ -99,15 +99,6 @@ cmdEndProcedure( const std::string& cmdLine,std::istringstream&, std::ostream& o dgDEBUG(5)<<"Proc <" <<procName<<">: endproc"<<endl; procedureList[ procName ] = currentProc; - -// std::string toto="toto"; -// for( Procedure::iterator ins=procedureList[ toto ].begin (); -// ins!=procedureList[ toto ].end (); ++ins ) -// { -// dgDEBUG(15) << "Proc <" << procName << "> : " -// << ins->cmd << " -> " << ins->args <<endl; -// } - currentProc.clear (); if( g_shell.deregisterFunction( procName )) -- GitLab