Commit 48e05f15 authored by Olivier Stasse's avatar Olivier Stasse

Fix typo. Enforce 80 columns policy.

parent db1c58f5
Pipeline #5300 passed with stage
in 3 minutes and 43 seconds
This diff is collapsed.
......@@ -19,36 +19,45 @@
#include <boost/assign/list_of.hpp>
/* --- GETTER --------------------------------------------------------- */
namespace dynamicgraph {
namespace command {
template <class E, typename T>
class DirectGetter : public Command {
public:
/// Pointer to method that sets parameter of type T
typedef T (E::*GetterMethod)() const;
/// Constructor
DirectGetter(E& entity, T* ptr, const std::string& docString)
: Command(entity, std::vector<Value::Type>(), docString), T_ptr(ptr) {}
protected:
virtual Value doExecute() { return Value(*T_ptr); }
private:
T* T_ptr;
};
template <class E, typename T>
DirectGetter<E, T>* makeDirectGetter(E& entity, T* ptr, const std::string& docString) {
return new DirectGetter<E, T>(entity, ptr, docString);
}
inline std::string docDirectGetter(const std::string& name, const std::string& type) {
return std::string("\nGet the ") + name + ".\n\nNo input.\nReturn an " + type + ".\n\n";
}
} // namespace command
namespace dynamicgraph
{
namespace command
{
template <class E, typename T>
class DirectGetter : public Command
{
public:
/// Pointer to method that sets parameter of type T
typedef T (E::*GetterMethod)() const;
/// Constructor
DirectGetter(E& entity, T* ptr, const std::string& docString)
: Command(entity, std::vector<Value::Type>(), docString), T_ptr(ptr)
{}
protected:
virtual Value doExecute() { return Value(*T_ptr); }
private:
T* T_ptr;
};
template <class E, typename T>
DirectGetter<E, T>* makeDirectGetter
(E& entity, T* ptr, const std::string& docString)
{
return new DirectGetter<E, T>(entity, ptr, docString);
}
inline std::string docDirectGetter
(const std::string& name, const std::string& type)
{
return std::string("\nGet the ") + name +
".\n\nNo input.\nReturn an " + type + ".\n\n";
}
} // namespace command
} // namespace dynamicgraph
#endif // __dg_command_direct_getter_h__
......@@ -19,37 +19,47 @@
#include <boost/assign/list_of.hpp>
/* --- SETTER --------------------------------------------------------- */
namespace dynamicgraph {
namespace command {
template <class E, typename T>
class DirectSetter : public Command {
public:
DirectSetter(E& entity, T* ptr, const std::string& docString)
: Command(entity, boost::assign::list_of(ValueHelper<T>::TypeID), docString), T_ptr(ptr) {}
protected:
virtual Value doExecute() {
const std::vector<Value>& values = getParameterValues();
T val = values[0].value();
(*T_ptr) = val;
return Value(); // void
}
private:
T* T_ptr;
};
template <class E, typename T>
DirectSetter<E, T>* makeDirectSetter(E& entity, T* ptr, const std::string& docString) {
return new DirectSetter<E, T>(entity, ptr, docString);
}
inline std::string docDirectSetter(const std::string& name, const std::string& type) {
return std::string("\nSet the ") + name + ".\n\nInput:\n - a " + type + ".\nVoid return.\n\n";
}
} // namespace command
namespace dynamicgraph
{
namespace command
{
template <class E, typename T>
class DirectSetter : public Command
{
public:
DirectSetter(E& entity, T* ptr, const std::string& docString)
: Command(entity, boost::assign::list_of(ValueHelper<T>::TypeID),
docString), T_ptr(ptr) {}
protected:
virtual Value doExecute()
{
const std::vector<Value>& values = getParameterValues();
T val = values[0].value();
(*T_ptr) = val;
return Value(); // void
}
private:
T* T_ptr;
};
template <class E, typename T>
DirectSetter<E, T>* makeDirectSetter
(E& entity, T* ptr, const std::string& docString)
{
return new DirectSetter<E, T>(entity, ptr, docString);
}
inline std::string docDirectSetter
(const std::string& name, const std::string& type)
{
return std::string("\nSet the ") + name + ".\n\nInput:\n - a " + type +
".\nVoid return.\n\n";
}
} // namespace command
} // namespace dynamicgraph
#endif // __dg_command_direct_setter_h__
......@@ -9,21 +9,28 @@
#include <sstream>
namespace dynamicgraph {
class Entity;
namespace command {
template <class E, typename T>
Getter<E, T>::Getter(E& entity, GetterMethod getterMethod, const std::string& docstring)
: Command(entity, std::vector<Value::Type>(), docstring), getterMethod_(getterMethod) {}
template <class E, typename T>
Value Getter<E, T>::doExecute() {
E& entity = static_cast<E&>(owner());
T value = (entity.*getterMethod_)();
return Value(value);
}
} // namespace command
namespace dynamicgraph
{
class Entity;
namespace command
{
template <class E, typename T>
Getter<E, T>::Getter
(E& entity, GetterMethod getterMethod,
const std::string& docstring)
: Command(entity, std::vector<Value::Type>(), docstring),
getterMethod_(getterMethod)
{}
template <class E, typename T>
Value Getter<E, T>::doExecute()
{
E& entity = static_cast<E&>(owner());
T value = (entity.*getterMethod_)();
return Value(value);
}
} // namespace command
} // namespace dynamicgraph
#endif // DYNAMIC_GRAPH_COMMAND_GETTER_T_CPP
This diff is collapsed.
......@@ -11,59 +11,64 @@
#include "dynamic-graph/value.h"
#include "dynamic-graph/dynamic-graph-api.h"
namespace dynamicgraph {
class Entity;
namespace command {
/// Abstract class for entity commands
///
/// This class provide a mean to control entities from external python script.
///
/// A command
/// \li is owned by an entity,
/// \li takes parameters of type Value,
/// \li return an instance of Value when calling Command::execute()
///
/// At construction, the prototype of the command is defined by providing
/// a vector of Value::Type.
///
/// Parameters are set by calling Command::setParameterValues with a
/// vector of Values the types of which should fit the vector specified
/// at construction.
class DYNAMIC_GRAPH_DLLAPI Command {
public:
virtual ~Command();
/// Store the owner entity and a vector of value types
/// \param entity reference to Entity owning this command.
/// \param valueTypes vector specifying the number and types of parameters
/// \param docstring documentation of the command
Command(Entity& entity, const std::vector<Value::Type>& valueTypes, const std::string& docstring);
/// Return the value type of all parameters
const std::vector<Value::Type>& valueTypes() const;
/// Set parameter values
void setParameterValues(const std::vector<Value>& values);
/// Get parameter values
const std::vector<Value>& getParameterValues() const;
/// Execute the command after checking parameters
Value execute();
/// Get a reference to the Entity owning this command
Entity& owner();
/// Get documentation string
std::string getDocstring() const;
namespace dynamicgraph
{
class Entity;
namespace command
{
/// Abstract class for entity commands
///
/// This class provide a mean to control entities from external
/// python script.
///
/// A command
/// \li is owned by an entity,
/// \li takes parameters of type Value,
/// \li return an instance of Value when calling Command::execute()
///
/// At construction, the prototype of the command is defined by providing
/// a vector of Value::Type.
///
/// Parameters are set by calling Command::setParameterValues with a
/// vector of Values the types of which should fit the vector specified
/// at construction.
class DYNAMIC_GRAPH_DLLAPI Command
{
public:
virtual ~Command();
/// Store the owner entity and a vector of value types
/// \param entity reference to Entity owning this command.
/// \param valueTypes vector specifying the number and types of parameters
/// \param docstring documentation of the command
Command(Entity& entity, const std::vector<Value::Type>& valueTypes,
const std::string& docstring);
/// Return the value type of all parameters
const std::vector<Value::Type>& valueTypes() const;
/// Set parameter values
void setParameterValues(const std::vector<Value>& values);
/// Get parameter values
const std::vector<Value>& getParameterValues() const;
/// Execute the command after checking parameters
Value execute();
/// Get a reference to the Entity owning this command
Entity& owner();
/// Get documentation string
std::string getDocstring() const;
protected:
/// Specific action performed by the command
virtual Value doExecute() = 0;
protected:
/// Specific action performed by the command
virtual Value doExecute() = 0;
private:
Entity& owner_;
std::vector<Value::Type> valueTypeVector_;
std::vector<Value> valueVector_;
std::string docstring_;
private:
Entity& owner_;
std::vector<Value::Type> valueTypeVector_;
std::vector<Value> valueVector_;
std::string docstring_;
public:
static const std::vector<Value::Type> EMPTY_ARG;
};
} // namespace command
public:
static const std::vector<Value::Type> EMPTY_ARG;
};
} // namespace command
} // namespace dynamicgraph
#endif // DYNAMIC_GRAPH_COMMAND_H
......@@ -30,72 +30,81 @@
outputbuffer << tmpbuffer.str() << charbuffer << std::endl; \
} while (0)
namespace dynamicgraph {
/// \ingroup debug
///
/// \brief Logging class.
///
/// This class should never be used directly, please use the
/// debugging macro instead.
class DYNAMIC_GRAPH_DLLAPI DebugTrace {
public:
static const int SIZE = 512;
std::stringstream tmpbuffer;
std::ostream& outputbuffer;
char charbuffer[SIZE + 1];
int traceLevel;
int traceLevelTemplate;
DebugTrace(std::ostream& os) : outputbuffer(os) {}
inline void trace(const int level, const char* format, ...) {
if (level <= traceLevel) DG_COMMON_TRACES;
tmpbuffer.str("");
}
inline void trace(const char* format, ...) {
DG_COMMON_TRACES;
tmpbuffer.str("");
}
inline void trace(const int level = -1) {
if (level <= traceLevel) {
outputbuffer << tmpbuffer.str();
namespace dynamicgraph
{
/// \ingroup debug
///
/// \brief Logging class.
///
/// This class should never be used directly, please use the
/// debugging macro instead.
class DYNAMIC_GRAPH_DLLAPI DebugTrace
{
public:
static const int SIZE = 512;
std::stringstream tmpbuffer;
std::ostream& outputbuffer;
char charbuffer[SIZE + 1];
int traceLevel;
int traceLevelTemplate;
DebugTrace(std::ostream& os) : outputbuffer(os) {}
inline void trace(const int level, const char* format, ...)
{
if (level <= traceLevel) DG_COMMON_TRACES;
tmpbuffer.str("");
}
}
inline void traceTemplate(const int level, const char* format, ...) {
if (level <= traceLevelTemplate) DG_COMMON_TRACES;
tmpbuffer.str("");
}
inline void traceTemplate(const char* format, ...) {
DG_COMMON_TRACES;
tmpbuffer.str("");
}
inline DebugTrace& pre(const std::ostream&) { return *this; }
inline void trace(const char* format, ...)
{
DG_COMMON_TRACES;
tmpbuffer.str("");
}
inline void trace(const int level = -1)
{
if (level <= traceLevel) {
outputbuffer << tmpbuffer.str();
tmpbuffer.str("");
}
}
inline DebugTrace& pre(const std::ostream&, int level) {
traceLevel = level;
return *this;
}
inline void traceTemplate(const int level, const char* format, ...)
{
if (level <= traceLevelTemplate) DG_COMMON_TRACES;
tmpbuffer.str("");
}
static const char* DEBUG_FILENAME_DEFAULT;
static void openFile(const char* filename = DEBUG_FILENAME_DEFAULT);
static void closeFile(const char* filename = DEBUG_FILENAME_DEFAULT);
};
inline void traceTemplate(const char* format, ...)
{
DG_COMMON_TRACES;
tmpbuffer.str("");
}
DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgDEBUGFLOW;
DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgERRORFLOW;
inline DebugTrace& pre(const std::ostream&) { return *this; }
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);
};
DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgDEBUGFLOW;
DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgERRORFLOW;
} // end of namespace dynamicgraph
#ifdef VP_DEBUG
#define dgPREDEBUG __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
#define dgPREERROR "\t!! " << __FILE__ << ": " << __FUNCTION__ << "(#" << __LINE__ << ") :"
#define dgPREERROR "\t!! " << __FILE__ << ": " << __FUNCTION__ << \
"(#" << __LINE__ << ") :"
#define dgDEBUG(level) \
if ((level > VP_DEBUG_MODE) || (!dgDEBUGFLOW.outputbuffer.good())) \
......@@ -138,15 +147,19 @@ DYNAMIC_GRAPH_DLLAPI extern DebugTrace dgERRORFLOW;
if (!dgDEBUGFLOW.outputbuffer.good()) \
; \
else \
dgDEBUGFLOW.pre(dgDEBUGFLOW.tmpbuffer << dgPREDEBUG, VP_TEMPLATE_DEBUG_MODE).trace
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) \
......@@ -168,13 +181,15 @@ inline void dgERRORF(const int, const char*, ...) { return; }
inline void dgERRORF(const char*, ...) { return; }
namespace dynamicgraph {
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);
return os;
}
namespace dynamicgraph
{
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);
return os;
}
} // namespace dynamicgraph
// TEMPLATE
......
......@@ -24,127 +24,171 @@ using dynamicgraph::ExceptionSignal;
* Input Vector format: [N](val1,val2,val3,...,valN)
* e.g. [5](1,23,32.2,12.12,32)
*/
namespace Eigen {
typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE eigen_index;
inline std::istringstream &operator>>(std::istringstream &iss, dynamicgraph::Vector &inst) {
unsigned int _size;
double _dbl_val;
char _ch;
boost::format fmt("Failed to enter %s as vector. Reenter as [N](val1,val2,val3,...,valN)");
fmt % iss.str();
if (iss >> _ch && _ch != '[') {
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
} else {
if (iss >> _size && !iss.fail()) {
inst.resize(_size);
} else
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
if (iss >> _ch && _ch != ']')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
else {
if (iss >> _ch && _ch != '(')
namespace Eigen
{
typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE eigen_index;
inline std::istringstream &operator>>
(std::istringstream &iss, dynamicgraph::Vector &inst)
{
unsigned int _size;
double _dbl_val;
char _ch;
boost::format fmt("Failed to enter %s as vector."
" Reenter as [N](val1,val2,val3,...,valN)");
fmt % iss.str();
if (iss >> _ch && _ch != '[')
{
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
else {
for (unsigned int i = 0; i < _size; i++) {
iss >> _dbl_val;
if (iss.peek() == ',' || iss.peek() == ' ') iss.ignore();
inst(i) = _dbl_val;
}
if (iss >> _ch && _ch != ')') throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
}
}
else
{
if (iss >> _size && !iss.fail())
{
inst.resize(_size);
}
else
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
if (iss >> _ch && _ch != ']')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
else
{
if (iss >> _ch && _ch != '(')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
else
{
for (unsigned int i = 0; i < _size; i++)
{
iss >> _dbl_val;
if (iss.peek() == ',' || iss.peek() == ' ') iss.ignore();
inst(i) = _dbl_val;
}
if (iss >> _ch && _ch != ')')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
}
}
}
return iss;
}
return iss;
}
/* \brief Eigen Matrix input from istream
*
* Matrix format: [M,N]((val11,val12,val13,...,val1N),...,(valM1,valM2,...,valMN))
* e.g. [2,5]((1 23 32.2 12.12 32),(2 32 23 92.01 19.2))
*/
template <typename Derived>
inline std::istringstream &operator>>(std::istringstream &iss, DenseBase<Derived> &inst) {
unsigned int _colsize;
unsigned int _rowsize;
double _dbl_val;
char _ch;
boost::format fmt(
"Failed to enter %s as matrix. Reenter as ((val11,val12,val13,...,val1N),...,(valM1,valM2,...,valMN))");
MatrixXd _tmp_matrix;
fmt % iss.str();
if (iss >> _ch && _ch != '[') {
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
} else {
iss >> _rowsize;
if (iss.peek() == ',' || iss.peek() == ' ') iss.ignore();
iss >> _colsize;
if (iss.fail())
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
else {
_tmp_matrix.resize(_rowsize, _colsize);
if (iss >> _ch && _ch != ']')
/* \brief Eigen Matrix input from istream
*
* Matrix format: [M,N]((val11,val12,val13,...,val1N),...,
* (valM1,valM2,...,valMN))
* e.g. [2,5]((1 23 32.2 12.12 32),(2 32 23 92.01 19.2))
*/
template <typename Derived>
inline std::istringstream &operator>>
(std::istringstream &iss, DenseBase<Derived> &inst)
{
unsigned int _colsize;
unsigned int _rowsize;
double _dbl_val;
char _ch;
boost::format
fmt("Failed to enter %s as matrix. Reenter as "
"((val11,val12,val13,...,val1N),"
"...,(valM1,valM2,...,valMN))");
MatrixXd _tmp_matrix;
fmt % iss.str();
if (iss >> _ch && _ch != '[')
{
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
else {
if (iss >> _ch && _ch != '(')
}
else
{
iss >> _rowsize;
if (iss.peek() == ',' || iss.peek() == ' ') iss.ignore();
iss >> _colsize;
if (iss.fail())
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
else {
for (unsigned int j = 0; j < _rowsize; j++) {
if (iss >> _ch && _ch != '(') throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
for (unsigned int i = 0; i < _colsize; i++) {
iss >> _dbl_val;
if (iss.peek() == ',' || iss.peek() == ' ') iss.ignore();
_tmp_matrix(j, i) = _dbl_val;
}
if (iss >> _ch && _ch != ')') throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
if (iss.peek() == ',' || iss.peek() == ' ') iss.ignore();
else
{
_tmp_matrix.resize(_rowsize, _colsize);
if (iss >> _ch && _ch != ']')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
else
{
if (iss >> _ch && _ch != '(')
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
else
{
for (unsigned int j = 0; j < _rowsize; j++)
{
if (iss >> _ch && _ch != '(')
throw ExceptionSignal
(ExceptionSignal::GENERIC, fmt.str());
for (unsigned int i = 0; i < _colsize; i++)
{
iss >> _dbl_val;
if (iss.peek() == ',' || iss.peek() == ' ')
iss.ignore();
_tmp_matrix(j, i) = _dbl_val;
}
if (iss >> _ch && _ch != ')')
throw ExceptionSignal
(ExceptionSignal::