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 1205 additions and 428 deletions
......@@ -8,8 +8,8 @@
// Utility header files including all signal headers
#include <dynamic-graph/signal.h>
#include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h>
#include <dynamic-graph/signal.h>
#endif //! DYNAMIC_GRAPH_ALL_SIGNALS_H
......@@ -10,28 +10,30 @@
/* Create a command from a bind directly. Examples are:
* addCommand("myProcVoid",
* makeCommandVoid0(*this,&ClassName::functionNoArg,
* docCommandVoid0("Simple line doc here.")));
* makeCommandVoid0(*this,&ClassName::functionNoArg,
* docCommandVoid0("Simple line doc here.")));
* addCommand("myProcOneString",
* makeCommandVoid1(*this,&EntityName::functionOneStringArg,
* docCommandVoid1("Simple line doc here.",
* "string")));
* makeCommandVoid1(*this,&EntityName::functionOneStringArg,
* docCommandVoid1("Simple line doc here.",
* "string")));
*
*/
#include "dynamic-graph/command.h"
#include <boost/assign/list_of.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
/* --- FUNCTION 0 ARGS ------------------------------------------------------ */
#include "dynamic-graph/command.h"
/* --- FUNCTION 0 ARGS ----------------------------------------------------- */
namespace dynamicgraph {
namespace command {
template <class E>
struct CommandVoid0 : public Command {
CommandVoid0(E& entity, boost::function<void(void)> function, const std::string& docString)
CommandVoid0(E &entity, boost::function<void(void)> function,
const std::string &docString)
: Command(entity, EMPTY_ARG, docString), fptr(function) {}
protected:
......@@ -46,21 +48,26 @@ struct CommandVoid0 : public Command {
};
template <class E>
CommandVoid0<E>* makeCommandVoid0(E& entity, boost::function<void(void)> function, const std::string& docString) {
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(E*)> function, const std::string& docString) {
CommandVoid0<E> *makeCommandVoid0(E &entity,
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, void (E::*function)(void), const std::string& docString) {
CommandVoid0<E> *makeCommandVoid0(E &entity, void (E::*function)(void),
const std::string &docString) {
return new CommandVoid0<E>(entity, boost::bind(function, &entity), docString);
}
inline std::string docCommandVoid0(const std::string& doc) {
inline std::string docCommandVoid0(const std::string &doc) {
return std::string("\n") + doc + "\n\nNo input.\nVoid return.\n\n";
}
......@@ -73,12 +80,12 @@ namespace command {
template <class E, typename T>
struct CommandVoid1 : public Command {
typedef boost::function<void(const T&)> function_t;
typedef boost::function<void(E*, const T&)> memberFunction_t;
typedef void (E::*memberFunction_ptr_t)(const T&);
typedef boost::function<void(const T &)> function_t;
CommandVoid1(E& entity, function_t function, const std::string& docString)
: Command(entity, boost::assign::list_of(ValueHelper<T>::TypeID), docString), fptr(function) {}
CommandVoid1(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() {
......@@ -93,29 +100,36 @@ struct CommandVoid1 : public Command {
};
template <class E, typename T>
CommandVoid1<E, T>* makeCommandVoid1(E& entity, boost::function<void(const T&)> function,
// typename CommandVoid1<E,T>::function_t function ,
const std::string& docString) {
CommandVoid1<E, T> *makeCommandVoid1(
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,
// The following syntaxt don't compile when not specializing the template
// arg... why ???
// typename CommandVoid1<E,T>::memberFunction_t function ,
boost::function<void(E*, const T&)> function, const std::string& docString) {
return new CommandVoid1<E, T>(entity, boost::bind(function, &entity, _1), docString);
CommandVoid1<E, T> *makeCommandVoid1(
E &entity,
// The following syntaxt don't compile when not specializing
// the template arg... why ???
boost::function<void(E *, const T &)> function,
const std::string &docString) {
return new CommandVoid1<E, T>(entity, boost::bind(function, &entity, _1),
docString);
}
template <class E, typename T>
CommandVoid1<E, T>* makeCommandVoid1(E& entity, void (E::*function)(const T&), const std::string& docString) {
return new CommandVoid1<E, T>(entity, boost::bind(function, &entity, _1), docString);
CommandVoid1<E, T> *makeCommandVoid1(E &entity, void (E::*function)(const T &),
const std::string &docString) {
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";
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
......@@ -127,12 +141,13 @@ namespace command {
template <class E, typename T1, typename T2>
struct CommandVoid2 : public Command {
typedef boost::function<void(const T1&, const T2&)> function_t;
typedef boost::function<void(E*, const T1&, const T2&)> memberFunction_t;
typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&);
typedef boost::function<void(const T1 &, const T2 &)> function_t;
CommandVoid2(E& entity, function_t function, const std::string& docString)
: Command(entity, boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID), docString),
CommandVoid2(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:
......@@ -149,31 +164,38 @@ struct CommandVoid2 : public Command {
};
template <class E, typename T1, typename T2>
CommandVoid2<E, T1, T2>* makeCommandVoid2(E& entity, boost::function<void(const T1&, const T2&)> function,
const std::string& docString) {
CommandVoid2<E, T1, T2> *makeCommandVoid2(
E &entity, boost::function<void(const T1 &, const T2 &)> function,
const std::string &docString) {
return new CommandVoid2<E, T1, T2>(entity, function, docString);
}
template <class E, typename T1, typename T2>
CommandVoid2<E, T1, T2>* makeCommandVoid2(E& entity,
// The following syntaxt don't compile when not specializing the template
// arg... why ???
// typename CommandVoid2<E,T1,T2>::memberFunction_t function ,
boost::function<void(E*, const T1&, const T2&)> function,
const std::string& docString) {
return new CommandVoid2<E, T1, T2>(entity, boost::bind(function, &entity, _1, _2), docString);
CommandVoid2<E, T1, T2> *makeCommandVoid2(
E &entity,
// The following syntaxt don't compile when not specializing
// the template arg... why ???
boost::function<void(E *, const T1 &, const T2 &)> function,
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, void (E::*function)(const T1&, const T2&),
const std::string& docString) {
return new CommandVoid2<E, T1, T2>(entity, boost::bind(function, &entity, _1, _2), docString);
CommandVoid2<E, T1, T2> *makeCommandVoid2(E &entity,
void (E::*function)(const T1 &,
const T2 &),
const std::string &docString) {
return new CommandVoid2<E, T1, T2>(
entity, boost::bind(function, &entity, _1, _2), 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");
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
......@@ -185,13 +207,12 @@ namespace command {
template <class E, typename T1, typename T2, typename T3>
struct CommandVoid3 : public Command {
typedef boost::function<void(const T1&, const T2&, const T3&)> function_t;
typedef boost::function<void(E*, const T1&, const T2&, const T3&)> memberFunction_t;
typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&, const T3);
typedef boost::function<void(const T1 &, const T2 &, const T3 &)> function_t;
CommandVoid3(E& entity, function_t function, const std::string& docString)
CommandVoid3(E &entity, function_t function, const std::string &docString)
: Command(entity,
boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID),
boost::assign::list_of(ValueHelper<T1>::TypeID)(
ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID),
docString),
fptr(function) {}
......@@ -210,32 +231,39 @@ struct CommandVoid3 : public Command {
};
template <class E, typename T1, typename T2, typename T3>
CommandVoid3<E, T1, T2, T3>* makeCommandVoid3(E& entity, typename CommandVoid3<E, T1, T2, T3>::function_t function,
const std::string& docString) {
CommandVoid3<E, T1, T2, T3> *makeCommandVoid3(
E &entity, typename CommandVoid3<E, T1, T2, T3>::function_t function,
const std::string &docString) {
return new CommandVoid3<E, T1, T2, T3>(entity, function, docString);
}
template <class E, typename T1, typename T2, typename T3>
CommandVoid3<E, T1, T2, T3>* makeCommandVoid3(E& entity,
// The following syntaxt don't compile when not specializing the template
// arg... why ???
// typename CommandVoid3<E,T1,T2>::memberFunction_t function ,
boost::function<void(E*, const T1&, const T2&, const T3&)> function,
const std::string& docString) {
return new CommandVoid3<E, T1, T2, T3>(entity, boost::bind(function, &entity, _1, _2, _3), docString);
CommandVoid3<E, T1, T2, T3> *makeCommandVoid3(
E &entity,
// The following syntaxt don't compile when not specializing the template
// arg... why ???
boost::function<void(E *, const T1 &, const T2 &, const T3 &)> function,
const std::string &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>* makeCommandVoid3(E& entity, void (E::*function)(const T1&, const T2&, const T3&),
const std::string& docString) {
return new CommandVoid3<E, T1, T2, T3>(entity, boost::bind(function, &entity, _1, _2, _3), docString);
CommandVoid3<E, T1, T2, T3> *makeCommandVoid3(
E &entity, void (E::*function)(const T1 &, const T2 &, const T3 &),
const std::string &docString) {
return new CommandVoid3<E, T1, T2, T3>(
entity, boost::bind(function, &entity, _1, _2, _3), 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");
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
......@@ -247,13 +275,15 @@ namespace command {
template <class E, typename T1, typename T2, typename T3, typename T4>
struct CommandVoid4 : public Command {
typedef boost::function<void(const T1&, const T2&, const T3&, const T4&)> function_t;
typedef boost::function<void(E*, const T1&, const T2&, const T3&, const T4&)> memberFunction_t;
typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&, const T3&, const T4&);
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 &,
const T4 &);
CommandVoid4(E& entity, function_t function, const std::string& docString)
CommandVoid4(E &entity, function_t function, const std::string &docString)
: Command(entity,
boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
boost::assign::list_of(ValueHelper<T1>::TypeID)(
ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
ValueHelper<T4>::TypeID),
docString),
fptr(function) {}
......@@ -274,31 +304,400 @@ struct CommandVoid4 : public Command {
};
template <class E, typename T1, typename T2, typename T3, typename T4>
CommandVoid4<E, T1, T2, T3, T4>* makeCommandVoid4(E& entity,
typename CommandVoid4<E, T1, T2, T3, T4>::function_t function,
const std::string& docString) {
CommandVoid4<E, T1, T2, T3, T4> *makeCommandVoid4(
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>* makeCommandVoid4(
E& entity, boost::function<void(E*, const T1&, const T2&, const T3&, const T4&)> function,
const std::string& docString) {
return new CommandVoid4<E, T1, T2, T3, T4>(entity, boost::bind(function, &entity, _1, _2, _3, _4), docString);
CommandVoid4<E, T1, T2, T3, T4> *makeCommandVoid4(
E &entity,
boost::function<void(E *, const T1 &, const T2 &, const T3 &, const T4 &)>
function,
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,
void (E::*function)(const T1&, const T2&, const T3&, const T4&),
const std::string& docString) {
return new CommandVoid4<E, T1, T2, T3, T4>(entity, boost::bind(function, &entity, _1, _2, _3, _4), docString);
CommandVoid4<E, T1, T2, T3, T4> *makeCommandVoid4(
E &entity,
void (E::*function)(const T1 &, const T2 &, const T3 &, const T4 &),
const std::string &docString) {
return new CommandVoid4<E, T1, T2, T3, T4>(
entity, boost::bind(function, &entity, _1, _2, _3, _4), docString);
return NULL;
}
inline std::string docCommandVoid4(const std::string &doc,
const std::string &type1,
const std::string &type2,
const std::string &type3,
const std::string &type4) {
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" + "Void return.\n\n");
}
} // namespace command
} // namespace dynamicgraph
/* --- FUNCTION 5 ARGS ------------------------------------------------------ */
namespace dynamicgraph {
namespace command {
template <class E, typename T1, typename T2, typename T3, typename T4,
typename T5>
struct CommandVoid5 : public Command {
typedef boost::function<void(const T1 &, const T2 &, const T3 &, const T4 &,
const T5 &)>
function_t;
typedef void (E::*memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &,
const T4 &, const T5 &);
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 docCommandVoid4(const std::string& doc, const std::string& type1, const std::string& type2,
const std::string& type3, const std::string& type4) {
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" + "Void return.\n\n");
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
......@@ -310,15 +709,11 @@ inline std::string docCommandVoid4(const std::string& doc, const std::string& ty
namespace dynamicgraph {
namespace command {
template <class E>
struct CommandVerbose : public Command {
typedef boost::function<void(std::ostream&)> function_t;
typedef boost::function<void(E*, std::ostream&)> memberFunction_t;
typedef void (E::*memberFunctionConst_ptr_t)(std::ostream&) const;
typedef void (E::*memberFunction_ptr_t)(std::ostream&);
typedef boost::function<void(std::ostream &)> function_t;
CommandVerbose(E& entity, function_t function, const std::string& docString)
CommandVerbose(E &entity, function_t function, const std::string &docString)
: Command(entity, EMPTY_ARG, docString), fptr(function) {}
protected:
......@@ -334,30 +729,205 @@ struct CommandVerbose : public Command {
};
template <class E>
CommandVerbose<E>* makeCommandVerbose(E& entity, typename CommandVerbose<E>::function_t function,
const std::string& docString) {
CommandVerbose<E> *makeCommandVerbose(
E &entity, typename CommandVerbose<E>::function_t function,
const std::string &docString) {
return new CommandVerbose<E>(entity, function, docString);
return NULL;
}
template <class E>
CommandVerbose<E>* makeCommandVerbose(E& entity,
// void (E::*function) (std::ostream&) const,
typename CommandVerbose<E>::memberFunctionConst_ptr_t function,
const std::string& docString) {
return new CommandVerbose<E>(entity, boost::bind(function, &entity, _1), docString);
CommandVerbose<E> *makeCommandVerbose(E &entity,
void (E::*function)(std::ostream &),
const std::string &docString) {
return new CommandVerbose<E>(entity, boost::bind(function, &entity, _1),
docString);
return NULL;
}
template <class E>
CommandVerbose<E>* makeCommandVerbose(E& entity, typename CommandVerbose<E>::memberFunction_ptr_t function,
const std::string& docString) {
return new CommandVerbose<E>(entity, boost::bind(function, &entity, _1), docString);
inline std::string docCommandVerbose(const std::string &doc) {
return std::string("\n") + doc + "\n\nNo input.\n Return a string.\n\n";
}
/*************************/
/* Template return types */
/*************************/
template <class E, class ReturnType>
struct CommandReturnType0 : public Command {
CommandReturnType0(E &entity, boost::function<ReturnType(void)> function,
const std::string &docString)
: Command(entity, EMPTY_ARG, docString), fptr(function) {}
protected:
virtual Value doExecute() {
assert(getParameterValues().size() == 0);
Value res(fptr());
return res;
}
private:
boost::function<ReturnType(void)> fptr;
};
template <class E, class ReturnType>
CommandReturnType0<E, ReturnType> *makeCommandReturnType0(
E &entity, boost::function<ReturnType(void)> function,
const std::string &docString) {
return new CommandReturnType0<E, ReturnType>(entity, function, docString);
}
template <class E, class ReturnType>
CommandReturnType0<E, ReturnType> *makeCommandReturnType0(
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;
}
inline std::string docCommandVerbose(const std::string& doc) {
return std::string("\n") + doc + "\n\nNo input.\n Return a string.\n\n";
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
......
......@@ -15,9 +15,10 @@
*
*/
#include "dynamic-graph/command.h"
#include <boost/assign/list_of.hpp>
#include "dynamic-graph/command.h"
/* --- GETTER --------------------------------------------------------- */
namespace dynamicgraph {
namespace command {
......@@ -29,23 +30,26 @@ class DirectGetter : public Command {
typedef T (E::*GetterMethod)() const;
/// Constructor
DirectGetter(E& entity, T* ptr, const std::string& docString)
DirectGetter(E &entity, T *ptr, const std::string &docString)
: Command(entity, std::vector<Value::Type>(), docString), T_ptr(ptr) {}
protected:
virtual Value doExecute() { return Value(*T_ptr); }
private:
T* T_ptr;
T *T_ptr;
};
template <class E, typename T>
DirectGetter<E, T>* makeDirectGetter(E& entity, T* ptr, const std::string& docString) {
DirectGetter<E, T> *makeDirectGetter(E &entity, T *ptr,
const std::string &docString) {
return new DirectGetter<E, T>(entity, ptr, docString);
}
inline std::string docDirectGetter(const std::string& name, const std::string& type) {
return std::string("\nGet the ") + name + ".\n\nNo input.\nReturn an " + type + ".\n\n";
inline std::string docDirectGetter(const std::string &name,
const std::string &type) {
return std::string("\nGet the ") + name + ".\n\nNo input.\nReturn an " +
type + ".\n\n";
}
} // namespace command
......
......@@ -15,9 +15,10 @@
*
*/
#include "dynamic-graph/command.h"
#include <boost/assign/list_of.hpp>
#include "dynamic-graph/command.h"
/* --- SETTER --------------------------------------------------------- */
namespace dynamicgraph {
namespace command {
......@@ -25,28 +26,33 @@ namespace command {
template <class E, typename T>
class DirectSetter : public Command {
public:
DirectSetter(E& entity, T* ptr, const std::string& docString)
: Command(entity, boost::assign::list_of(ValueHelper<T>::TypeID), docString), T_ptr(ptr) {}
DirectSetter(E &entity, T *ptr, const std::string &docString)
: Command(entity, boost::assign::list_of(ValueHelper<T>::TypeID),
docString),
T_ptr(ptr) {}
protected:
virtual Value doExecute() {
const std::vector<Value>& values = getParameterValues();
const std::vector<Value> &values = getParameterValues();
T val = values[0].value();
(*T_ptr) = val;
return Value(); // void
}
private:
T* T_ptr;
T *T_ptr;
};
template <class E, typename T>
DirectSetter<E, T>* makeDirectSetter(E& entity, T* ptr, const std::string& docString) {
DirectSetter<E, T> *makeDirectSetter(E &entity, T *ptr,
const std::string &docString) {
return new DirectSetter<E, T>(entity, ptr, docString);
}
inline std::string docDirectSetter(const std::string& name, const std::string& type) {
return std::string("\nSet the ") + name + ".\n\nInput:\n - a " + type + ".\nVoid return.\n\n";
inline std::string docDirectSetter(const std::string &name,
const std::string &type) {
return std::string("\nSet the ") + name + ".\n\nInput:\n - a " + type +
".\nVoid return.\n\n";
}
} // namespace command
......
......@@ -47,7 +47,7 @@ class Getter : public Command {
/// Pointer to method that sets parameter of type T
typedef T (E::*GetterMethod)() const;
/// Constructor
Getter(E& entity, GetterMethod getterMethod, const std::string& docString);
Getter(E &entity, GetterMethod getterMethod, const std::string &docString);
protected:
virtual Value doExecute();
......
......@@ -7,6 +7,8 @@
#ifndef DYNAMIC_GRAPH_COMMAND_GETTER_T_CPP
#define DYNAMIC_GRAPH_COMMAND_GETTER_T_CPP
#include "dynamic-graph/command-getter.h"
#include <sstream>
namespace dynamicgraph {
......@@ -14,12 +16,14 @@ class Entity;
namespace command {
template <class E, typename T>
Getter<E, T>::Getter(E& entity, GetterMethod getterMethod, const std::string& docstring)
: Command(entity, std::vector<Value::Type>(), docstring), getterMethod_(getterMethod) {}
Getter<E, T>::Getter(E &entity, GetterMethod getterMethod,
const std::string &docstring)
: Command(entity, std::vector<Value::Type>(), docstring),
getterMethod_(getterMethod) {}
template <class E, typename T>
Value Getter<E, T>::doExecute() {
E& entity = static_cast<E&>(owner());
E &entity = static_cast<E &>(owner());
T value = (entity.*getterMethod_)();
return Value(value);
}
......
......@@ -45,9 +45,9 @@ template <class E, typename T>
class Setter : public Command {
public:
/// Pointer to method that sets parameter of type T
typedef void (E::*SetterMethod)(const T&);
typedef void (E::*SetterMethod)(const T &);
/// Constructor
Setter(E& entity, SetterMethod setterMethod, const std::string& docString);
Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
protected:
virtual Value doExecute();
......
......@@ -7,8 +7,11 @@
#ifndef DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP
#define DYNAMIC_GRAPH_COMMAND_SETTER_T_CPP
#include <sstream>
#include "dynamic-graph/command-setter.h"
#include <boost/assign/list_of.hpp>
#include <sstream>
#include "dynamic-graph/linear-algebra.h"
namespace dynamicgraph {
......@@ -22,9 +25,9 @@ template <class E>
class Setter<E, bool> : public Command {
public:
/// Pointer to method that sets parameter of type bool
typedef void (E::*SetterMethod)(const bool&);
typedef void (E::*SetterMethod)(const bool &);
/// Constructor
Setter(E& entity, SetterMethod setterMethod, const std::string& docString);
Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
protected:
virtual Value doExecute();
......@@ -34,15 +37,17 @@ class Setter<E, bool> : public Command {
}; // Class Setter
template <class E>
Setter<E, bool>::Setter(E& entity, SetterMethod setterMethod, const std::string& docString)
: Command(entity, boost::assign::list_of(Value::BOOL), docString), setterMethod_(setterMethod) {}
Setter<E, bool>::Setter(E &entity, SetterMethod setterMethod,
const std::string &docString)
: Command(entity, boost::assign::list_of(Value::BOOL), docString),
setterMethod_(setterMethod) {}
template <class E>
Value Setter<E, bool>::doExecute() {
const std::vector<Value>& values = getParameterValues();
const std::vector<Value> &values = getParameterValues();
// Get parameter
bool value = values[0].value();
E& entity = static_cast<E&>(owner());
E &entity = static_cast<E &>(owner());
(entity.*setterMethod_)(value);
return Value();
}
......@@ -54,9 +59,9 @@ template <class E>
class Setter<E, unsigned> : public Command {
public:
/// Pointer to method that sets parameter of type unsigned
typedef void (E::*SetterMethod)(const unsigned&);
typedef void (E::*SetterMethod)(const unsigned &);
/// Constructor
Setter(E& entity, SetterMethod setterMethod, const std::string& docString);
Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
protected:
virtual Value doExecute();
......@@ -66,15 +71,17 @@ class Setter<E, unsigned> : public Command {
}; // Class Setter
template <class E>
Setter<E, unsigned>::Setter(E& entity, SetterMethod setterMethod, const std::string& docString)
: Command(entity, boost::assign::list_of(Value::UNSIGNED), docString), setterMethod_(setterMethod) {}
Setter<E, unsigned>::Setter(E &entity, SetterMethod setterMethod,
const std::string &docString)
: Command(entity, boost::assign::list_of(Value::UNSIGNED), docString),
setterMethod_(setterMethod) {}
template <class E>
Value Setter<E, unsigned>::doExecute() {
const std::vector<Value>& values = getParameterValues();
const std::vector<Value> &values = getParameterValues();
// Get parameter
unsigned value = values[0].value();
E& entity = static_cast<E&>(owner());
E &entity = static_cast<E &>(owner());
(entity.*setterMethod_)(value);
return Value();
}
......@@ -86,9 +93,9 @@ template <class E>
class Setter<E, int> : public Command {
public:
/// Pointer to method that sets parameter of type int
typedef void (E::*SetterMethod)(const int&);
typedef void (E::*SetterMethod)(const int &);
/// Constructor
Setter(E& entity, SetterMethod setterMethod, const std::string& docString);
Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
protected:
virtual Value doExecute();
......@@ -98,15 +105,17 @@ class Setter<E, int> : public Command {
}; // Class Setter
template <class E>
Setter<E, int>::Setter(E& entity, SetterMethod setterMethod, const std::string& docString)
: Command(entity, boost::assign::list_of(Value::INT), docString), setterMethod_(setterMethod) {}
Setter<E, int>::Setter(E &entity, SetterMethod setterMethod,
const std::string &docString)
: Command(entity, boost::assign::list_of(Value::INT), docString),
setterMethod_(setterMethod) {}
template <class E>
Value Setter<E, int>::doExecute() {
const std::vector<Value>& values = getParameterValues();
const std::vector<Value> &values = getParameterValues();
// Get parameter
int value = values[0].value();
E& entity = static_cast<E&>(owner());
E &entity = static_cast<E &>(owner());
(entity.*setterMethod_)(value);
return Value();
}
......@@ -118,9 +127,9 @@ template <class E>
class Setter<E, float> : public Command {
public:
/// Pointer to method that sets parameter of type float
typedef void (E::*SetterMethod)(const float&);
typedef void (E::*SetterMethod)(const float &);
/// Constructor
Setter(E& entity, SetterMethod setterMethod, const std::string& docString);
Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
protected:
virtual Value doExecute();
......@@ -130,15 +139,17 @@ class Setter<E, float> : public Command {
}; // Class Setter
template <class E>
Setter<E, float>::Setter(E& entity, SetterMethod setterMethod, const std::string& docString)
: Command(entity, boost::assign::list_of(Value::FLOAT), docString), setterMethod_(setterMethod) {}
Setter<E, float>::Setter(E &entity, SetterMethod setterMethod,
const std::string &docString)
: Command(entity, boost::assign::list_of(Value::FLOAT), docString),
setterMethod_(setterMethod) {}
template <class E>
Value Setter<E, float>::doExecute() {
const std::vector<Value>& values = getParameterValues();
const std::vector<Value> &values = getParameterValues();
// Get parameter
float value = values[0].value();
E& entity = static_cast<E&>(owner());
E &entity = static_cast<E &>(owner());
(entity.*setterMethod_)(value);
return Value();
}
......@@ -150,9 +161,9 @@ template <class E>
class Setter<E, double> : public Command {
public:
/// Pointer to method that sets parameter of type double
typedef void (E::*SetterMethod)(const double&);
typedef void (E::*SetterMethod)(const double &);
/// Constructor
Setter(E& entity, SetterMethod setterMethod, const std::string& docString);
Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
protected:
virtual Value doExecute();
......@@ -162,15 +173,17 @@ class Setter<E, double> : public Command {
}; // Class Setter
template <class E>
Setter<E, double>::Setter(E& entity, SetterMethod setterMethod, const std::string& docString)
: Command(entity, boost::assign::list_of(Value::DOUBLE), docString), setterMethod_(setterMethod) {}
Setter<E, double>::Setter(E &entity, SetterMethod setterMethod,
const std::string &docString)
: Command(entity, boost::assign::list_of(Value::DOUBLE), docString),
setterMethod_(setterMethod) {}
template <class E>
Value Setter<E, double>::doExecute() {
const std::vector<Value>& values = getParameterValues();
const std::vector<Value> &values = getParameterValues();
// Get parameter
double value = values[0].value();
E& entity = static_cast<E&>(owner());
E &entity = static_cast<E &>(owner());
(entity.*setterMethod_)(value);
return Value();
}
......@@ -182,9 +195,9 @@ template <class E>
class Setter<E, std::string> : public Command {
public:
/// Pointer to method that sets parameter of type std::string
typedef void (E::*SetterMethod)(const std::string&);
typedef void (E::*SetterMethod)(const std::string &);
/// Constructor
Setter(E& entity, SetterMethod setterMethod, const std::string& docString);
Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
protected:
virtual Value doExecute();
......@@ -194,15 +207,17 @@ class Setter<E, std::string> : public Command {
}; // Class Setter
template <class E>
Setter<E, std::string>::Setter(E& entity, SetterMethod setterMethod, const std::string& docString)
: Command(entity, boost::assign::list_of(Value::STRING), docString), setterMethod_(setterMethod) {}
Setter<E, std::string>::Setter(E &entity, SetterMethod setterMethod,
const std::string &docString)
: Command(entity, boost::assign::list_of(Value::STRING), docString),
setterMethod_(setterMethod) {}
template <class E>
Value Setter<E, std::string>::doExecute() {
const std::vector<Value>& values = getParameterValues();
const std::vector<Value> &values = getParameterValues();
// Get parameter
std::string value = values[0].value();
E& entity = static_cast<E&>(owner());
E &entity = static_cast<E &>(owner());
(entity.*setterMethod_)(value);
return Value();
}
......@@ -214,9 +229,9 @@ template <class E>
class Setter<E, Vector> : public Command {
public:
/// Pointer to method that sets parameter of type Vector
typedef void (E::*SetterMethod)(const Vector&);
typedef void (E::*SetterMethod)(const Vector &);
/// Constructor
Setter(E& entity, SetterMethod setterMethod, const std::string& docString);
Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
protected:
virtual Value doExecute();
......@@ -226,15 +241,17 @@ class Setter<E, Vector> : public Command {
}; // Class Setter
template <class E>
Setter<E, Vector>::Setter(E& entity, SetterMethod setterMethod, const std::string& docString)
: Command(entity, boost::assign::list_of(Value::VECTOR), docString), setterMethod_(setterMethod) {}
Setter<E, Vector>::Setter(E &entity, SetterMethod setterMethod,
const std::string &docString)
: Command(entity, boost::assign::list_of(Value::VECTOR), docString),
setterMethod_(setterMethod) {}
template <class E>
Value Setter<E, Vector>::doExecute() {
const std::vector<Value>& values = getParameterValues();
const std::vector<Value> &values = getParameterValues();
// Get parameter
Vector value = values[0].value();
E& entity = static_cast<E&>(owner());
E &entity = static_cast<E &>(owner());
(entity.*setterMethod_)(value);
return Value();
}
......@@ -246,9 +263,9 @@ template <class E>
class Setter<E, Matrix> : public Command {
public:
/// Pointer to method that sets parameter of type Matrix
typedef void (E::*SetterMethod)(const Matrix&);
typedef void (E::*SetterMethod)(const Matrix &);
/// Constructor
Setter(E& entity, SetterMethod setterMethod, const std::string& docString);
Setter(E &entity, SetterMethod setterMethod, const std::string &docString);
protected:
virtual Value doExecute();
......@@ -258,15 +275,17 @@ class Setter<E, Matrix> : public Command {
}; // 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) {}
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();
const std::vector<Value> &values = getParameterValues();
// Get parameter
Matrix value = values[0].value();
E& entity = static_cast<E&>(owner());
E &entity = static_cast<E &>(owner());
(entity.*setterMethod_)(value);
return Value();
}
......
......@@ -8,15 +8,18 @@
#define DYNAMIC_GRAPH_COMMAND_H
#include <vector>
#include "dynamic-graph/value.h"
#include "dynamic-graph/dynamic-graph-api.h"
#include "dynamic-graph/value.h"
namespace dynamicgraph {
class Entity;
namespace command {
/// \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
/// python script.
///
/// A command
/// \li is owned by an entity,
......@@ -36,17 +39,18 @@ class DYNAMIC_GRAPH_DLLAPI Command {
/// \param entity reference to Entity owning this command.
/// \param valueTypes vector specifying the number and types of parameters
/// \param docstring documentation of the command
Command(Entity& entity, const std::vector<Value::Type>& valueTypes, const std::string& docstring);
Command(Entity &entity, const std::vector<Value::Type> &valueTypes,
const std::string &docstring);
/// Return the value type of all parameters
const std::vector<Value::Type>& valueTypes() const;
const std::vector<Value::Type> &valueTypes() const;
/// Set parameter values
void setParameterValues(const std::vector<Value>& values);
void setParameterValues(const std::vector<Value> &values);
/// Get parameter values
const std::vector<Value>& getParameterValues() const;
const std::vector<Value> &getParameterValues() const;
/// Execute the command after checking parameters
Value execute();
/// Get a reference to the Entity owning this command
Entity& owner();
Entity &owner();
/// Get documentation string
std::string getDocstring() const;
......@@ -55,7 +59,7 @@ class DYNAMIC_GRAPH_DLLAPI Command {
virtual Value doExecute() = 0;
private:
Entity& owner_;
Entity &owner_;
std::vector<Value::Type> valueTypeVector_;
std::vector<Value> valueVector_;
std::string docstring_;
......
......@@ -5,14 +5,14 @@
#ifndef DYNAMIC_GRAPH_DEBUG_HH
#define DYNAMIC_GRAPH_DEBUG_HH
#include <cstdio>
#include <dynamic-graph/dynamic-graph-api.h>
#include <cstdarg>
#include <cstdio>
#include <dynamic-graph/fwd.hh>
#include <fstream>
#include <sstream>
#include <dynamic-graph/fwd.hh>
#include <dynamic-graph/dynamic-graph-api.h>
#ifndef VP_DEBUG_MODE
#define VP_DEBUG_MODE 0
#endif //! VP_DEBUG_MODE
......@@ -42,19 +42,19 @@ class DYNAMIC_GRAPH_DLLAPI DebugTrace {
static const int SIZE = 512;
std::stringstream tmpbuffer;
std::ostream& outputbuffer;
std::ostream &outputbuffer;
char charbuffer[SIZE + 1];
int traceLevel;
int traceLevelTemplate;
DebugTrace(std::ostream& os) : outputbuffer(os) {}
DebugTrace(std::ostream &os) : outputbuffer(os) {}
inline void trace(const int level, const char* format, ...) {
inline void trace(const int level, const char *format, ...) {
if (level <= traceLevel) DG_COMMON_TRACES;
tmpbuffer.str("");
}
inline void trace(const char* format, ...) {
inline void trace(const char *format, ...) {
DG_COMMON_TRACES;
tmpbuffer.str("");
}
......@@ -66,26 +66,26 @@ class DYNAMIC_GRAPH_DLLAPI DebugTrace {
}
}
inline void traceTemplate(const int level, const char* format, ...) {
inline void traceTemplate(const int level, const char *format, ...) {
if (level <= traceLevelTemplate) DG_COMMON_TRACES;
tmpbuffer.str("");
}
inline void traceTemplate(const char* format, ...) {
inline void traceTemplate(const char *format, ...) {
DG_COMMON_TRACES;
tmpbuffer.str("");
}
inline DebugTrace& pre(const std::ostream&) { return *this; }
inline DebugTrace &pre(const std::ostream &) { return *this; }
inline DebugTrace& pre(const std::ostream&, int level) {
inline DebugTrace &pre(const std::ostream &, int level) {
traceLevel = level;
return *this;
}
static const char* DEBUG_FILENAME_DEFAULT;
static void openFile(const char* filename = DEBUG_FILENAME_DEFAULT);
static void closeFile(const char* filename = DEBUG_FILENAME_DEFAULT);
static const char *DEBUG_FILENAME_DEFAULT;
static void openFile(const char *filename = DEBUG_FILENAME_DEFAULT);
static void closeFile(const char *filename = DEBUG_FILENAME_DEFAULT);
};
DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgDEBUGFLOW;
......@@ -95,7 +95,8 @@ DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgERRORFLOW;
#ifdef VP_DEBUG
#define dgPREDEBUG __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
#define dgPREERROR "\t!! " << __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
#define dgPREERROR \
"\t!! " << __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
#define dgDEBUG(level) \
if ((level > VP_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good())) \
......@@ -134,19 +135,24 @@ DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgERRORFLOW;
else \
dgDEBUGFLOW.outputbuffer << dgPREDEBUG
#define dgTDEBUGF \
if (!dgDEBUGFLOW.outputbuffer.good()) \
; \
else \
dgDEBUGFLOW.pre(dgDEBUGFLOW.tmpbuffer << dgPREDEBUG, VP_TEMPLATE_DEBUG_MODE).trace
#define dgTDEBUGF \
if (!dgDEBUGFLOW.outputbuffer.good()) \
; \
else \
dgDEBUGFLOW \
.pre(dgDEBUGFLOW.tmpbuffer << dgPREDEBUG, VP_TEMPLATE_DEBUG_MODE) \
.trace
inline bool dgDEBUG_ENABLE(const int& level) { return level <= VP_DEBUG_MODE; }
inline bool dgDEBUG_ENABLE(const int &level) { return level <= VP_DEBUG_MODE; }
inline bool dgTDEBUG_ENABLE(const int& level) { return level <= VP_TEMPLATE_DEBUG_MODE; }
inline bool dgTDEBUG_ENABLE(const int &level) {
return level <= VP_TEMPLATE_DEBUG_MODE;
}
#else // VP_DEBUG
#define dgPREERROR "\t!! " << __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
#define dgPREERROR \
"\t!! " << __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
#define dgDEBUG(level) \
if (1) \
......@@ -160,16 +166,16 @@ inline bool dgTDEBUG_ENABLE(const int& level) { return level <= VP_TEMPLATE_DEBU
#define dgERROR dgERRORFLOW.outputbuffer << dgPREERROR
inline void dgDEBUGF(const int, const char*, ...) { return; }
inline void dgDEBUGF(const int, const char *, ...) { return; }
inline void dgDEBUGF(const char*, ...) { return; }
inline void dgDEBUGF(const char *, ...) { return; }
inline void dgERRORF(const int, const char*, ...) { return; }
inline void dgERRORF(const int, const char *, ...) { return; }
inline void dgERRORF(const char*, ...) { return; }
inline void dgERRORF(const char *, ...) { return; }
namespace dynamicgraph {
inline std::ostream& __null_stream() {
inline std::ostream &__null_stream() {
// This function should never be called. With -O3,
// it should not appear in the generated binary.
static std::ostream os(NULL);
......@@ -184,9 +190,9 @@ inline std::ostream& __null_stream() {
else \
::dynamicgraph::__null_stream()
inline void dgTDEBUGF(const int, const char*, ...) { return; }
inline void dgTDEBUGF(const int, const char *, ...) { return; }
inline void dgTDEBUGF(const char*, ...) { return; }
inline void dgTDEBUGF(const char *, ...) { return; }
#define dgDEBUG_ENABLE(level) false
#define dgTDEBUG_ENABLE(level) false
......
......@@ -7,12 +7,12 @@
#ifndef DYNAMIC_GRAPH_EIGEN_IO_H
#define DYNAMIC_GRAPH_EIGEN_IO_H
#include <boost/format.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <dynamic-graph/exception-signal.h>
#include <dynamic-graph/linear-algebra.h>
#include <Eigen/Geometry>
#include <boost/format.hpp>
#include <boost/numeric/conversion/cast.hpp>
using dynamicgraph::ExceptionSignal;
......@@ -27,11 +27,14 @@ using dynamicgraph::ExceptionSignal;
namespace Eigen {
typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE eigen_index;
inline std::istringstream &operator>>(std::istringstream &iss, dynamicgraph::Vector &inst) {
inline std::istringstream &operator>>(std::istringstream &iss,
dynamicgraph::Vector &inst) {
unsigned int _size;
double _dbl_val;
char _ch;
boost::format fmt("Failed to enter %s as vector. Reenter as [N](val1,val2,val3,...,valN)");
boost::format fmt(
"Failed to enter %s as vector."
" Reenter as [N](val1,val2,val3,...,valN)");
fmt % iss.str();
if (iss >> _ch && _ch != '[') {
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
......@@ -51,7 +54,8 @@ inline std::istringstream &operator>>(std::istringstream &iss, dynamicgraph::Vec
if (iss.peek() == ',' || iss.peek() == ' ') iss.ignore();
inst(i) = _dbl_val;
}
if (iss >> _ch && _ch != ')') throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
if (iss >> _ch && _ch != ')')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
}
}
}
......@@ -60,18 +64,22 @@ inline std::istringstream &operator>>(std::istringstream &iss, dynamicgraph::Vec
/* \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),...,
* (valM1,valM2,...,valMN))
* e.g. [2,5]((1 23 32.2 12.12 32),(2 32 23 92.01 19.2))
*/
template <typename Derived>
inline std::istringstream &operator>>(std::istringstream &iss, DenseBase<Derived> &inst) {
inline std::istringstream &operator>>(std::istringstream &iss,
DenseBase<Derived> &inst) {
unsigned int _colsize;
unsigned int _rowsize;
double _dbl_val;
char _ch;
boost::format fmt(
"Failed to enter %s as matrix. Reenter as ((val11,val12,val13,...,val1N),...,(valM1,valM2,...,valMN))");
"Failed to enter %s as matrix. Reenter as "
"((val11,val12,val13,...,val1N),"
"...,(valM1,valM2,...,valMN))");
MatrixXd _tmp_matrix;
fmt % iss.str();
if (iss >> _ch && _ch != '[') {
......@@ -91,16 +99,19 @@ inline std::istringstream &operator>>(std::istringstream &iss, DenseBase<Derived
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
else {
for (unsigned int j = 0; j < _rowsize; j++) {
if (iss >> _ch && _ch != '(') throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
if (iss >> _ch && _ch != '(')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
for (unsigned int i = 0; i < _colsize; i++) {
iss >> _dbl_val;
if (iss.peek() == ',' || iss.peek() == ' ') iss.ignore();
_tmp_matrix(j, i) = _dbl_val;
}
if (iss >> _ch && _ch != ')') throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
if (iss >> _ch && _ch != ')')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
if (iss.peek() == ',' || iss.peek() == ' ') iss.ignore();
}
if (iss >> _ch && _ch != ')') throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
if (iss >> _ch && _ch != ')')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
}
}
}
......@@ -109,7 +120,8 @@ inline std::istringstream &operator>>(std::istringstream &iss, DenseBase<Derived
return iss;
}
inline std::istringstream &operator>>(std::istringstream &iss, Transform<double, 3, Affine> &inst) {
inline std::istringstream &operator>>(std::istringstream &iss,
Transform<double, 3, Affine> &inst) {
MatrixXd M;
iss >> M;
inst.matrix() = M;
......@@ -118,12 +130,15 @@ inline std::istringstream &operator>>(std::istringstream &iss, Transform<double,
/* \brief Eigen Homogeneous Matrix output
*
* Matrix format: [M,N]((val11,val12,val13,...,val1N),...,(valM1,valM2,...,valMN))
* Matrix format: [M,N]((val11,val12,val13,...,val1N),...,
* (valM1,valM2,...,valMN))
* e.g. [2,5]((1 23 32.2 12.12 32),(2 32 23 92.01 19.2))
*/
inline std::ostream &operator<<(std::ostream &os, Transform<double, 3, Affine> MH) {
IOFormat boostFmt(StreamPrecision, DontAlignCols, ",", ",", "(", ")", "(", ")");
inline std::ostream &operator<<(std::ostream &os,
Transform<double, 3, Affine> MH) {
IOFormat boostFmt(StreamPrecision, DontAlignCols, ",", ",", "(", ")", "(",
")");
os << "[4,4]" << MH.matrix().format(boostFmt);
return os;
......@@ -137,7 +152,8 @@ inline std::ostream &operator<<(std::ostream &os, AngleAxisd quat) {
return os;
}
inline std::istringstream &operator>>(std::istringstream &iss, AngleAxisd &inst) {
inline std::istringstream &operator>>(std::istringstream &iss,
AngleAxisd &inst) {
VectorXd v(4);
iss >> v;
inst.angle() = v(0);
......
......@@ -5,19 +5,18 @@
#ifndef DYNAMIC_GRAPH_ENTITY_H
#define DYNAMIC_GRAPH_ENTITY_H
#include <iosfwd>
#include <map>
#include <sstream>
#include <string>
#include <boost/noncopyable.hpp>
#include <dynamic-graph/fwd.hh>
#include <dynamic-graph/dynamic-graph-api.h>
#include <dynamic-graph/exception-factory.h>
#include <dynamic-graph/logger.h>
#include <dynamic-graph/signal-array.h>
#include <dynamic-graph/signal-base.h>
#include <dynamic-graph/logger.h>
#include <boost/noncopyable.hpp>
#include <dynamic-graph/fwd.hh>
#include <iosfwd>
#include <map>
#include <sstream>
#include <string>
/// \brief Helper macro for entity declaration.
///
......@@ -38,7 +37,7 @@
/// this macro are correctly initialized.
#define DYNAMIC_GRAPH_ENTITY_DECL() \
public: \
virtual const std::string& getClassName() const { return CLASS_NAME; } \
virtual const std::string &getClassName() const { return CLASS_NAME; } \
static const std::string CLASS_NAME
namespace dynamicgraph {
......@@ -52,41 +51,94 @@ namespace dynamicgraph {
/// DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN macro in factory.h.
class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable {
public:
typedef std::map<std::string, SignalBase<int>*> SignalMap;
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);
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 { return name; }
virtual const std::string &getClassName() const {
static std::string ret("Entity");
return ret;
}
/** \brief Returns the Entity documentation
\return The documentation is provided as std::string object.
*/
virtual std::string getDocString() const;
bool hasSignal(const std::string& signame) const;
SignalBase<int>& getSignal(const std::string& signalName);
const SignalBase<int>& getSignal(const std::string& signalName) const;
std::ostream& displaySignalList(std::ostream& os) const;
virtual std::ostream& writeGraph(std::ostream& os) const;
virtual std::ostream& writeCompletionList(std::ostream& os) const;
virtual void display(std::ostream& os) const;
virtual SignalBase<int>* test() { return 0; }
virtual void test2(SignalBase<int>*) { return; }
const std::string& getCommandList() const;
/** \brief Test if a signal of name signame is present.
\return True if the signal is present, False otherwise
*/
bool hasSignal(const std::string &signame) const;
/** \brief Provides a reference to the signal named signalName.
\param signalName: Name of the signal
\return A reference to the signal with a temporal dependency.
*/
SignalBase<int> &getSignal(const std::string &signalName);
/** \brief Provides a const reference to the signal named signalName.
\param signalName: Name of the signal
\return A const reference to the signal with a temporal dependency.
*/
const SignalBase<int> &getSignal(const std::string &signalName) const;
/** \brief Display the list of signals of this entity in output stream os.
\param os: the output stream where to display the list of signals.
\returns The output stream given in parameter.
*/
std::ostream &displaySignalList(std::ostream &os) const;
/** \brief This method is used to write down in os the edges of the graph
by calling the signals writeGraph method.
\param os: The output stream where to write the informations.
\return os: The output stream.
*/
virtual std::ostream &writeGraph(std::ostream &os) const;
/** \brief This method is used write in the output stream os the
signals names and the commands of the entity.
\param os: The output stream where to write the list of objects
related to the entity.
*/
virtual std::ostream &writeCompletionList(std::ostream &os) const;
/** \brief Display information on the entity inside the output stream os.
*/
virtual void display(std::ostream &os) const;
virtual SignalBase<int> *test() { return 0; }
virtual void test2(SignalBase<int> *) { return; }
const std::string &getCommandList() const;
/** \brief Provides the std::map where all the commands are registered
\returns A map of pointers towards Command objects
*/
CommandMap_t getNewStyleCommandMap();
command::Command* getNewStyleCommand(const std::string& cmdName);
/** \brief Provides the pointer towards the Command object cmdName.
\param cmdName: Name of the command
*/
command::Command *getNewStyleCommand(const std::string &cmdName);
/** \brief Provides a map of all the signals.
\returns A copy of the map with all the pointers towards
the entity signals.
*/
SignalMap getSignalMap() const;
/** \name Logger related methods */
/** \{*/
/// \brief Send messages \param msg with level t. Add string file and line to message.
void sendMsg(const std::string& msg, MsgType t = MSG_TYPE_INFO, const char* file = "", int line = 0);
/// \name Logger related methods
/// \{
Logger &logger() { return logger_; };
Logger const &logger() const { return logger_; };
/// \brief Send messages \c msg with level \c t.
/// Add string file and line to message.
void sendMsg(const std::string &msg, MsgType t = MSG_TYPE_INFO,
const std::string &lineId = "");
/// \brief Specify the verbosity level of the logger.
void setLoggerVerbosityLevel(LoggerVerbosity lv) { logger_.setVerbosity(lv); }
......@@ -101,19 +153,23 @@ class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable {
double getTimeSample() { return logger_.getTimeSample(); }
/// \brief Set the period of the stream period
bool setStreamPrintPeriod(double t) { return logger_.setStreamPrintPeriod(t); }
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 addCommand(const std::string &name, command::Command *command);
void entityRegistration();
void entityDeregistration();
void signalRegistration(const SignalArray<int>& signals);
void signalDeregistration(const std::string& name);
void signalRegistration(const SignalArray<int> &signals);
void signalDeregistration(const std::string &name);
std::string name;
SignalMap signalMap;
......@@ -121,7 +177,8 @@ class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable {
Logger logger_;
};
DYNAMIC_GRAPH_DLLAPI std::ostream& operator<<(std::ostream& os, const dynamicgraph::Entity& ent);
DYNAMIC_GRAPH_DLLAPI std::ostream &operator<<(std::ostream &os,
const dynamicgraph::Entity &ent);
} // end of namespace dynamicgraph
#endif //! DYNAMIC_GRAPH_ENTITY_H
......@@ -5,19 +5,21 @@
#ifndef 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/dynamic-graph-api.h>
#include <string>
// Uncomment this macros to have lines parameter on the throw display
// #define DYNAMIC-GRAPH_EXCEPTION_PASSING_PARAM
#define DG_RETHROW \
(const ::dynamicgraph::ExceptionAbstract& err) { throw err; }
(const ::dynamicgraph::ExceptionAbstract &err) { throw err; }
#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
#define DG_THROW throw ::dynamicgraph::ExceptionAbstract::Param(__LINE__, __FUNCTION__, __FILE__) +
#define DG_THROW \
throw ::dynamicgraph::ExceptionAbstract::Param(__LINE__, __FUNCTION__, \
__FILE__) +
#else
#define DG_THROW throw
#endif // DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
......@@ -35,14 +37,21 @@ class DYNAMIC_GRAPH_DLLAPI ExceptionAbstract : public std::exception {
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;
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;
const char *filePTR;
char file[BUFFER_SIZE];
bool pointersSet;
bool set;
......@@ -55,31 +64,40 @@ class DYNAMIC_GRAPH_DLLAPI ExceptionAbstract : public std::exception {
///
/// 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 };
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 = "");
explicit ExceptionAbstract(const int &code, const std::string &msg = "");
virtual ~ExceptionAbstract() throw() {}
virtual const std::string& getExceptionName() const { return EXCEPTION_NAME; }
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;
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;
const char *getMessage() const;
virtual const char* what() const throw() { return getStringMessage().c_str(); }
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);
DYNAMIC_GRAPH_DLLAPI friend std::ostream &operator<<(
std::ostream &os, const ExceptionAbstract &err);
protected:
/// \brief Error code.
......@@ -97,13 +115,13 @@ class DYNAMIC_GRAPH_DLLAPI ExceptionAbstract : public std::exception {
mutable Param p;
template <class Exc>
friend const Exc& operator+(const ExceptionAbstract::Param& p, const Exc& e) {
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) {
friend Exc &operator+(const ExceptionAbstract::Param &p, Exc &e) {
e.p.initCopy(p);
return e;
}
......
......@@ -5,12 +5,12 @@
#ifndef DYNAMIC_GRAPH_EXCEPTION_FACTORY_H
#define DYNAMIC_GRAPH_EXCEPTION_FACTORY_H
#include <string>
#include <dynamic-graph/fwd.hh>
#include <dynamic-graph/dynamic-graph-api.h>
#include <dynamic-graph/exception-abstract.h>
#include <dynamic-graph/fwd.hh>
#include <string>
namespace dynamicgraph {
/// \ingroup error
///
......@@ -32,13 +32,17 @@ class DYNAMIC_GRAPH_DLLAPI ExceptionFactory : public ExceptionAbstract {
static const std::string EXCEPTION_NAME;
explicit ExceptionFactory(const ExceptionFactory::ErrorCodeEnum& errcode, const std::string& msg = "");
explicit ExceptionFactory(const ExceptionFactory::ErrorCodeEnum &errcode,
const std::string &msg = "");
ExceptionFactory(const ExceptionFactory::ErrorCodeEnum& errcode, const std::string& msg, const char* format, ...);
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; }
virtual const std::string &getExceptionName() const {
return ExceptionFactory::EXCEPTION_NAME;
}
};
} // end of namespace dynamicgraph
......
......@@ -6,10 +6,11 @@
#ifndef 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/exception-abstract.h>
#include <dynamic-graph/fwd.hh>
namespace dynamicgraph {
/// \ingroup error
///
......@@ -18,9 +19,7 @@ namespace dynamicgraph {
class DYNAMIC_GRAPH_DLLAPI ExceptionSignal : public ExceptionAbstract {
public:
enum ErrorCodeEnum {
GENERIC = ExceptionAbstract::SIGNAL
,
GENERIC = ExceptionAbstract::SIGNAL,
READWRITE_LOCK,
COPY_NOT_INITIALIZED,
NOT_INITIALIZED,
......@@ -31,11 +30,13 @@ class DYNAMIC_GRAPH_DLLAPI ExceptionSignal : public ExceptionAbstract {
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, ...);
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; }
virtual const std::string &getExceptionName() const { return EXCEPTION_NAME; }
};
} // end of namespace dynamicgraph
......
......@@ -5,12 +5,12 @@
#ifndef DYNAMIC_GRAPH_EXCEPTION_TRACES_H
#define DYNAMIC_GRAPH_EXCEPTION_TRACES_H
#include <string>
#include <dynamic-graph/fwd.hh>
#include <dynamic-graph/dynamic-graph-api.h>
#include <dynamic-graph/exception-abstract.h>
#include <dynamic-graph/fwd.hh>
#include <string>
namespace dynamicgraph {
/// \ingroup error
///
......@@ -21,11 +21,13 @@ class DYNAMIC_GRAPH_DLLAPI ExceptionTraces : public ExceptionAbstract {
static const std::string EXCEPTION_NAME;
explicit ExceptionTraces(const ExceptionTraces::ErrorCodeEnum& errcode, const std::string& msg = "");
ExceptionTraces(const ExceptionTraces::ErrorCodeEnum& errcode, const std::string& msg, const char* format, ...);
explicit ExceptionTraces(const ExceptionTraces::ErrorCodeEnum &errcode,
const std::string &msg = "");
ExceptionTraces(const ExceptionTraces::ErrorCodeEnum &errcode,
const std::string &msg, const char *format, ...);
virtual ~ExceptionTraces() throw() {}
virtual const std::string& getExceptionName() const { return EXCEPTION_NAME; }
virtual const std::string &getExceptionName() const { return EXCEPTION_NAME; }
};
} // end of namespace dynamicgraph.
......
......@@ -5,15 +5,14 @@
#ifndef DYNAMIC_GRAPH_FACTORY_HH
#define DYNAMIC_GRAPH_FACTORY_HH
#include <map>
#include <string>
#include <vector>
#include <dynamic-graph/dynamic-graph-api.h>
#include <dynamic-graph/exception-factory.h>
#include <boost/noncopyable.hpp>
#include <dynamic-graph/fwd.hh>
#include <dynamic-graph/exception-factory.h>
#include <dynamic-graph/dynamic-graph-api.h>
#include <map>
#include <string>
#include <vector>
/// \ingroup dgraph
///
......@@ -24,12 +23,16 @@
/// \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
/// such as classic C string delimited by double quotes).
#define DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CLASSTYPE, CLASSNAME) \
const std::string CLASSTYPE::CLASS_NAME = CLASSNAME; \
extern "C" { \
::dynamicgraph::Entity* EntityMaker_##CLASSTYPE(const std::string& objname) { return new CLASSTYPE(objname); } \
::dynamicgraph::EntityRegisterer reg_##CLASSTYPE(CLASSNAME, &EntityMaker_##CLASSTYPE); \
} \
#define DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CLASSTYPE, CLASSNAME) \
const std::string CLASSTYPE::CLASS_NAME = CLASSNAME; \
extern "C" { \
::dynamicgraph::Entity *EntityMaker_##CLASSTYPE( \
const std::string &objname) { \
return new CLASSTYPE(objname); \
} \
::dynamicgraph::EntityRegisterer reg_##CLASSTYPE(CLASSNAME, \
&EntityMaker_##CLASSTYPE); \
} \
struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
namespace dynamicgraph {
......@@ -79,12 +82,12 @@ 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&);
typedef Entity *(*EntityConstructor_ptr)(const std::string &);
~FactoryStorage();
/// \brief Get pointer to unique object of the class
static FactoryStorage* getInstance();
static FactoryStorage *getInstance();
/// \brief Destroy the unique instance of the class
static void destroy();
......@@ -101,7 +104,7 @@ class DYNAMIC_GRAPH_DLLAPI FactoryStorage : private boost::noncopyable {
/// \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);
void registerEntity(const std::string &entname, EntityConstructor_ptr ent);
/// \brief Delete an entity from the factory.
///
......@@ -110,7 +113,7 @@ class DYNAMIC_GRAPH_DLLAPI FactoryStorage : private boost::noncopyable {
/// OBJECT_CONFLICT.
///
/// \param entname the entity name (as passed to registerEntity before)
void deregisterEntity(const std::string& entname);
void deregisterEntity(const std::string &entname);
/// \brief Instantiate (and allocate) an entity.
///
......@@ -130,21 +133,22 @@ class DYNAMIC_GRAPH_DLLAPI FactoryStorage : private boost::noncopyable {
/// \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;
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;
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;
void listEntities(std::vector<std::string> &list) const;
private:
/// \brief Constructor the factory.
......@@ -165,7 +169,7 @@ class DYNAMIC_GRAPH_DLLAPI FactoryStorage : private boost::noncopyable {
EntityMap entityMap;
/// \pointer to the unique object of the class
static FactoryStorage* instance_;
static FactoryStorage *instance_;
};
/// \ingroup dgraph
......@@ -180,7 +184,8 @@ class DYNAMIC_GRAPH_DLLAPI FactoryStorage : private boost::noncopyable {
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);
explicit EntityRegisterer(const std::string &entityClassName,
FactoryStorage::EntityConstructor_ptr maker);
/// \brief Unregister entity to the global factory.
~EntityRegisterer();
......
......@@ -5,7 +5,18 @@
#ifndef DYNAMIC_GRAPH_FWD_HH
#define DYNAMIC_GRAPH_FWD_HH
#include <boost/smart_ptr.hpp>
namespace dynamicgraph {
// to be replace by std:: when we switch to C++11 and later
using boost::const_pointer_cast;
using boost::dynamic_pointer_cast;
using boost::make_shared;
using boost::shared_ptr;
using boost::static_pointer_cast;
using boost::weak_ptr;
class DebugTrace;
class PluginRefMap;
......@@ -17,21 +28,16 @@ class ExceptionSignal;
class ExceptionTraces;
class FactoryStorage;
class Interpreter;
typedef shared_ptr<Interpreter> InterpreterShPtr_t;
class InterpreterHelper;
class Logger;
class OutStringStream;
class PluginLoader;
class PoolStorage;
class SignalCaster;
class SignalCastRegisterer;
class Tracer;
class TracerRealTime;
template <typename T>
class DefaultCastRegisterer;
template <typename T, typename Time>
class Signal;
......
......@@ -27,14 +27,17 @@ namespace dynamicgraph {
/** Enum representing the different kind of messages.
*/
enum MsgType {
MSG_TYPE_DEBUG = 0,
MSG_TYPE_INFO = 1,
MSG_TYPE_WARNING = 2,
MSG_TYPE_ERROR = 3,
MSG_TYPE_DEBUG_STREAM = 4,
MSG_TYPE_INFO_STREAM = 5,
MSG_TYPE_WARNING_STREAM = 6,
MSG_TYPE_ERROR_STREAM = 7
MSG_TYPE_TYPE_BITS = 1 << 0 | 1 << 1 | 1 << 2 | 1 << 3, // 15
MSG_TYPE_STREAM_BIT = 1 << 4, // 16
MSG_TYPE_DEBUG = 1 << 3, // 1
MSG_TYPE_INFO = 1 << 2, // 2
MSG_TYPE_WARNING = 1 << 1, // 4
MSG_TYPE_ERROR = 1 << 0, // 8
MSG_TYPE_DEBUG_STREAM = MSG_TYPE_DEBUG | MSG_TYPE_STREAM_BIT, // 17
MSG_TYPE_INFO_STREAM = MSG_TYPE_INFO | MSG_TYPE_STREAM_BIT, // 18
MSG_TYPE_WARNING_STREAM = MSG_TYPE_WARNING | MSG_TYPE_STREAM_BIT, // 20
MSG_TYPE_ERROR_STREAM = MSG_TYPE_ERROR | MSG_TYPE_STREAM_BIT // 24
};
} // namespace dynamicgraph
......@@ -43,64 +46,94 @@ enum MsgType {
/* --------------------------------------------------------------------- */
#include <map>
#include <iomanip> // std::setprecision
/// \todo These 3 headers should be removed.
#include <dynamic-graph/linear-algebra.h>
#include <dynamic-graph/real-time-logger-def.h>
#include <boost/assign.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <dynamic-graph/deprecated.hh>
#include <fstream>
#include <iomanip> // std::setprecision
#include <sstream>
#include "boost/assign.hpp"
#include <dynamic-graph/linear-algebra.h>
namespace dynamicgraph {
//#define LOGGER_VERBOSITY_INFO_WARNING_ERROR
#define LOGGER_VERBOSITY_ALL
#define SEND_MSG(msg, type) sendMsg(msg, type, __FILE__, __LINE__)
#define SEND_MSG(msg, type) \
sendMsg(msg, type, __FILE__ ":" BOOST_PP_STRINGIZE(__LINE__))
#define SEND_DEBUG_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_DEBUG_STREAM)
#define SEND_INFO_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_INFO_STREAM)
#define SEND_WARNING_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_WARNING_STREAM)
#define SEND_ERROR_STREAM_MSG(msg) SEND_MSG(msg, MSG_TYPE_ERROR_STREAM)
/*template<typename T>
std::string toString(const T& v, const int precision=3, const int width=-1)
{
#define _DYNAMIC_GRAPH_ENTITY_MSG(entity, type) \
(entity).logger().stream(type, __FILE__ BOOST_PP_STRINGIZE(__LINE__))
#define DYNAMIC_GRAPH_ENTITY_DEBUG(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_DEBUG)
#define DYNAMIC_GRAPH_ENTITY_INFO(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_INFO)
#define DYNAMIC_GRAPH_ENTITY_WARNING(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_WARNING)
#define DYNAMIC_GRAPH_ENTITY_ERROR(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_ERROR)
#define DYNAMIC_GRAPH_ENTITY_DEBUG_STREAM(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_DEBUG_STREAM)
#define DYNAMIC_GRAPH_ENTITY_INFO_STREAM(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_INFO_STREAM)
#define DYNAMIC_GRAPH_ENTITY_WARNING_STREAM(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_WARNING_STREAM)
#define DYNAMIC_GRAPH_ENTITY_ERROR_STREAM(entity) \
_DYNAMIC_GRAPH_ENTITY_MSG(entity, MSG_TYPE_ERROR_STREAM)
template <typename T>
std::string toString(const T &v, const int precision = 3,
const int width = -1) {
std::stringstream ss;
if(width>precision)
ss<<std::fixed<<std::setw(width)<<std::setprecision(precision)<<v;
if (width > precision)
ss << std::fixed << std::setw(width) << std::setprecision(precision) << v;
else
ss<<std::fixed<<std::setprecision(precision)<<v;
ss << std::fixed << std::setprecision(precision) << v;
return ss.str();
}*/
}
template <typename T>
std::string toString(const std::vector<T>& v, const int precision = 3, const int width = -1,
const std::string separator = ", ") {
std::string toString(const std::vector<T> &v, const int precision = 3,
const int width = -1, const std::string separator = ", ") {
std::stringstream ss;
if (width > precision) {
for (int i = 0; i < v.size() - 1; i++)
ss << std::fixed << std::setw(width) << std::setprecision(precision) << v[i] << separator;
ss << std::fixed << std::setw(width) << std::setprecision(precision) << v[v.size() - 1];
for (unsigned int i = 0; i < v.size() - 1; i++)
ss << std::fixed << std::setw(width) << std::setprecision(precision)
<< v[i] << separator;
ss << std::fixed << std::setw(width) << std::setprecision(precision)
<< v[v.size() - 1];
} else {
for (int i = 0; i < v.size() - 1; i++) ss << std::fixed << std::setprecision(precision) << v[i] << separator;
for (unsigned int i = 0; i < v.size() - 1; i++)
ss << std::fixed << std::setprecision(precision) << v[i] << separator;
ss << std::fixed << std::setprecision(precision) << v[v.size() - 1];
}
return ss.str();
}
// template<typename T, int N>
// std::string toString(const Eigen::Matrix<T, N, 1, 0, N, 1>& v, const std::string separator=", ",
// const int precision=3, const int width=-1)
template <typename T>
std::string toString(const Eigen::MatrixBase<T>& v, const int precision = 3, const int width = -1,
const std::string separator = ", ") {
std::string toString(const Eigen::MatrixBase<T> &v, const int precision = 3,
const int width = -1, const std::string separator = ", ") {
std::stringstream ss;
if (width > precision) {
for (int i = 0; i < v.size() - 1; i++)
ss << std::fixed << std::setw(width) << std::setprecision(precision) << v[i] << separator;
ss << std::fixed << std::setw(width) << std::setprecision(precision) << v[v.size() - 1];
for (unsigned int i = 0; i < v.size() - 1; i++)
ss << std::fixed << std::setw(width) << std::setprecision(precision)
<< v[i] << separator;
ss << std::fixed << std::setw(width) << std::setprecision(precision)
<< v[v.size() - 1];
} else {
for (int i = 0; i < v.size() - 1; i++) ss << std::fixed << std::setprecision(precision) << v[i] << separator;
for (unsigned int i = 0; i < v.size() - 1; i++)
ss << std::fixed << std::setprecision(precision) << v[i] << separator;
ss << std::setprecision(precision) << v[v.size() - 1];
}
......@@ -108,11 +141,11 @@ std::string toString(const Eigen::MatrixBase<T>& v, const int precision = 3, con
}
enum LoggerVerbosity {
VERBOSITY_ALL,
VERBOSITY_INFO_WARNING_ERROR,
VERBOSITY_WARNING_ERROR,
VERBOSITY_ERROR,
VERBOSITY_NONE
VERBOSITY_ALL = MSG_TYPE_DEBUG,
VERBOSITY_INFO_WARNING_ERROR = MSG_TYPE_INFO,
VERBOSITY_WARNING_ERROR = MSG_TYPE_WARNING,
VERBOSITY_ERROR = MSG_TYPE_ERROR,
VERBOSITY_NONE = 0
};
/// \ingroup debug
......@@ -132,15 +165,24 @@ enum LoggerVerbosity {
/// }
///
/// // Somewhere in your library
/// dynamicgraph::LoggerVerbosity aLoggerVerbosityLevel = VERBOSITY_WARNING_ERROR;
/// dynamicgraph::LoggerVerbosity aLoggerVerbosityLevel =
/// VERBOSITY_WARNING_ERROR;
/// entity.setLoggerVerbosityLevel(aLoggerVerbosityLevel);
/// ...
/// std::string aMsg=aBaseMsg+" WARNING";
/// entity.sendMsg(aMsg,dynamicgraph::MSG_TYPE_WARNING, __FILE__,__LINE__);
/// // using macros
/// DYNAMIC_GRAPH_ENTITY_WARNING(entity) << "your message\n";
///
/// \endcode
/// // or the equivalent code without macros:
/// // Please use '\n' instead of std::endl and flushing will have no effect
/// entity.logger.stream(dynamicgraph::MSG_TYPE_WARNING,
/// __FILE__ BOOST_PP_STRINGIZE(__LINE__))
/// << your message << '\n';
///
/// \endcode
///
/// \todo remove m_timeSample and streamPrintPeriod to rather use a simple
/// integer counting the number of calls. This will achieve exactly the
/// same behaviour without rouding numerical errors.
class Logger {
public:
/** Constructor */
......@@ -153,12 +195,40 @@ class Logger {
* to decrement the internal Logger's counter. */
void countdown();
/** Get an output stream independently of the debug level.
*/
RTLoggerStream stream() {
return ::dynamicgraph::RealTimeLogger::instance().front();
}
/** Print the specified message on standard output if the verbosity level
* allows it. The file name and the line number are used to identify
* the point where sendMsg is called so that streaming messages are
* printed only every streamPrintPeriod iterations.
* allows it. The lineId is used to identify the point where sendMsg is
* called so that streaming messages are printed only every streamPrintPeriod
* iterations.
* \param type specifies the verbosity level, for instance MSG_TYPE_DEBUG
* \param lineId typically __FILE__ ":" BOOST_PP_STRINGIZE(__LINE__)
*/
RTLoggerStream stream(MsgType type, const std::string &lineId = "") {
RealTimeLogger &rtlogger = ::dynamicgraph::RealTimeLogger::instance();
if (acceptMsg(type, lineId)) return rtlogger.front();
return rtlogger.emptyStream();
}
/** \deprecated instead, use
* \code
* stream(type, lineId) << msg << '\n';
* \endcode
*/
[[deprecated("use stream(type, lineId) << msg")]] void sendMsg(
std::string msg, MsgType type, const std::string &lineId = "");
/** \deprecated instead, use
* \code
* stream(type, lineId) << msg << '\n';
* \endcode
*/
void sendMsg(std::string msg, MsgType type, const char* file = "", int line = 0);
[[deprecated("use stream(type, lineId) << msg")]] void sendMsg(
std::string msg, MsgType type, const std::string &file, int line);
/** Set the sampling time at which the method countdown()
* is going to be called. */
......@@ -181,26 +251,37 @@ class Logger {
LoggerVerbosity getVerbosity();
protected:
LoggerVerbosity m_lv; /// verbosity of the logger
double m_timeSample; /// specify the period of call of the countdown method
LoggerVerbosity m_lv; /// verbosity of the logger
double m_timeSample;
/// specify the period of call of the countdown method
double m_streamPrintPeriod; /// specify the time period of the stream prints
double m_printCountdown; /// every time this is < 0 (i.e. every _streamPrintPeriod sec) print stuff
double m_printCountdown;
/// every time this is < 0 (i.e. every _streamPrintPeriod sec) print stuff
/** Pointer to the dynamic structure which holds the collection of streaming messages */
std::map<std::string, double> m_stream_msg_counters;
typedef std::map<std::string, double> StreamCounterMap_t;
/** Pointer to the dynamic structure which holds
the collection of streaming messages */
StreamCounterMap_t m_stream_msg_counters;
bool isStreamMsg(MsgType m) {
return m == MSG_TYPE_ERROR_STREAM || m == MSG_TYPE_DEBUG_STREAM || m == MSG_TYPE_INFO_STREAM ||
m == MSG_TYPE_WARNING_STREAM;
}
bool isDebugMsg(MsgType m) { return m == MSG_TYPE_DEBUG_STREAM || m == MSG_TYPE_DEBUG; }
inline bool isStreamMsg(MsgType m) { return (m & MSG_TYPE_STREAM_BIT); }
bool isInfoMsg(MsgType m) { return m == MSG_TYPE_INFO_STREAM || m == MSG_TYPE_INFO; }
/** Check whether a message of type \p m and from \p c lineId should be
* accepted. \note If \p m is a stream type, the internal counter associated
* to \p lineId is updated.
*/
bool acceptMsg(MsgType m, const std::string &lineId) {
// If more verbose than the current verbosity level
if ((m & MSG_TYPE_TYPE_BITS) > m_lv) return false;
bool isWarningMsg(MsgType m) { return m == MSG_TYPE_WARNING_STREAM || m == MSG_TYPE_WARNING; }
// if print is allowed by current verbosity level
if (isStreamMsg(m)) return checkStreamPeriod(lineId);
return true;
}
bool isErrorMsg(MsgType m) { return m == MSG_TYPE_ERROR_STREAM || m == MSG_TYPE_ERROR; }
/** Check whether a message from \c lineId should be accepted.
* \note The internal counter associated to \c lineId is updated.
*/
bool checkStreamPeriod(const std::string &lineId);
};
} // namespace dynamicgraph
......
// Copyright 2010, Thomas Moulard, JRL, CNRS/AIST
//
#ifndef DYNAMIC_GRAPH_NULL_PTR_HH
#define DYNAMIC_GRAPH_NULL_PTR_HH
namespace dynamicgraph {
const class {
public:
template <class T>
operator T*() const {
return 0;
}
template <class C, class T>
operator T C::*() const {
return 0;
}
private:
void operator&() const;
} nullptr = {};
} // end of namespace dynamicgraph.
#endif //! DYNAMIC_GRAPH_NULL_PTR_HH