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