diff --git a/include/dynamic-graph/entity.h b/include/dynamic-graph/entity.h index 267a7fc59e858a2a6bd220caa06e2e36c5c2f9b8..3eb63f38e6daebe34752b8e5185aebdb12887a6f 100644 --- a/include/dynamic-graph/entity.h +++ b/include/dynamic-graph/entity.h @@ -30,6 +30,31 @@ # include <dynamic-graph/signal-array.h> # include <dynamic-graph/signal-base.h> +/// \brief Helper macro for entity declaration. +/// +/// This macro should be called in the declaration of all entities. +/// Example: +/// <code> +/// class A : public dynamicgraph::entity +/// { +/// DYNAMIC_GRAPH_ENTITY_DECL(); +/// +/// public: +// // your class here +/// }; +/// </code> +/// +/// Caution: you *MUST* call DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN in the +/// associated source file to ensure that the attributes generated by +/// this macro are correctly initialized. +# define DYNAMIC_GRAPH_ENTITY_DECL() \ + public: \ + virtual const std::string& getClassName () const \ + { \ + return CLASS_NAME; \ + } \ + static const std::string CLASS_NAME + namespace dynamicgraph { /// \ingroup dgraph @@ -50,8 +75,6 @@ namespace dynamicgraph typedef std::map< std::string,SignalBase<int>* > SignalMap; typedef std::map<const std::string, command::Command*> CommandMap_t; - static const std::string CLASS_NAME; - explicit Entity (const std::string& name); virtual ~Entity (); @@ -59,7 +82,6 @@ namespace dynamicgraph { return name; } - virtual const std::string& getClassName () const = 0; SignalBase<int>& getSignal (const std::string& signalName); diff --git a/include/dynamic-graph/tracer-real-time.h b/include/dynamic-graph/tracer-real-time.h index 19966a9e4209f04b306fe9a265c73d609a8b5071..d89291fdacd18d43e6d135c0f6d6418cd405ac48 100644 --- a/include/dynamic-graph/tracer-real-time.h +++ b/include/dynamic-graph/tracer-real-time.h @@ -52,13 +52,8 @@ namespace dynamicgraph /// \brief Main class of the tracer real-time plug-in. class DG_TRACERREALTIME_DLLAPI TracerRealTime : public Tracer { + DYNAMIC_GRAPH_ENTITY_DECL (); public: - static const std::string CLASS_NAME; - virtual const std::string& getClassName () const - { - return CLASS_NAME; - } - TracerRealTime (const std::string n); virtual ~TracerRealTime () {} diff --git a/include/dynamic-graph/tracer.h b/include/dynamic-graph/tracer.h index 041563f8053fd4c80c631c243dafca5cc06fce77..409036b7c7ff5b1753c39ed4b3fb079495dc03f0 100644 --- a/include/dynamic-graph/tracer.h +++ b/include/dynamic-graph/tracer.h @@ -36,18 +36,10 @@ namespace dynamicgraph /// \brief Tracer plug-in main class. class DG_TRACER_DLLAPI Tracer : public Entity { + DYNAMIC_GRAPH_ENTITY_DECL (); protected: typedef std::list< const SignalBase<int>* > SignalList; SignalList toTraceSignals; - - - public: - static const std::string CLASS_NAME; - virtual const std::string& getClassName () const - { - return CLASS_NAME; - } - public: enum TraceStyle {