From a40852bb2bf62cd6e93d259fdc9aac0754480ffc Mon Sep 17 00:00:00 2001 From: florent <florent@laas.fr> Date: Wed, 24 Nov 2010 12:26:09 +0100 Subject: [PATCH] Command constructor takes a documentation string as input. * include/dynamic-graph/command-getter.h, * include/dynamic-graph/command-getter.t.cpp, * include/dynamic-graph/command-setter.h, * include/dynamic-graph/command-setter.t.cpp, * include/dynamic-graph/command.h, * src/command/command.cpp. --- include/dynamic-graph/command-getter.h | 3 +- include/dynamic-graph/command-getter.t.cpp | 5 +- include/dynamic-graph/command-setter.h | 3 +- include/dynamic-graph/command-setter.t.cpp | 64 ++++++++++++++-------- include/dynamic-graph/command.h | 7 ++- src/command/command.cpp | 11 +++- 6 files changed, 61 insertions(+), 32 deletions(-) diff --git a/include/dynamic-graph/command-getter.h b/include/dynamic-graph/command-getter.h index 336eea5..73e845e 100644 --- a/include/dynamic-graph/command-getter.h +++ b/include/dynamic-graph/command-getter.h @@ -58,7 +58,8 @@ namespace dynamicgraph { /// Pointer to method that sets paramter of type T typedef T (E::*GetterMethod) () const; /// Constructor - Getter(E& entity, GetterMethod); + Getter(E& entity, GetterMethod getterMethod, + const std::string& docString); protected: virtual Value doExecute(); diff --git a/include/dynamic-graph/command-getter.t.cpp b/include/dynamic-graph/command-getter.t.cpp index 98d5522..63e06bd 100644 --- a/include/dynamic-graph/command-getter.t.cpp +++ b/include/dynamic-graph/command-getter.t.cpp @@ -25,8 +25,9 @@ namespace dynamicgraph { namespace command { template <class E, typename T> - Getter<E, T>::Getter(E& entity, GetterMethod getterMethod) : - Command(entity, std::vector<Value::Type>()), + Getter<E, T>::Getter(E& entity, GetterMethod getterMethod, + const std::string& docstring) : + Command(entity, std::vector<Value::Type>(), docstring), getterMethod_(getterMethod) { } diff --git a/include/dynamic-graph/command-setter.h b/include/dynamic-graph/command-setter.h index f6648c1..588567e 100644 --- a/include/dynamic-graph/command-setter.h +++ b/include/dynamic-graph/command-setter.h @@ -58,7 +58,8 @@ namespace dynamicgraph { /// Pointer to method that sets paramter of type T typedef void (E::*SetterMethod) (const T&); /// Constructor - Setter(E& entity, SetterMethod); + Setter(E& entity, SetterMethod setterMethod, + const std::string& docString); protected: virtual Value doExecute(); diff --git a/include/dynamic-graph/command-setter.t.cpp b/include/dynamic-graph/command-setter.t.cpp index 7d26fc4..937c7ed 100644 --- a/include/dynamic-graph/command-setter.t.cpp +++ b/include/dynamic-graph/command-setter.t.cpp @@ -35,7 +35,8 @@ namespace dynamicgraph { /// Pointer to method that sets paramter of type bool typedef void (E::*SetterMethod) (const bool&); /// Constructor - Setter(E& entity, SetterMethod); + Setter(E& entity, SetterMethod setterMethod, + const std::string& docString); protected: virtual Value doExecute(); @@ -45,8 +46,9 @@ namespace dynamicgraph { }; // Class Setter template <class E> - Setter<E, bool>::Setter(E& entity, SetterMethod setterMethod) : - Command(entity, boost::assign::list_of(Value::BOOL)), + Setter<E, bool>::Setter(E& entity, SetterMethod setterMethod, + const std::string& docString) : + Command(entity, boost::assign::list_of(Value::BOOL), docString), setterMethod_(setterMethod) { } @@ -71,7 +73,8 @@ namespace dynamicgraph { /// Pointer to method that sets paramter of type unsigned typedef void (E::*SetterMethod) (const unsigned&); /// Constructor - Setter(E& entity, SetterMethod); + Setter(E& entity, SetterMethod setterMethod, + const std::string& docString); protected: virtual Value doExecute(); @@ -81,8 +84,9 @@ namespace dynamicgraph { }; // Class Setter template <class E> - Setter<E, unsigned>::Setter(E& entity, SetterMethod setterMethod) : - Command(entity, boost::assign::list_of(Value::UNSIGNED)), + Setter<E, unsigned>::Setter(E& entity, SetterMethod setterMethod, + const std::string& docString) : + Command(entity, boost::assign::list_of(Value::UNSIGNED), docString), setterMethod_(setterMethod) { } @@ -107,7 +111,8 @@ namespace dynamicgraph { /// Pointer to method that sets paramter of type int typedef void (E::*SetterMethod) (const int&); /// Constructor - Setter(E& entity, SetterMethod); + Setter(E& entity, SetterMethod setterMethod, + const std::string& docString); protected: virtual Value doExecute(); @@ -117,8 +122,9 @@ namespace dynamicgraph { }; // Class Setter template <class E> - Setter<E, int>::Setter(E& entity, SetterMethod setterMethod) : - Command(entity, boost::assign::list_of(Value::INT)), + Setter<E, int>::Setter(E& entity, SetterMethod setterMethod, + const std::string& docString) : + Command(entity, boost::assign::list_of(Value::INT), docString), setterMethod_(setterMethod) { } @@ -143,7 +149,8 @@ namespace dynamicgraph { /// Pointer to method that sets paramter of type float typedef void (E::*SetterMethod) (const float&); /// Constructor - Setter(E& entity, SetterMethod); + Setter(E& entity, SetterMethod setterMethod, + const std::string& docString); protected: virtual Value doExecute(); @@ -153,8 +160,9 @@ namespace dynamicgraph { }; // Class Setter template <class E> - Setter<E, float>::Setter(E& entity, SetterMethod setterMethod) : - Command(entity, boost::assign::list_of(Value::FLOAT)), + Setter<E, float>::Setter(E& entity, SetterMethod setterMethod, + const std::string& docString) : + Command(entity, boost::assign::list_of(Value::FLOAT), docString), setterMethod_(setterMethod) { } @@ -179,7 +187,8 @@ namespace dynamicgraph { /// Pointer to method that sets paramter of type double typedef void (E::*SetterMethod) (const double&); /// Constructor - Setter(E& entity, SetterMethod); + Setter(E& entity, SetterMethod setterMethod, + const std::string& docString); protected: virtual Value doExecute(); @@ -189,8 +198,9 @@ namespace dynamicgraph { }; // Class Setter template <class E> - Setter<E, double>::Setter(E& entity, SetterMethod setterMethod) : - Command(entity, boost::assign::list_of(Value::DOUBLE)), + Setter<E, double>::Setter(E& entity, SetterMethod setterMethod, + const std::string& docString) : + Command(entity, boost::assign::list_of(Value::DOUBLE), docString), setterMethod_(setterMethod) { } @@ -215,7 +225,8 @@ namespace dynamicgraph { /// Pointer to method that sets paramter of type std::string typedef void (E::*SetterMethod) (const std::string&); /// Constructor - Setter(E& entity, SetterMethod); + Setter(E& entity, SetterMethod setterMethod, + const std::string& docString); protected: virtual Value doExecute(); @@ -225,8 +236,9 @@ namespace dynamicgraph { }; // Class Setter template <class E> - Setter<E, std::string>::Setter(E& entity, SetterMethod setterMethod) : - Command(entity, boost::assign::list_of(Value::STRING)), + Setter<E, std::string>::Setter(E& entity, SetterMethod setterMethod, + const std::string& docString) : + Command(entity, boost::assign::list_of(Value::STRING), docString), setterMethod_(setterMethod) { } @@ -251,7 +263,8 @@ namespace dynamicgraph { /// Pointer to method that sets paramter of type Vector typedef void (E::*SetterMethod) (const Vector&); /// Constructor - Setter(E& entity, SetterMethod); + Setter(E& entity, SetterMethod setterMethod, + const std::string& docString); protected: virtual Value doExecute(); @@ -261,8 +274,9 @@ namespace dynamicgraph { }; // Class Setter template <class E> - Setter<E, Vector>::Setter(E& entity, SetterMethod setterMethod) : - Command(entity, boost::assign::list_of(Value::VECTOR)), + Setter<E, Vector>::Setter(E& entity, SetterMethod setterMethod, + const std::string& docString) : + Command(entity, boost::assign::list_of(Value::VECTOR), docString), setterMethod_(setterMethod) { } @@ -287,7 +301,8 @@ namespace dynamicgraph { /// Pointer to method that sets paramter of type Matrix typedef void (E::*SetterMethod) (const Matrix&); /// Constructor - Setter(E& entity, SetterMethod); + Setter(E& entity, SetterMethod setterMethod, + const std::string& docString); protected: virtual Value doExecute(); @@ -297,8 +312,9 @@ namespace dynamicgraph { }; // Class Setter template <class E> - Setter<E, Matrix>::Setter(E& entity, SetterMethod setterMethod) : - Command(entity, boost::assign::list_of(Value::MATRIX)), + Setter<E, Matrix>::Setter(E& entity, SetterMethod setterMethod, + const std::string& docString) : + Command(entity, boost::assign::list_of(Value::MATRIX), docString), setterMethod_(setterMethod) { } diff --git a/include/dynamic-graph/command.h b/include/dynamic-graph/command.h index f15e793..cbfd7a9 100644 --- a/include/dynamic-graph/command.h +++ b/include/dynamic-graph/command.h @@ -47,7 +47,9 @@ namespace dynamicgraph { /// Store the owner entity and a vector of value types /// \param entity reference to Entity owning this command. /// \param valueTypes vector specifying the number and types of parameters - Command(Entity& entity, const std::vector<Value::Type>& valueTypes); + /// \param docstring documentation of the command + Command(Entity& entity, const std::vector<Value::Type>& valueTypes, + const std::string& docstring); /// Return the value type of all parameters const std::vector<Value::Type> valueTypes() const; /// Set parameter values @@ -58,6 +60,8 @@ namespace dynamicgraph { Value execute(); /// Get a reference to the Entity owning this command Entity& owner(); + /// Get documentation string + std::string getDocstring() const; protected: /// Specific action performed by the command virtual Value doExecute() = 0; @@ -65,6 +69,7 @@ namespace dynamicgraph { Entity& owner_; std::vector<Value::Type> valueTypeVector_; std::vector<Value> valueVector_; + std::string docstring_; }; } // namespace command } // namespace dynamicgraph diff --git a/src/command/command.cpp b/src/command/command.cpp index 8d7ed1a..2c71ef0 100644 --- a/src/command/command.cpp +++ b/src/command/command.cpp @@ -24,8 +24,9 @@ namespace dynamicgraph { Command::~Command() {} Command::Command(Entity& entity, - const std::vector<Value::Type>& valueTypes) : - owner_(entity), valueTypeVector_(valueTypes) + const std::vector<Value::Type>& valueTypes, + const std::string& docstring) : + owner_(entity), valueTypeVector_(valueTypes), docstring_(docstring) { } @@ -62,7 +63,7 @@ namespace dynamicgraph { } Value Command::execute() - { + { return doExecute(); } @@ -70,5 +71,9 @@ namespace dynamicgraph { { return owner_; } + std::string Command::getDocstring() const + { + return docstring_; + } } // namespace command } //namespace dynamicgraph -- GitLab