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 2325 additions and 1977 deletions
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
// //
#ifndef DYNAMIC_GRAPH_ALL_SIGNALS_H #ifndef DYNAMIC_GRAPH_ALL_SIGNALS_H
# define DYNAMIC_GRAPH_ALL_SIGNALS_H #define DYNAMIC_GRAPH_ALL_SIGNALS_H
// Utility header files including all signal headers // Utility header files including all signal headers
# include <dynamic-graph/signal.h> #include <dynamic-graph/signal-ptr.h>
# include <dynamic-graph/signal-ptr.h> #include <dynamic-graph/signal-time-dependent.h>
# include <dynamic-graph/signal-time-dependent.h> #include <dynamic-graph/signal.h>
#endif //! DYNAMIC_GRAPH_ALL_SIGNALS_H #endif //! DYNAMIC_GRAPH_ALL_SIGNALS_H
This diff is collapsed.
...@@ -15,47 +15,44 @@ ...@@ -15,47 +15,44 @@
* *
*/ */
#include "dynamic-graph/command.h"
#include <boost/assign/list_of.hpp> #include <boost/assign/list_of.hpp>
#include "dynamic-graph/command.h"
/* --- GETTER --------------------------------------------------------- */ /* --- GETTER --------------------------------------------------------- */
namespace dynamicgraph { namespace dynamicgraph {
namespace command { namespace command {
template <class E, typename T> template <class E, typename T>
class DirectGetter class DirectGetter : public Command {
: public Command public:
{ /// Pointer to method that sets parameter of type T
public: typedef T (E::*GetterMethod)() const;
/// Pointer to method that sets parameter of type T
typedef T (E::*GetterMethod) () const; /// Constructor
DirectGetter(E &entity, T *ptr, const std::string &docString)
/// Constructor : Command(entity, std::vector<Value::Type>(), docString), T_ptr(ptr) {}
DirectGetter(E& entity,T* ptr,
const std::string& docString) protected:
: Command(entity, std::vector<Value::Type>(), docString), virtual Value doExecute() { return Value(*T_ptr); }
T_ptr(ptr) {}
private:
protected: T *T_ptr;
virtual Value doExecute() { return Value(*T_ptr); } };
private:
T* T_ptr; template <class E, typename T>
}; DirectGetter<E, T> *makeDirectGetter(E &entity, T *ptr,
const std::string &docString) {
template <class E, typename T> return new DirectGetter<E, T>(entity, ptr, docString);
DirectGetter<E,T>* }
makeDirectGetter( E& entity,T* ptr,
const std::string& docString) inline std::string docDirectGetter(const std::string &name,
{ return new DirectGetter<E,T>(entity,ptr,docString); } const std::string &type) {
return std::string("\nGet the ") + name + ".\n\nNo input.\nReturn an " +
inline std::string docDirectGetter( const std::string& name, type + ".\n\n";
const std::string& type ) }
{
return std::string("\nGet the ")+name+".\n\nNo input.\nReturn an "+type+".\n\n"; } // namespace command
} } // namespace dynamicgraph
} // namespace command #endif // __dg_command_direct_getter_h__
} // namespace dynamicgraph
#endif // __dg_command_direct_getter_h__
...@@ -15,50 +15,47 @@ ...@@ -15,50 +15,47 @@
* *
*/ */
#include "dynamic-graph/command.h"
#include <boost/assign/list_of.hpp> #include <boost/assign/list_of.hpp>
#include "dynamic-graph/command.h"
/* --- SETTER --------------------------------------------------------- */ /* --- SETTER --------------------------------------------------------- */
namespace dynamicgraph { namespace dynamicgraph {
namespace command { namespace command {
template <class E, typename T> template <class E, typename T>
class DirectSetter class DirectSetter : public Command {
: public Command public:
{ DirectSetter(E &entity, T *ptr, const std::string &docString)
public: : Command(entity, boost::assign::list_of(ValueHelper<T>::TypeID),
DirectSetter(E& entity,T* ptr,const std::string& docString) docString),
:Command(entity, boost::assign::list_of(ValueHelper<T>::TypeID), docString) T_ptr(ptr) {}
,T_ptr(ptr)
{} protected:
virtual Value doExecute() {
protected: const std::vector<Value> &values = getParameterValues();
virtual Value doExecute() T val = values[0].value();
{ (*T_ptr) = val;
const std::vector<Value>& values = getParameterValues(); return Value(); // void
T val = values[0].value(); }
(*T_ptr) = val;
return Value(); // void private:
} T *T_ptr;
private: };
T* T_ptr;
}; template <class E, typename T>
DirectSetter<E, T> *makeDirectSetter(E &entity, T *ptr,
template <class E, typename T> const std::string &docString) {
DirectSetter<E,T>* return new DirectSetter<E, T>(entity, ptr, docString);
makeDirectSetter( E& entity,T* ptr, }
const std::string& docString)
{ return new DirectSetter<E,T>(entity,ptr,docString); } inline std::string docDirectSetter(const std::string &name,
const std::string &type) {
inline std::string docDirectSetter( const std::string& name, return std::string("\nSet the ") + name + ".\n\nInput:\n - a " + type +
const std::string& type ) ".\nVoid return.\n\n";
{ }
return std::string("\nSet the ")+name+".\n\nInput:\n - a "
+type+".\nVoid return.\n\n"; } // namespace command
} } // namespace dynamicgraph
} // namespace command #endif // __dg_command_direct_setter_h__
} // namespace dynamicgraph
#endif // __dg_command_direct_setter_h__
...@@ -10,54 +10,53 @@ ...@@ -10,54 +10,53 @@
#include "dynamic-graph/command.h" #include "dynamic-graph/command.h"
namespace dynamicgraph { namespace dynamicgraph {
namespace command { namespace command {
/// ///
/// Command that calls a parameter getter function /// Command that calls a parameter getter function
/// ///
/// This class is templated by a type E deriving from entity and /// This class is templated by a type E deriving from entity and
/// a type T of data. /// a type T of data.
/// ///
/// Let us assume that class E has a private member of type T and a /// Let us assume that class E has a private member of type T and a
/// public getter function for this member: /// public getter function for this member:
/// \code /// \code
/// class E : public Entity /// class E : public Entity
/// { /// {
/// public: /// public:
/// E (const std::string& inName) : Entity(inName) {} /// E (const std::string& inName) : Entity(inName) {}
/// T getParameter() const {return parameter_;} /// T getParameter() const {return parameter_;}
/// private: /// private:
/// T parameter_; /// T parameter_;
/// }; /// };
/// \endcode /// \endcode
/// Then the command defined by: /// Then the command defined by:
/// \code /// \code
/// E entity("MyEntity"); /// E entity("MyEntity");
/// Getter<E,T> command(entity, &E::getParameter) /// Getter<E,T> command(entity, &E::getParameter)
/// \endcode /// \endcode
/// returns the value of <c>entity.parameter_</c> upon invocation. /// returns the value of <c>entity.parameter_</c> upon invocation.
/// ///
/// \note /// \note
/// \li T should be a type supported by class Value, /// \li T should be a type supported by class Value,
/// \li prototype of E::getParameter should be exactly as specified in this /// \li prototype of E::getParameter should be exactly as specified in this
/// example. /// example.
template <class E, typename T> template <class E, typename T>
class Getter : public Command { class Getter : public Command {
public: public:
/// Pointer to method that sets parameter of type T /// Pointer to method that sets parameter of type T
typedef T (E::*GetterMethod) () const; typedef T (E::*GetterMethod)() const;
/// Constructor /// Constructor
Getter(E& entity, GetterMethod getterMethod, Getter(E &entity, GetterMethod getterMethod, const std::string &docString);
const std::string& docString);
protected: protected:
virtual Value doExecute(); virtual Value doExecute();
private: private:
GetterMethod getterMethod_; GetterMethod getterMethod_;
}; };
} // namespace command } // namespace command
} // namespace dynamicgraph } // namespace dynamicgraph
#include "dynamic-graph/command-getter.t.cpp" #include "dynamic-graph/command-getter.t.cpp"
#endif //DYNAMIC_GRAPH_COMMAND_GETTER_H #endif // DYNAMIC_GRAPH_COMMAND_GETTER_H
...@@ -7,28 +7,27 @@ ...@@ -7,28 +7,27 @@
#ifndef DYNAMIC_GRAPH_COMMAND_GETTER_T_CPP #ifndef DYNAMIC_GRAPH_COMMAND_GETTER_T_CPP
#define DYNAMIC_GRAPH_COMMAND_GETTER_T_CPP #define DYNAMIC_GRAPH_COMMAND_GETTER_T_CPP
#include "dynamic-graph/command-getter.h"
#include <sstream> #include <sstream>
namespace dynamicgraph { namespace dynamicgraph {
class Entity; class Entity;
namespace command { namespace command {
template <class E, typename T> template <class E, typename T>
Getter<E, T>::Getter(E& entity, GetterMethod getterMethod, Getter<E, T>::Getter(E &entity, GetterMethod getterMethod,
const std::string& docstring) : const std::string &docstring)
Command(entity, std::vector<Value::Type>(), docstring), : Command(entity, std::vector<Value::Type>(), docstring),
getterMethod_(getterMethod) getterMethod_(getterMethod) {}
{
}
template <class E, typename T> template <class E, typename T>
Value Getter<E, T>::doExecute() Value Getter<E, T>::doExecute() {
{ E &entity = static_cast<E &>(owner());
E& entity = static_cast<E&>(owner()); T value = (entity.*getterMethod_)();
T value = (entity.*getterMethod_)(); return Value(value);
return Value(value); }
} } // namespace command
} // namespace command } // namespace dynamicgraph
} // namespace dynamicgraph
#endif // DYNAMIC_GRAPH_COMMAND_GETTER_T_CPP #endif // DYNAMIC_GRAPH_COMMAND_GETTER_T_CPP
...@@ -10,54 +10,53 @@ ...@@ -10,54 +10,53 @@
#include "dynamic-graph/command.h" #include "dynamic-graph/command.h"
namespace dynamicgraph { namespace dynamicgraph {
namespace command { namespace command {
/// ///
/// Command that calls a parameter setter function /// Command that calls a parameter setter function
/// ///
/// This class is templated by a type E deriving from entity and /// This class is templated by a type E deriving from entity and
/// a type T of data. /// a type T of data.
/// ///
/// Let us assume that class E has a private member of type T and a /// Let us assume that class E has a private member of type T and a
/// public setter function for this member: /// public setter function for this member:
/// \code /// \code
/// class E : public Entity /// class E : public Entity
/// { /// {
/// public: /// public:
/// E (const std::string& inName) : Entity(inName) {} /// E (const std::string& inName) : Entity(inName) {}
/// void setParameter(const T& parameter) {parameter_ = parameter;} /// void setParameter(const T& parameter) {parameter_ = parameter;}
/// private: /// private:
/// T parameter_; /// T parameter_;
/// }; /// };
/// \endcode /// \endcode
/// Then the command defined by: /// Then the command defined by:
/// \code /// \code
/// E entity("MyEntity"); /// E entity("MyEntity");
/// Setter<E,T> command(entity, &E::getParameter) /// Setter<E,T> command(entity, &E::getParameter)
/// \endcode /// \endcode
/// sets the value of <c>entity.parameter_</c> upon invocation. /// sets the value of <c>entity.parameter_</c> upon invocation.
/// ///
/// \note /// \note
/// \li T should be a type supported by class Value, /// \li T should be a type supported by class Value,
/// \li prototype of E::setParameter should be exactly as specified in this /// \li prototype of E::setParameter should be exactly as specified in this
/// example. /// example.
template <class E, typename T> template <class E, typename T>
class Setter : public Command { class Setter : public Command {
public: public:
/// Pointer to method that sets parameter of type T /// Pointer to method that sets parameter of type T
typedef void (E::*SetterMethod) (const T&); typedef void (E::*SetterMethod)(const T &);
/// Constructor /// Constructor
Setter(E& entity, SetterMethod setterMethod, Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
const std::string& docString);
protected: protected:
virtual Value doExecute(); virtual Value doExecute();
private: private:
SetterMethod setterMethod_; SetterMethod setterMethod_;
}; };
} // namespace command } // namespace command
} // namespace dynamicgraph } // namespace dynamicgraph
#include "dynamic-graph/command-setter.t.cpp" #include "dynamic-graph/command-setter.t.cpp"
#endif //DYNAMIC_GRAPH_COMMAND_SETTER_H #endif // DYNAMIC_GRAPH_COMMAND_SETTER_H
...@@ -7,319 +7,290 @@ ...@@ -7,319 +7,290 @@
#ifndef DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP #ifndef DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP
#define DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP #define DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP
#include <sstream> #include "dynamic-graph/command-setter.h"
#include <boost/assign/list_of.hpp> #include <boost/assign/list_of.hpp>
#include <sstream>
#include "dynamic-graph/linear-algebra.h" #include "dynamic-graph/linear-algebra.h"
namespace dynamicgraph { namespace dynamicgraph {
class Entity; class Entity;
namespace command { namespace command {
// //
// Template specialization: bool // Template specialization: bool
// //
template <class E> template <class E>
class Setter<E, bool> : public Command { class Setter<E, bool> : public Command {
public: public:
/// Pointer to method that sets parameter of type bool /// Pointer to method that sets parameter of type bool
typedef void (E::*SetterMethod) (const bool&); typedef void (E::*SetterMethod)(const bool &);
/// Constructor /// Constructor
Setter(E& entity, SetterMethod setterMethod, Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
const std::string& docString);
protected:
protected: virtual Value doExecute();
virtual Value doExecute();
private:
private: SetterMethod setterMethod_;
SetterMethod setterMethod_; }; // Class Setter
}; // Class Setter
template <class E>
template <class E> Setter<E, bool>::Setter(E &entity, SetterMethod setterMethod,
Setter<E, bool>::Setter(E& entity, SetterMethod setterMethod, const std::string &docString)
const std::string& docString) : : Command(entity, boost::assign::list_of(Value::BOOL), docString),
Command(entity, boost::assign::list_of(Value::BOOL), docString), setterMethod_(setterMethod) {}
setterMethod_(setterMethod)
{ template <class E>
} Value Setter<E, bool>::doExecute() {
const std::vector<Value> &values = getParameterValues();
template <class E> // Get parameter
Value Setter<E, bool>::doExecute() bool value = values[0].value();
{ E &entity = static_cast<E &>(owner());
const std::vector<Value>& values = getParameterValues(); (entity.*setterMethod_)(value);
// Get parameter return Value();
bool value = values[0].value(); }
E& entity = static_cast<E&>(owner());
(entity.*setterMethod_)(value); //
return Value(); // Template specialization: unsigned
} //
template <class E>
// class Setter<E, unsigned> : public Command {
// Template specialization: unsigned public:
// /// Pointer to method that sets parameter of type unsigned
template <class E> typedef void (E::*SetterMethod)(const unsigned &);
class Setter<E, unsigned> : public Command { /// Constructor
public: Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
/// Pointer to method that sets parameter of type unsigned
typedef void (E::*SetterMethod) (const unsigned&); protected:
/// Constructor virtual Value doExecute();
Setter(E& entity, SetterMethod setterMethod,
const std::string& docString); private:
SetterMethod setterMethod_;
protected: }; // Class Setter
virtual Value doExecute();
template <class E>
private: Setter<E, unsigned>::Setter(E &entity, SetterMethod setterMethod,
SetterMethod setterMethod_; const std::string &docString)
}; // Class Setter : Command(entity, boost::assign::list_of(Value::UNSIGNED), docString),
setterMethod_(setterMethod) {}
template <class E>
Setter<E, unsigned>::Setter(E& entity, SetterMethod setterMethod, template <class E>
const std::string& docString) : Value Setter<E, unsigned>::doExecute() {
Command(entity, boost::assign::list_of(Value::UNSIGNED), docString), const std::vector<Value> &values = getParameterValues();
setterMethod_(setterMethod) // Get parameter
{ unsigned value = values[0].value();
} E &entity = static_cast<E &>(owner());
(entity.*setterMethod_)(value);
template <class E> return Value();
Value Setter<E, unsigned>::doExecute() }
{
const std::vector<Value>& values = getParameterValues(); //
// Get parameter // Template specialization: int
unsigned value = values[0].value(); //
E& entity = static_cast<E&>(owner()); template <class E>
(entity.*setterMethod_)(value); class Setter<E, int> : public Command {
return Value(); public:
} /// Pointer to method that sets parameter of type int
typedef void (E::*SetterMethod)(const int &);
// /// Constructor
// Template specialization: int Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
//
template <class E> protected:
class Setter<E, int> : public Command { virtual Value doExecute();
public:
/// Pointer to method that sets parameter of type int private:
typedef void (E::*SetterMethod) (const int&); SetterMethod setterMethod_;
/// Constructor }; // Class Setter
Setter(E& entity, SetterMethod setterMethod,
const std::string& docString); template <class E>
Setter<E, int>::Setter(E &entity, SetterMethod setterMethod,
protected: const std::string &docString)
virtual Value doExecute(); : Command(entity, boost::assign::list_of(Value::INT), docString),
setterMethod_(setterMethod) {}
private:
SetterMethod setterMethod_; template <class E>
}; // Class Setter Value Setter<E, int>::doExecute() {
const std::vector<Value> &values = getParameterValues();
template <class E> // Get parameter
Setter<E, int>::Setter(E& entity, SetterMethod setterMethod, int value = values[0].value();
const std::string& docString) : E &entity = static_cast<E &>(owner());
Command(entity, boost::assign::list_of(Value::INT), docString), (entity.*setterMethod_)(value);
setterMethod_(setterMethod) return Value();
{ }
}
//
template <class E> // Template specialization: float
Value Setter<E, int>::doExecute() //
{ template <class E>
const std::vector<Value>& values = getParameterValues(); class Setter<E, float> : public Command {
// Get parameter public:
int value = values[0].value(); /// Pointer to method that sets parameter of type float
E& entity = static_cast<E&>(owner()); typedef void (E::*SetterMethod)(const float &);
(entity.*setterMethod_)(value); /// Constructor
return Value(); Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
}
protected:
// virtual Value doExecute();
// Template specialization: float
// private:
template <class E> SetterMethod setterMethod_;
class Setter<E, float> : public Command { }; // Class Setter
public:
/// Pointer to method that sets parameter of type float template <class E>
typedef void (E::*SetterMethod) (const float&); Setter<E, float>::Setter(E &entity, SetterMethod setterMethod,
/// Constructor const std::string &docString)
Setter(E& entity, SetterMethod setterMethod, : Command(entity, boost::assign::list_of(Value::FLOAT), docString),
const std::string& docString); setterMethod_(setterMethod) {}
protected: template <class E>
virtual Value doExecute(); Value Setter<E, float>::doExecute() {
const std::vector<Value> &values = getParameterValues();
private: // Get parameter
SetterMethod setterMethod_; float value = values[0].value();
}; // Class Setter E &entity = static_cast<E &>(owner());
(entity.*setterMethod_)(value);
template <class E> return Value();
Setter<E, float>::Setter(E& entity, SetterMethod setterMethod, }
const std::string& docString) :
Command(entity, boost::assign::list_of(Value::FLOAT), docString), //
setterMethod_(setterMethod) // Template specialization: double
{ //
} template <class E>
class Setter<E, double> : public Command {
template <class E> public:
Value Setter<E, float>::doExecute() /// Pointer to method that sets parameter of type double
{ typedef void (E::*SetterMethod)(const double &);
const std::vector<Value>& values = getParameterValues(); /// Constructor
// Get parameter Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
float value = values[0].value();
E& entity = static_cast<E&>(owner()); protected:
(entity.*setterMethod_)(value); virtual Value doExecute();
return Value();
} private:
SetterMethod setterMethod_;
// }; // Class Setter
// Template specialization: double
// template <class E>
template <class E> Setter<E, double>::Setter(E &entity, SetterMethod setterMethod,
class Setter<E, double> : public Command { const std::string &docString)
public: : Command(entity, boost::assign::list_of(Value::DOUBLE), docString),
/// Pointer to method that sets parameter of type double setterMethod_(setterMethod) {}
typedef void (E::*SetterMethod) (const double&);
/// Constructor template <class E>
Setter(E& entity, SetterMethod setterMethod, Value Setter<E, double>::doExecute() {
const std::string& docString); const std::vector<Value> &values = getParameterValues();
// Get parameter
protected: double value = values[0].value();
virtual Value doExecute(); E &entity = static_cast<E &>(owner());
(entity.*setterMethod_)(value);
private: return Value();
SetterMethod setterMethod_; }
}; // Class Setter
//
template <class E> // Template specialization: std::string
Setter<E, double>::Setter(E& entity, SetterMethod setterMethod, //
const std::string& docString) : template <class E>
Command(entity, boost::assign::list_of(Value::DOUBLE), docString), class Setter<E, std::string> : public Command {
setterMethod_(setterMethod) public:
{ /// Pointer to method that sets parameter of type std::string
} typedef void (E::*SetterMethod)(const std::string &);
/// Constructor
template <class E> Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
Value Setter<E, double>::doExecute()
{ protected:
const std::vector<Value>& values = getParameterValues(); virtual Value doExecute();
// Get parameter
double value = values[0].value(); private:
E& entity = static_cast<E&>(owner()); SetterMethod setterMethod_;
(entity.*setterMethod_)(value); }; // Class Setter
return Value();
} template <class E>
Setter<E, std::string>::Setter(E &entity, SetterMethod setterMethod,
// const std::string &docString)
// Template specialization: std::string : Command(entity, boost::assign::list_of(Value::STRING), docString),
// setterMethod_(setterMethod) {}
template <class E>
class Setter<E, std::string> : public Command { template <class E>
public: Value Setter<E, std::string>::doExecute() {
/// Pointer to method that sets parameter of type std::string const std::vector<Value> &values = getParameterValues();
typedef void (E::*SetterMethod) (const std::string&); // Get parameter
/// Constructor std::string value = values[0].value();
Setter(E& entity, SetterMethod setterMethod, E &entity = static_cast<E &>(owner());
const std::string& docString); (entity.*setterMethod_)(value);
return Value();
protected: }
virtual Value doExecute();
//
private: // Template specialization: Vector
SetterMethod setterMethod_; //
}; // Class Setter template <class E>
class Setter<E, Vector> : public Command {
template <class E> public:
Setter<E, std::string>::Setter(E& entity, SetterMethod setterMethod, /// Pointer to method that sets parameter of type Vector
const std::string& docString) : typedef void (E::*SetterMethod)(const Vector &);
Command(entity, boost::assign::list_of(Value::STRING), docString), /// Constructor
setterMethod_(setterMethod) Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
{
} protected:
virtual Value doExecute();
template <class E>
Value Setter<E, std::string>::doExecute() private:
{ SetterMethod setterMethod_;
const std::vector<Value>& values = getParameterValues(); }; // Class Setter
// Get parameter
std::string value = values[0].value(); template <class E>
E& entity = static_cast<E&>(owner()); Setter<E, Vector>::Setter(E &entity, SetterMethod setterMethod,
(entity.*setterMethod_)(value); const std::string &docString)
return Value(); : Command(entity, boost::assign::list_of(Value::VECTOR), docString),
} setterMethod_(setterMethod) {}
// template <class E>
// Template specialization: Vector Value Setter<E, Vector>::doExecute() {
// const std::vector<Value> &values = getParameterValues();
template <class E> // Get parameter
class Setter<E, Vector> : public Command { Vector value = values[0].value();
public: E &entity = static_cast<E &>(owner());
/// Pointer to method that sets parameter of type Vector (entity.*setterMethod_)(value);
typedef void (E::*SetterMethod) (const Vector&); return Value();
/// Constructor }
Setter(E& entity, SetterMethod setterMethod,
const std::string& docString); //
// Template specialization: Matrix
protected: //
virtual Value doExecute(); template <class E>
class Setter<E, Matrix> : public Command {
private: public:
SetterMethod setterMethod_; /// Pointer to method that sets parameter of type Matrix
}; // Class Setter typedef void (E::*SetterMethod)(const Matrix &);
/// Constructor
template <class E> Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
Setter<E, Vector>::Setter(E& entity, SetterMethod setterMethod,
const std::string& docString) : protected:
Command(entity, boost::assign::list_of(Value::VECTOR), docString), virtual Value doExecute();
setterMethod_(setterMethod)
{ private:
} SetterMethod setterMethod_;
}; // Class Setter
template <class E>
Value Setter<E, Vector>::doExecute() template <class E>
{ Setter<E, Matrix>::Setter(E &entity, SetterMethod setterMethod,
const std::vector<Value>& values = getParameterValues(); const std::string &docString)
// Get parameter : Command(entity, boost::assign::list_of(Value::MATRIX), docString),
Vector value = values[0].value(); setterMethod_(setterMethod) {}
E& entity = static_cast<E&>(owner());
(entity.*setterMethod_)(value); template <class E>
return Value(); Value Setter<E, Matrix>::doExecute() {
} const std::vector<Value> &values = getParameterValues();
// Get parameter
// Matrix value = values[0].value();
// Template specialization: Matrix E &entity = static_cast<E &>(owner());
// (entity.*setterMethod_)(value);
template <class E> return Value();
class Setter<E, Matrix> : public Command { }
public:
/// Pointer to method that sets parameter of type Matrix } // namespace command
typedef void (E::*SetterMethod) (const Matrix&); } // namespace dynamicgraph
/// Constructor
Setter(E& entity, SetterMethod setterMethod, #endif // DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP
const std::string& docString);
protected:
virtual Value doExecute();
private:
SetterMethod setterMethod_;
}; // Class Setter
template <class E>
Setter<E, Matrix>::Setter(E& entity, SetterMethod setterMethod,
const std::string& docString) :
Command(entity, boost::assign::list_of(Value::MATRIX), docString),
setterMethod_(setterMethod)
{
}
template <class E>
Value Setter<E, Matrix>::doExecute()
{
const std::vector<Value>& values = getParameterValues();
// Get parameter
Matrix value = values[0].value();
E& entity = static_cast<E&>(owner());
(entity.*setterMethod_)(value);
return Value();
}
} // namespace command
} // namespace dynamicgraph
#endif // DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP
...@@ -8,61 +8,66 @@ ...@@ -8,61 +8,66 @@
#define DYNAMIC_GRAPH_COMMAND_H #define DYNAMIC_GRAPH_COMMAND_H
#include <vector> #include <vector>
#include "dynamic-graph/value.h"
#include "dynamic-graph/dynamic-graph-api.h" #include "dynamic-graph/dynamic-graph-api.h"
#include "dynamic-graph/value.h"
namespace dynamicgraph { namespace dynamicgraph {
class Entity; class Entity;
namespace command { namespace command {
/// Abstract class for entity commands /// \ingroup dgraph
/// /// Abstract class for entity commands
/// This class provide a mean to control entities from external python script. ///
/// /// This class provide a mean to control entities from external
/// A command /// python script.
/// \li is owned by an entity, ///
/// \li takes parameters of type Value, /// A command
/// \li return an instance of Value when calling Command::execute() /// \li is owned by an entity,
/// /// \li takes parameters of type Value,
/// At construction, the prototype of the command is defined by providing /// \li return an instance of Value when calling Command::execute()
/// a vector of Value::Type. ///
/// /// At construction, the prototype of the command is defined by providing
/// Parameters are set by calling Command::setParameterValues with a /// a vector of Value::Type.
/// vector of Values the types of which should fit the vector specified ///
/// at construction. /// Parameters are set by calling Command::setParameterValues with a
class DYNAMIC_GRAPH_DLLAPI Command /// vector of Values the types of which should fit the vector specified
{ /// at construction.
public: class DYNAMIC_GRAPH_DLLAPI Command {
virtual ~Command(); public:
/// Store the owner entity and a vector of value types virtual ~Command();
/// \param entity reference to Entity owning this command. /// Store the owner entity and a vector of value types
/// \param valueTypes vector specifying the number and types of parameters /// \param entity reference to Entity owning this command.
/// \param docstring documentation of the 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
const std::string& docstring); Command(Entity &entity, const std::vector<Value::Type> &valueTypes,
/// Return the value type of all parameters const std::string &docstring);
const std::vector<Value::Type>& valueTypes() const; /// Return the value type of all parameters
/// Set parameter values const std::vector<Value::Type> &valueTypes() const;
void setParameterValues(const std::vector<Value>& values); /// Set parameter values
/// Get parameter values void setParameterValues(const std::vector<Value> &values);
const std::vector<Value>& getParameterValues() const; /// Get parameter values
/// Execute the command after checking parameters const std::vector<Value> &getParameterValues() const;
Value execute(); /// Execute the command after checking parameters
/// Get a reference to the Entity owning this command Value execute();
Entity& owner(); /// Get a reference to the Entity owning this command
/// Get documentation string Entity &owner();
std::string getDocstring() const; /// Get documentation string
protected: std::string getDocstring() const;
/// Specific action performed by the command
virtual Value doExecute() = 0; protected:
private: /// Specific action performed by the command
Entity& owner_; virtual Value doExecute() = 0;
std::vector<Value::Type> valueTypeVector_;
std::vector<Value> valueVector_; private:
std::string docstring_; Entity &owner_;
public: std::vector<Value::Type> valueTypeVector_;
static const std::vector<Value::Type> EMPTY_ARG; std::vector<Value> valueVector_;
}; std::string docstring_;
} // namespace command
} // namespace dynamicgraph public:
static const std::vector<Value::Type> EMPTY_ARG;
};
} // namespace command
} // namespace dynamicgraph
#endif //DYNAMIC_GRAPH_COMMAND_H #endif // DYNAMIC_GRAPH_COMMAND_H
This diff is collapsed.
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
// //
#ifndef DYNAMIC_GRAPH_API_H #ifndef DYNAMIC_GRAPH_API_H
# define DYNAMIC_GRAPH_API_H #define DYNAMIC_GRAPH_API_H
# include <dynamic-graph/config.hh> #include <dynamic-graph/config.hh>
#endif //! DYNAMIC_GRAPH_API_H #endif //! DYNAMIC_GRAPH_API_H
...@@ -7,157 +7,160 @@ ...@@ -7,157 +7,160 @@
#ifndef DYNAMIC_GRAPH_EIGEN_IO_H #ifndef DYNAMIC_GRAPH_EIGEN_IO_H
#define DYNAMIC_GRAPH_EIGEN_IO_H #define DYNAMIC_GRAPH_EIGEN_IO_H
#include <boost/format.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <dynamic-graph/exception-signal.h> #include <dynamic-graph/exception-signal.h>
#include <dynamic-graph/linear-algebra.h> #include <dynamic-graph/linear-algebra.h>
#include <Eigen/Geometry> #include <Eigen/Geometry>
#include <boost/format.hpp>
#include <boost/numeric/conversion/cast.hpp>
using dynamicgraph::ExceptionSignal; using dynamicgraph::ExceptionSignal;
//TODO: Eigen 3.3 onwards has a global Eigen::Index definition. // TODO: Eigen 3.3 onwards has a global Eigen::Index definition.
//If Eigen version is updated, use Eigen::Index instead of this macro. // If Eigen version is updated, use Eigen::Index instead of this macro.
/* \brief Eigen Vector input from istream
/* \brief Eigen Vector input from istream *
* * Input Vector format: [N](val1,val2,val3,...,valN)
* Input Vector format: [N](val1,val2,val3,...,valN) * e.g. [5](1,23,32.2,12.12,32)
* e.g. [5](1,23,32.2,12.12,32) */
*/
namespace Eigen { namespace Eigen {
typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE eigen_index; typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE eigen_index;
inline std::istringstream& operator >> (std::istringstream &iss, inline std::istringstream &operator>>(std::istringstream &iss,
dynamicgraph::Vector &inst) { dynamicgraph::Vector &inst) {
unsigned int _size; unsigned int _size;
double _dbl_val; double _dbl_val;
char _ch; char _ch;
boost::format fmt ("Failed to enter %s as vector. Reenter as [N](val1,val2,val3,...,valN)"); boost::format fmt(
fmt %iss.str(); "Failed to enter %s as vector."
if(iss>> _ch && _ch != '['){ " Reenter as [N](val1,val2,val3,...,valN)");
fmt % iss.str();
if (iss >> _ch && _ch != '[') {
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
} else {
if (iss >> _size && !iss.fail()) {
inst.resize(_size);
} else
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
if (iss >> _ch && _ch != ']')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str()); throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
}
else { else {
if(iss >> _size && !iss.fail()){ if (iss >> _ch && _ch != '(')
inst.resize(_size); throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
}
else
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
if(iss >> _ch && _ch != ']')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
else { else {
if(iss>> _ch && _ch != '(') for (unsigned int i = 0; i < _size; i++) {
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str()); iss >> _dbl_val;
else { if (iss.peek() == ',' || iss.peek() == ' ') iss.ignore();
for (unsigned int i=0;i<_size; i++){ inst(i) = _dbl_val;
iss >> _dbl_val; }
if (iss.peek() == ',' || iss.peek() == ' ') if (iss >> _ch && _ch != ')')
iss.ignore(); throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
inst(i) = _dbl_val;
}
if(iss >> _ch && _ch != ')')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
}
} }
} }
return iss;
} }
return iss;
}
/* \brief Eigen Matrix input from istream /* \brief Eigen Matrix input from istream
* *
* Matrix format: [M,N]((val11,val12,val13,...,val1N),...,(valM1,valM2,...,valMN)) * Matrix format: [M,N]((val11,val12,val13,...,val1N),...,
* e.g. [2,5]((1 23 32.2 12.12 32),(2 32 23 92.01 19.2)) * (valM1,valM2,...,valMN))
*/ * e.g. [2,5]((1 23 32.2 12.12 32),(2 32 23 92.01 19.2))
*/
template<typename Derived>
inline std::istringstream& operator >> (std::istringstream &iss, template <typename Derived>
DenseBase<Derived> &inst) { inline std::istringstream &operator>>(std::istringstream &iss,
unsigned int _colsize; DenseBase<Derived> &inst) {
unsigned int _rowsize; unsigned int _colsize;
double _dbl_val; unsigned int _rowsize;
char _ch; double _dbl_val;
boost::format fmt ("Failed to enter %s as matrix. Reenter as ((val11,val12,val13,...,val1N),...,(valM1,valM2,...,valMN))"); char _ch;
MatrixXd _tmp_matrix; boost::format fmt(
fmt %iss.str(); "Failed to enter %s as matrix. Reenter as "
if(iss>> _ch && _ch != '['){ "((val11,val12,val13,...,val1N),"
"...,(valM1,valM2,...,valMN))");
MatrixXd _tmp_matrix;
fmt % iss.str();
if (iss >> _ch && _ch != '[') {
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
} else {
iss >> _rowsize;
if (iss.peek() == ',' || iss.peek() == ' ') iss.ignore();
iss >> _colsize;
if (iss.fail())
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str()); throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
}
else { else {
iss >>_rowsize; _tmp_matrix.resize(_rowsize, _colsize);
if (iss.peek() == ',' || iss.peek() == ' ') if (iss >> _ch && _ch != ']')
iss.ignore(); throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
iss >> _colsize;
if (iss.fail())
throw ExceptionSignal(ExceptionSignal::GENERIC,fmt.str());
else { else {
_tmp_matrix.resize(_rowsize,_colsize); if (iss >> _ch && _ch != '(')
if(iss >> _ch && _ch != ']') throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str()); else {
else { for (unsigned int j = 0; j < _rowsize; j++) {
if(iss>> _ch && _ch != '(') if (iss >> _ch && _ch != '(')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str()); throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
else { for (unsigned int i = 0; i < _colsize; i++) {
for (unsigned int j=0;j<_rowsize; j++){ iss >> _dbl_val;
if(iss>> _ch && _ch != '(') if (iss.peek() == ',' || iss.peek() == ' ') iss.ignore();
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str()); _tmp_matrix(j, i) = _dbl_val;
for (unsigned int i=0;i<_colsize; i++){ }
iss >> _dbl_val; if (iss >> _ch && _ch != ')')
if (iss.peek() == ',' || iss.peek() == ' ') throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
iss.ignore(); if (iss.peek() == ',' || iss.peek() == ' ') iss.ignore();
_tmp_matrix(j,i) = _dbl_val; }
} if (iss >> _ch && _ch != ')')
if(iss >> _ch && _ch != ')') throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str()); }
if (iss.peek() == ',' || iss.peek() == ' ')
iss.ignore();
}
if(iss >> _ch && _ch != ')')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
}
}
} }
} }
inst = _tmp_matrix;
return iss;
} }
inst = _tmp_matrix;
return iss;
}
inline std::istringstream &operator>>(std::istringstream &iss,
Transform<double, 3, Affine> &inst) {
MatrixXd M;
iss >> M;
inst.matrix() = M;
return iss;
}
inline std::istringstream& operator >> (std::istringstream &iss, /* \brief Eigen Homogeneous Matrix output
Transform<double,3,Affine> &inst) { *
MatrixXd M; iss >> M; inst.matrix() = M; return iss; } * Matrix format: [M,N]((val11,val12,val13,...,val1N),...,
* (valM1,valM2,...,valMN))
* e.g. [2,5]((1 23 32.2 12.12 32),(2 32 23 92.01 19.2))
*/
/* \brief Eigen Homogeneous Matrix output
*
* Matrix format: [M,N]((val11,val12,val13,...,val1N),...,(valM1,valM2,...,valMN))
* e.g. [2,5]((1 23 32.2 12.12 32),(2 32 23 92.01 19.2))
*/
inline std::ostream& operator << (std::ostream &os,
Transform<double,3,Affine> MH) {
IOFormat boostFmt(StreamPrecision, DontAlignCols,
",", ",",
"(",")",
"(",")");
os << "[4,4]"<< MH.matrix().format(boostFmt); return os; }
inline std::ostream &operator<<(std::ostream &os,
Transform<double, 3, Affine> MH) {
IOFormat boostFmt(StreamPrecision, DontAlignCols, ",", ",", "(", ")", "(",
")");
inline std::ostream& operator << (std::ostream &os, os << "[4,4]" << MH.matrix().format(boostFmt);
AngleAxisd quat) { return os;
VectorXd v(4); v(0) = quat.angle(); v.tail<3>() = quat.axis(); }
os << v; return os; }
inline std::istringstream& operator >> (std::istringstream &iss, inline std::ostream &operator<<(std::ostream &os, AngleAxisd quat) {
AngleAxisd &inst) { VectorXd v(4);
VectorXd v(4); iss >>v; v(0) = quat.angle();
inst.angle() = v(0); inst.axis() = v.tail<3>(); v.tail<3>() = quat.axis();
return iss; } os << v;
return os;
}
inline std::istringstream &operator>>(std::istringstream &iss,
AngleAxisd &inst) {
VectorXd v(4);
iss >> v;
inst.angle() = v(0);
inst.axis() = v.tail<3>();
return iss;
} }
} // namespace Eigen
#endif //DYNAMIC_GRAPH_EIGEN_IO_H #endif // DYNAMIC_GRAPH_EIGEN_IO_H
...@@ -6,17 +6,14 @@ ...@@ -6,17 +6,14 @@
#ifndef __sot_core_entity_helper_H__ #ifndef __sot_core_entity_helper_H__
#define __sot_core_entity_helper_H__ #define __sot_core_entity_helper_H__
namespace dynamicgraph {
namespace dynamicgraph template <typename Ent>
{ struct EntityHelper {
typedef Ent EntityClassName;
// static const std::string CLASS_NAME; TO BE ADDED IN DG DIRECTLY
};
template< typename Ent > } // namespace dynamicgraph
struct EntityHelper
{
typedef Ent EntityClassName;
//static const std::string CLASS_NAME; TO BE ADDED IN DG DIRECTLY
};
} // namespace dynamicgraph #endif // __sot_core_entity_helper_H__
#endif // __sot_core_entity_helper_H__
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.