Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cberge/dynamic-graph
  • ostasse/dynamic-graph
  • gsaurel/dynamic-graph
  • stack-of-tasks/dynamic-graph
4 results
Show changes
Showing
with 1663 additions and 1471 deletions
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-Japan, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: ExceptionTraces.h
* Project: SOT
* Author: Nicolas Mansard
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// -*- mode: c++ -*-
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
// JRL, CNRS/AIST.
//
#ifndef __TRACES_EXCEPTION_H
#define __TRACES_EXCEPTION_H
/* --------------------------------------------------------------------- */
/* --- INCLUDE --------------------------------------------------------- */
/* --------------------------------------------------------------------- */
#include <dynamic-graph/exception-abstract.h>
#ifndef DYNAMIC_GRAPH_EXCEPTION_TRACES_H
#define DYNAMIC_GRAPH_EXCEPTION_TRACES_H
#include <dynamic-graph/dynamic-graph-api.h>
#include <dynamic-graph/exception-abstract.h>
/* --------------------------------------------------------------------- */
/* --- CLASS ----------------------------------------------------------- */
/* --------------------------------------------------------------------- */
#include <dynamic-graph/fwd.hh>
#include <string>
namespace dynamicgraph {
/* \class ExceptionTraces
*/
class DYNAMICGRAPH_EXPORT ExceptionTraces
:public ExceptionAbstract
{
/// \ingroup error
///
/// \brief Exceptions raised when an error related to traces happen.
class DYNAMIC_GRAPH_DLLAPI ExceptionTraces : public ExceptionAbstract {
public:
enum ErrorCodeEnum
{
GENERIC = ExceptionAbstract::TRACES
,NOT_OPEN
};
enum ErrorCodeEnum { GENERIC = ExceptionAbstract::TRACES, NOT_OPEN };
static const std::string EXCEPTION_NAME;
virtual const std::string& getExceptionName( void ) const { return EXCEPTION_NAME; }
public:
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
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-Japan, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: g_factory.h
* Project: DYNAMIC-GRAPH
* Author: François Bleibel (from Nicolas Mansard)
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#ifndef __FACTORY_HH__
#define __FACTORY_HH__
/* --------------------------------------------------------------------- */
/* --- INCLUDE --------------------------------------------------------- */
/* --------------------------------------------------------------------- */
/* --- STD --- */
#include <map>
#include <string>
// -*- mode: c++ -*-
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
// JRL, CNRS/AIST.
//
/* --- DYNAMIC-GRAPH --- */
#include <dynamic-graph/exception-factory.h>
#ifndef DYNAMIC_GRAPH_FACTORY_HH
#define DYNAMIC_GRAPH_FACTORY_HH
#include <dynamic-graph/dynamic-graph-api.h>
#include <dynamic-graph/exception-factory.h>
namespace dynamicgraph {
#include <boost/noncopyable.hpp>
#include <dynamic-graph/fwd.hh>
#include <map>
#include <string>
#include <vector>
/// \ingroup dgraph
///
/// \brief Automatically register a class to the global factory
/// by relying on the static initialization.
///
/// \param CLASSTYPE the Entity type to be registered
/// \param CLASSNAME the name of the Entity to be registered (this must
/// be a std::string or a type implicitly castable into a std::string
/// such as classic C string delimited by double quotes).
#define DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CLASSTYPE, CLASSNAME) \
const std::string CLASSTYPE::CLASS_NAME = CLASSNAME; \
extern "C" { \
::dynamicgraph::Entity *EntityMaker_##CLASSTYPE( \
const std::string &objname) { \
return new CLASSTYPE(objname); \
} \
::dynamicgraph::EntityRegisterer reg_##CLASSTYPE(CLASSNAME, \
&EntityMaker_##CLASSTYPE); \
} \
struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
class Entity;
/* --------------------------------------------------------------------- */
/* --- FACTORY ---------------------------------------------------------- */
/* --------------------------------------------------------------------- */
/*! \class FactoryStorage
* \ingroup dgraph
* \brief The Factory class is responsible for creating Entity objects.
*
* Entities can register themselves through the helper class EntityRegisterer.
* This object also provides access to command-line functions.
*
*
*/
class DYNAMICGRAPH_EXPORT FactoryStorage
{
namespace dynamicgraph {
/// \ingroup dgraph
///
/// \brief Provides a way to create Entity objects from their class
/// name.
///
/// The dynamic graph frameworks relies on entities (see Entity)
/// which defines atomic processing units. This class provides a
/// robust way to enumerate and instantiate these entities.
/// Each entity has a name (its type name) and can be instantiated.
/// Each instance also has a name.
///
/// For instance one can define a C++ class called MyEntity which
/// inherits from dynamicgraph::Entity. This type can be registered
/// into the factory to teach the framework that:
/// - this entity exists
/// - this entity can be instantiated (and how to instantiate it).
///
/// To achieve this, one must pass an entity name and a function pointer.
///
/// The entity name will identify the class <b>at run-time</b>
/// (be careful: this may not be equivalent to the C++ class name
/// even if it is recommended to do so).
///
/// The function pointer must point on a function taking a string as
/// input and returning an instance of the Entity (the concrete
/// subclass, not directly the upper Entity class).
///
/// The instances returned by this function <b>must</b> be
/// dynamically allocated and the caller <b>must</b> get the
/// ownership of the instance (i.e. it will free it when required).
///
/// To finish, please note that the instance name indicates to the
/// entity how the instance itself is called at run-time. This name
/// does not need to be unique and no check is done on it. It is
/// the caller responsibility to make sure that the instance name is
/// appropriate and to check for uniqueness if required.
///
///
/// This class is a singleton. The rationale is that each
/// unique name must identify a unique Entity. The use of a single
/// instance of this class enforces this behavior, instantiating one
/// yourself would break this property.
class DYNAMIC_GRAPH_DLLAPI FactoryStorage : private boost::noncopyable {
public:
/// \brief Function pointer providing an entity instance from its
/// name.
typedef Entity *(*EntityConstructor_ptr)(const std::string &);
~FactoryStorage();
/// \brief Get pointer to unique object of the class
static FactoryStorage *getInstance();
/// \brief Destroy the unique instance of the class
static void destroy();
/// \brief Add a new entity to the factory.
///
/// It is not allowed to have several entities using the same
/// name. If this is the case, an ExceptionFactory exception will
/// be raised with the code OBJECT_CONFLICT.
///
/// If the function pointer is null, an ExceptionFactory exception
/// will be raised with the code OBJECT_CONFLICT.
///
/// \param entname the name used to subscribe the entity.
/// \param ent pointer to a function allocating an entity from an
/// instance name.
void registerEntity(const std::string &entname, EntityConstructor_ptr ent);
/// \brief Delete an entity from the factory.
///
/// If the provided entity name does not exist in the factory,
/// an ExceptionFactory exception will be raised with the code
/// OBJECT_CONFLICT.
///
/// \param entname the entity name (as passed to registerEntity before)
void deregisterEntity(const std::string &entname);
/// \brief Instantiate (and allocate) an entity.
///
/// An instance called objname of the entity which type is classname
/// will be allocated by this method.
///
/// It is <b>the caller</b> responsibility to free the
/// returned object.
///
/// If the class name does not exist, an ExceptionFactory
/// exception will be raised with the code UNREFERED_OBJECT.
///
/// The instance name (objname) is passed to the Entity
/// constructor and it is the caller responsibility to avoid
/// instance name conflicts if necessary.
///
/// \param classname the name of the Entity type
/// \param objname the instance name
/// \return Dynamically allocated instance of classname.
Entity *newEntity(const std::string &classname,
const std::string &objname) const;
/// \brief Check if an Entity associated with a particular name
/// has already been registered.
///
/// \param name entity name
/// \return Do the entity exist?
bool existEntity(const std::string &name) const;
/// \brief List the available entities.
///
/// Available entities are appended to the method argument.
///
/// \param list Available entities will be appended to list.
void listEntities(std::vector<std::string> &list) const;
typedef Entity* (*EntityConstructor_ptr)( const std::string& );
protected:
typedef std::map< std::string,EntityConstructor_ptr > EntityMap;
private:
/// \brief Constructor the factory.
///
/// After the initialization, no entities will be available.
/// registerEntity has to be used to add new entities to the
/// object.
explicit FactoryStorage();
/// \brief Entity map type.
///
/// This maps entity names to functions pointers which can be
/// used to instantiate an Entity.
typedef std::map<std::string, EntityConstructor_ptr> EntityMap;
/// \brief The entity map storing information about how to
/// instantiate an Entity.
EntityMap entityMap;
public:
~FactoryStorage( void );
void registerEntity( const std::string& entname,EntityConstructor_ptr ent );
void deregisterEntity( const std::string& entname );
Entity* newEntity( const std::string& name,const std::string& objname );
bool existEntity( const std::string& name, EntityMap::iterator& entPtr );
bool existEntity( const std::string& name );
void commandLine( const std::string& cmdLine,std::istringstream& cmdArgs,
std::ostream& os );
/// \pointer to the unique object of the class
static FactoryStorage *instance_;
};
DYNAMICGRAPH_EXPORT extern FactoryStorage g_factory;
/* --- REGISTERER ----------------------------------------------------------- */
/* --- REGISTERER ----------------------------------------------------------- */
/* --- REGISTERER ----------------------------------------------------------- */
/// \ingroup dgraph
///
/// \brief This class automatically register an Entity to the
/// global factory at initialization and unregister it during
/// instance destruction.
///
/// This class is mainly used by the
/// DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN macro and is of little interest
/// by itself.
class DYNAMIC_GRAPH_DLLAPI EntityRegisterer : private boost::noncopyable {
public:
/// \brief Register entity to the global factory.
explicit EntityRegisterer(const std::string &entityClassName,
FactoryStorage::EntityConstructor_ptr maker);
/* -------------------------------------------------------------------------- */
/* --- ENTITY REGISTERER ---------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/// \brief Unregister entity to the global factory.
~EntityRegisterer();
/*! A helper class to register an entity.
*
*/
class DYNAMICGRAPH_EXPORT EntityRegisterer
{
private:
EntityRegisterer( void );
std::string entityName;
public:
EntityRegisterer( const std::string& entityClassName,
FactoryStorage::EntityConstructor_ptr maker);
~EntityRegisterer( void );
/// \brief Name of the entity registered when the instance has
/// been initialized.
const std::string entityName;
};
} // end of namespace dynamicgraph
/*! This macro should be used to automatically register an entity
* of classType to the g_factory. It is then possible to create it
* with the g_factory.
*/
#define DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(classType,className) \
const std::string classType::CLASS_NAME = className; \
extern "C" { \
Entity *EntityMaker##_##classType( const std::string& objname ) \
{ \
return new classType( objname ); \
} \
EntityRegisterer reg##_##classType( className, \
&EntityMaker##_##classType ); \
} \
} // namespace dynamicgraph
#endif /* #ifndef __FACTORY_HH__ */
#endif //! DYNAMIC_GRAPH_FACTORY_HH
// LocalWords: unregister
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-Japan, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: shell-functions.h
* Project: DYNAMIC-GRAPH
* Author: François Bleibel (from Nicolas Mansard)
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#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 )
/*! @ingroup dgraph
\brief This plugin implements a bunch of useful shell commands.
These include debug commands such as timing and exception catching,
and user interaction commands such as display and beep commands.
For more information, load the plugin and type help on a sot shell.
*/
class DYNAMICGRAPH_EXPORT 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 );
};
#endif //#ifndef __DYNAMIC-GRAPH_SHELL_FUNCTIONS_HH__
// Copyright 2010-2019, CNRS, JRL, AIST, LAAS
// Thomas Moulard, Olivier Stasse
//
#ifndef DYNAMIC_GRAPH_FWD_HH
#define DYNAMIC_GRAPH_FWD_HH
#include <boost/smart_ptr.hpp>
namespace dynamicgraph {
// to be replace by std:: when we switch to C++11 and later
using boost::const_pointer_cast;
using boost::dynamic_pointer_cast;
using boost::make_shared;
using boost::shared_ptr;
using boost::static_pointer_cast;
using boost::weak_ptr;
class DebugTrace;
class PluginRefMap;
class Entity;
class EntityRegisterer;
class ExceptionAbstract;
class ExceptionFactory;
class ExceptionSignal;
class ExceptionTraces;
class FactoryStorage;
class Interpreter;
typedef shared_ptr<Interpreter> InterpreterShPtr_t;
class InterpreterHelper;
class Logger;
class OutStringStream;
class PluginLoader;
class PoolStorage;
class Tracer;
class TracerRealTime;
template <typename T, typename Time>
class Signal;
template <typename Time>
class SignalArray;
template <typename Time>
class SignalArray_const;
template <typename Time>
class SignalBase;
template <typename T, typename Time>
class SignalPtr;
template <typename T, typename Time>
class SignalTimeDependent;
template <typename Time>
class TimeDependency;
namespace command {
class Command;
} // end of namespace command.
} // end of namespace dynamicgraph.
#endif //! DYNAMIC_GRAPH_FWD_HH
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-Japan, 2010
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: interpreter.h
* Project: DYNAMIC-GRAPH
* Author: O. Stasse,
* F. Bleibel,
* N. Mansard
*
* Description
* ============
* \file This class provides an entry point for any interpreter
* willing to connect to the dynamic-graph.
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#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 DYNAMICGRAPH_EXPORT InterpreterHelper
{
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 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& 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.signame1: the input signal.
\param[in] obj2.signame2: the output signal.
*/
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 <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 */
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-Japan, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: interpreter.h
* Project: DYNAMIC-GRAPH
* Author: François Bleibel (from Nicolas Mansard)
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#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 DYNAMICGRAPH_EXPORT 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.
*/
class DYNAMICGRAPH_EXPORT 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) );\
}
DYNAMICGRAPH_EXPORT extern Interpreter g_shell;
} // namespace dynamicgraph
#endif /* #ifndef */
//
// Copyright 2010 CNRS
//
// Author: Florent Lamiraux
//
#ifndef DYNAMIC_GRAPH_LINEAR_ALGEBRA_H
#define DYNAMIC_GRAPH_LINEAR_ALGEBRA_H
#include <Eigen/Core>
#include <Eigen/Geometry>
namespace dynamicgraph {
typedef Eigen::MatrixXd Matrix;
typedef Eigen::VectorXd Vector;
} // namespace dynamicgraph
#endif // DYNAMIC_GRAPH_LINEAR_ALGEBRA_H
/*
* Copyright 2015, 2019
* LAAS-CNRS
* Andrea Del Prete, François Bailly, Olivier Stasse
*
*/
#ifndef __dynamic_graph_logger_H__
#define __dynamic_graph_logger_H__
/* --------------------------------------------------------------------- */
/* --- API ------------------------------------------------------------- */
/* --------------------------------------------------------------------- */
#if defined(WIN32)
#if defined(logger_EXPORTS)
#define LOGGER_EXPORT __declspec(dllexport)
#else
#define LOGGER_EXPORT __declspec(dllimport)
#endif
#else
#define LOGGER_EXPORT
#endif
namespace dynamicgraph {
/** Enum representing the different kind of messages.
*/
enum MsgType {
MSG_TYPE_TYPE_BITS = 1 << 0 | 1 << 1 | 1 << 2 | 1 << 3, // 15
MSG_TYPE_STREAM_BIT = 1 << 4, // 16
MSG_TYPE_DEBUG = 1 << 3, // 1
MSG_TYPE_INFO = 1 << 2, // 2
MSG_TYPE_WARNING = 1 << 1, // 4
MSG_TYPE_ERROR = 1 << 0, // 8
MSG_TYPE_DEBUG_STREAM = MSG_TYPE_DEBUG | MSG_TYPE_STREAM_BIT, // 17
MSG_TYPE_INFO_STREAM = MSG_TYPE_INFO | MSG_TYPE_STREAM_BIT, // 18
MSG_TYPE_WARNING_STREAM = MSG_TYPE_WARNING | MSG_TYPE_STREAM_BIT, // 20
MSG_TYPE_ERROR_STREAM = MSG_TYPE_ERROR | MSG_TYPE_STREAM_BIT // 24
};
} // namespace dynamicgraph
/* --------------------------------------------------------------------- */
/* --- INCLUDE --------------------------------------------------------- */
/* --------------------------------------------------------------------- */
#include <map>
/// \todo These 3 headers should be removed.
#include <dynamic-graph/linear-algebra.h>
#include <dynamic-graph/real-time-logger-def.h>
#include <boost/assign.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <dynamic-graph/deprecated.hh>
#include <fstream>
#include <iomanip> // std::setprecision
#include <sstream>
namespace dynamicgraph {
//#define LOGGER_VERBOSITY_INFO_WARNING_ERROR
#define LOGGER_VERBOSITY_ALL
#define SEND_MSG(msg, type) \
sendMsg(msg, type, __FILE__ ":" BOOST_PP_STRINGIZE(__LINE__))
#define SEND_DEBUG_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_DEBUG_STREAM)
#define SEND_INFO_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_INFO_STREAM)
#define SEND_WARNING_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_WARNING_STREAM)
#define SEND_ERROR_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_ERROR_STREAM)
#define _DYNAMIC_GRAPH_ENTITY_MSG(entity, type) \
(entity).logger().stream(type, __FILE__ BOOST_PP_STRINGIZE(__LINE__))
#define DYNAMIC_GRAPH_ENTITY_DEBUG(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_DEBUG)
#define DYNAMIC_GRAPH_ENTITY_INFO(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_INFO)
#define DYNAMIC_GRAPH_ENTITY_WARNING(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_WARNING)
#define DYNAMIC_GRAPH_ENTITY_ERROR(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_ERROR)
#define DYNAMIC_GRAPH_ENTITY_DEBUG_STREAM(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_DEBUG_STREAM)
#define DYNAMIC_GRAPH_ENTITY_INFO_STREAM(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_INFO_STREAM)
#define DYNAMIC_GRAPH_ENTITY_WARNING_STREAM(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_WARNING_STREAM)
#define DYNAMIC_GRAPH_ENTITY_ERROR_STREAM(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_ERROR_STREAM)
template <typename T>
std::string toString(const T &v, const int precision = 3,
const int width = -1) {
std::stringstream ss;
if (width > precision)
ss << std::fixed << std::setw(width) << std::setprecision(precision) << v;
else
ss << std::fixed << std::setprecision(precision) << v;
return ss.str();
}
template <typename T>
std::string toString(const std::vector<T> &v, const int precision = 3,
const int width = -1, const std::string separator = ", ") {
std::stringstream ss;
if (width > precision) {
for (unsigned int i = 0; i < v.size() - 1; i++)
ss << std::fixed << std::setw(width) << std::setprecision(precision)
<< v[i] << separator;
ss << std::fixed << std::setw(width) << std::setprecision(precision)
<< v[v.size() - 1];
} else {
for (unsigned int i = 0; i < v.size() - 1; i++)
ss << std::fixed << std::setprecision(precision) << v[i] << separator;
ss << std::fixed << std::setprecision(precision) << v[v.size() - 1];
}
return ss.str();
}
template <typename T>
std::string toString(const Eigen::MatrixBase<T> &v, const int precision = 3,
const int width = -1, const std::string separator = ", ") {
std::stringstream ss;
if (width > precision) {
for (unsigned int i = 0; i < v.size() - 1; i++)
ss << std::fixed << std::setw(width) << std::setprecision(precision)
<< v[i] << separator;
ss << std::fixed << std::setw(width) << std::setprecision(precision)
<< v[v.size() - 1];
} else {
for (unsigned int i = 0; i < v.size() - 1; i++)
ss << std::fixed << std::setprecision(precision) << v[i] << separator;
ss << std::setprecision(precision) << v[v.size() - 1];
}
return ss.str();
}
enum LoggerVerbosity {
VERBOSITY_ALL = MSG_TYPE_DEBUG,
VERBOSITY_INFO_WARNING_ERROR = MSG_TYPE_INFO,
VERBOSITY_WARNING_ERROR = MSG_TYPE_WARNING,
VERBOSITY_ERROR = MSG_TYPE_ERROR,
VERBOSITY_NONE = 0
};
/// \ingroup debug
///
/// \brief Class for logging messages
///
/// It is intended to be used like this:
/// \code
/// #define ENABLE_RT_LOG
/// #include <dynamic-graph/real-time-logger.h>
///
/// // Somewhere in the main function of your executable
/// int main (int argc, char** argv) {
/// std::ofstream of;
/// of.open("/tmp/dg-LOGS.txt",std::ofstream::out|std::ofstream::app);
/// dgADD_OSTREAM_TO_RTLOG (of);
/// }
///
/// // Somewhere in your library
/// dynamicgraph::LoggerVerbosity aLoggerVerbosityLevel =
/// VERBOSITY_WARNING_ERROR;
/// entity.setLoggerVerbosityLevel(aLoggerVerbosityLevel);
/// ...
/// // using macros
/// DYNAMIC_GRAPH_ENTITY_WARNING(entity) << "your message\n";
///
/// // or the equivalent code without macros:
/// // Please use '\n' instead of std::endl and flushing will have no effect
/// entity.logger.stream(dynamicgraph::MSG_TYPE_WARNING,
/// __FILE__ BOOST_PP_STRINGIZE(__LINE__))
/// << your message << '\n';
///
/// \endcode
///
/// \todo remove m_timeSample and streamPrintPeriod to rather use a simple
/// integer counting the number of calls. This will achieve exactly the
/// same behaviour without rouding numerical errors.
class Logger {
public:
/** Constructor */
Logger(double timeSample = 0.001, double streamPrintPeriod = 1.0);
/** Destructor */
~Logger();
/** Method to be called at every control iteration
* to decrement the internal Logger's counter. */
void countdown();
/** Get an output stream independently of the debug level.
*/
RTLoggerStream stream() {
return ::dynamicgraph::RealTimeLogger::instance().front();
}
/** Print the specified message on standard output if the verbosity level
* allows it. The lineId is used to identify the point where sendMsg is
* called so that streaming messages are printed only every streamPrintPeriod
* iterations.
* \param type specifies the verbosity level, for instance MSG_TYPE_DEBUG
* \param lineId typically __FILE__ ":" BOOST_PP_STRINGIZE(__LINE__)
*/
RTLoggerStream stream(MsgType type, const std::string &lineId = "") {
RealTimeLogger &rtlogger = ::dynamicgraph::RealTimeLogger::instance();
if (acceptMsg(type, lineId)) return rtlogger.front();
return rtlogger.emptyStream();
}
/** \deprecated instead, use
* \code
* stream(type, lineId) << msg << '\n';
* \endcode
*/
[[deprecated("use stream(type, lineId) << msg")]] void sendMsg(
std::string msg, MsgType type, const std::string &lineId = "");
/** \deprecated instead, use
* \code
* stream(type, lineId) << msg << '\n';
* \endcode
*/
[[deprecated("use stream(type, lineId) << msg")]] void sendMsg(
std::string msg, MsgType type, const std::string &file, int line);
/** Set the sampling time at which the method countdown()
* is going to be called. */
bool setTimeSample(double t);
/** Get the sampling time at which the method countdown()
* is going to be called. */
double getTimeSample();
/** Set the time period for printing of streaming messages. */
bool setStreamPrintPeriod(double s);
/** Get the time period for printing of streaming messages. */
double getStreamPrintPeriod();
/** Set the verbosity level of the logger. */
void setVerbosity(LoggerVerbosity lv);
/** Get the verbosity level of the logger. */
LoggerVerbosity getVerbosity();
protected:
LoggerVerbosity m_lv; /// verbosity of the logger
double m_timeSample;
/// specify the period of call of the countdown method
double m_streamPrintPeriod; /// specify the time period of the stream prints
double m_printCountdown;
/// every time this is < 0 (i.e. every _streamPrintPeriod sec) print stuff
typedef std::map<std::string, double> StreamCounterMap_t;
/** Pointer to the dynamic structure which holds
the collection of streaming messages */
StreamCounterMap_t m_stream_msg_counters;
inline bool isStreamMsg(MsgType m) { return (m & MSG_TYPE_STREAM_BIT); }
/** Check whether a message of type \p m and from \p c lineId should be
* accepted. \note If \p m is a stream type, the internal counter associated
* to \p lineId is updated.
*/
bool acceptMsg(MsgType m, const std::string &lineId) {
// If more verbose than the current verbosity level
if ((m & MSG_TYPE_TYPE_BITS) > m_lv) return false;
// if print is allowed by current verbosity level
if (isStreamMsg(m)) return checkStreamPeriod(lineId);
return true;
}
/** Check whether a message from \c lineId should be accepted.
* \note The internal counter associated to \c lineId is updated.
*/
bool checkStreamPeriod(const std::string &lineId);
};
} // namespace dynamicgraph
#endif // #ifndef __sot_torque_control_logger_H__
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-Japan, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: plugin-loader.h
* Project: DYNAMIC-GRAPH
* Author: François Bleibel (from Nicolas Mansard)
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#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 DYNAMICGRAPH_EXPORT PluginLoader
{
protected:
/*! \brief Directory from where the dynamic libraries are loaded. */
std::string pluginDirectory;
/*! \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;
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.
For non-re-entrant plugins this method HAS TO be called. */
void unloadAllPlugins();
const std::map< std::string,std::string > getLoadedPluginNames( void )
{ return loadedPluginNames; }
const std::string& searchPlugin( const std::string& plugname );
};
} // namespace dynamicgraph
#endif /* #ifndef __PLUGINLOADER_HH__ */
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-Japan, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: g_pool.h
* Project: DYNAMIC-GRAPH
* Author: François Bleibel (from Nicolas Mansard)
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#ifndef POOL_H_
#define POOL_H_
/* --------------------------------------------------------------------- */
/* --- INCLUDE --------------------------------------------------------- */
/* --------------------------------------------------------------------- */
/* --- STD --- */
#include <map>
#include <string>
#include <sstream>
// -*- mode: c++ -*-
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
// JRL, CNRS/AIST.
//
/* --- DYNAMIC-GRAPH --- */
#ifndef DYNAMIC_GRAPH_POOL_H
#define DYNAMIC_GRAPH_POOL_H
#include <dynamic-graph/dynamic-graph-api.h>
#include <dynamic-graph/exception-factory.h>
#include <dynamic-graph/signal-base.h>
#include <dynamic-graph/dynamic-graph-api.h>
namespace dynamicgraph
{
class Entity;
/* --------------------------------------------------------------------- */
/* --- CLASS ----------------------------------------------------------- */
/* --------------------------------------------------------------------- */
#include <dynamic-graph/fwd.hh>
#include <map>
#include <sstream>
#include <string>
namespace dynamicgraph {
/*! @ingroup dgraph
\brief This class keep tracks of all the objects in the stack of Tasks.
\brief Singleton that keeps track of all the entities.
This class gives access to and remembers all the entities created
during its life.
......@@ -57,81 +29,90 @@ class Entity;
\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 DYNAMICGRAPH_EXPORT PoolStorage
{
*/
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;
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;
/// \brief Get unique instance of the class.
static PoolStorage *getInstance();
/// \brief Destroy the unique instance of the class
static void destroy();
/*! @} */
public:
/*! \brief Default destructor */
~PoolStorage( void );
~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 );
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 );
void deregisterEntity(const std::string &entname);
/*! \brief Unregister an entity.
\par[in] entity: iterator in the map,
*/
void deregisterEntity(const Entities::iterator &entity);
/*! \brief Get an entity.
\par[in] entname: The name of the entity,
\return Pointer towards the entity.
*/
Entity& getEntity( const std::string& name );
Entity &getEntity(const std::string &name);
/// Const access to entity map
const Entities &getEntityMap() const;
/*! \brief Test if the entity exists. */
bool existEntity(const std::string &name);
/*! \brief Test if the entity exists. If it does, return a pointer on it. */
bool existEntity(const std::string &name, Entity *&ptr);
/*! \brief Disallocate an entity.
\par[in] entname: The name of the entity,
*/
void clearPlugin( const std::string& name );
void clearPlugin(const std::string &name);
/*! @} */
///
/// \brief Get a signal by name
///
/// \param sigpath stream containing a string of the form "entity.signal"
SignalBase<int> &getSignal(std::istringstream &sigpath);
/*! \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.
/*! \brief This method write a graph description on the file named
FileName. */
void writeGraph(const std::string &aFileName);
void writeCompletionList(std::ostream &os);
The commands specific to the <b>g_pool<\b> object are:
\li <b>list</b> : List all the entities registered in the g_pool.s
protected:
/*! \name Fields of the class to manage the three entities.
Also the name is singular, those are true sets.
@{
*/
void commandLine( const std::string& objectName,const std::string& functionName,
std::istringstream& cmdArg, std::ostream& os );
/*! \brief Set of basic objects of the SoT */
Entities entityMap;
/*! \brief This method write a graph description on the file named FileName. */
void writeGraph(const std::string &aFileName);
void writeCompletionList(std::ostream& os);
private:
PoolStorage() {}
static PoolStorage *instance_;
};
DYNAMICGRAPH_EXPORT extern dynamicgraph::PoolStorage g_pool;
inline PoolStorage &g_pool() { return *PoolStorage::getInstance(); }
} // namespace dynamicgraph
} // end of namespace dynamicgraph.
#endif /* POOL_H_ */
#endif //! DYNAMIC_GRAPH_POOL_H
/* Copyright LAAS, CNRS
* Author: O. Stasse, 2019
* See LICENSE file in the root directory of this repository.
*/
#ifndef DYNAMIC_GRAPH_PROCESS_LIST_H_
#define DYNAMIC_GRAPH_PROCESS_LIST_H_
#include <dynamic-graph/dynamic-graph-api.h>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <dynamic-graph/fwd.hh>
namespace dynamicgraph {
namespace CPU {
class DYNAMIC_GRAPH_DLLAPI ProcessData {};
class DYNAMIC_GRAPH_DLLAPI ProcessList {
public:
ProcessList();
};
/// This class gather information on a specific CPU.
///
class DYNAMIC_GRAPH_DLLAPI CPUData {
public:
CPUData();
int cpu_id_;
inline unsigned long long int computePeriod(unsigned long long int &a,
unsigned long long int &b) {
return (a > b) ? a - b : 0;
}
/// \brief Various classes of time spend by the CPU
/// @{
/// Total time
unsigned long long int total_time_;
/// Time spend in user mode
unsigned long long int user_mode_time_;
/// Time spend in user mode with low priority (nice mode)
unsigned long long int nice_time_;
/// Time spend in system mode
unsigned long long int system_time_;
/// Time spend in system mode
unsigned long long int system_all_time_;
/// Time spend in doing nothing.
unsigned long long int idle_time_;
/// Time spend in doing nothing.
unsigned long long int idle_all_time_;
/// Time spend in waiting an input/output to complete.
unsigned long long int iowait_time_;
/// Time spend in servicing hardware interrupts.
unsigned long long int irq_time_;
/// Time spend in servicing software interrupts.
unsigned long long int softirq_time_;
/// Time spend in other operating systems in a virtualized environments
/// Never doing this for control !
unsigned long long int steal_time_;
/// Time spend running a virtual CPU for guest operating systems
/// under the control of the Linux kernel
unsigned long long int guest_time_;
/// Time spent running a niced guest
/// (virtual CPU for guest operating systems under the
/// control of the Linux kernel)
unsigned long long int guest_nice_time_;
/// @}
/// \brief Various classes of time spend by the CPU by period
/// @{
/// Total time
unsigned long long int total_period_;
/// Time spend in user mode
unsigned long long int user_mode_period_;
/// Time spend in user mode with low priority (nice mode)
unsigned long long int nice_period_;
/// Time spend in system mode
unsigned long long int system_period_;
/// Time spend in all system mode
unsigned long long int system_all_period_;
/// Time spend in doing nothing.
unsigned long long int idle_period_;
/// Time spend in doing nothing.
unsigned long long int idle_all_period_;
/// Time spend in waiting an input/output to complete.
unsigned long long int iowait_period_;
/// Time spend in servicing hardware interrupts.
unsigned long long int irq_period_;
/// Time spend in servicing software interrupts.
unsigned long long int softirq_period_;
/// Time spend in other operating systems in a virtualized environments
/// Never doing this for control !
unsigned long long int steal_period_;
/// Time spend running a virtual CPU for guest operating systems
/// under the control of the Linux kernel
unsigned long long int guest_period_;
/// @}
double percent_;
void ProcessLine(std::istringstream &aCPULine);
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive &ar, const unsigned int version) {
ar &version;
ar &total_time_;
ar &user_mode_time_;
ar &nice_time_;
ar &system_time_;
ar &system_all_time_;
ar &idle_time_;
ar &idle_all_time_;
ar &iowait_time_;
ar &irq_time_;
ar &softirq_time_;
ar &steal_time_;
ar &guest_time_;
ar &guest_nice_time_;
ar &percent_;
}
};
/// This class gathers information on a computer.
/// This includes a list of CPU
class DYNAMIC_GRAPH_DLLAPI System {
private:
bool init_;
public:
System();
/// Read /proc/state file to extract CPU count.
void init();
/// Update CPU data information from /proc/stat
void readProcStat();
/// Friend class for serialization.
friend class boost::serialization::access;
/// Number of CPU.
unsigned int cpuNb_;
void ProcessCPULine(unsigned int cpunb, std::istringstream &aCPULine);
/// \brief Vector of CPU informations.
std::vector<CPUData> vCPUData_;
/// \brief Global CPU information.
CPUData gCPUData_;
template <class Archive>
void serialize(Archive &ar, const unsigned int version) {
ar &version;
ar &cpuNb_;
ar &gCPUData_;
ar &vCPUData_;
}
};
} // namespace CPU
} // namespace dynamicgraph
#endif /* DYNAMIC_GRAPH_PROCESS_LIST_H_ */
// -*- mode: c++ -*-
// Copyright 2018, Joseph Mirabel LAAS-CNRS
//
#ifndef DYNAMIC_GRAPH_LOGGER_REAL_TIME_DEF_H
#define DYNAMIC_GRAPH_LOGGER_REAL_TIME_DEF_H
#include <boost/shared_ptr.hpp>
#include <boost/thread/mutex.hpp>
#include <dynamic-graph/config.hh>
#include <sstream>
#include <vector>
namespace dynamicgraph {
/// \ingroup debug
///
/// \brief Stream for the real-time logger.
///
/// You should inherit from this class in order to redirect the logs where you
/// want.
/// \sa LoggerIOStream
class LoggerStream {
public:
virtual void write(const char *c) = 0;
};
/// Write to an ostream object.
///
/// The easieast is to use the macro dgADD_OSTREAM_TO_RTLOG(ostr) where
/// `ostr` can be `std::cout` or an std::ofstream...
class LoggerIOStream : public LoggerStream {
public:
LoggerIOStream(std::ostream &os) : os_(os) {}
virtual ~LoggerIOStream() {}
virtual void write(const char *c) { os_ << c; }
private:
std::ostream &os_;
};
typedef boost::shared_ptr<LoggerStream> LoggerStreamPtr_t;
class RealTimeLogger;
/// \cond DEVEL
/// \brief write entries to intenal buffer.
///
/// The entry starts when an instance is created and ends when is is deleted.
/// This class is only used by RealTimeLogger.
class RTLoggerStream {
public:
inline RTLoggerStream(RealTimeLogger *logger, std::ostream &os)
: ok_(logger != NULL), logger_(logger), os_(os) {}
template <typename T>
inline RTLoggerStream &operator<<(T t) {
if (ok_) os_ << t;
return *this;
}
inline RTLoggerStream &operator<<(std::ostream &(*pf)(std::ostream &)) {
if (ok_) os_ << pf;
return *this;
}
inline ~RTLoggerStream();
inline bool isNull() { return !ok_; }
private:
const bool ok_;
RealTimeLogger *logger_;
std::ostream &os_;
};
/// \endcond DEVEL
/// \ingroup debug
///
/// \brief Main class of the real-time logger.
///
/// It is intended to be used like this:
/// \code
/// #define ENABLE_RT_LOG
/// #include <dynamic-graph/real-time-logger.h>
///
/// // Somewhere in the main function of your executable
/// int main (int argc, char** argv) {
/// dgADD_OSTREAM_TO_RTLOG (std::cout);
/// }
///
/// // Somewhere in your library
/// dgRTLOG() << "your message. Prefer to use \n than std::endl."
/// \endcode
///
/// \note Thread safety. This class expects to have:
/// - only one reader: the one who take the log entries and write them
/// somewhere.
/// - one writer at a time. Writing to the logs is **never** a blocking
/// operation. If the resource is busy, the log entry is discarded.
class DYNAMIC_GRAPH_DLLAPI RealTimeLogger {
public:
static RealTimeLogger &instance();
static void destroy();
/// \todo add an argument to preallocate the internal string
/// to a given size.
RealTimeLogger(const std::size_t &bufferSize);
inline void clearOutputStreams() { outputs_.clear(); }
inline void addOutputStream(const LoggerStreamPtr_t &os) {
outputs_.push_back(os);
}
/// Write next message to output.
/// It does nothing if the buffer is empty.
/// \return true if it wrote something
bool spinOnce();
/// Return an object onto which a real-time thread can write.
/// The message is considered finished when the object is destroyed.
RTLoggerStream front();
/// Return an empty stream object.
RTLoggerStream emptyStream() { return RTLoggerStream(NULL, oss_); }
inline void frontReady() {
backIdx_ = (backIdx_ + 1) % buffer_.size();
wmutex.unlock();
}
inline bool empty() const { return frontIdx_ == backIdx_; }
inline bool full() const {
return ((backIdx_ + 1) % buffer_.size()) == frontIdx_;
}
inline std::size_t size() const {
if (frontIdx_ <= backIdx_)
return backIdx_ - frontIdx_;
else
return backIdx_ + buffer_.size() - frontIdx_;
}
inline std::size_t getBufferSize() { return buffer_.size(); }
~RealTimeLogger();
private:
struct Data {
std::stringbuf buf;
};
std::vector<LoggerStreamPtr_t> outputs_;
std::vector<Data *> buffer_;
/// Index of the next value to be read.
std::size_t frontIdx_;
/// Index of the slot where to write next value
/// (does not contain valid data).
std::size_t backIdx_;
std::ostream oss_;
/// The writer mutex.
boost::mutex wmutex;
std::size_t nbDiscarded_;
struct thread;
static RealTimeLogger *instance_;
static thread *thread_;
};
RTLoggerStream::~RTLoggerStream() {
if (ok_) {
os_ << std::ends;
logger_->frontReady();
}
}
} // end of namespace dynamicgraph
#endif //! DYNAMIC_GRAPH_LOGGER_REAL_TIME_DEF_H
// -*- mode: c++ -*-
// Copyright 2018, Joseph Mirabel LAAS-CNRS
//
#ifndef DYNAMIC_GRAPH_LOGGER_REAL_TIME_H
#define DYNAMIC_GRAPH_LOGGER_REAL_TIME_H
#ifdef ENABLE_RT_LOG
#define dgADD_OSTREAM_TO_RTLOG(ostr) \
::dynamicgraph::RealTimeLogger::instance().addOutputStream( \
::dynamicgraph::LoggerStreamPtr_t( \
new ::dynamicgraph::LoggerIOStream(ostr)))
#define dgRTLOG() ::dynamicgraph::RealTimeLogger::instance().front()
#else // ENABLE_RT_LOG
#define dgADD_OSTREAM_TO_RTLOG(ostr) struct __end_with_semicolon
#define dgRTLOG() \
if (1) \
; \
else \
__null_stream()
#endif
#include <dynamic-graph/real-time-logger-def.h>
#endif //! DYNAMIC_GRAPH_LOGGER_REAL_TIME_H
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-Japan, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: shell-procedure.h
* Project: DYNAMIC-GRAPH
* Author: François Bleibel (from Nicolas Mansard)
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#ifndef __SHELL_PROCEDURE_HH__
#define __SHELL_PROCEDURE_HH__
/* --------------------------------------------------------------------- */
/* --- INCLUDE --------------------------------------------------------- */
/* --------------------------------------------------------------------- */
/* DYNAMIC-GRAPH */
#include <dynamic-graph/exception-factory.h>
#include <dynamic-graph/interpreter.h>
/* --- STD --- */
#include <string>
#include <map>
#include <sstream>
#include <list>
#include <vector>
/* --- BOOST --- */
#include <boost/function.hpp>
#include <boost/bind.hpp>
/* --------------------------------------------------------------------- */
/* --- API ------------------------------------------------------------- */
/* --------------------------------------------------------------------- */
#if defined (WIN32)
# if defined (shell_procedure_EXPORTS)
# define ShellProcedure_EXPORT __declspec(dllexport)
# else
# define ShellProcedure_EXPORT __declspec(dllimport)
# endif
#else
# define ShellProcedure_EXPORT
#endif
/* --------------------------------------------------------------------- */
/* --- CLASS ----------------------------------------------------------- */
/* --------------------------------------------------------------------- */
/*! @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 ShellProcedure_EXPORT ShellProcedure
{
public:
struct Instruction
{
std::string cmd;
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(); }
};
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 //#ifndef __DYNAMIC-GRAPH_SHELL_PROCEDURE_HH__
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-Japan, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: SignalArray.h
* Project: DYNAMIC-GRAPH
* Author: Nicolas Mansard
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#ifndef __SIGNAL_ARRAY_HH
#define __SIGNAL_ARRAY_HH
// -*- mode: c++ -*-
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
// JRL, CNRS/AIST.
//
#include <dynamic-graph/signal-base.h>
#ifndef DYNAMIC_GRAPH_SIGNAL_ARRAY_H
#define DYNAMIC_GRAPH_SIGNAL_ARRAY_H
#include <dynamic-graph/dynamic-graph-api.h>
#include <dynamic-graph/signal-base.h>
#include <stdio.h>
namespace dynamicgraph {
#include <vector>
template<class Time>
class SignalArray;
namespace dynamicgraph {
template<class Time>
class SignalArray_const
{
/// \ingroup dgraph
///
/// \brief TODO
template <class Time>
class SignalArray_const {
public:
static const int DEFAULT_SIZE = 20;
static const int DEFAULT_SIZE = 20;
protected:
const SignalBase<Time> ** const_array;
unsigned int size,rank;
std::vector<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())
{
createArray();
for( unsigned int i=0;i<rank;++i ) const_array[i]=&siga[i];
}
SignalArray_const<Time> ( const SignalArray_const<Time>& siga )
: const_array(NULL),size(DEFAULT_SIZE),rank(siga.getSize())
{
createArray();
for( unsigned int i=0;i<rank;++i ) const_array[i]=&siga[i];
}
virtual ~SignalArray_const<Time>( void )
{
if( NULL!=const_array ) delete [] const_array;
}
SignalArray_const<Time>(const unsigned int &sizeARG = DEFAULT_SIZE)
: const_array(sizeARG), size(sizeARG), rank(0) {}
SignalArray_const<Time>(const SignalBase<Time> &sig)
: const_array(DEFAULT_SIZE), size(DEFAULT_SIZE), rank(0) {
addElmt(&sig);
}
SignalArray_const<Time>(const SignalArray<Time> &siga)
: const_array(siga.getSize()),
size(siga.getSize()),
rank(siga.getSize()) {
for (unsigned int i = 0; i < rank; ++i) const_array[i] = &siga[i];
}
SignalArray_const<Time>(const SignalArray_const<Time> &siga)
: const_array(siga.getSize()),
size(siga.getSize()),
rank(siga.getSize()) {
for (unsigned int i = 0; i < rank; ++i) const_array[i] = &siga[i];
}
virtual ~SignalArray_const<Time>() {}
protected:
void createArray( void )
{
if(0<size) { const_array = new const SignalBase<Time>* [size]; }
void addElmt(const SignalBase<Time> *el) {
if (rank >= size) {
size += DEFAULT_SIZE;
const_array.resize(size);
}
void addElmt( const SignalBase<Time>* el )
{ if(rank<size) const_array[rank++] = el; }
const_array[rank++] = el;
}
public:
virtual SignalArray_const<Time>& operator<< (const SignalBase<Time>& sig)
{ addElmt( &sig ); return *this; }
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; }
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(sig1);
res << sig2;
return res;
}
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>
{
/// \ingroup dgraph
///
/// \brief TODO
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;
mutable std::vector<SignalBase<Time> *> array;
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> ( 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];
}
virtual ~SignalArray<Time>( void )
{
if( NULL!=array ) delete [] array;
}
SignalArray<Time>(const unsigned int &sizeARG = DEFAULT_SIZE)
: SignalArray_const<Time>(0), array(sizeARG) {
size = sizeARG;
}
SignalArray<Time>(SignalBase<Time> &sig)
: SignalArray_const<Time>(0), array(DEFAULT_SIZE) {
size = DEFAULT_SIZE;
addElmt(&sig);
}
SignalArray<Time>(const SignalArray<Time> &siga)
: SignalArray_const<Time>(siga.getSize()), array(siga.getSize()) {
rank = siga.getSize();
for (unsigned int i = 0; i < rank; ++i) array[i] = &siga[i];
}
virtual ~SignalArray<Time>() {}
protected:
void createArray( void )
{
if(0<size) { array = new SignalBase<Time>* [size]; }
void addElmt(SignalBase<Time> *el) {
if (rank >= size) {
size += DEFAULT_SIZE;
array.resize(size);
}
void addElmt( SignalBase<Time>* el )
{ if(rank<size) array[rank++] = el; }
public: //protected:
virtual SignalArray<Time>& operator<< (SignalBase<Time>& sig)
{ addElmt( &sig ); return *this; }
virtual SignalArray_const<Time> operator<< (const SignalBase<Time>& sig) const
{
SignalArray_const<Time> res(size);
res=*this;
res<<sig;
return res;
}
array[rank++] = el;
}
public:
virtual SignalBase<Time>& operator[] ( const unsigned int& idx ) const
{
return *array[idx];
}
virtual SignalArray<Time> &operator<<(SignalBase<Time> &sig) {
addElmt(&sig);
return *this;
}
virtual SignalArray_const<Time> operator<<(
const SignalBase<Time> &sig) const {
SignalArray_const<Time> res(*this);
res << sig;
return res;
}
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(sig1);
res << sig2;
return res;
}
DYNAMICGRAPH_EXPORT 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
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-Japan, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: signal-base.h
* Project: DYNAMIC-GRAPH
* Author: Nicolas Mansard
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#ifndef __SIGNAL_ABSTRACT_HH
#define __SIGNAL_ABSTRACT_HH
#include <string>
#include <sstream>
#include <iostream>
// -*- mode: c++ -*-
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
// JRL, CNRS/AIST.
// LAAS, CNRS
//
#ifndef DYNAMIC_GRAPH_SIGNAL_BASE_H
#define DYNAMIC_GRAPH_SIGNAL_BASE_H
#include <dynamic-graph/exception-signal.h>
#include <boost/noncopyable.hpp>
#include <dynamic-graph/fwd.hh>
#include <sstream>
#include <string>
#include <typeinfo>
namespace dynamicgraph {
template< class Time >
class SignalBase : public boost::noncopyable
{
protected:
std::string name;
Time signalTime;
bool ready;
/** \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:
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; }
explicit SignalBase(std::string name = "")
: name(name), signalTime(0), ready(false) {}
virtual void setPeriodTime( const Time& p ) {}
virtual Time getPeriodTime( void ) const { return 1; }
virtual ~SignalBase() {}
public:
/// \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; }
/* --- CONSTRUCTORS ------------------------------------------------------- */
SignalBase( std::string name ="" )
: name(name),signalTime(0),ready(false) {}
virtual ~SignalBase( void ) {}
void getClassName(std::string &aClassName) const {
aClassName = typeid(this).name();
}
virtual void setPeriodTime(const Time &) {}
/* --- DEPENDENCIES ------------------------------------------------------- */
virtual Time getPeriodTime() const { return 1; }
virtual void addDependency( const SignalBase<Time>& signal ) {}
virtual void removeDependency( const SignalBase<Time>& signal ) {}
virtual void clearDependencies( void ) {}
/// \}
virtual bool needUpdate( const Time& t ) const {return ready;}
inline void setReady( const bool sready = true ) { ready = sready; }
/// \name Dependencies
/// \{
virtual std::ostream &
writeGraph (std::ostream & os ) const
{
return os;
}
virtual void addDependency(const SignalBase<Time> &) {}
virtual std::ostream&
displayDependencies( std::ostream& os,const int depth=-1,
std::string space="",
std::string next1="",std::string next2="" ) const
{
os << space << next1 << "-- ";
display(os); return os;
}
/* --- PLUG --------------------------------------------------------------- */
virtual void removeDependency(const SignalBase<Time> &) {}
/* Plug the arg-signal on the <this> object. Plug-in is always
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).
* 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.
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 isPlugged() 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& value )
{ 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& os ) 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 & t)
{ 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& os ) 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() ); }
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); }
} // namespace dynamicgraph
#endif // #ifndef __SIGNAL_ABSTRACT_HH
/*
* Local variables:
* c-basic-offset: 4
* End:
*/
/// 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
// -*- c++-mode -*-
// Copyright 2010 François Bleibel Thomas Moulard, Olivier Stasse,
// Nicolas Mansard
//
#ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HELPER_HH
#define DYNAMIC_GRAPH_SIGNAL_CASTER_HELPER_HH
#pragma warning "This file is now useless"
#endif // #ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HELPER_HH
/*
* SignalCaster.h
*
* Created on: Jun 14, 2010
* Author: Francois Bleibel
*/
// -*- c++-mode -*-
// Copyright 2010 François Bleibel Thomas Moulard, Olivier Stasse
//
#ifndef SIGNALCASTER_H_
#define SIGNALCASTER_H_
#ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HH
#define DYNAMIC_GRAPH_SIGNAL_CASTER_HH
#include <dynamic-graph/dynamic-graph-api.h>
#include <dynamic-graph/eigen-io.h>
#include <dynamic-graph/linear-algebra.h>
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
#include <map>
#include <typeinfo>
#include <boost/function/function1.hpp>
#include <boost/function/function2.hpp>
#include <boost/any.hpp>
#include <boost/tuple/tuple.hpp>
#include <iostream>
#include <vector>
#include <dynamic-graph/dynamic-graph-api.h>
#include "dynamic-graph/exception-signal.h"
namespace dynamicgraph {
/*! This class allows serialization of a number of objects into (disp) and from
* (cast) std i/o streams. The transformation is done at run-time, i.e. SignalCaster
* doesn't know about the type of objects it casts to. It also allows registering of
* user-defined casts. A cast is identified by the compiler
* The mapping from a type to a serialization function is dynamic, hence it is more
* complex than a typical template-based compile-time resolve. So disp, cast and
* trace are costly functions and should be used as such.
*/
class DYNAMICGRAPH_EXPORT SignalCaster {
public:
SignalCaster();
virtual ~SignalCaster();
/*! Typedef of displayer functions that take an encapsulated 'any' object
* and displays, cast, or trace it on an output stream (serialization).
*/
typedef boost::function2<void, const boost::any&, std::ostream&> displayer_type;
typedef boost::function1<boost::any, std::istringstream&> caster_type;
typedef boost::function2<void, const boost::any&, std::ostream&> tracer_type;
/// Displays an object using a registered displayer function
void disp(const boost::any& object, std::ostream& os);
/// Traces an object using a registered trace function
void trace(const boost::any& object, std::ostream& os);
/// Casts an object using a registered cast function
boost::any cast(const std::type_info&, std::istringstream& iss);
/// Registers a cast
void registerCast(const std::type_info& type, displayer_type displayer,
caster_type caster, tracer_type tracer);
/// Unregisters a cast
void unregisterCast(const std::type_info& type);
/// Checks if there is a displayer registered with type_name
bool existsCast(const std::type_info& type);
private:
/// Container for the three cast functions
typedef boost::tuple<displayer_type, caster_type, tracer_type> cast_functions_type;
/*! This map associates the typename of objects and the corresponding
* using boost::function with 'compatible' syntax
*/
std::map<std::string, cast_functions_type> functions_;
/// Inherit from this class if you want to keep default implementation for some
/// functions.
template <typename T>
struct signal_io_base {
/// serialize a signal value.
inline static void disp(const T &value, std::ostream &os) { os << value; }
/// deserialize a signal value.
inline static T cast(std::istringstream &is) {
T inst;
is >> inst;
if (is.fail()) {
throw ExceptionSignal(ExceptionSignal::GENERIC,
"failed to serialize " + is.str());
}
return inst;
}
/// write a signal value to log file
inline static void trace(const T &value, std::ostream &os) { os << value; }
};
/// The library-wide instance of SignalCaster
extern DYNAMICGRAPH_EXPORT SignalCaster g_caster;
/*!
* 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 argument.
* The code is provided here so the class does not need to be exported.
*/
class SignalCastRegisterer {
public:
inline SignalCastRegisterer(const std::type_info& type, SignalCaster::displayer_type displayer,
SignalCaster::caster_type caster, SignalCaster::tracer_type tracer) {
g_caster.registerCast(type, displayer, caster, tracer);
}
/// Inherit from this class if tracing is not implemented for a given type.
template <typename T>
struct signal_io_unimplemented {
inline static void disp(const T &, std::ostream &) {
throw std::logic_error("this disp is not implemented.");
}
inline static T cast(std::istringstream &) {
throw std::logic_error("this cast is not implemented.");
}
inline static void trace(const T &, std::ostream &) {
throw std::logic_error("this trace is not implemented.");
}
};
/*! This class can be used to register default casts, i.e. casts already supported by
* the object to an std::iostream through the operators >> and << .
*/
template<typename T> class DefaultCastRegisterer : public SignalCastRegisterer {
public:
DefaultCastRegisterer() : SignalCastRegisterer(typeid(T), disp, cast, trace) {}
static boost::any cast(std::istringstream& iss) { T inst; iss >> inst; return inst; }
static void disp(const boost::any& object, std::ostream& os) { os << boost::any_cast<T>(object) << std::endl;; }
static void trace(const boost::any& object, std::ostream& os) { disp(object,os); }
/// Class used for I/O operations in Signal<T,Time>
template <typename T>
struct signal_io : signal_io_base<T> {};
/// Template specialization of signal_disp for Eigen objects
template <typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows,
int _MaxCols>
struct signal_io<
Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>>
: signal_io_base<
Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>> {
typedef Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>
matrix_type;
inline static void disp(const matrix_type &value, std::ostream &os) {
static const Eigen::IOFormat row_format(
Eigen::StreamPrecision, Eigen::DontAlignCols, " ", " ", "", "", "", "");
os << value.format(row_format);
}
inline static void trace(const matrix_type &value, std::ostream &os) {
static const Eigen::IOFormat row_format(Eigen::StreamPrecision,
Eigen::DontAlignCols, "\t", "\t",
"", "", "", "");
os << value.format(row_format);
}
};
/*!
* Global signal cast template (helper) functions
*
* 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)
{ g_caster.disp(value, os); }
/// Template specialization of signal_io for Eigen quaternion objects
template <typename _Scalar, int _Options>
struct signal_io<Eigen::Quaternion<_Scalar, _Options>>
: signal_io_base<Eigen::Quaternion<_Scalar, _Options>> {
typedef Eigen::Quaternion<_Scalar, _Options> quat_type;
typedef Eigen::Matrix<_Scalar, 4, 1, _Options> matrix_type;
template<typename T> T signal_cast(std::istringstream& iss)
{
return boost::any_cast<T>(g_caster.cast(typeid(T), iss));
}
inline static void disp(const quat_type &value, std::ostream &os) {
signal_io<matrix_type>::disp(value.coeffs(), os);
}
template<typename T> void signal_trace(const T& value, std::ostream& os)
{ g_caster.trace(value, os); }
inline static quat_type cast(std::istringstream &is) {
return quat_type(signal_io<matrix_type>::cast(is));
}
inline static void trace(const quat_type &value, std::ostream &os) {
signal_io<matrix_type>::trace(value.coeffs(), os);
}
};
/// Template specialization of signal_io for std::string.
/// Do not print '\n' at the end.
template <>
struct signal_io<std::string> : signal_io_base<std::string> {
inline static std::string cast(std::istringstream &iss) { return iss.str(); }
};
/// Template specialization of signal_io for double
/// to workaround the limitations of the stream based approach.
///
/// When dealing with double: displaying a double on a stream
/// is *NOT* the opposite of reading a double from a stream.
///
/// In practice, it means that there is no way to read
/// a NaN, +inf, -inf from a stream!
///
/// To workaround this problem, parse special values manually
/// (the strings used are the one produces by displaying special
/// values on a stream).
template <>
struct signal_io<double> : signal_io_base<double> {
inline static double cast(std::istringstream &iss) {
std::string tmp(iss.str());
if (tmp == "nan")
return std::numeric_limits<double>::quiet_NaN();
else if (tmp == "inf" || tmp == "+inf")
return std::numeric_limits<double>::infinity();
else if (tmp == "-inf")
return -1. * std::numeric_limits<double>::infinity();
try {
return boost::lexical_cast<double>(tmp);
} catch (boost::bad_lexical_cast &) {
boost::format fmt("failed to serialize %s (to double)");
fmt % tmp;
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
}
}
};
} // namespace dynamicgraph
} // end of namespace dynamicgraph.
#endif /* SIGNALCASTER_H_ */
#endif //! DYNAMIC_GRAPH_SIGNAL_CASTER_HH
/*
* Copyright 2011, 2019
* LAAS-CNRS
* Nicolas Mansard, François Bailly
*
*/
#ifndef __dynamic_graph_signal_helper_H__
#define __dynamic_graph_signal_helper_H__
/* --- COMMON INCLUDE -------------------------------------------------- */
/* dg signals */
#include <dynamic-graph/entity.h>
#include <dynamic-graph/linear-algebra.h>
#include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h>
/* --- MACROS ---------------------------------------------------------- */
#define SIGNAL_OUT_FUNCTION_NAME(name) name##SOUT_function
#define DECLARE_SIGNAL(name, IO, type) \
::dynamicgraph::Signal<type, int> m_##name##S##IO
#define CONSTRUCT_SIGNAL(name, IO, type) \
m_##name##S##IO(getClassName() + "(" + getName() + ")::" + #IO + "put(" + \
#type + ")::" + #name)
#define BIND_SIGNAL_TO_FUNCTION(name, IO, type) \
m_##name##S##IO.setFunction(boost::bind( \
&EntityClassName::SIGNAL_OUT_FUNCTION_NAME(name), this, _1, _2));
/**/
#define DECLARE_SIGNAL_IN(name, type) \
::dynamicgraph::SignalPtr<type, int> m_##name##SIN
#define CONSTRUCT_SIGNAL_IN(name, type) \
m_##name##SIN(NULL, getClassName() + "(" + getName() + ")::input(" + #type + \
")::" + #name)
/**/
#define DECLARE_SIGNAL_OUT_FUNCTION(name, type) \
type &SIGNAL_OUT_FUNCTION_NAME(name)(type &, int)
#define DEFINE_SIGNAL_OUT_FUNCTION(name, type) \
type &EntityClassName::SIGNAL_OUT_FUNCTION_NAME(name)(type & s, int iter)
#define SIGNAL_OUT_FUNCTION(name) name##SOUT_function
#define DECLARE_SIGNAL_OUT(name, type) \
public: \
::dynamicgraph::SignalTimeDependent<type, int> m_##name##SOUT; \
\
protected: \
type &SIGNAL_OUT_FUNCTION(name)(type &, int)
#define CONSTRUCT_SIGNAL_OUT(name, type, dep) \
m_##name##SOUT( \
boost::bind(&EntityClassName::name##SOUT_function, this, _1, _2), dep, \
getClassName() + "(" + getName() + ")::output(" + #type + ")::" + #name)
/**************** INNER SIGNALS *******************/
#define SIGNAL_INNER_FUNCTION_NAME(name) name##SINNER_function
#define DECLARE_SIGNAL_INNER_FUNCTION(name, type) \
type &SIGNAL_INNER_FUNCTION_NAME(name)(type &, int)
#define DEFINE_SIGNAL_INNER_FUNCTION(name, type) \
type &EntityClassName::SIGNAL_INNER_FUNCTION_NAME(name)(type & s, int iter)
#define DECLARE_SIGNAL_INNER(name, type) \
public: \
::dynamicgraph::SignalTimeDependent<type, int> m_##name##SINNER; \
\
protected: \
DECLARE_SIGNAL_INNER_FUNCTION(name, type)
#define CONSTRUCT_SIGNAL_INNER(name, type, dep) \
m_##name##SINNER( \
boost::bind(&EntityClassName::name##SINNER_function, this, _1, _2), dep, \
getClassName() + "(" + getName() + ")::inner(" + #type + ")::" + #name)
#endif // __dynamic_graph_signal_helper_H__
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Copyright Projet JRL-Japan, 2007
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* File: SignalPtr.h
* Project: DYNAMIC-GRAPH
* Author: Nicolas Mansard
*
* Version control
* ===============
*
* $Id$
*
* Description
* ============
*
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// -*- mode: c++ -*-
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
// JRL, CNRS/AIST.
//
#ifndef __SIGNAL_PTR_HH
#define __SIGNAL_PTR_HH
#include <iostream>
#ifndef DYNAMIC_GRAPH_SIGNAL_PTR_H
#define DYNAMIC_GRAPH_SIGNAL_PTR_H
#include <dynamic-graph/exception-signal.h>
#include <dynamic-graph/signal.h>
namespace dynamicgraph {
template< class T,class Time >
class SignalPtr
: public virtual Signal<T,Time>
{
/// \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.
///
/// If the signal provided as a parameter of the plug operation
/// cannot be casted in type T, but is compatible then the class
/// holds a reference to an abstract object.
///
template <class T, class Time>
class SignalPtr : public virtual Signal<T, Time> {
public:
using SignalBase<Time>::getName;
using SignalBase<Time>::getName;
protected:
Signal<T,Time>* signalPtr;
bool modeNoThrow;
bool transmitAbstract;
SignalBase<Time> * abstractTransmitter;
T* transmitAbstractData;
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 --- */
SignalPtr(Signal<T, Time> *ptr, std::string name = "")
: Signal<T, Time>(name),
signalPtr(ptr),
modeNoThrow(false),
transmitAbstract(false),
abstractTransmitter(NULL) {}
virtual ~SignalPtr() { signalPtr = 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; }
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
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;
/* 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(); }
public:
/* --- PLUG-IN OPERATION --- */
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() { plug(NULL); }
virtual bool isPlugged() 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*() { return *getPtr(); }
inline const Signal<T, Time> &operator*() const { return *getPtr(); }
inline operator bool() const { return isPlugged(); }
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
* pointer dereference :
* Prefere -> () to ()
*/
virtual const T &operator()(const Time &t);
/* Similarly, Prefere ->access to .access
*/
virtual const T &access(const Time &t);
virtual const T &accessCopy() const;
inline void setConstantDefault(const T &t) {
Signal<T, Time>::setConstant(t);
modeNoThrow = true;
}
virtual inline void setConstantDefault() { setConstantDefault(accessCopy()); }
inline void unsetConstantDefault() { modeNoThrow = false; }
virtual void checkCompatibility();
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 explicite
* pointer dereference :
* Prefere ->() to ()
*/
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;
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; }
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); }
virtual void setReference( const T* t,typename Signal<T,Time>::Mutex *m=NULL )
{ 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); }
/* 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; }
virtual std::ostream& displayDependencies( std::ostream& os,const int depth=-1,
std::string space="",
std::string next1="",
std::string next2="" ) const;
protected: // Interdiction of the rest of the heritage
virtual void addDependency( const SignalBase<Time>& signal ) {}
virtual void removeDependency( const SignalBase<Time>& signal ) {}
virtual void clearDependencies( void ) {}
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);
}
virtual void setReference(const T *t,
typename Signal<T, Time>::Mutex *m = NULL) {
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);
}
/* 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;
}
virtual std::ostream &displayDependencies(std::ostream &os,
const int depth = -1,
std::string space = "",
std::string next1 = "",
std::string next2 = "") const;
protected: // Interdiction of the rest of the heritage
using Signal<T, Time>::addDependency;
virtual void addDependency() {}
using Signal<T, Time>::removeDependency;
virtual void removeDependency() {}
virtual void clearDependencies() {}
};
} // namespace dynamicgraph
} // end of namespace dynamicgraph
#include <dynamic-graph/signal-ptr.t.cpp>
#endif // #ifndef __SIGNAL_PTR_HH
/*
* Local variables:
* c-basic-offset: 4
* End:
*/
#endif //! DYNAMIC_GRAPH_SIGNAL_PTR_H