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
...@@ -10,482 +10,927 @@ ...@@ -10,482 +10,927 @@
/* Create a command from a bind directly. Examples are: /* Create a command from a bind directly. Examples are:
* addCommand("myProcVoid", * addCommand("myProcVoid",
* makeCommandVoid0(*this,&ClassName::functionNoArg, * makeCommandVoid0(*this,&ClassName::functionNoArg,
* docCommandVoid0("Simple line doc here."))); * docCommandVoid0("Simple line doc here.")));
* addCommand("myProcOneString", * addCommand("myProcOneString",
* makeCommandVoid1(*this,&EntityName::functionOneStringArg, * makeCommandVoid1(*this,&EntityName::functionOneStringArg,
* docCommandVoid1("Simple line doc here.", * docCommandVoid1("Simple line doc here.",
* "string"))); * "string")));
* *
*/ */
#include "dynamic-graph/command.h"
#include <boost/assign/list_of.hpp> #include <boost/assign/list_of.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/function.hpp>
#include "dynamic-graph/command.h"
/* --- FUNCTION 0 ARGS ------------------------------------------------------ */ /* --- FUNCTION 0 ARGS ----------------------------------------------------- */
namespace dynamicgraph { namespace dynamicgraph {
namespace command { namespace command {
template <class E > template <class E>
struct CommandVoid0 struct CommandVoid0 : public Command {
: public Command CommandVoid0(E &entity, boost::function<void(void)> function,
{ const std::string &docString)
CommandVoid0(E& entity, boost::function<void(void)> function, : Command(entity, EMPTY_ARG, docString), fptr(function) {}
const std::string& docString)
:Command(entity, EMPTY_ARG, docString) protected:
,fptr(function) virtual Value doExecute() {
{} assert(getParameterValues().size() == 0);
fptr();
protected: return Value(); // void
virtual Value doExecute() }
{
assert( getParameterValues().size() == 0 ); private:
fptr(); boost::function<void(void)> fptr;
return Value(); // void };
}
private: template <class E>
boost::function<void(void)> fptr; CommandVoid0<E> *makeCommandVoid0(E &entity,
}; boost::function<void(void)> function,
const std::string &docString) {
return new CommandVoid0<E>(entity, function, docString);
template <class E > }
CommandVoid0<E>* makeCommandVoid0(E& entity, boost::function<void(void)> function ,
const std::string& docString) template <class E>
{ CommandVoid0<E> *makeCommandVoid0(E &entity,
return new CommandVoid0<E>( entity,function,docString ); boost::function<void(E *)> function,
} const std::string &docString) {
return new CommandVoid0<E>(entity, boost::bind(function, &entity), docString);
template <class E > }
CommandVoid0<E>* makeCommandVoid0(E& entity, boost::function<void(E*)> function ,
const std::string& docString) template <class E>
{ CommandVoid0<E> *makeCommandVoid0(E &entity, void (E::*function)(void),
return new CommandVoid0<E>( entity, const std::string &docString) {
boost::bind(function,&entity),docString ); return new CommandVoid0<E>(entity, boost::bind(function, &entity), docString);
} }
template <class E > inline std::string docCommandVoid0(const std::string &doc) {
CommandVoid0<E>* makeCommandVoid0(E& entity, void (E::*function) (void), return std::string("\n") + doc + "\n\nNo input.\nVoid return.\n\n";
const std::string& docString) }
{
return new CommandVoid0<E>( entity, } // namespace command
boost::bind(function,&entity),docString ); } // namespace dynamicgraph
}
inline std::string docCommandVoid0( const std::string& doc )
{
return std::string("\n")+doc +"\n\nNo input.\nVoid return.\n\n";
}
} // namespace command
} // namespace dynamicgraph
/* --- FUNCTION 1 ARGS ------------------------------------------------------ */ /* --- FUNCTION 1 ARGS ------------------------------------------------------ */
namespace dynamicgraph { namespace dynamicgraph {
namespace command { namespace command {
template <class E,typename T > template <class E, typename T>
struct CommandVoid1 struct CommandVoid1 : public Command {
: public Command typedef boost::function<void(const T &)> function_t;
{
typedef boost::function<void(const T&)> function_t; CommandVoid1(E &entity, function_t function, const std::string &docString)
typedef boost::function<void(E*,const T&)> memberFunction_t; : Command(entity, boost::assign::list_of(ValueHelper<T>::TypeID),
typedef void (E::*memberFunction_ptr_t) (const T&); docString),
fptr(function) {}
CommandVoid1(E& entity, function_t function,
const std::string& docString) protected:
:Command(entity, boost::assign::list_of(ValueHelper<T>::TypeID), docString) virtual Value doExecute() {
,fptr(function) assert(getParameterValues().size() == 1);
{} T val = getParameterValues()[0].value();
fptr(val);
protected: return Value(); // void
virtual Value doExecute() }
{
assert( getParameterValues().size() == 1 ); private:
T val = getParameterValues()[0].value(); function_t fptr;
fptr(val); };
return Value(); // void
} template <class E, typename T>
private: CommandVoid1<E, T> *makeCommandVoid1(
function_t fptr; E &entity, boost::function<void(const T &)> function,
}; // typename CommandVoid1<E,T>::function_t function ,
const std::string &docString) {
return new CommandVoid1<E, T>(entity, function, docString);
template <class E,typename T > }
CommandVoid1<E,T>*
makeCommandVoid1(E& entity, template <class E, typename T>
boost::function<void(const T&)> function, CommandVoid1<E, T> *makeCommandVoid1(
//typename CommandVoid1<E,T>::function_t function , E &entity,
const std::string& docString) // The following syntaxt don't compile when not specializing
{ // the template arg... why ???
return new CommandVoid1<E,T>( entity,function,docString ); boost::function<void(E *, const T &)> function,
} const std::string &docString) {
return new CommandVoid1<E, T>(entity, boost::bind(function, &entity, _1),
template <class E,typename T > docString);
CommandVoid1<E,T>* }
makeCommandVoid1(E& entity,
// The following syntaxt don't compile when not specializing the template template <class E, typename T>
// arg... why ??? CommandVoid1<E, T> *makeCommandVoid1(E &entity, void (E::*function)(const T &),
//typename CommandVoid1<E,T>::memberFunction_t function , const std::string &docString) {
boost::function<void(E*,const T&)> function, return new CommandVoid1<E, T>(entity, boost::bind(function, &entity, _1),
const std::string& docString) docString);
{ return NULL;
return new CommandVoid1<E,T>( entity, }
boost::bind(function,&entity,_1),docString );
} inline std::string docCommandVoid1(const std::string &doc,
const std::string &type) {
template <class E,typename T > return std::string("\n") + doc + "\n\nInput:\n - A " + type +
CommandVoid1<E,T>* ".\nVoid return.\n\n";
makeCommandVoid1(E& entity, }
void (E::*function) (const T&),
const std::string& docString) } // namespace command
{ } // namespace dynamicgraph
return new CommandVoid1<E,T>( entity,
boost::bind(function,&entity,_1),docString );
return NULL;
}
inline std::string docCommandVoid1( const std::string& doc, const std::string& type )
{
return std::string("\n")+doc +"\n\nInput:\n - A "+type+".\nVoid return.\n\n";
}
} // namespace command
} // namespace dynamicgraph
/* --- FUNCTION 2 ARGS ------------------------------------------------------ */ /* --- FUNCTION 2 ARGS ------------------------------------------------------ */
namespace dynamicgraph { namespace dynamicgraph {
namespace command { namespace command {
template <class E,typename T1,typename T2 > template <class E, typename T1, typename T2>
struct CommandVoid2 struct CommandVoid2 : public Command {
: public Command typedef boost::function<void(const T1 &, const T2 &)> function_t;
{
typedef boost::function<void(const T1&,const T2&)> function_t; CommandVoid2(E &entity, function_t function, const std::string &docString)
typedef boost::function<void(E*,const T1&,const T2&)> memberFunction_t; : Command(entity,
typedef void (E::*memberFunction_ptr_t) (const T1&,const T2&); boost::assign::list_of(ValueHelper<T1>::TypeID)(
ValueHelper<T2>::TypeID),
CommandVoid2(E& entity, function_t function, docString),
const std::string& docString) fptr(function) {}
:Command(entity,
boost::assign::list_of protected:
(ValueHelper<T1>::TypeID) virtual Value doExecute() {
(ValueHelper<T2>::TypeID), docString) assert(getParameterValues().size() == 2);
,fptr(function) T1 val1 = getParameterValues()[0].value();
{} T2 val2 = getParameterValues()[1].value();
fptr(val1, val2);
protected: return Value(); // void
virtual Value doExecute() }
{
assert( getParameterValues().size() == 2 ); private:
T1 val1 = getParameterValues()[0].value(); function_t fptr;
T2 val2 = getParameterValues()[1].value(); };
fptr(val1,val2);
return Value(); // void template <class E, typename T1, typename T2>
} CommandVoid2<E, T1, T2> *makeCommandVoid2(
private: E &entity, boost::function<void(const T1 &, const T2 &)> function,
function_t fptr; const std::string &docString) {
}; return new CommandVoid2<E, T1, T2>(entity, function, docString);
}
template <class E,typename T1,typename T2 > template <class E, typename T1, typename T2>
CommandVoid2<E,T1,T2>* CommandVoid2<E, T1, T2> *makeCommandVoid2(
makeCommandVoid2(E& entity, E &entity,
boost::function<void(const T1&,const T2&)> function, // The following syntaxt don't compile when not specializing
const std::string& docString) // the template arg... why ???
{ boost::function<void(E *, const T1 &, const T2 &)> function,
return new CommandVoid2<E,T1,T2>( entity,function,docString ); const std::string &docString) {
} return new CommandVoid2<E, T1, T2>(
entity, boost::bind(function, &entity, _1, _2), docString);
template <class E,typename T1,typename T2 > }
CommandVoid2<E,T1,T2>*
makeCommandVoid2(E& entity, template <class E, typename T1, typename T2>
// The following syntaxt don't compile when not specializing the template CommandVoid2<E, T1, T2> *makeCommandVoid2(E &entity,
// arg... why ??? void (E::*function)(const T1 &,
//typename CommandVoid2<E,T1,T2>::memberFunction_t function , const T2 &),
boost::function<void(E*,const T1&,const T2&)> function, const std::string &docString) {
const std::string& docString) return new CommandVoid2<E, T1, T2>(
{ entity, boost::bind(function, &entity, _1, _2), docString);
return new CommandVoid2<E,T1,T2>( entity, return NULL;
boost::bind(function,&entity,_1,_2),docString ); }
}
inline std::string docCommandVoid2(const std::string &doc,
template <class E,typename T1,typename T2 > const std::string &type1,
CommandVoid2<E,T1,T2>* const std::string &type2) {
makeCommandVoid2(E& entity, return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
void (E::*function) (const T1&,const T2&), "Input:\n - A " + type2 + ".\n" + "Void return.\n\n");
const std::string& docString) }
{
return new CommandVoid2<E,T1,T2>( entity, } // namespace command
boost::bind(function,&entity,_1,_2), } // namespace dynamicgraph
docString );
return NULL;
}
inline std::string docCommandVoid2( const std::string& doc,
const std::string& type1,
const std::string& type2 )
{
return (std::string("\n")+doc+"\n\n"
+"Input:\n - A "+type1+".\n"
+"Input:\n - A "+type2+".\n"
+"Void return.\n\n" );
}
} // namespace command
} // namespace dynamicgraph
/* --- FUNCTION 3 ARGS ------------------------------------------------------ */ /* --- FUNCTION 3 ARGS ------------------------------------------------------ */
namespace dynamicgraph { namespace dynamicgraph {
namespace command { namespace command {
template <class E,typename T1,typename T2,typename T3 > template <class E, typename T1, typename T2, typename T3>
struct CommandVoid3 struct CommandVoid3 : public Command {
: public Command typedef boost::function<void(const T1 &, const T2 &, const T3 &)> function_t;
{
typedef boost::function<void(const T1&,const T2&,const T3&)> function_t; CommandVoid3(E &entity, function_t function, const std::string &docString)
typedef boost::function<void(E*,const T1&,const T2&,const T3&)> memberFunction_t; : Command(entity,
typedef void (E::*memberFunction_ptr_t) (const T1&,const T2&,const T3); boost::assign::list_of(ValueHelper<T1>::TypeID)(
ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID),
CommandVoid3(E& entity, function_t function, docString),
const std::string& docString) fptr(function) {}
:Command(entity,
boost::assign::list_of protected:
(ValueHelper<T1>::TypeID) virtual Value doExecute() {
(ValueHelper<T2>::TypeID) assert(getParameterValues().size() == 3);
(ValueHelper<T3>::TypeID), docString) T1 val1 = getParameterValues()[0].value();
,fptr(function) T2 val2 = getParameterValues()[1].value();
{} T3 val3 = getParameterValues()[2].value();
fptr(val1, val2, val3);
protected: return Value(); // void
virtual Value doExecute() }
{
assert( getParameterValues().size() == 3 ); private:
T1 val1 = getParameterValues()[0].value(); function_t fptr;
T2 val2 = getParameterValues()[1].value(); };
T3 val3 = getParameterValues()[2].value();
fptr(val1,val2,val3); template <class E, typename T1, typename T2, typename T3>
return Value(); // void CommandVoid3<E, T1, T2, T3> *makeCommandVoid3(
} E &entity, typename CommandVoid3<E, T1, T2, T3>::function_t function,
private: const std::string &docString) {
function_t fptr; return new CommandVoid3<E, T1, T2, T3>(entity, function, docString);
}; }
template <class E, typename T1, typename T2, typename T3>
template <class E,typename T1,typename T2,typename T3 > CommandVoid3<E, T1, T2, T3> *makeCommandVoid3(
CommandVoid3<E,T1,T2,T3>* E &entity,
makeCommandVoid3(E& entity, // The following syntaxt don't compile when not specializing the template
typename CommandVoid3<E,T1,T2,T3>::function_t function , // arg... why ???
const std::string& docString) boost::function<void(E *, const T1 &, const T2 &, const T3 &)> function,
{ const std::string &docString) {
return new CommandVoid3<E,T1,T2,T3>( entity,function,docString ); return new CommandVoid3<E, T1, T2, T3>(
} entity, boost::bind(function, &entity, _1, _2, _3), docString);
}
template <class E,typename T1,typename T2,typename T3 >
CommandVoid3<E,T1,T2,T3>* template <class E, typename T1, typename T2, typename T3>
makeCommandVoid3(E& entity, CommandVoid3<E, T1, T2, T3> *makeCommandVoid3(
// The following syntaxt don't compile when not specializing the template E &entity, void (E::*function)(const T1 &, const T2 &, const T3 &),
// arg... why ??? const std::string &docString) {
//typename CommandVoid3<E,T1,T2>::memberFunction_t function , return new CommandVoid3<E, T1, T2, T3>(
boost::function<void(E*,const T1&,const T2&,const T3&)> function, entity, boost::bind(function, &entity, _1, _2, _3), docString);
const std::string& docString) return NULL;
{ }
return new CommandVoid3<E,T1,T2,T3>( entity,
boost::bind(function,&entity,_1,_2,_3),docString ); inline std::string docCommandVoid3(const std::string &doc,
} const std::string &type1,
const std::string &type2,
template <class E,typename T1,typename T2,typename T3 > const std::string &type3) {
CommandVoid3<E,T1,T2,T3>* return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
makeCommandVoid3(E& entity, "Input:\n - A " + type2 + ".\n" + "Input:\n - A " + type3 + ".\n" +
void (E::*function) (const T1&,const T2&,const T3&), "Void return.\n\n");
const std::string& docString) }
{
return new CommandVoid3<E,T1,T2,T3>( entity, } // namespace command
boost::bind(function,&entity,_1,_2,_3), } // namespace dynamicgraph
docString );
return NULL;
}
inline std::string docCommandVoid3( const std::string& doc,
const std::string& type1,
const std::string& type2,
const std::string& type3 )
{
return (std::string("\n")+doc+"\n\n"
+"Input:\n - A "+type1+".\n"
+"Input:\n - A "+type2+".\n"
+"Input:\n - A "+type3+".\n"
+"Void return.\n\n" );
}
} // namespace command
} // namespace dynamicgraph
/* --- FUNCTION 4 ARGS ------------------------------------------------------ */ /* --- FUNCTION 4 ARGS ------------------------------------------------------ */
namespace dynamicgraph { namespace dynamicgraph {
namespace command { namespace command {
template <class E,typename T1,typename T2,typename T3,typename T4 > template <class E, typename T1, typename T2, typename T3, typename T4>
struct CommandVoid4 struct CommandVoid4 : public Command {
: public Command typedef boost::function<void(const T1 &, const T2 &, const T3 &, const T4 &)>
{ function_t;
typedef boost::function<void(const T1&,const T2&,const T3&,const T4&)> function_t; typedef void (E::*memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &,
typedef boost::function<void(E*,const T1&,const T2&,const T3&,const T4&)> memberFunction_t; const T4 &);
typedef void (E::*memberFunction_ptr_t) (const T1&,const T2&,const T3&,const T4&);
CommandVoid4(E &entity, function_t function, const std::string &docString)
CommandVoid4(E& entity, function_t function, : Command(entity,
const std::string& docString) boost::assign::list_of(ValueHelper<T1>::TypeID)(
:Command(entity, ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
boost::assign::list_of ValueHelper<T4>::TypeID),
(ValueHelper<T1>::TypeID) docString),
(ValueHelper<T2>::TypeID) fptr(function) {}
(ValueHelper<T3>::TypeID)
(ValueHelper<T4>::TypeID) protected:
, docString) virtual Value doExecute() {
,fptr(function) assert(getParameterValues().size() == 4);
{} T1 val1 = getParameterValues()[0].value();
T2 val2 = getParameterValues()[1].value();
protected: T3 val3 = getParameterValues()[2].value();
virtual Value doExecute() T4 val4 = getParameterValues()[3].value();
{ fptr(val1, val2, val3, val4);
assert( getParameterValues().size() == 4 ); return Value(); // void
T1 val1 = getParameterValues()[0].value(); }
T2 val2 = getParameterValues()[1].value();
T3 val3 = getParameterValues()[2].value(); private:
T4 val4 = getParameterValues()[3].value(); function_t fptr;
fptr(val1,val2,val3,val4); };
return Value(); // void
} template <class E, typename T1, typename T2, typename T3, typename T4>
private: CommandVoid4<E, T1, T2, T3, T4> *makeCommandVoid4(
function_t fptr; E &entity, typename CommandVoid4<E, T1, T2, T3, T4>::function_t function,
}; const std::string &docString) {
return new CommandVoid4<E, T1, T2, T3, T4>(entity, function, docString);
}
template <class E,typename T1,typename T2,typename T3,typename T4 >
CommandVoid4<E,T1,T2,T3,T4>* template <class E, typename T1, typename T2, typename T3, typename T4>
makeCommandVoid4(E& entity, CommandVoid4<E, T1, T2, T3, T4> *makeCommandVoid4(
typename CommandVoid4<E,T1,T2,T3,T4>::function_t function , E &entity,
const std::string& docString) boost::function<void(E *, const T1 &, const T2 &, const T3 &, const T4 &)>
{ function,
return new CommandVoid4<E,T1,T2,T3,T4>( entity,function,docString ); const std::string &docString) {
} return new CommandVoid4<E, T1, T2, T3, T4>(
entity, boost::bind(function, &entity, _1, _2, _3, _4), docString);
template <class E,typename T1,typename T2,typename T3,typename T4 > }
CommandVoid4<E,T1,T2,T3,T4>*
makeCommandVoid4(E& entity, template <class E, typename T1, typename T2, typename T3, typename T4>
boost::function<void(E*,const T1&,const T2&,const T3&,const T4&)> function, CommandVoid4<E, T1, T2, T3, T4> *makeCommandVoid4(
const std::string& docString) E &entity,
{ void (E::*function)(const T1 &, const T2 &, const T3 &, const T4 &),
return new CommandVoid4<E,T1,T2,T3,T4>( entity, const std::string &docString) {
boost::bind(function,&entity,_1,_2,_3,_4),docString ); return new CommandVoid4<E, T1, T2, T3, T4>(
} entity, boost::bind(function, &entity, _1, _2, _3, _4), docString);
return NULL;
template <class E,typename T1,typename T2,typename T3,typename T4 > }
CommandVoid4<E,T1,T2,T3,T4>*
makeCommandVoid4(E& entity, inline std::string docCommandVoid4(const std::string &doc,
void (E::*function) (const T1&,const T2&,const T3&,const T4&), const std::string &type1,
const std::string& docString) const std::string &type2,
{ const std::string &type3,
return new CommandVoid4<E,T1,T2,T3,T4>( entity, const std::string &type4) {
boost::bind(function,&entity,_1,_2,_3,_4), return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
docString ); "Input:\n - A " + type2 + ".\n" + "Input:\n - A " + type3 + ".\n" +
return NULL; "Input:\n - A " + type4 + ".\n" + "Void return.\n\n");
} }
inline std::string docCommandVoid4( const std::string& doc, } // namespace command
const std::string& type1, } // namespace dynamicgraph
const std::string& type2,
const std::string& type3, /* --- FUNCTION 5 ARGS ------------------------------------------------------ */
const std::string& type4 ) namespace dynamicgraph {
{ namespace command {
return (std::string("\n")+doc+"\n\n"
+"Input:\n - A "+type1+".\n" template <class E, typename T1, typename T2, typename T3, typename T4,
+"Input:\n - A "+type2+".\n" typename T5>
+"Input:\n - A "+type3+".\n" struct CommandVoid5 : public Command {
+"Input:\n - A "+type4+".\n" typedef boost::function<void(const T1 &, const T2 &, const T3 &, const T4 &,
+"Void return.\n\n" ); const T5 &)>
} function_t;
typedef void (E::*memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &,
} // namespace command const T4 &, const T5 &);
} // namespace dynamicgraph
CommandVoid5(E &entity, function_t function, const std::string &docString)
: Command(entity,
boost::assign::list_of(ValueHelper<T1>::TypeID)(
ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID),
docString),
fptr(function) {}
protected:
virtual Value doExecute() {
assert(getParameterValues().size() == 5);
T1 val1 = getParameterValues()[0].value();
T2 val2 = getParameterValues()[1].value();
T3 val3 = getParameterValues()[2].value();
T4 val4 = getParameterValues()[3].value();
T5 val5 = getParameterValues()[4].value();
fptr(val1, val2, val3, val4, val5);
return Value(); // void
}
private:
function_t fptr;
};
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5>
CommandVoid5<E, T1, T2, T3, T4, T5> *makeCommandVoid5(
E &entity,
typename CommandVoid5<E, T1, T2, T3, T4, T5>::function_t function,
const std::string &docString) {
return new CommandVoid5<E, T1, T2, T3, T4, T5>(entity, function, docString);
}
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5>
CommandVoid5<E, T1, T2, T3, T4, T5> *makeCommandVoid5(
E &entity,
boost::function<void(E *, const T1 &, const T2 &, const T3 &, const T4 &,
const T5 &)>
function,
const std::string &docString) {
return new CommandVoid5<E, T1, T2, T3, T4, T5>(
entity, boost::bind(function, &entity, _1, _2, _3, _4, _5), docString);
}
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5>
CommandVoid5<E, T1, T2, T3, T4, T5> *makeCommandVoid5(
E &entity,
void (E::*function)(const T1 &, const T2 &, const T3 &, const T4 &,
const T5 &),
const std::string &docString) {
return new CommandVoid5<E, T1, T2, T3, T4, T5>(
entity, boost::bind(function, &entity, _1, _2, _3, _4, _5), docString);
return NULL;
}
inline std::string docCommandVoid5(const std::string &doc,
const std::string &type1,
const std::string &type2,
const std::string &type3,
const std::string &type4,
const std::string &type5) {
return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
"Input:\n - A " + type2 + ".\n" + "Input:\n - A " + type3 + ".\n" +
"Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
"Void return.\n\n");
}
} // namespace command
} // namespace dynamicgraph
/* --- FUNCTION 6 ARGS ------------------------------------------------------ */
namespace dynamicgraph {
namespace command {
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6>
struct CommandVoid6 : public Command {
typedef boost::function<void(const T1 &, const T2 &, const T3 &, const T4 &,
const T5 &, const T6 &)>
function_t;
typedef void (E::*memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &,
const T4 &, const T5 &, const T6 &);
CommandVoid6(E &entity, function_t function, const std::string &docString)
: Command(entity,
boost::assign::list_of(ValueHelper<T1>::TypeID)(
ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID)(
ValueHelper<T6>::TypeID),
docString),
fptr(function) {}
protected:
virtual Value doExecute() {
assert(getParameterValues().size() == 6);
T1 val1 = getParameterValues()[0].value();
T2 val2 = getParameterValues()[1].value();
T3 val3 = getParameterValues()[2].value();
T4 val4 = getParameterValues()[3].value();
T5 val5 = getParameterValues()[4].value();
T6 val6 = getParameterValues()[5].value();
fptr(val1, val2, val3, val4, val5, val6);
return Value(); // void
}
private:
function_t fptr;
};
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6>
CommandVoid6<E, T1, T2, T3, T4, T5, T6> *makeCommandVoid6(
E &entity,
typename CommandVoid6<E, T1, T2, T3, T4, T5, T6>::function_t function,
const std::string &docString) {
return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(entity, function,
docString);
}
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6>
CommandVoid6<E, T1, T2, T3, T4, T5, T6> *makeCommandVoid6(
E &entity,
boost::function<void(E *, const T1 &, const T2 &, const T3 &, const T4 &,
const T5 &, const T6 &)>
function,
const std::string &docString) {
return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(
entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6),
docString);
}
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6>
CommandVoid6<E, T1, T2, T3, T4, T5, T6> *makeCommandVoid6(
E &entity,
void (E::*function)(const T1 &, const T2 &, const T3 &, const T4 &,
const T5 &, const T6 &),
const std::string &docString) {
return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(
entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6),
docString);
return NULL;
}
inline std::string docCommandVoid6(
const std::string &doc, const std::string &type1, const std::string &type2,
const std::string &type3, const std::string &type4,
const std::string &type5, const std::string &type6) {
return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
"Input:\n - A " + type2 + ".\n" + "Input:\n - A " + type3 + ".\n" +
"Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
"Input:\n - A " + type6 + ".\n" + "Void return.\n\n");
}
} // namespace command
} // namespace dynamicgraph
/* --- FUNCTION 7 ARGS ------------------------------------------------------ */
namespace dynamicgraph {
namespace command {
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7>
struct CommandVoid7 : public Command {
typedef boost::function<void(const T1 &, const T2 &, const T3 &, const T4 &,
const T5 &, const T6 &, const T7 &)>
function_t;
typedef void (E::*memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &,
const T4 &, const T5 &, const T6 &,
const T7 &);
CommandVoid7(E &entity, function_t function, const std::string &docString)
: Command(entity,
boost::assign::list_of(ValueHelper<T1>::TypeID)(
ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID)(
ValueHelper<T6>::TypeID)(ValueHelper<T7>::TypeID),
docString),
fptr(function) {}
protected:
virtual Value doExecute() {
assert(getParameterValues().size() == 7);
T1 val1 = getParameterValues()[0].value();
T2 val2 = getParameterValues()[1].value();
T3 val3 = getParameterValues()[2].value();
T4 val4 = getParameterValues()[3].value();
T5 val5 = getParameterValues()[4].value();
T6 val6 = getParameterValues()[5].value();
T7 val7 = getParameterValues()[6].value();
fptr(val1, val2, val3, val4, val5, val6, val7);
return Value(); // void
}
private:
function_t fptr;
};
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7>
CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7> *makeCommandVoid7(
E &entity,
typename CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>::function_t function,
const std::string &docString) {
return new CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>(entity, function,
docString);
}
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7>
CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7> *makeCommandVoid7(
E &entity,
boost::function<void(E *, const T1 &, const T2 &, const T3 &, const T4 &,
const T5 &, const T6 &, const T7 &)>
function,
const std::string &docString) {
return new CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>(
entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7),
docString);
}
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7>
CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7> *makeCommandVoid7(
E &entity,
void (E::*function)(const T1 &, const T2 &, const T3 &, const T4 &,
const T5 &, const T6 &, const T7 &),
const std::string &docString) {
return new CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>(
entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7),
docString);
return NULL;
}
inline std::string docCommandVoid7(
const std::string &doc, const std::string &type1, const std::string &type2,
const std::string &type3, const std::string &type4,
const std::string &type5, const std::string &type6,
const std::string &type7) {
return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
"Input:\n - A " + type2 + ".\n" + "Input:\n - A " + type3 + ".\n" +
"Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
"Input:\n - A " + type6 + ".\n" + "Input:\n - A " + type7 + ".\n" +
"Void return.\n\n");
}
} // namespace command
} // namespace dynamicgraph
/* --- FUNCTION 8 ARGS ------------------------------------------------------ */
namespace dynamicgraph {
namespace command {
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8>
struct CommandVoid8 : public Command {
typedef boost::function<void(const T1 &, const T2 &, const T3 &, const T4 &,
const T5 &, const T6 &, const T7 &, const T8 &)>
function_t;
typedef void (E::*memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &,
const T4 &, const T5 &, const T6 &,
const T7 &, const T8 &);
CommandVoid8(E &entity, function_t function, const std::string &docString)
: Command(entity,
boost::assign::list_of(ValueHelper<T1>::TypeID)(
ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID)(
ValueHelper<T6>::TypeID)(ValueHelper<T7>::TypeID)(
ValueHelper<T8>::TypeID),
docString),
fptr(function) {}
protected:
virtual Value doExecute() {
assert(getParameterValues().size() == 8);
T1 val1 = getParameterValues()[0].value();
T2 val2 = getParameterValues()[1].value();
T3 val3 = getParameterValues()[2].value();
T4 val4 = getParameterValues()[3].value();
T5 val5 = getParameterValues()[4].value();
T6 val6 = getParameterValues()[5].value();
T7 val7 = getParameterValues()[6].value();
T8 val8 = getParameterValues()[7].value();
fptr(val1, val2, val3, val4, val5, val6, val7, val8);
return Value(); // void
}
private:
function_t fptr;
};
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8>
CommandVoid8<E, T1, T2, T3, T4, T5, T6, T7, T8> *makeCommandVoid8(
E &entity,
typename CommandVoid8<E, T1, T2, T3, T4, T5, T6, T7, T8>::function_t
function,
const std::string &docString) {
return new CommandVoid8<E, T1, T2, T3, T4, T5, T6, T7, T8>(entity, function,
docString);
}
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8>
CommandVoid8<E, T1, T2, T3, T4, T5, T6, T7, T8> *makeCommandVoid8(
E &entity,
boost::function<void(E *, const T1 &, const T2 &, const T3 &, const T4 &,
const T5 &, const T6 &, const T7 &, const T8 &)>
function,
const std::string &docString) {
return new CommandVoid8<E, T1, T2, T3, T4, T5, T6, T7, T8>(
entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7, _8),
docString);
}
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8>
CommandVoid8<E, T1, T2, T3, T4, T5, T6, T7, T8> *makeCommandVoid8(
E &entity,
void (E::*function)(const T1 &, const T2 &, const T3 &, const T4 &,
const T5 &, const T6 &, const T7 &, const T8 &),
const std::string &docString) {
return new CommandVoid8<E, T1, T2, T3, T4, T5, T6, T7, T8>(
entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7, _8),
docString);
return NULL;
}
inline std::string docCommandVoid8(
const std::string &doc, const std::string &type1, const std::string &type2,
const std::string &type3, const std::string &type4,
const std::string &type5, const std::string &type6,
const std::string &type7, const std::string &type8) {
return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
"Input:\n - A " + type2 + ".\n" + "Input:\n - A " + type3 + ".\n" +
"Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
"Input:\n - A " + type6 + ".\n" + "Input:\n - A " + type7 + ".\n" +
"Input:\n - A " + type8 + ".\n" + "Void return.\n\n");
}
} // namespace command
} // namespace dynamicgraph
/* --- FUNCTION VERBOSE ----------------------------------------------------- */ /* --- FUNCTION VERBOSE ----------------------------------------------------- */
/* This bind a function void f( ostream& ) that display some results into /* This bind a function void f( ostream& ) that display some results into
* a string f( void ) that return some string results. */ * a string f( void ) that return some string results. */
namespace dynamicgraph { namespace dynamicgraph {
namespace command { namespace command {
template <class E>
template <class E > struct CommandVerbose : public Command {
struct CommandVerbose typedef boost::function<void(std::ostream &)> function_t;
: public Command
{ CommandVerbose(E &entity, function_t function, const std::string &docString)
typedef boost::function<void(std::ostream&)> function_t; : Command(entity, EMPTY_ARG, docString), fptr(function) {}
typedef boost::function<void(E*,std::ostream&)> memberFunction_t;
typedef void (E::*memberFunctionConst_ptr_t) (std::ostream&) const; protected:
typedef void (E::*memberFunction_ptr_t) (std::ostream&); virtual Value doExecute() {
assert(getParameterValues().size() == 0);
CommandVerbose(E& entity, function_t function, std::ostringstream oss;
const std::string& docString) fptr(oss);
:Command(entity, EMPTY_ARG, docString) return Value(oss.str()); // return string
,fptr(function) }
{}
private:
protected: function_t fptr;
virtual Value doExecute() };
{
assert( getParameterValues().size() == 0 ); template <class E>
std::ostringstream oss; CommandVerbose<E> *makeCommandVerbose(
fptr(oss); E &entity, typename CommandVerbose<E>::function_t function,
return Value( oss.str() ); // return string const std::string &docString) {
} return new CommandVerbose<E>(entity, function, docString);
private: return NULL;
function_t fptr; }
};
template <class E>
template <class E > CommandVerbose<E> *makeCommandVerbose(E &entity,
CommandVerbose<E>* void (E::*function)(std::ostream &),
makeCommandVerbose(E& entity, const std::string &docString) {
typename CommandVerbose<E>::function_t function, return new CommandVerbose<E>(entity, boost::bind(function, &entity, _1),
const std::string& docString) docString);
{ return NULL;
return new CommandVerbose<E>( entity,function,docString ); }
return NULL;
} inline std::string docCommandVerbose(const std::string &doc) {
return std::string("\n") + doc + "\n\nNo input.\n Return a string.\n\n";
template <class E > }
CommandVerbose<E>* /*************************/
makeCommandVerbose(E& entity, /* Template return types */
//void (E::*function) (std::ostream&) const, /*************************/
typename CommandVerbose<E>::memberFunctionConst_ptr_t function,
const std::string& docString) template <class E, class ReturnType>
{ struct CommandReturnType0 : public Command {
return new CommandVerbose<E>( entity, CommandReturnType0(E &entity, boost::function<ReturnType(void)> function,
boost::bind(function,&entity,_1),docString ); const std::string &docString)
return NULL; : Command(entity, EMPTY_ARG, docString), fptr(function) {}
}
protected:
template <class E > virtual Value doExecute() {
CommandVerbose<E>* assert(getParameterValues().size() == 0);
makeCommandVerbose(E& entity, Value res(fptr());
typename CommandVerbose<E>::memberFunction_ptr_t function, return res;
const std::string& docString) }
{
return new CommandVerbose<E>( entity, private:
boost::bind(function,&entity,_1),docString ); boost::function<ReturnType(void)> fptr;
return NULL; };
}
template <class E, class ReturnType>
inline std::string docCommandVerbose( const std::string& doc ) CommandReturnType0<E, ReturnType> *makeCommandReturnType0(
{ E &entity, boost::function<ReturnType(void)> function,
return std::string("\n")+doc +"\n\nNo input.\n Return a string.\n\n"; const std::string &docString) {
} return new CommandReturnType0<E, ReturnType>(entity, function, docString);
}
} // namespace command
} // namespace dynamicgraph template <class E, class ReturnType>
CommandReturnType0<E, ReturnType> *makeCommandReturnType0(
#endif // __dg_command_bind_h__ E &entity, boost::function<ReturnType(E *)> function,
const std::string &docString) {
return new CommandReturnType0<E, ReturnType>(
entity, boost::bind(function, &entity), docString);
}
template <class E, class ReturnType>
CommandReturnType0<E, ReturnType> *makeCommandReturnType0(
E &entity, ReturnType (E::*function)(void), const std::string &docString) {
return new CommandReturnType0<E, ReturnType>(
entity, boost::bind(function, &entity), docString);
}
template <typename ReturnType>
inline std::string docCommandReturnType0(
const std::string &doc, const std::string & /* return_type */) {
return std::string("\n") + doc + "\n\nNo input.\n" +
typeid(ReturnType).name() + " return.\n\n";
}
} // namespace command
} // namespace dynamicgraph
/* --- FUNCTION 1 ARGS ------------------------------------------------------ */
namespace dynamicgraph {
namespace command {
template <class E, typename ReturnType, typename T>
struct CommandReturnType1 : public Command {
typedef boost::function<ReturnType(const T &)> function_t;
CommandReturnType1(E &entity, function_t function,
const std::string &docString)
: Command(entity, boost::assign::list_of(ValueHelper<T>::TypeID),
docString),
fptr(function) {}
protected:
virtual Value doExecute() {
assert(getParameterValues().size() == 1);
T val = getParameterValues()[0].value();
Value res(fptr(val));
return res;
}
private:
function_t fptr;
};
template <class E, typename ReturnType, typename T>
CommandReturnType1<E, ReturnType, T> *makeCommandReturnType1(
E &entity, boost::function<ReturnType(const T &)> function,
const std::string &docString) {
return new CommandReturnType1<E, ReturnType, T>(entity, function, docString);
}
template <class E, typename ReturnType, typename T>
CommandReturnType1<E, ReturnType, T> *makeCommandReturnType1(
E &entity,
// The following syntaxt don't compile when not
// specializing the template arg... why ???
boost::function<ReturnType(E *, const T &)> function,
const std::string &docString) {
return new CommandReturnType1<E, ReturnType, T>(
entity, boost::bind(function, &entity, _1), docString);
}
template <class E, typename ReturnType, typename T>
CommandReturnType1<E, ReturnType, T> *makeCommandReturnType1(
E &entity, ReturnType (E::*function)(const T &),
const std::string &docString) {
return new CommandReturnType1<E, ReturnType, T>(
entity, boost::bind(function, &entity, _1), docString);
return NULL;
}
template <typename ReturnType>
inline std::string docCommandReturnType1(const std::string &doc,
const std::string &type) {
return std::string("\n") + doc + "\n\nInput:\n - A " + type + ".\n" +
typeid(ReturnType).name() + "return.\n\n";
}
} // namespace command
} // namespace dynamicgraph
/*********** FUNCTION 2 Arguments ************************/
namespace dynamicgraph {
namespace command {
template <class E, typename ReturnType, typename T1, typename T2>
struct CommandReturnType2 : public Command {
typedef boost::function<ReturnType(const T1 &, const T2 &)> function_t;
CommandReturnType2(E &entity, function_t function,
const std::string &docString)
: Command(entity,
boost::assign::list_of(ValueHelper<T1>::TypeID)(
ValueHelper<T2>::TypeID),
docString),
fptr(function) {}
protected:
virtual Value doExecute() {
assert(getParameterValues().size() == 2);
T1 val1 = getParameterValues()[0].value();
T2 val2 = getParameterValues()[1].value();
Value res(fptr(val1, val2));
return res;
}
private:
function_t fptr;
};
template <class E, typename ReturnType, typename T1, typename T2>
CommandReturnType2<E, ReturnType, T1, T2> *makeCommandReturnType2(
E &entity, boost::function<ReturnType(const T1 &, const T2 &)> function,
const std::string &docString) {
return new CommandReturnType2<E, ReturnType, T1, T2>(entity, function,
docString);
}
template <class E, typename ReturnType, typename T1, typename T2>
CommandReturnType2<E, ReturnType, T1, T2> *makeCommandReturnType2(
E &entity,
// The following syntaxt don't compile when not specializing the template
// arg... why ???
boost::function<ReturnType(E *, const T1 &, const T2 &)> function,
const std::string &docString) {
return new CommandReturnType2<E, ReturnType, T1, T2>(
entity, boost::bind(function, &entity, _1, _2), docString);
}
template <class E, typename ReturnType, typename T1, typename T2>
CommandReturnType2<E, ReturnType, T1, T2> *makeCommandReturnType2(
E &entity, ReturnType (E::*function)(const T1 &, const T2 &),
const std::string &docString) {
return new CommandReturnType2<E, ReturnType, T1, T2>(
entity, boost::bind(function, &entity, _1, _2), docString);
return NULL;
}
template <typename ReturnType>
inline std::string docCommandReturnType2(const std::string &doc,
const std::string &type1,
const std::string &type2) {
return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" +
"Input:\n - A " + type2 + ".\n" +
"ReturnType:\n - Returns:" + typeid(ReturnType).name() + +".\n\n");
}
} // namespace command
} // namespace dynamicgraph
#endif // __dg_command_bind_h__
...@@ -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
...@@ -4,259 +4,211 @@ ...@@ -4,259 +4,211 @@
// //
#ifndef DYNAMIC_GRAPH_DEBUG_HH #ifndef DYNAMIC_GRAPH_DEBUG_HH
# define DYNAMIC_GRAPH_DEBUG_HH #define DYNAMIC_GRAPH_DEBUG_HH
# include <cstdio> #include <dynamic-graph/dynamic-graph-api.h>
# include <cstdarg>
# include <fstream> #include <cstdarg>
# include <sstream> #include <cstdio>
#include <dynamic-graph/fwd.hh>
# include <dynamic-graph/fwd.hh> #include <fstream>
# include <dynamic-graph/dynamic-graph-api.h> #include <sstream>
#ifndef VP_DEBUG_MODE
# ifndef VP_DEBUG_MODE #define VP_DEBUG_MODE 0
# define VP_DEBUG_MODE 0 #endif //! VP_DEBUG_MODE
# endif //! VP_DEBUG_MODE
#ifndef VP_TEMPLATE_DEBUG_MODE
# ifndef VP_TEMPLATE_DEBUG_MODE #define VP_TEMPLATE_DEBUG_MODE 0
# define VP_TEMPLATE_DEBUG_MODE 0 #endif //! VP_TEMPLATE_DEBUG_MODE
# endif //! VP_TEMPLATE_DEBUG_MODE
#define DG_COMMON_TRACES \
#define DG_COMMON_TRACES \ do { \
do { \ va_list arg; \
va_list arg; \ va_start(arg, format); \
va_start (arg, format); \ vsnprintf(charbuffer, SIZE, format, arg); \
vsnprintf (charbuffer, SIZE, format, arg); \ va_end(arg); \
va_end (arg); \ outputbuffer << tmpbuffer.str() << charbuffer << std::endl; \
outputbuffer << tmpbuffer.str () << charbuffer << std::endl; \ } while (0)
} while(0)
namespace dynamicgraph {
namespace dynamicgraph /// \ingroup debug
{ ///
/// \ingroup debug /// \brief Logging class.
/// ///
/// \brief Logging class. /// This class should never be used directly, please use the
/// /// debugging macro instead.
/// This class should never be used directly, please use the class DYNAMIC_GRAPH_DLLAPI DebugTrace {
/// debugging macro instead. public:
class DYNAMIC_GRAPH_DLLAPI DebugTrace static const int SIZE = 512;
{
public: std::stringstream tmpbuffer;
static const int SIZE = 512; std::ostream &outputbuffer;
char charbuffer[SIZE + 1];
std::stringstream tmpbuffer; int traceLevel;
std::ostream& outputbuffer; int traceLevelTemplate;
char charbuffer[SIZE+1];
int traceLevel; DebugTrace(std::ostream &os) : outputbuffer(os) {}
int traceLevelTemplate;
inline void trace(const int level, const char *format, ...) {
DebugTrace (std::ostream& os) if (level <= traceLevel) DG_COMMON_TRACES;
: outputbuffer (os) tmpbuffer.str("");
{} }
inline void trace (const int level, const char* format, ...) inline void trace(const char *format, ...) {
{ DG_COMMON_TRACES;
if (level <= traceLevel) tmpbuffer.str("");
DG_COMMON_TRACES; tmpbuffer.str(""); }
}
inline void trace(const int level = -1) {
inline void trace (const char* format, ...) if (level <= traceLevel) {
{ outputbuffer << tmpbuffer.str();
DG_COMMON_TRACES;
tmpbuffer.str(""); tmpbuffer.str("");
} }
}
inline void trace (const int level=-1) inline void traceTemplate(const int level, const char *format, ...) {
{ if (level <= traceLevelTemplate) DG_COMMON_TRACES;
if (level <= traceLevel) { tmpbuffer.str("");
outputbuffer << tmpbuffer.str (); tmpbuffer.str(""); }
}
}
inline void traceTemplate (const int level, const char* format, ...) inline void traceTemplate(const char *format, ...) {
{ DG_COMMON_TRACES;
if (level <= traceLevelTemplate) tmpbuffer.str("");
DG_COMMON_TRACES; }
tmpbuffer.str("");
}
inline void traceTemplate (const char* format, ...) inline DebugTrace &pre(const std::ostream &) { return *this; }
{
DG_COMMON_TRACES;
tmpbuffer.str("");
}
inline DebugTrace& pre (const std::ostream&) inline DebugTrace &pre(const std::ostream &, int level) {
{ traceLevel = level;
return *this; return *this;
} }
inline DebugTrace& pre (const std::ostream&, int level) static const char *DEBUG_FILENAME_DEFAULT;
{ static void openFile(const char *filename = DEBUG_FILENAME_DEFAULT);
traceLevel = level; static void closeFile(const char *filename = DEBUG_FILENAME_DEFAULT);
return *this; };
}
static const char* DEBUG_FILENAME_DEFAULT; DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgDEBUGFLOW;
static void openFile (const char* filename = DEBUG_FILENAME_DEFAULT); DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgERRORFLOW;
static void closeFile( const char* filename = DEBUG_FILENAME_DEFAULT); } // end of namespace dynamicgraph
};
DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgDEBUGFLOW; #ifdef VP_DEBUG
DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgERRORFLOW;
} // end of namespace dynamicgraph
# ifdef VP_DEBUG #define dgPREDEBUG __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
#define dgPREERROR \
"\t!! " << __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
# define dgPREDEBUG \ #define dgDEBUG(level) \
__FILE__ << ": " <<__FUNCTION__ << "(#" << __LINE__ << ") :" if ((level > VP_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good())) \
# define dgPREERROR \ ; \
"\t!! "<<__FILE__ << ": " <<__FUNCTION__ << "(#" << __LINE__ << ") :" else \
# define dgDEBUG(level) \
if ((level > VP_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good ())) \
; \
else \
dgDEBUGFLOW.outputbuffer << dgPREDEBUG dgDEBUGFLOW.outputbuffer << dgPREDEBUG
# define dgDEBUGMUTE(level) \ #define dgDEBUGMUTE(level) \
if ((level > VP_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good ())) \ if ((level > VP_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good())) \
; \ ; \
else \ else \
dgDEBUGFLOW.outputbuffer dgDEBUGFLOW.outputbuffer
# define dgERROR \ #define dgERROR \
if (!dgDEBUGFLOW.outputbuffer.good ()) \ if (!dgDEBUGFLOW.outputbuffer.good()) \
; \ ; \
else \ else \
dgERRORFLOW.outputbuffer << dgPREERROR dgERRORFLOW.outputbuffer << dgPREERROR
# define dgDEBUGF \ #define dgDEBUGF \
if (!dgDEBUGFLOW.outputbuffer.good ()) \ if (!dgDEBUGFLOW.outputbuffer.good()) \
; \ ; \
else \ else \
dgDEBUGFLOW.pre (dgDEBUGFLOW.tmpbuffer << dgPREDEBUG, VP_DEBUG_MODE).trace dgDEBUGFLOW.pre(dgDEBUGFLOW.tmpbuffer << dgPREDEBUG, VP_DEBUG_MODE).trace
# define dgERRORF \ #define dgERRORF \
if (!dgDEBUGFLOW.outputbuffer.good ()) \ if (!dgDEBUGFLOW.outputbuffer.good()) \
; \ ; \
else \ else \
dgERRORFLOW.pre (dgERRORFLOW.tmpbuffer << dgPREERROR).trace dgERRORFLOW.pre(dgERRORFLOW.tmpbuffer << dgPREERROR).trace
// TEMPLATE // TEMPLATE
# define dgTDEBUG(level) \ #define dgTDEBUG(level) \
if ((level > VP_TEMPLATE_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good ())) \ if ((level > VP_TEMPLATE_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good())) \
; \ ; \
else \ else \
dgDEBUGFLOW.outputbuffer << dgPREDEBUG dgDEBUGFLOW.outputbuffer << dgPREDEBUG
# define dgTDEBUGF \ #define dgTDEBUGF \
if (!dgDEBUGFLOW.outputbuffer.good ()) \ if (!dgDEBUGFLOW.outputbuffer.good()) \
; \ ; \
else \ else \
dgDEBUGFLOW.pre \ dgDEBUGFLOW \
(dgDEBUGFLOW.tmpbuffer << dgPREDEBUG, VP_TEMPLATE_DEBUG_MODE).trace .pre(dgDEBUGFLOW.tmpbuffer << dgPREDEBUG, VP_TEMPLATE_DEBUG_MODE) \
.trace
inline bool dgDEBUG_ENABLE (const int & level) inline bool dgDEBUG_ENABLE(const int &level) { return level <= VP_DEBUG_MODE; }
{
return level<=VP_DEBUG_MODE;
}
inline bool dgTDEBUG_ENABLE (const int & level) inline bool dgTDEBUG_ENABLE(const int &level) {
{ return level <= VP_TEMPLATE_DEBUG_MODE;
return level<=VP_TEMPLATE_DEBUG_MODE;
} }
# else // VP_DEBUG #else // VP_DEBUG
# define dgPREERROR \ #define dgPREERROR \
"\t!! "<<__FILE__ << ": " <<__FUNCTION__ << "(#" << __LINE__ << ") :" "\t!! " << __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
# define dgDEBUG(level) \ #define dgDEBUG(level) \
if (1) \ if (1) \
; \ ; \
else \ else \
::dynamicgraph::__null_stream() ::dynamicgraph::__null_stream()
# define dgDEBUGMUTE (level) \ #define dgDEBUGMUTE \
if (1) \ (level) if (1); \
; \ else ::dynamicgraph::__null_stream()
else \
::dynamicgraph::__null_stream()
# define dgERROR \ #define dgERROR dgERRORFLOW.outputbuffer << dgPREERROR
dgERRORFLOW.outputbuffer << dgPREERROR
inline void dgDEBUGF (const int, const char*, ...) inline void dgDEBUGF(const int, const char *, ...) { return; }
{
return;
}
inline void dgDEBUGF (const char*, ...) inline void dgDEBUGF(const char *, ...) { return; }
{
return;
}
inline void dgERRORF (const int, const char*, ...) inline void dgERRORF(const int, const char *, ...) { return; }
{
return;
}
inline void dgERRORF (const char*, ...) inline void dgERRORF(const char *, ...) { return; }
{
return;
}
namespace dynamicgraph namespace dynamicgraph {
{ inline std::ostream &__null_stream() {
inline std::ostream& __null_stream ()
{
// This function should never be called. With -O3, // This function should never be called. With -O3,
// it should not appear in the generated binary. // it should not appear in the generated binary.
static std::ostream os (NULL); return os; static std::ostream os(NULL);
return os;
} }
} } // namespace dynamicgraph
// TEMPLATE // TEMPLATE
# define dgTDEBUG(level) \ #define dgTDEBUG(level) \
if (1) \ if (1) \
; \ ; \
else \ else \
::dynamicgraph::__null_stream() ::dynamicgraph::__null_stream()
inline void dgTDEBUGF (const int, const char*, ...) inline void dgTDEBUGF(const int, const char *, ...) { return; }
{
return;
}
inline void dgTDEBUGF (const char*, ...)
{
return;
}
# define dgDEBUG_ENABLE(level) false inline void dgTDEBUGF(const char *, ...) { return; }
# define dgTDEBUG_ENABLE(level) false
# endif //! VP_DEBUG #define dgDEBUG_ENABLE(level) false
#define dgTDEBUG_ENABLE(level) false
# define dgDEBUGIN(level) \ #endif //! VP_DEBUG
dgDEBUG(level) << "# In {" << std::endl
# define dgDEBUGOUT(level) \ #define dgDEBUGIN(level) dgDEBUG(level) << "# In {" << std::endl
dgDEBUG(level) << "# Out }" << std::endl
# define dgDEBUGINOUT(level) \ #define dgDEBUGOUT(level) dgDEBUG(level) << "# Out }" << std::endl
dgDEBUG(level) << "# In/Out { }" << std::endl
#define dgDEBUGINOUT(level) dgDEBUG(level) << "# In/Out { }" << std::endl
# define dgTDEBUGIN(level) \ #define dgTDEBUGIN(level) dgTDEBUG(level) << "# In {" << std::endl
dgTDEBUG(level) << "# In {" << std::endl
# define dgTDEBUGOUT(level) \ #define dgTDEBUGOUT(level) dgTDEBUG(level) << "# Out }" << std::endl
dgTDEBUG(level) << "# Out }" << std::endl
# define dgTDEBUGINOUT(level) \ #define dgTDEBUGINOUT(level) dgTDEBUG(level) << "# In/Out { }" << std::endl
dgTDEBUG(level) << "# In/Out { }" << std::endl
#endif //! DYNAMIC_GRAPH_DEBUG_HH #endif //! DYNAMIC_GRAPH_DEBUG_HH
...@@ -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__
...@@ -4,20 +4,19 @@ ...@@ -4,20 +4,19 @@
// //
#ifndef DYNAMIC_GRAPH_ENTITY_H #ifndef DYNAMIC_GRAPH_ENTITY_H
# define DYNAMIC_GRAPH_ENTITY_H #define DYNAMIC_GRAPH_ENTITY_H
# include <iosfwd> #include <dynamic-graph/dynamic-graph-api.h>
# include <map> #include <dynamic-graph/exception-factory.h>
# include <sstream> #include <dynamic-graph/logger.h>
# include <string> #include <dynamic-graph/signal-array.h>
#include <dynamic-graph/signal-base.h>
# include <boost/noncopyable.hpp>
#include <boost/noncopyable.hpp>
# include <dynamic-graph/fwd.hh> #include <dynamic-graph/fwd.hh>
# include <dynamic-graph/dynamic-graph-api.h> #include <iosfwd>
# include <dynamic-graph/exception-factory.h> #include <map>
# include <dynamic-graph/signal-array.h> #include <sstream>
# include <dynamic-graph/signal-base.h> #include <string>
# include <dynamic-graph/logger.h>
/// \brief Helper macro for entity declaration. /// \brief Helper macro for entity declaration.
/// ///
...@@ -36,117 +35,150 @@ ...@@ -36,117 +35,150 @@
/// Caution: you *MUST* call DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN in the /// Caution: you *MUST* call DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN in the
/// associated source file to ensure that the attributes generated by /// associated source file to ensure that the attributes generated by
/// this macro are correctly initialized. /// this macro are correctly initialized.
# define DYNAMIC_GRAPH_ENTITY_DECL() \ #define DYNAMIC_GRAPH_ENTITY_DECL() \
public: \ public: \
virtual const std::string& getClassName () const \ virtual const std::string &getClassName() const { return CLASS_NAME; } \
{ \
return CLASS_NAME; \
} \
static const std::string CLASS_NAME static const std::string CLASS_NAME
namespace dynamicgraph namespace dynamicgraph {
{ /// \ingroup dgraph
/// \ingroup dgraph ///
/// /// \brief This class represents an entity, i.e. a generic
/// \brief This class represents an entity, i.e. a generic /// computational unit that provides input and output signals.
/// computational unit that provides input and output signals. ///
/// /// These signals link the entities together to form a complete
/// These signals link the entities together to form a complete /// computation graph. To declare a new entity, please see the
/// computation graph. To declare a new entity, please see the /// DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN macro in factory.h.
/// DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN macro in factory.h. class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable {
class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable public:
{ typedef std::map<std::string, SignalBase<int> *> SignalMap;
public: typedef std::map<const std::string, command::Command *> CommandMap_t;
typedef std::map< std::string,SignalBase<int>* > SignalMap;
typedef std::map<const std::string, command::Command*> CommandMap_t; explicit Entity(const std::string &name);
virtual ~Entity();
explicit Entity (const std::string& name);
virtual ~Entity (); const std::string &getName() const { return name; }
virtual const std::string &getClassName() const {
const std::string& getName () const static std::string ret("Entity");
{ return ret;
return name; }
} /** \brief Returns the Entity documentation
virtual const std::string& getClassName () const \return The documentation is provided as std::string object.
{ */
static std::string ret("Entity"); virtual std::string getDocString() const;
return ret;
} /** \brief Test if a signal of name signame is present.
virtual std::string getDocString () const; \return True if the signal is present, False otherwise
bool hasSignal( const std::string & signame ) const; */
SignalBase<int>& getSignal (const std::string& signalName); bool hasSignal(const std::string &signame) const;
const SignalBase<int>& getSignal (const std::string& signalName) const;
std::ostream& displaySignalList(std::ostream& os) const; /** \brief Provides a reference to the signal named signalName.
virtual std::ostream& writeGraph (std::ostream& os) const; \param signalName: Name of the signal
virtual std::ostream& writeCompletionList (std::ostream& os) const; \return A reference to the signal with a temporal dependency.
*/
virtual void display (std::ostream& os) const; SignalBase<int> &getSignal(const std::string &signalName);
virtual SignalBase<int>* test () /** \brief Provides a const reference to the signal named signalName.
{ \param signalName: Name of the signal
return 0; \return A const reference to the signal with a temporal dependency.
} */
const SignalBase<int> &getSignal(const std::string &signalName) const;
virtual void test2 (SignalBase<int>*)
{ /** \brief Display the list of signals of this entity in output stream os.
return ; \param os: the output stream where to display the list of signals.
} \returns The output stream given in parameter.
*/
const std::string& getCommandList () const; std::ostream &displaySignalList(std::ostream &os) const;
CommandMap_t getNewStyleCommandMap();
command::Command* getNewStyleCommand( const std::string& cmdName ); /** \brief This method is used to write down in os the edges of the graph
by calling the signals writeGraph method.
SignalMap getSignalMap() const; \param os: The output stream where to write the informations.
\return os: The output stream.
/** \name Logger related methods */ */
/** \{*/ virtual std::ostream &writeGraph(std::ostream &os) const;
/// \brief Send messages \param msg with level t. Add string file and line to message.
void sendMsg(const std::string &msg, /** \brief This method is used write in the output stream os the
MsgType t=MSG_TYPE_INFO, signals names and the commands of the entity.
const char *file="", \param os: The output stream where to write the list of objects
int line=0); related to the entity.
*/
/// \brief Specify the verbosity level of the logger. virtual std::ostream &writeCompletionList(std::ostream &os) const;
void setLoggerVerbosityLevel(LoggerVerbosity lv)
{logger_.setVerbosity(lv);} /** \brief Display information on the entity inside the output stream os.
*/
/// \brief Get the logger's verbosity level. virtual void display(std::ostream &os) const;
LoggerVerbosity getLoggerVerbosityLevel()
{ return logger_.getVerbosity(); } virtual SignalBase<int> *test() { return 0; }
/// \brief Set the time sample. virtual void test2(SignalBase<int> *) { return; }
bool setTimeSample(double t)
{ return logger_.setTimeSample(t); } const std::string &getCommandList() const;
/// \brief Get the time sample. /** \brief Provides the std::map where all the commands are registered
double getTimeSample() \returns A map of pointers towards Command objects
{ return logger_.getTimeSample();} */
CommandMap_t getNewStyleCommandMap();
/// \brief Set the period of the stream period /** \brief Provides the pointer towards the Command object cmdName.
bool setStreamPrintPeriod(double t) \param cmdName: Name of the command
{ return logger_.setStreamPrintPeriod(t); } */
command::Command *getNewStyleCommand(const std::string &cmdName);
/// \brief Get the period of the stream period
double getStreamPrintPeriod() /** \brief Provides a map of all the signals.
{ return logger_.getStreamPrintPeriod();} \returns A copy of the map with all the pointers towards
the entity signals.
protected: */
void addCommand(const std::string& name,command::Command* command); SignalMap getSignalMap() const;
void entityRegistration (); /// \name Logger related methods
void entityDeregistration (); /// \{
void signalRegistration (const SignalArray<int>& signals); Logger &logger() { return logger_; };
void signalDeregistration (const std::string& name); Logger const &logger() const { return logger_; };
std::string name; /// \brief Send messages \c msg with level \c t.
SignalMap signalMap; /// Add string file and line to message.
CommandMap_t commandMap; void sendMsg(const std::string &msg, MsgType t = MSG_TYPE_INFO,
Logger logger_; const std::string &lineId = "");
};
/// \brief Specify the verbosity level of the logger.
DYNAMIC_GRAPH_DLLAPI std::ostream& void setLoggerVerbosityLevel(LoggerVerbosity lv) { logger_.setVerbosity(lv); }
operator<< (std::ostream& os, const dynamicgraph::Entity& ent);
} // end of namespace dynamicgraph /// \brief Get the logger's verbosity level.
LoggerVerbosity getLoggerVerbosityLevel() { return logger_.getVerbosity(); }
#endif //! DYNAMIC_GRAPH_ENTITY_H
/// \brief Set the time sample.
bool setTimeSample(double t) { return logger_.setTimeSample(t); }
/// \brief Get the time sample.
double getTimeSample() { return logger_.getTimeSample(); }
/// \brief Set the period of the stream period
bool setStreamPrintPeriod(double t) {
return logger_.setStreamPrintPeriod(t);
}
/// \brief Get the period of the stream period
double getStreamPrintPeriod() { return logger_.getStreamPrintPeriod(); }
/// \}
protected:
void addCommand(const std::string &name, command::Command *command);
void entityRegistration();
void entityDeregistration();
void signalRegistration(const SignalArray<int> &signals);
void signalDeregistration(const std::string &name);
std::string name;
SignalMap signalMap;
CommandMap_t commandMap;
Logger logger_;
};
DYNAMIC_GRAPH_DLLAPI std::ostream &operator<<(std::ostream &os,
const dynamicgraph::Entity &ent);
} // end of namespace dynamicgraph
#endif //! DYNAMIC_GRAPH_ENTITY_H
...@@ -4,154 +4,134 @@ ...@@ -4,154 +4,134 @@
// //
#ifndef DYNAMIC_GRAPH_EXCEPTION_ABSTRACT_H #ifndef DYNAMIC_GRAPH_EXCEPTION_ABSTRACT_H
# define DYNAMIC_GRAPH_EXCEPTION_ABSTRACT_H #define DYNAMIC_GRAPH_EXCEPTION_ABSTRACT_H
# include <string> #include <dynamic-graph/dynamic-graph-api.h>
# include <dynamic-graph/fwd.hh> #include <dynamic-graph/fwd.hh>
# include <dynamic-graph/dynamic-graph-api.h> #include <string>
// Uncomment this macros to have lines parameter on the throw display // Uncomment this macros to have lines parameter on the throw display
// #define DYNAMIC-GRAPH_EXCEPTION_PASSING_PARAM // #define DYNAMIC-GRAPH_EXCEPTION_PASSING_PARAM
# define DG_RETHROW \ #define DG_RETHROW \
(const ::dynamicgraph::ExceptionAbstract& err) \ (const ::dynamicgraph::ExceptionAbstract &err) { throw err; }
{ \
throw err; \ #ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
#define DG_THROW \
throw ::dynamicgraph::ExceptionAbstract::Param(__LINE__, __FUNCTION__, \
__FILE__) +
#else
#define DG_THROW throw
#endif // DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
namespace dynamicgraph {
/// \ingroup error
///
/// \brief Abstract root class for all dynamic-graph exceptions.
class DYNAMIC_GRAPH_DLLAPI ExceptionAbstract : public std::exception {
public:
/// \ingroup error
///
/// \brief Class owned by exceptions to store error locations.
class Param {
public:
static const int BUFFER_SIZE = 80;
Param(const int &_line, const char *_function, const char *_file);
Param()
: functionPTR(),
function(),
line(),
filePTR(),
file(),
pointersSet(false),
set(false) {}
Param &initCopy(const Param &p);
const char *functionPTR;
char function[BUFFER_SIZE];
int line;
const char *filePTR;
char file[BUFFER_SIZE];
bool pointersSet;
bool set;
};
/// \brief Categories error code.
///
/// Each value matches categories used by a subclass of
/// ExceptionAbstract.
///
/// This is the programmer responsibility to make sure there is
/// enough room between two categories error code.
enum ExceptionEnum {
ABSTRACT = 0,
SIGNAL = 100,
FACTORY = 200,
TRACES = 300,
TOOLS = 700
};
static const std::string EXCEPTION_NAME;
explicit ExceptionAbstract(const int &code, const std::string &msg = "");
virtual ~ExceptionAbstract() throw() {}
virtual const std::string &getExceptionName() const { return EXCEPTION_NAME; }
/// \brief Access to the error code.
int getCode() const;
/// \brief Reference access to the error message (can be empty).
const std::string &getStringMessage() const;
/// \brief Access to the pointer on the array of \e char related
/// to the error string.
///
/// Cannot be \e NULL.
const char *getMessage() const;
virtual const char *what() const throw() {
return getStringMessage().c_str();
} }
# ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM /// \brief Print the error structure.
# define DG_THROW \ DYNAMIC_GRAPH_DLLAPI friend std::ostream &operator<<(
throw ::dynamicgraph::ExceptionAbstract::Param \ std::ostream &os, const ExceptionAbstract &err);
(__LINE__, __FUNCTION__, __FILE__) +
# else
# define DG_THROW \
throw
# endif // DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
protected:
/// \brief Error code.
/// \sa ErrorCodeEnum
int code;
namespace dynamicgraph /// \brief Error message (can be empty).
{ std::string message;
/// \ingroup error
#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
/// \brief Optional mutable attribute to store exception location.
/// ///
/// \brief Abstract root class for all dynamic-graph exceptions. /// Only present if DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
class DYNAMIC_GRAPH_DLLAPI ExceptionAbstract : public std::exception /// preprocessor symbol exists.
{ mutable Param p;
public:
/// \ingroup error template <class Exc>
/// friend const Exc &operator+(const ExceptionAbstract::Param &p, const Exc &e) {
/// \brief Class owned by exceptions to store error locations. e.p.initCopy(p);
class Param return e;
{ }
public:
static const int BUFFER_SIZE = 80; template <class Exc>
friend Exc &operator+(const ExceptionAbstract::Param &p, Exc &e) {
Param (const int& _line, const char* _function, const char* _file); e.p.initCopy(p);
Param () return e;
: functionPTR (), }
function (),
line (), #endif // DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
filePTR (),
file (), private:
pointersSet (false), /// \brief Forbid the empty constructor (private).
set (false) ExceptionAbstract();
{} };
Param& initCopy (const Param& p); } // end of namespace dynamicgraph
const char* functionPTR;
char function[BUFFER_SIZE];
int line;
const char* filePTR;
char file[BUFFER_SIZE];
bool pointersSet;
bool set;
};
/// \brief Categories error code.
///
/// Each value matches categories used by a subclass of
/// ExceptionAbstract.
///
/// This is the programmer responsibility to make sure there is
/// enough room between two categories error code.
enum ExceptionEnum
{
ABSTRACT = 0,
SIGNAL = 100,
FACTORY = 200,
TRACES = 300,
TOOLS = 700
};
static const std::string EXCEPTION_NAME;
explicit ExceptionAbstract (const int& code, const std::string& msg = "");
virtual ~ExceptionAbstract () throw ()
{}
virtual const std::string& getExceptionName () const
{
return EXCEPTION_NAME;
}
/// \brief Access to the error code.
int getCode () const;
/// \brief Reference access to the error message (can be empty).
const std::string& getStringMessage () const;
/// \brief Access to the pointer on the array of \e char related
/// to the error string.
///
/// Cannot be \e NULL.
const char* getMessage () const;
virtual const char* what () const throw ()
{
return getStringMessage ().c_str ();
}
/// \brief Print the error structure.
DYNAMIC_GRAPH_DLLAPI friend std::ostream&
operator << (std::ostream & os, const ExceptionAbstract & err);
protected:
/// \brief Error code.
/// \sa ErrorCodeEnum
int code;
/// \brief Error message (can be empty).
std::string message;
# ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
/// \brief Optional mutable attribute to store exception location.
///
/// Only present if DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
/// preprocessor symbol exists.
mutable Param p;
template<class Exc>
friend const Exc&
operator+ (const ExceptionAbstract::Param& p, const Exc& e)
{
e.p.initCopy(p);
return e;
}
template<class Exc>
friend Exc&
operator+ (const ExceptionAbstract::Param& p, Exc& e)
{
e.p.initCopy (p);
return e;
}
# endif // DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
private:
/// \brief Forbid the empty constructor (private).
ExceptionAbstract ();
};
} // end of namespace dynamicgraph
#endif //! DYNAMIC_GRAPH_EXCEPTION_ABSTRACT_H #endif //! DYNAMIC_GRAPH_EXCEPTION_ABSTRACT_H
...@@ -4,51 +4,46 @@ ...@@ -4,51 +4,46 @@
// //
#ifndef DYNAMIC_GRAPH_EXCEPTION_FACTORY_H #ifndef DYNAMIC_GRAPH_EXCEPTION_FACTORY_H
# define DYNAMIC_GRAPH_EXCEPTION_FACTORY_H #define DYNAMIC_GRAPH_EXCEPTION_FACTORY_H
# include <string> #include <dynamic-graph/dynamic-graph-api.h>
#include <dynamic-graph/exception-abstract.h>
# include <dynamic-graph/fwd.hh>
# include <dynamic-graph/dynamic-graph-api.h> #include <dynamic-graph/fwd.hh>
# include <dynamic-graph/exception-abstract.h> #include <string>
namespace dynamicgraph namespace dynamicgraph {
{ /// \ingroup error
/// \ingroup error ///
/// /// \brief Generic error class.
/// \brief Generic error class. class DYNAMIC_GRAPH_DLLAPI ExceptionFactory : public ExceptionAbstract {
class DYNAMIC_GRAPH_DLLAPI ExceptionFactory : public ExceptionAbstract public:
{ enum ErrorCodeEnum {
public: GENERIC = ExceptionAbstract::FACTORY,
enum ErrorCodeEnum UNREFERED_OBJECT,
{ UNREFERED_SIGNAL,
GENERIC = ExceptionAbstract::FACTORY UNREFERED_FUNCTION,
,UNREFERED_OBJECT DYNAMIC_LOADING,
,UNREFERED_SIGNAL SIGNAL_CONFLICT,
,UNREFERED_FUNCTION FUNCTION_CONFLICT,
,DYNAMIC_LOADING OBJECT_CONFLICT,
,SIGNAL_CONFLICT SYNTAX_ERROR,
,FUNCTION_CONFLICT READ_FILE
,OBJECT_CONFLICT
,SYNTAX_ERROR
,READ_FILE
};
static const std::string EXCEPTION_NAME;
explicit ExceptionFactory (const ExceptionFactory::ErrorCodeEnum& errcode,
const std::string & msg = "");
ExceptionFactory (const ExceptionFactory::ErrorCodeEnum& errcode,
const std::string& msg, const char* format, ...);
virtual ~ExceptionFactory () throw ()
{}
virtual const std::string& getExceptionName () const
{
return ExceptionFactory::EXCEPTION_NAME;
}
}; };
} // end of namespace dynamicgraph
#endif //! DYNAMIC_GRAPH_EXCEPTION_FACTORY_H static const std::string EXCEPTION_NAME;
explicit ExceptionFactory(const ExceptionFactory::ErrorCodeEnum &errcode,
const std::string &msg = "");
ExceptionFactory(const ExceptionFactory::ErrorCodeEnum &errcode,
const std::string &msg, const char *format, ...);
virtual ~ExceptionFactory() throw() {}
virtual const std::string &getExceptionName() const {
return ExceptionFactory::EXCEPTION_NAME;
}
};
} // end of namespace dynamicgraph
#endif //! DYNAMIC_GRAPH_EXCEPTION_FACTORY_H
...@@ -4,48 +4,41 @@ ...@@ -4,48 +4,41 @@
// //
#ifndef DYNAMIC_GRAPH_EXCEPTION_SIGNAL_H #ifndef DYNAMIC_GRAPH_EXCEPTION_SIGNAL_H
# define DYNAMIC_GRAPH_EXCEPTION_SIGNAL_H #define DYNAMIC_GRAPH_EXCEPTION_SIGNAL_H
# include <dynamic-graph/fwd.hh> #include <dynamic-graph/dynamic-graph-api.h>
# include <dynamic-graph/dynamic-graph-api.h> #include <dynamic-graph/exception-abstract.h>
# include <dynamic-graph/exception-abstract.h>
#include <dynamic-graph/fwd.hh>
namespace dynamicgraph
{ namespace dynamicgraph {
/// \ingroup error /// \ingroup error
/// ///
/// \brief Exceptions raised when an error related to signals /// \brief Exceptions raised when an error related to signals
/// happen. /// happen.
class DYNAMIC_GRAPH_DLLAPI ExceptionSignal : public ExceptionAbstract class DYNAMIC_GRAPH_DLLAPI ExceptionSignal : public ExceptionAbstract {
{ public:
public: enum ErrorCodeEnum {
enum ErrorCodeEnum GENERIC = ExceptionAbstract::SIGNAL,
{ READWRITE_LOCK,
GENERIC = ExceptionAbstract::SIGNAL COPY_NOT_INITIALIZED,
NOT_INITIALIZED,
,READWRITE_LOCK PLUG_IMPOSSIBLE,
,COPY_NOT_INITIALIZED SET_IMPOSSIBLE,
,NOT_INITIALIZED BAD_CAST
,PLUG_IMPOSSIBLE
,SET_IMPOSSIBLE
,BAD_CAST
};
static const std::string EXCEPTION_NAME;
explicit ExceptionSignal (const ExceptionSignal::ErrorCodeEnum& errcode,
const std::string & msg = "" );
ExceptionSignal (const ExceptionSignal::ErrorCodeEnum& errcode,
const std::string & msg, const char* format, ...);
virtual ~ExceptionSignal () throw ()
{}
virtual const std::string& getExceptionName () const
{
return EXCEPTION_NAME;
}
}; };
} // end of namespace dynamicgraph static const std::string EXCEPTION_NAME;
#endif //!DYNAMIC_GRAPH_EXCEPTION_SIGNAL_H explicit ExceptionSignal(const ExceptionSignal::ErrorCodeEnum &errcode,
const std::string &msg = "");
ExceptionSignal(const ExceptionSignal::ErrorCodeEnum &errcode,
const std::string &msg, const char *format, ...);
virtual ~ExceptionSignal() throw() {}
virtual const std::string &getExceptionName() const { return EXCEPTION_NAME; }
};
} // end of namespace dynamicgraph
#endif //! DYNAMIC_GRAPH_EXCEPTION_SIGNAL_H
...@@ -4,41 +4,31 @@ ...@@ -4,41 +4,31 @@
// //
#ifndef DYNAMIC_GRAPH_EXCEPTION_TRACES_H #ifndef DYNAMIC_GRAPH_EXCEPTION_TRACES_H
# define DYNAMIC_GRAPH_EXCEPTION_TRACES_H #define DYNAMIC_GRAPH_EXCEPTION_TRACES_H
# include <string> #include <dynamic-graph/dynamic-graph-api.h>
#include <dynamic-graph/exception-abstract.h>
# include <dynamic-graph/fwd.hh> #include <dynamic-graph/fwd.hh>
# include <dynamic-graph/dynamic-graph-api.h> #include <string>
# include <dynamic-graph/exception-abstract.h>
namespace dynamicgraph namespace dynamicgraph {
{ /// \ingroup error
/// \ingroup error ///
/// /// \brief Exceptions raised when an error related to traces happen.
/// \brief Exceptions raised when an error related to traces happen. class DYNAMIC_GRAPH_DLLAPI ExceptionTraces : public ExceptionAbstract {
class DYNAMIC_GRAPH_DLLAPI ExceptionTraces : public ExceptionAbstract public:
{ enum ErrorCodeEnum { GENERIC = ExceptionAbstract::TRACES, NOT_OPEN };
public:
enum ErrorCodeEnum
{
GENERIC = ExceptionAbstract::TRACES
,NOT_OPEN
};
static const std::string EXCEPTION_NAME; static const std::string EXCEPTION_NAME;
explicit ExceptionTraces (const ExceptionTraces::ErrorCodeEnum& errcode, explicit ExceptionTraces(const ExceptionTraces::ErrorCodeEnum &errcode,
const std::string & msg = ""); const std::string &msg = "");
ExceptionTraces (const ExceptionTraces::ErrorCodeEnum& errcode, ExceptionTraces(const ExceptionTraces::ErrorCodeEnum &errcode,
const std::string& msg, const char* format, ...); const std::string &msg, const char *format, ...);
virtual ~ExceptionTraces () throw () virtual ~ExceptionTraces() throw() {}
{}
virtual const std::string& getExceptionName () const virtual const std::string &getExceptionName() const { return EXCEPTION_NAME; }
{ };
return EXCEPTION_NAME; } // end of namespace dynamicgraph.
}
};
} // end of namespace dynamicgraph.
#endif //! DYNAMIC_GRAPH_EXCEPTION_TRACES_H #endif //! DYNAMIC_GRAPH_EXCEPTION_TRACES_H
...@@ -4,16 +4,15 @@ ...@@ -4,16 +4,15 @@
// //
#ifndef DYNAMIC_GRAPH_FACTORY_HH #ifndef DYNAMIC_GRAPH_FACTORY_HH
# define DYNAMIC_GRAPH_FACTORY_HH #define DYNAMIC_GRAPH_FACTORY_HH
# include <map> #include <dynamic-graph/dynamic-graph-api.h>
# include <string> #include <dynamic-graph/exception-factory.h>
# include <vector>
# include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <dynamic-graph/fwd.hh>
# include <dynamic-graph/fwd.hh> #include <map>
# include <dynamic-graph/exception-factory.h> #include <string>
# include <dynamic-graph/dynamic-graph-api.h> #include <vector>
/// \ingroup dgraph /// \ingroup dgraph
/// ///
...@@ -24,187 +23,180 @@ ...@@ -24,187 +23,180 @@
/// \param CLASSNAME the name of the Entity to be registered (this must /// \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 /// be a std::string or a type implicitly castable into a std::string
/// such as classic C string delimited by double quotes). /// such as classic C string delimited by double quotes).
# define DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CLASSTYPE, CLASSNAME) \ #define DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CLASSTYPE, CLASSNAME) \
const std::string CLASSTYPE::CLASS_NAME = CLASSNAME; \ const std::string CLASSTYPE::CLASS_NAME = CLASSNAME; \
extern "C" { \ extern "C" { \
::dynamicgraph::Entity* \ ::dynamicgraph::Entity *EntityMaker_##CLASSTYPE( \
EntityMaker_##CLASSTYPE(const std::string& objname) \ const std::string &objname) { \
{ \ return new CLASSTYPE(objname); \
return new CLASSTYPE (objname); \ } \
} \ ::dynamicgraph::EntityRegisterer reg_##CLASSTYPE(CLASSNAME, \
::dynamicgraph::EntityRegisterer \ &EntityMaker_##CLASSTYPE); \
reg_##CLASSTYPE (CLASSNAME, \ } \
&EntityMaker_##CLASSTYPE); \
} \
struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
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();
namespace dynamicgraph /// \brief Add a new entity to the factory.
{
/// \ingroup dgraph
/// ///
/// \brief Provides a way to create Entity objects from their class /// It is not allowed to have several entities using the same
/// name. /// 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.
/// ///
/// The dynamic graph frameworks relies on entities (see Entity) /// If the provided entity name does not exist in the factory,
/// which defines atomic processing units. This class provides a /// an ExceptionFactory exception will be raised with the code
/// robust way to enumerate and instantiate these entities. /// OBJECT_CONFLICT.
/// 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 /// \param entname the entity name (as passed to registerEntity before)
/// inherits from dynamicgraph::Entity. This type can be registered void deregisterEntity(const std::string &entname);
/// into the factory to teach the framework that:
/// - this entity exists /// \brief Instantiate (and allocate) an entity.
/// - this entity can be instantiated (and how to instantiate it).
/// ///
/// To achieve this, one must pass an entity name and a function pointer. /// An instance called objname of the entity which type is classname
/// will be allocated by this method.
/// ///
/// The entity name will identify the class <b>at run-time</b> /// It is <b>the caller</b> responsibility to free the
/// (be careful: this may not be equivalent to the C++ class name /// returned object.
/// even if it is recommended to do so).
/// ///
/// The function pointer must point on a function taking a string as /// If the class name does not exist, an ExceptionFactory
/// input and returning an instance of the Entity (the concrete /// exception will be raised with the code UNREFERED_OBJECT.
/// subclass, not directly the upper Entity class).
/// ///
/// The instances returned by this function <b>must</b> be /// The instance name (objname) is passed to the Entity
/// dynamically allocated and the caller <b>must</b> get the /// constructor and it is the caller responsibility to avoid
/// ownership of the instance (i.e. it will free it when required). /// instance name conflicts if necessary.
/// ///
/// To finish, please note that the instance name indicates to the /// \param classname the name of the Entity type
/// entity how the instance itself is called at run-time. This name /// \param objname the instance name
/// does not need to be unique and no check is done on it. It is /// \return Dynamically allocated instance of classname.
/// the caller responsibility to make sure that the instance name is Entity *newEntity(const std::string &classname,
/// appropriate and to check for uniqueness if required. 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.
/// ///
/// This class is a singleton. The rationale is that each /// Available entities are appended to the method argument.
/// 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;
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;
/// \pointer to the unique object of the class
static FactoryStorage* instance_;
};
/// \ingroup dgraph
/// ///
/// \brief This class automatically register an Entity to the /// \param list Available entities will be appended to list.
/// global factory at initialization and unregister it during void listEntities(std::vector<std::string> &list) const;
/// instance destruction.
private:
/// \brief Constructor the factory.
/// ///
/// This class is mainly used by the /// After the initialization, no entities will be available.
/// DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN macro and is of little interest /// registerEntity has to be used to add new entities to the
/// by itself. /// object.
class DYNAMIC_GRAPH_DLLAPI EntityRegisterer : private boost::noncopyable explicit FactoryStorage();
{
public: /// \brief Entity map type.
/// \brief Register entity to the global factory. ///
explicit EntityRegisterer (const std::string& entityClassName, /// This maps entity names to functions pointers which can be
FactoryStorage::EntityConstructor_ptr maker); /// used to instantiate an Entity.
typedef std::map<std::string, EntityConstructor_ptr> EntityMap;
/// \brief Unregister entity to the global factory.
~EntityRegisterer (); /// \brief The entity map storing information about how to
private: /// instantiate an Entity.
/// \brief Name of the entity registered when the instance has EntityMap entityMap;
/// been initialized.
const std::string entityName; /// \pointer to the unique object of the class
}; static FactoryStorage *instance_;
};
/// \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);
/// \brief Unregister entity to the global factory.
~EntityRegisterer();
private:
/// \brief Name of the entity registered when the instance has
/// been initialized.
const std::string entityName;
};
} // end of namespace dynamicgraph } // end of namespace dynamicgraph
#endif //! DYNAMIC_GRAPH_FACTORY_HH #endif //! DYNAMIC_GRAPH_FACTORY_HH
// LocalWords: unregister // LocalWords: unregister
...@@ -3,62 +3,64 @@ ...@@ -3,62 +3,64 @@
// //
#ifndef DYNAMIC_GRAPH_FWD_HH #ifndef DYNAMIC_GRAPH_FWD_HH
# define DYNAMIC_GRAPH_FWD_HH #define DYNAMIC_GRAPH_FWD_HH
namespace dynamicgraph #include <boost/smart_ptr.hpp>
{
class DebugTrace; namespace dynamicgraph {
class PluginRefMap; // to be replace by std:: when we switch to C++11 and later
class Entity; using boost::const_pointer_cast;
class EntityRegisterer; using boost::dynamic_pointer_cast;
class ExceptionAbstract; using boost::make_shared;
class ExceptionFactory; using boost::shared_ptr;
class ExceptionSignal; using boost::static_pointer_cast;
class ExceptionTraces; using boost::weak_ptr;
class FactoryStorage;
class Interpreter; class DebugTrace;
class InterpreterHelper;
class Logger; class PluginRefMap;
class OutStringStream; class Entity;
class PluginLoader; class EntityRegisterer;
class PoolStorage; class ExceptionAbstract;
class ExceptionFactory;
class SignalCaster; class ExceptionSignal;
class SignalCastRegisterer; class ExceptionTraces;
class FactoryStorage;
class Tracer; class Interpreter;
class TracerRealTime; typedef shared_ptr<Interpreter> InterpreterShPtr_t;
class InterpreterHelper;
template <typename T> class Logger;
class DefaultCastRegisterer; class OutStringStream;
class PluginLoader;
template <typename T, typename Time> class PoolStorage;
class Signal;
class Tracer;
template <typename Time> class TracerRealTime;
class SignalArray;
template <typename T, typename Time>
template <typename Time> class Signal;
class SignalArray_const;
template <typename Time>
template <typename Time> class SignalArray;
class SignalBase;
template <typename Time>
class SignalArray_const;
template <typename T, typename Time>
class SignalPtr; template <typename Time>
template <typename T, typename Time> class SignalBase;
class SignalTimeDependent;
template <typename Time> template <typename T, typename Time>
class TimeDependency; class SignalPtr;
template <typename T, typename Time>
namespace command class SignalTimeDependent;
{ template <typename Time>
class Command; class TimeDependency;
} // end of namespace command.
namespace command {
} // end of namespace dynamicgraph. class Command;
} // end of namespace command.
#endif //! DYNAMIC_GRAPH_FWD_HH } // end of namespace dynamicgraph.
#endif //! DYNAMIC_GRAPH_FWD_HH