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 519 additions and 447 deletions
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <dynamic-graph/dynamic-graph-api.h> #include <dynamic-graph/dynamic-graph-api.h>
#include <dynamic-graph/signal-base.h> #include <dynamic-graph/signal-base.h>
#include <stdio.h> #include <stdio.h>
#include <vector> #include <vector>
namespace dynamicgraph { namespace dynamicgraph {
...@@ -15,16 +16,16 @@ namespace dynamicgraph { ...@@ -15,16 +16,16 @@ namespace dynamicgraph {
/// \ingroup dgraph /// \ingroup dgraph
/// ///
/// \brief TODO /// \brief TODO
template <class Time> class SignalArray_const { template <class Time>
class SignalArray_const {
public: public:
static const int DEFAULT_SIZE = 20; static const int DEFAULT_SIZE = 20;
protected: protected:
std::vector<const SignalBase<Time> *> const_array; std::vector<const SignalBase<Time> *> const_array;
unsigned int size, rank; unsigned int size, rank;
public: public:
SignalArray_const<Time>(const unsigned int &sizeARG = DEFAULT_SIZE) SignalArray_const<Time>(const unsigned int &sizeARG = DEFAULT_SIZE)
: const_array(sizeARG), size(sizeARG), rank(0) {} : const_array(sizeARG), size(sizeARG), rank(0) {}
...@@ -34,22 +35,22 @@ public: ...@@ -34,22 +35,22 @@ public:
} }
SignalArray_const<Time>(const SignalArray<Time> &siga) SignalArray_const<Time>(const SignalArray<Time> &siga)
: const_array(siga.getSize()), size(siga.getSize()), : const_array(siga.getSize()),
size(siga.getSize()),
rank(siga.getSize()) { rank(siga.getSize()) {
for (unsigned int i = 0; i < rank; ++i) for (unsigned int i = 0; i < rank; ++i) const_array[i] = &siga[i];
const_array[i] = &siga[i];
} }
SignalArray_const<Time>(const SignalArray_const<Time> &siga) SignalArray_const<Time>(const SignalArray_const<Time> &siga)
: const_array(siga.getSize()), size(siga.getSize()), : const_array(siga.getSize()),
size(siga.getSize()),
rank(siga.getSize()) { rank(siga.getSize()) {
for (unsigned int i = 0; i < rank; ++i) for (unsigned int i = 0; i < rank; ++i) const_array[i] = &siga[i];
const_array[i] = &siga[i];
} }
virtual ~SignalArray_const<Time>() {} virtual ~SignalArray_const<Time>() {}
protected: protected:
void addElmt(const SignalBase<Time> *el) { void addElmt(const SignalBase<Time> *el) {
if (rank >= size) { if (rank >= size) {
size += DEFAULT_SIZE; size += DEFAULT_SIZE;
...@@ -58,13 +59,13 @@ protected: ...@@ -58,13 +59,13 @@ protected:
const_array[rank++] = el; const_array[rank++] = el;
} }
public: public:
virtual SignalArray_const<Time> &operator<<(const SignalBase<Time> &sig) { virtual SignalArray_const<Time> &operator<<(const SignalBase<Time> &sig) {
addElmt(&sig); addElmt(&sig);
return *this; return *this;
} }
public: public:
virtual const SignalBase<Time> &operator[](const unsigned int &idx) const { virtual const SignalBase<Time> &operator[](const unsigned int &idx) const {
return *const_array[idx]; return *const_array[idx];
} }
...@@ -82,16 +83,17 @@ SignalArray_const<Time> operator<<(const SignalBase<Time> &sig1, ...@@ -82,16 +83,17 @@ SignalArray_const<Time> operator<<(const SignalBase<Time> &sig1,
/// \ingroup dgraph /// \ingroup dgraph
/// ///
/// \brief TODO /// \brief TODO
template <class Time> class SignalArray : public SignalArray_const<Time> { template <class Time>
public: class SignalArray : public SignalArray_const<Time> {
public:
using SignalArray_const<Time>::DEFAULT_SIZE; using SignalArray_const<Time>::DEFAULT_SIZE;
using SignalArray_const<Time>::size; using SignalArray_const<Time>::size;
using SignalArray_const<Time>::rank; using SignalArray_const<Time>::rank;
protected: protected:
mutable std::vector<SignalBase<Time> *> array; mutable std::vector<SignalBase<Time> *> array;
public: public:
SignalArray<Time>(const unsigned int &sizeARG = DEFAULT_SIZE) SignalArray<Time>(const unsigned int &sizeARG = DEFAULT_SIZE)
: SignalArray_const<Time>(0), array(sizeARG) { : SignalArray_const<Time>(0), array(sizeARG) {
size = sizeARG; size = sizeARG;
...@@ -106,13 +108,12 @@ public: ...@@ -106,13 +108,12 @@ public:
SignalArray<Time>(const SignalArray<Time> &siga) SignalArray<Time>(const SignalArray<Time> &siga)
: SignalArray_const<Time>(siga.getSize()), array(siga.getSize()) { : SignalArray_const<Time>(siga.getSize()), array(siga.getSize()) {
rank = siga.getSize(); rank = siga.getSize();
for (unsigned int i = 0; i < rank; ++i) for (unsigned int i = 0; i < rank; ++i) array[i] = &siga[i];
array[i] = &siga[i];
} }
virtual ~SignalArray<Time>() {} virtual ~SignalArray<Time>() {}
protected: protected:
void addElmt(SignalBase<Time> *el) { void addElmt(SignalBase<Time> *el) {
if (rank >= size) { if (rank >= size) {
size += DEFAULT_SIZE; size += DEFAULT_SIZE;
...@@ -121,14 +122,14 @@ protected: ...@@ -121,14 +122,14 @@ protected:
array[rank++] = el; array[rank++] = el;
} }
public: public:
virtual SignalArray<Time> &operator<<(SignalBase<Time> &sig) { virtual SignalArray<Time> &operator<<(SignalBase<Time> &sig) {
addElmt(&sig); addElmt(&sig);
return *this; return *this;
} }
virtual SignalArray_const<Time> virtual SignalArray_const<Time> operator<<(
operator<<(const SignalBase<Time> &sig) const { const SignalBase<Time> &sig) const {
SignalArray_const<Time> res(*this); SignalArray_const<Time> res(*this);
res << sig; res << sig;
return res; return res;
...@@ -148,6 +149,6 @@ SignalArray<Time> operator<<(SignalBase<Time> &sig1, SignalBase<Time> &sig2) { ...@@ -148,6 +149,6 @@ SignalArray<Time> operator<<(SignalBase<Time> &sig1, SignalBase<Time> &sig2) {
DYNAMIC_GRAPH_DLLAPI extern SignalArray<int> sotNOSIGNAL; DYNAMIC_GRAPH_DLLAPI extern SignalArray<int> sotNOSIGNAL;
} // end of namespace dynamicgraph. } // end of namespace dynamicgraph.
#endif //! DYNAMIC_GRAPH_SIGNAL_ARRAY_H #endif //! DYNAMIC_GRAPH_SIGNAL_ARRAY_H
...@@ -6,14 +6,14 @@ ...@@ -6,14 +6,14 @@
#ifndef DYNAMIC_GRAPH_SIGNAL_BASE_H #ifndef DYNAMIC_GRAPH_SIGNAL_BASE_H
#define DYNAMIC_GRAPH_SIGNAL_BASE_H #define DYNAMIC_GRAPH_SIGNAL_BASE_H
#include <dynamic-graph/exception-signal.h>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <dynamic-graph/fwd.hh>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <typeinfo> #include <typeinfo>
#include <dynamic-graph/exception-signal.h>
#include <dynamic-graph/fwd.hh>
namespace dynamicgraph { namespace dynamicgraph {
/** \brief The base class for signals: not to be used as such. /** \brief The base class for signals: not to be used as such.
...@@ -23,8 +23,9 @@ namespace dynamicgraph { ...@@ -23,8 +23,9 @@ namespace dynamicgraph {
value of the signal, which can involve an extra computation, value of the signal, which can involve an extra computation,
while the latter accesses a cached value, or 'copy'. while the latter accesses a cached value, or 'copy'.
*/ */
template <class Time> class SignalBase : public boost::noncopyable { template <class Time>
public: class SignalBase : public boost::noncopyable {
public:
explicit SignalBase(std::string name = "") explicit SignalBase(std::string name = "")
: name(name), signalTime(0), ready(false) {} : name(name), signalTime(0), ready(false) {}
...@@ -195,7 +196,7 @@ public: ...@@ -195,7 +196,7 @@ public:
} }
/// \} /// \}
protected: protected:
std::string name; std::string name;
Time signalTime; Time signalTime;
bool ready; bool ready;
...@@ -206,6 +207,6 @@ template <class Time> ...@@ -206,6 +207,6 @@ template <class Time>
std::ostream &operator<<(std::ostream &os, const SignalBase<Time> &sig) { std::ostream &operator<<(std::ostream &os, const SignalBase<Time> &sig) {
return sig.display(os); return sig.display(os);
} }
} // end of namespace dynamicgraph. } // end of namespace dynamicgraph.
#endif //! DYNAMIC_GRAPH_SIGNAL_BASE_H #endif //! DYNAMIC_GRAPH_SIGNAL_BASE_H
...@@ -8,4 +8,4 @@ ...@@ -8,4 +8,4 @@
#pragma warning "This file is now useless" #pragma warning "This file is now useless"
#endif // #ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HELPER_HH #endif // #ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HELPER_HH
...@@ -4,22 +4,23 @@ ...@@ -4,22 +4,23 @@
#ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HH #ifndef DYNAMIC_GRAPH_SIGNAL_CASTER_HH
#define DYNAMIC_GRAPH_SIGNAL_CASTER_HH #define DYNAMIC_GRAPH_SIGNAL_CASTER_HH
#include <map> #include <dynamic-graph/dynamic-graph-api.h>
#include <vector> #include <dynamic-graph/eigen-io.h>
#include <dynamic-graph/linear-algebra.h>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <map>
#include <vector>
#include "dynamic-graph/exception-signal.h" #include "dynamic-graph/exception-signal.h"
#include <dynamic-graph/dynamic-graph-api.h>
#include <dynamic-graph/eigen-io.h>
#include <dynamic-graph/linear-algebra.h>
namespace dynamicgraph { namespace dynamicgraph {
/// Inherit from this class if you want to keep default implementation for some /// Inherit from this class if you want to keep default implementation for some
/// functions. /// functions.
template <typename T> struct signal_io_base { template <typename T>
struct signal_io_base {
/// serialize a signal value. /// serialize a signal value.
inline static void disp(const T &value, std::ostream &os) { os << value; } inline static void disp(const T &value, std::ostream &os) { os << value; }
/// deserialize a signal value. /// deserialize a signal value.
...@@ -37,7 +38,8 @@ template <typename T> struct signal_io_base { ...@@ -37,7 +38,8 @@ template <typename T> struct signal_io_base {
}; };
/// Inherit from this class if tracing is not implemented for a given type. /// Inherit from this class if tracing is not implemented for a given type.
template <typename T> struct signal_io_unimplemented { template <typename T>
struct signal_io_unimplemented {
inline static void disp(const T &, std::ostream &) { inline static void disp(const T &, std::ostream &) {
throw std::logic_error("this disp is not implemented."); throw std::logic_error("this disp is not implemented.");
} }
...@@ -50,7 +52,8 @@ template <typename T> struct signal_io_unimplemented { ...@@ -50,7 +52,8 @@ template <typename T> struct signal_io_unimplemented {
}; };
/// Class used for I/O operations in Signal<T,Time> /// Class used for I/O operations in Signal<T,Time>
template <typename T> struct signal_io : signal_io_base<T> {}; template <typename T>
struct signal_io : signal_io_base<T> {};
/// Template specialization of signal_disp for Eigen objects /// Template specialization of signal_disp for Eigen objects
template <typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, template <typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows,
...@@ -98,7 +101,8 @@ struct signal_io<Eigen::Quaternion<_Scalar, _Options>> ...@@ -98,7 +101,8 @@ struct signal_io<Eigen::Quaternion<_Scalar, _Options>>
/// Template specialization of signal_io for std::string. /// Template specialization of signal_io for std::string.
/// Do not print '\n' at the end. /// Do not print '\n' at the end.
template <> struct signal_io<std::string> : signal_io_base<std::string> { template <>
struct signal_io<std::string> : signal_io_base<std::string> {
inline static std::string cast(std::istringstream &iss) { return iss.str(); } inline static std::string cast(std::istringstream &iss) { return iss.str(); }
}; };
...@@ -114,7 +118,8 @@ template <> struct signal_io<std::string> : signal_io_base<std::string> { ...@@ -114,7 +118,8 @@ template <> struct signal_io<std::string> : signal_io_base<std::string> {
/// To workaround this problem, parse special values manually /// To workaround this problem, parse special values manually
/// (the strings used are the one produces by displaying special /// (the strings used are the one produces by displaying special
/// values on a stream). /// values on a stream).
template <> struct signal_io<double> : signal_io_base<double> { template <>
struct signal_io<double> : signal_io_base<double> {
inline static double cast(std::istringstream &iss) { inline static double cast(std::istringstream &iss) {
std::string tmp(iss.str()); std::string tmp(iss.str());
...@@ -135,6 +140,6 @@ template <> struct signal_io<double> : signal_io_base<double> { ...@@ -135,6 +140,6 @@ template <> struct signal_io<double> : signal_io_base<double> {
} }
}; };
} // end of namespace dynamicgraph. } // end of namespace dynamicgraph.
#endif //! DYNAMIC_GRAPH_SIGNAL_CASTER_HH #endif //! DYNAMIC_GRAPH_SIGNAL_CASTER_HH
...@@ -19,18 +19,18 @@ ...@@ -19,18 +19,18 @@
/* --- MACROS ---------------------------------------------------------- */ /* --- MACROS ---------------------------------------------------------- */
#define SIGNAL_OUT_FUNCTION_NAME(name) name##SOUT_function #define SIGNAL_OUT_FUNCTION_NAME(name) name##SOUT_function
#define DECLARE_SIGNAL(name, IO, type) \ #define DECLARE_SIGNAL(name, IO, type) \
::dynamicgraph::Signal<type, int> m_##name##S##IO ::dynamicgraph::Signal<type, int> m_##name##S##IO
#define CONSTRUCT_SIGNAL(name, IO, type) \ #define CONSTRUCT_SIGNAL(name, IO, type) \
m_##name##S##IO(getClassName() + "(" + getName() + ")::" + #IO + "put(" + \ m_##name##S##IO(getClassName() + "(" + getName() + ")::" + #IO + "put(" + \
#type + ")::" + #name) #type + ")::" + #name)
#define BIND_SIGNAL_TO_FUNCTION(name, IO, type) \ #define BIND_SIGNAL_TO_FUNCTION(name, IO, type) \
m_##name##S##IO.setFunction(boost::bind( \ m_##name##S##IO.setFunction(boost::bind( \
&EntityClassName::SIGNAL_OUT_FUNCTION_NAME(name), this, _1, _2)); &EntityClassName::SIGNAL_OUT_FUNCTION_NAME(name), this, _1, _2));
/**/ /**/
#define DECLARE_SIGNAL_IN(name, type) \ #define DECLARE_SIGNAL_IN(name, type) \
::dynamicgraph::SignalPtr<type, int> m_##name##SIN ::dynamicgraph::SignalPtr<type, int> m_##name##SIN
#define CONSTRUCT_SIGNAL_IN(name, type) \ #define CONSTRUCT_SIGNAL_IN(name, type) \
m_##name##SIN(NULL, getClassName() + "(" + getName() + ")::input(" + #type + \ m_##name##SIN(NULL, getClassName() + "(" + getName() + ")::input(" + #type + \
...@@ -38,40 +38,40 @@ ...@@ -38,40 +38,40 @@
/**/ /**/
#define DECLARE_SIGNAL_OUT_FUNCTION(name, type) \ #define DECLARE_SIGNAL_OUT_FUNCTION(name, type) \
type &SIGNAL_OUT_FUNCTION_NAME(name)(type &, int) type &SIGNAL_OUT_FUNCTION_NAME(name)(type &, int)
#define DEFINE_SIGNAL_OUT_FUNCTION(name, type) \ #define DEFINE_SIGNAL_OUT_FUNCTION(name, type) \
type &EntityClassName::SIGNAL_OUT_FUNCTION_NAME(name)(type & s, int iter) type &EntityClassName::SIGNAL_OUT_FUNCTION_NAME(name)(type & s, int iter)
#define SIGNAL_OUT_FUNCTION(name) name##SOUT_function #define SIGNAL_OUT_FUNCTION(name) name##SOUT_function
#define DECLARE_SIGNAL_OUT(name, type) \ #define DECLARE_SIGNAL_OUT(name, type) \
public: \ public: \
::dynamicgraph::SignalTimeDependent<type, int> m_##name##SOUT; \ ::dynamicgraph::SignalTimeDependent<type, int> m_##name##SOUT; \
\ \
protected: \ protected: \
type &SIGNAL_OUT_FUNCTION(name)(type &, int) type &SIGNAL_OUT_FUNCTION(name)(type &, int)
#define CONSTRUCT_SIGNAL_OUT(name, type, dep) \ #define CONSTRUCT_SIGNAL_OUT(name, type, dep) \
m_##name##SOUT( \ m_##name##SOUT( \
boost::bind(&EntityClassName::name##SOUT_function, this, _1, _2), dep, \ boost::bind(&EntityClassName::name##SOUT_function, this, _1, _2), dep, \
getClassName() + "(" + getName() + ")::output(" + #type + ")::" + #name) getClassName() + "(" + getName() + ")::output(" + #type + ")::" + #name)
/**************** INNER SIGNALS *******************/ /**************** INNER SIGNALS *******************/
#define SIGNAL_INNER_FUNCTION_NAME(name) name##SINNER_function #define SIGNAL_INNER_FUNCTION_NAME(name) name##SINNER_function
#define DECLARE_SIGNAL_INNER_FUNCTION(name, type) \ #define DECLARE_SIGNAL_INNER_FUNCTION(name, type) \
type &SIGNAL_INNER_FUNCTION_NAME(name)(type &, int) type &SIGNAL_INNER_FUNCTION_NAME(name)(type &, int)
#define DEFINE_SIGNAL_INNER_FUNCTION(name, type) \ #define DEFINE_SIGNAL_INNER_FUNCTION(name, type) \
type &EntityClassName::SIGNAL_INNER_FUNCTION_NAME(name)(type & s, int iter) type &EntityClassName::SIGNAL_INNER_FUNCTION_NAME(name)(type & s, int iter)
#define DECLARE_SIGNAL_INNER(name, type) \ #define DECLARE_SIGNAL_INNER(name, type) \
public: \ public: \
::dynamicgraph::SignalTimeDependent<type, int> m_##name##SINNER; \ ::dynamicgraph::SignalTimeDependent<type, int> m_##name##SINNER; \
\ \
protected: \ protected: \
DECLARE_SIGNAL_INNER_FUNCTION(name, type) DECLARE_SIGNAL_INNER_FUNCTION(name, type)
#define CONSTRUCT_SIGNAL_INNER(name, type, dep) \ #define CONSTRUCT_SIGNAL_INNER(name, type, dep) \
...@@ -79,4 +79,4 @@ protected: \ ...@@ -79,4 +79,4 @@ protected: \
boost::bind(&EntityClassName::name##SINNER_function, this, _1, _2), dep, \ boost::bind(&EntityClassName::name##SINNER_function, this, _1, _2), dep, \
getClassName() + "(" + getName() + ")::inner(" + #type + ")::" + #name) getClassName() + "(" + getName() + ")::inner(" + #type + ")::" + #name)
#endif // __dynamic_graph_signal_helper_H__ #endif // __dynamic_graph_signal_helper_H__
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
#include <dynamic-graph/exception-signal.h> #include <dynamic-graph/exception-signal.h>
#include <dynamic-graph/signal.h> #include <dynamic-graph/signal.h>
#include <dynamic-graph/deprecated.hh>
namespace dynamicgraph { namespace dynamicgraph {
/// \ingroup dgraph /// \ingroup dgraph
/// ///
...@@ -27,10 +25,10 @@ namespace dynamicgraph { ...@@ -27,10 +25,10 @@ namespace dynamicgraph {
/// ///
template <class T, class Time> template <class T, class Time>
class SignalPtr : public virtual Signal<T, Time> { class SignalPtr : public virtual Signal<T, Time> {
public: public:
using SignalBase<Time>::getName; using SignalBase<Time>::getName;
protected: protected:
Signal<T, Time> *signalPtr; Signal<T, Time> *signalPtr;
bool modeNoThrow; bool modeNoThrow;
bool transmitAbstract; bool transmitAbstract;
...@@ -39,19 +37,22 @@ protected: ...@@ -39,19 +37,22 @@ protected:
inline bool autoref() const { return signalPtr == this; } inline bool autoref() const { return signalPtr == this; }
public: /* --- CONSTRUCTORS --- */ public: /* --- CONSTRUCTORS --- */
SignalPtr(Signal<T, Time> *ptr, std::string name = "") SignalPtr(Signal<T, Time> *ptr, std::string name = "")
: Signal<T, Time>(name), signalPtr(ptr), modeNoThrow(false), : Signal<T, Time>(name),
transmitAbstract(false), abstractTransmitter(NULL) {} signalPtr(ptr),
modeNoThrow(false),
transmitAbstract(false),
abstractTransmitter(NULL) {}
virtual ~SignalPtr() { signalPtr = NULL; } virtual ~SignalPtr() { signalPtr = NULL; }
public: public:
/* --- PLUG-IN OPERATION --- */ /* --- PLUG-IN OPERATION --- */
Signal<T, Time> *getPtr(); // throw Signal<T, Time> *getPtr(); // throw
const Signal<T, Time> *getPtr() const; // throw const Signal<T, Time> *getPtr() const; // throw
SignalBase<Time> *getAbstractPtr(); // throw SignalBase<Time> *getAbstractPtr(); // throw
const SignalBase<Time> *getAbstractPtr() const; // throw const SignalBase<Time> *getAbstractPtr() const; // throw
virtual void plug(SignalBase<Time> *ref); virtual void plug(SignalBase<Time> *ref);
virtual void unplug() { plug(NULL); } virtual void unplug() { plug(NULL); }
...@@ -68,7 +69,7 @@ public: ...@@ -68,7 +69,7 @@ public:
inline const Signal<T, Time> &operator*() const { return *getPtr(); } inline const Signal<T, Time> &operator*() const { return *getPtr(); }
inline operator bool() const { return isPlugged(); } inline operator bool() const { return isPlugged(); }
public: /* --- INHERITANCE --- */ public: /* --- INHERITANCE --- */
virtual bool needUpdate(const Time &t) const; virtual bool needUpdate(const Time &t) const;
virtual std::ostream &writeGraph(std::ostream &os) const; virtual std::ostream &writeGraph(std::ostream &os) const;
virtual std::ostream &display(std::ostream &os) const; virtual std::ostream &display(std::ostream &os) const;
...@@ -92,7 +93,7 @@ public: /* --- INHERITANCE --- */ ...@@ -92,7 +93,7 @@ public: /* --- INHERITANCE --- */
virtual void checkCompatibility(); virtual void checkCompatibility();
public: /* --- INHERITANCE --- */ public: /* --- INHERITANCE --- */
/* SignalPtr could be used as a classical signal, through the normal /* SignalPtr could be used as a classical signal, through the normal
* setting functions. The behavior is to plugged the signalPtr on * setting functions. The behavior is to plugged the signalPtr on
* the classical mother Signal layer of the object. * the classical mother Signal layer of the object.
...@@ -128,7 +129,7 @@ public: /* --- INHERITANCE --- */ ...@@ -128,7 +129,7 @@ public: /* --- INHERITANCE --- */
std::string next1 = "", std::string next1 = "",
std::string next2 = "") const; std::string next2 = "") const;
protected: // Interdiction of the rest of the heritage protected: // Interdiction of the rest of the heritage
using Signal<T, Time>::addDependency; using Signal<T, Time>::addDependency;
virtual void addDependency() {} virtual void addDependency() {}
using Signal<T, Time>::removeDependency; using Signal<T, Time>::removeDependency;
...@@ -136,7 +137,7 @@ protected: // Interdiction of the rest of the heritage ...@@ -136,7 +137,7 @@ protected: // Interdiction of the rest of the heritage
virtual void clearDependencies() {} virtual void clearDependencies() {}
}; };
} // end of namespace dynamicgraph } // end of namespace dynamicgraph
#include <dynamic-graph/signal-ptr.t.cpp> #include <dynamic-graph/signal-ptr.t.cpp>
#endif //! DYNAMIC_GRAPH_SIGNAL_PTR_H #endif //! DYNAMIC_GRAPH_SIGNAL_PTR_H
...@@ -17,10 +17,10 @@ bool SignalPtr<T, Time>::isAbstractPluged() const { ...@@ -17,10 +17,10 @@ bool SignalPtr<T, Time>::isAbstractPluged() const {
return ((NULL != signalPtr) || (abstractTransmitter)); return ((NULL != signalPtr) || (abstractTransmitter));
} }
template <class T, class Time> Signal<T, Time> *SignalPtr<T, Time>::getPtr() { template <class T, class Time>
Signal<T, Time> *SignalPtr<T, Time>::getPtr() {
dgTDEBUGIN(25); dgTDEBUGIN(25);
if (!isPlugged()) if (!isPlugged()) DG_THROW
DG_THROW
ExceptionSignal(ExceptionSignal::NOT_INITIALIZED, ExceptionSignal(ExceptionSignal::NOT_INITIALIZED,
"In SignalPtr: SIN ptr not set.", " (in signal <%s>)", "In SignalPtr: SIN ptr not set.", " (in signal <%s>)",
getName().c_str()); getName().c_str());
...@@ -110,7 +110,8 @@ void SignalPtr<T, Time>::plug(SignalBase<Time> *unknown_ref) { ...@@ -110,7 +110,8 @@ void SignalPtr<T, Time>::plug(SignalBase<Time> *unknown_ref) {
dgTDEBUGOUT(5); dgTDEBUGOUT(5);
} }
template <class T, class Time> void SignalPtr<T, Time>::checkCompatibility() { template <class T, class Time>
void SignalPtr<T, Time>::checkCompatibility() {
if (isPlugged() && (!autoref())) { if (isPlugged() && (!autoref())) {
getPtr()->checkCompatibility(); getPtr()->checkCompatibility();
} else if (isAbstractPluged() && (!autoref())) { } else if (isAbstractPluged() && (!autoref())) {
...@@ -127,7 +128,8 @@ bool SignalPtr<T, Time>::needUpdate(const Time &t) const { ...@@ -127,7 +128,8 @@ bool SignalPtr<T, Time>::needUpdate(const Time &t) const {
return Signal<T, Time>::needUpdate(t); return Signal<T, Time>::needUpdate(t);
} }
template <class T, class Time> const Time &SignalPtr<T, Time>::getTime() const { template <class T, class Time>
const Time &SignalPtr<T, Time>::getTime() const {
if ((isAbstractPluged()) && (!autoref())) { if ((isAbstractPluged()) && (!autoref())) {
return getAbstractPtr()->getTime(); return getAbstractPtr()->getTime();
} }
...@@ -158,7 +160,8 @@ const T &SignalPtr<T, Time>::access(const Time &t) { ...@@ -158,7 +160,8 @@ const T &SignalPtr<T, Time>::access(const Time &t) {
} }
} }
template <class T, class Time> const T &SignalPtr<T, Time>::accessCopy() const { template <class T, class Time>
const T &SignalPtr<T, Time>::accessCopy() const {
if (modeNoThrow && (!isPlugged()) && Signal<T, Time>::copyInit) if (modeNoThrow && (!isPlugged()) && Signal<T, Time>::copyInit)
return Signal<T, Time>::accessCopy(); return Signal<T, Time>::accessCopy();
else if (autoref()) else if (autoref())
...@@ -204,10 +207,11 @@ std::ostream &SignalPtr<T, Time>::display(std::ostream &os) const { ...@@ -204,10 +207,11 @@ std::ostream &SignalPtr<T, Time>::display(std::ostream &os) const {
} }
template <class T, class Time> template <class T, class Time>
std::ostream & std::ostream &SignalPtr<T, Time>::displayDependencies(std::ostream &os,
SignalPtr<T, Time>::displayDependencies(std::ostream &os, const int depth, const int depth,
std::string space, std::string next1, std::string space,
std::string next2) const { std::string next1,
std::string next2) const {
dgTDEBUGIN(25); dgTDEBUGIN(25);
if ((isAbstractPluged()) && (!autoref())) { if ((isAbstractPluged()) && (!autoref())) {
getAbstractPtr()->displayDependencies( getAbstractPtr()->displayDependencies(
...@@ -220,6 +224,6 @@ SignalPtr<T, Time>::displayDependencies(std::ostream &os, const int depth, ...@@ -220,6 +224,6 @@ SignalPtr<T, Time>::displayDependencies(std::ostream &os, const int depth,
return os; return os;
} }
} // end of namespace dynamicgraph. } // end of namespace dynamicgraph.
#endif //! DYNAMIC_GRAPH_SIGNAL_PTR_T_CPP #endif //! DYNAMIC_GRAPH_SIGNAL_PTR_T_CPP
...@@ -64,7 +64,7 @@ class SignalTimeDependent : public virtual Signal<T, Time>, ...@@ -64,7 +64,7 @@ class SignalTimeDependent : public virtual Signal<T, Time>,
public TimeDependency<Time> { public TimeDependency<Time> {
// TimeDependency<Time> timeDependency; // TimeDependency<Time> timeDependency;
public: public:
SignalTimeDependent(std::string name = ""); SignalTimeDependent(std::string name = "");
SignalTimeDependent(const SignalArray_const<Time> &arr, SignalTimeDependent(const SignalArray_const<Time> &arr,
std::string name = ""); std::string name = "");
...@@ -163,6 +163,6 @@ Time SignalTimeDependent<T, Time>::getPeriodTime() const { ...@@ -163,6 +163,6 @@ Time SignalTimeDependent<T, Time>::getPeriodTime() const {
return TimeDependency<Time>::getPeriodTime(); return TimeDependency<Time>::getPeriodTime();
} }
} // end of namespace dynamicgraph } // end of namespace dynamicgraph
#endif //! DYNAMIC_GRAPH_SIGNAL_TIME_DEPENDENT_H #endif //! DYNAMIC_GRAPH_SIGNAL_TIME_DEPENDENT_H
...@@ -10,14 +10,13 @@ ...@@ -10,14 +10,13 @@
#ifndef __SIGNAL_HH #ifndef __SIGNAL_HH
#define __SIGNAL_HH #define __SIGNAL_HH
#include <dynamic-graph/exception-signal.h>
#include <dynamic-graph/signal-base.h>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
#include <string> #include <string>
#include <dynamic-graph/exception-signal.h>
#include <dynamic-graph/signal-base.h>
#ifdef HAVE_LIBBOOST_THREAD #ifdef HAVE_LIBBOOST_THREAD
#include <boost/thread.hpp> #include <boost/thread.hpp>
#endif #endif
...@@ -38,8 +37,9 @@ namespace dynamicgraph { ...@@ -38,8 +37,9 @@ namespace dynamicgraph {
\li using the function setFunction(boost::function2) that will be called \li using the function setFunction(boost::function2) that will be called
when the signal's value is accessed. when the signal's value is accessed.
*/ */
template <class T, class Time> class Signal : public SignalBase<Time> { template <class T, class Time>
protected: class Signal : public SignalBase<Time> {
protected:
enum SignalType { CONSTANT, REFERENCE, REFERENCE_NON_CONST, FUNCTION }; enum SignalType { CONSTANT, REFERENCE, REFERENCE_NON_CONST, FUNCTION };
static const SignalType SIGNAL_TYPE_DEFAULT = CONSTANT; static const SignalType SIGNAL_TYPE_DEFAULT = CONSTANT;
...@@ -55,7 +55,7 @@ protected: ...@@ -55,7 +55,7 @@ protected:
bool keepReference; bool keepReference;
const static bool KEEP_REFERENCE_DEFAULT = false; const static bool KEEP_REFERENCE_DEFAULT = false;
public: public:
#ifdef HAVE_LIBBOOST_THREAD #ifdef HAVE_LIBBOOST_THREAD
typedef boost::try_mutex Mutex; typedef boost::try_mutex Mutex;
typedef boost::lock_error MutexError; typedef boost::lock_error MutexError;
...@@ -64,14 +64,14 @@ public: ...@@ -64,14 +64,14 @@ public:
typedef int *MutexError; typedef int *MutexError;
#endif #endif
protected: protected:
Mutex *providerMutex; Mutex *providerMutex;
using SignalBase<Time>::signalTime; using SignalBase<Time>::signalTime;
public: public:
using SignalBase<Time>::setReady; using SignalBase<Time>::setReady;
public: public:
/* --- Constructor/destrusctor --- */ /* --- Constructor/destrusctor --- */
Signal(std::string name); Signal(std::string name);
virtual ~Signal() {} virtual ~Signal() {}
...@@ -106,23 +106,23 @@ public: ...@@ -106,23 +106,23 @@ public:
aClassName = typeid(this).name(); aClassName = typeid(this).name();
} }
public: public:
/// checkCompatibility is used to get the object contained in the /// checkCompatibility is used to get the object contained in the
/// signal. This used to verify if a dynamic cast is possible or not. /// signal. This used to verify if a dynamic cast is possible or not.
virtual void checkCompatibility() { throw Tcopy; } virtual void checkCompatibility() { throw Tcopy; }
private: private:
const T &setTcopy(const T &t); const T &setTcopy(const T &t);
T &getTwork(); T &getTwork();
const T &getTwork() const; const T &getTwork() const;
const T &switchTcopy(); const T &switchTcopy();
}; };
} // end of namespace dynamicgraph } // end of namespace dynamicgraph
#include <dynamic-graph/signal.t.cpp> #include <dynamic-graph/signal.t.cpp>
#endif // #ifndef __SIGNAL_HH #endif // #ifndef __SIGNAL_HH
/* /*
* Local variables: * Local variables:
......
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
#define VP_TEMPLATE_DEBUG_MODE 0 #define VP_TEMPLATE_DEBUG_MODE 0
#include <dynamic-graph/debug.h> #include <dynamic-graph/debug.h>
#define __SIGNAL_INIT(name, Tcpy, Tref, TrefNC, mutex) \ #define __SIGNAL_INIT(name, Tcpy, Tref, TrefNC, mutex) \
SignalBase<Time>(name), signalType(SIGNAL_TYPE_DEFAULT), Tcopy1(Tcpy), \ SignalBase<Time>(name), signalType(SIGNAL_TYPE_DEFAULT), Tcopy1(Tcpy), \
Tcopy2(Tcpy), Tcopy(&Tcopy1), Treference(Tref), \ Tcopy2(Tcpy), Tcopy(&Tcopy1), Treference(Tref), \
TreferenceNonConst(TrefNC), Tfunction(), \ TreferenceNonConst(TrefNC), Tfunction(), \
keepReference(KEEP_REFERENCE_DEFAULT), providerMutex(mutex) keepReference(KEEP_REFERENCE_DEFAULT), providerMutex(mutex)
namespace dynamicgraph { namespace dynamicgraph {
...@@ -52,7 +52,8 @@ void Signal<T, Time>::trace(std::ostream &os) const { ...@@ -52,7 +52,8 @@ void Signal<T, Time>::trace(std::ostream &os) const {
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
template <class T, class Time> const T &Signal<T, Time>::setTcopy(const T &t) { template <class T, class Time>
const T &Signal<T, Time>::setTcopy(const T &t) {
if (Tcopy == &Tcopy1) { if (Tcopy == &Tcopy1) {
Tcopy2 = t; Tcopy2 = t;
copyInit = true; copyInit = true;
...@@ -66,21 +67,24 @@ template <class T, class Time> const T &Signal<T, Time>::setTcopy(const T &t) { ...@@ -66,21 +67,24 @@ template <class T, class Time> const T &Signal<T, Time>::setTcopy(const T &t) {
} }
} }
template <class T, class Time> T &Signal<T, Time>::getTwork() { template <class T, class Time>
T &Signal<T, Time>::getTwork() {
if (Tcopy == &Tcopy1) if (Tcopy == &Tcopy1)
return Tcopy2; return Tcopy2;
else else
return Tcopy1; return Tcopy1;
} }
template <class T, class Time> const T &Signal<T, Time>::getTwork() const { template <class T, class Time>
const T &Signal<T, Time>::getTwork() const {
if (Tcopy == &Tcopy1) if (Tcopy == &Tcopy1)
return Tcopy2; return Tcopy2;
else else
return Tcopy1; return Tcopy1;
} }
template <class T, class Time> const T &Signal<T, Time>::switchTcopy() { template <class T, class Time>
const T &Signal<T, Time>::switchTcopy() {
if (Tcopy == &Tcopy1) { if (Tcopy == &Tcopy1) {
Tcopy = &Tcopy2; Tcopy = &Tcopy2;
return Tcopy2; return Tcopy2;
...@@ -90,7 +94,8 @@ template <class T, class Time> const T &Signal<T, Time>::switchTcopy() { ...@@ -90,7 +94,8 @@ template <class T, class Time> const T &Signal<T, Time>::switchTcopy() {
} }
} }
template <class T, class Time> void Signal<T, Time>::setConstant(const T &t) { template <class T, class Time>
void Signal<T, Time>::setConstant(const T &t) {
signalType = CONSTANT; signalType = CONSTANT;
setTcopy(t); setTcopy(t);
setReady(); setReady();
...@@ -125,62 +130,64 @@ void Signal<T, Time>::setFunction(boost::function2<T &, T &, Time> t, ...@@ -125,62 +130,64 @@ void Signal<T, Time>::setFunction(boost::function2<T &, T &, Time> t,
setReady(); setReady();
} }
template <class T, class Time> const T &Signal<T, Time>::accessCopy() const { template <class T, class Time>
const T &Signal<T, Time>::accessCopy() const {
return *Tcopy; return *Tcopy;
} }
template <class T, class Time> const T &Signal<T, Time>::access(const Time &t) { template <class T, class Time>
const T &Signal<T, Time>::access(const Time &t) {
switch (signalType) { switch (signalType) {
case REFERENCE: case REFERENCE:
case REFERENCE_NON_CONST: { case REFERENCE_NON_CONST: {
if (NULL == providerMutex) { if (NULL == providerMutex) {
copyInit = true;
signalTime = t;
return setTcopy(*Treference);
} else {
try {
#ifdef HAVE_LIBBOOST_THREAD
boost::try_mutex::scoped_try_lock lock(*providerMutex);
#endif
copyInit = true; copyInit = true;
signalTime = t; signalTime = t;
return setTcopy(*Treference); return setTcopy(*Treference);
} catch (const MutexError &) { } else {
return accessCopy(); try {
#ifdef HAVE_LIBBOOST_THREAD
boost::try_mutex::scoped_try_lock lock(*providerMutex);
#endif
copyInit = true;
signalTime = t;
return setTcopy(*Treference);
} catch (const MutexError &) {
return accessCopy();
}
} }
}
break; break;
} }
case FUNCTION: { case FUNCTION: {
if (NULL == providerMutex) { if (NULL == providerMutex) {
signalTime = t;
Tfunction(getTwork(), t);
copyInit = true;
return switchTcopy();
} else {
try {
#ifdef HAVE_LIBBOOST_THREAD
boost::try_mutex::scoped_try_lock lock(*providerMutex);
#endif
signalTime = t; signalTime = t;
Tfunction(getTwork(), t); Tfunction(getTwork(), t);
copyInit = true; copyInit = true;
return switchTcopy(); return switchTcopy();
} catch (const MutexError &) { } else {
return accessCopy(); try {
#ifdef HAVE_LIBBOOST_THREAD
boost::try_mutex::scoped_try_lock lock(*providerMutex);
#endif
signalTime = t;
Tfunction(getTwork(), t);
copyInit = true;
return switchTcopy();
} catch (const MutexError &) {
return accessCopy();
}
} }
break;
} }
break; case CONSTANT:
} default:
case CONSTANT: if (this->getReady()) {
default: setReady(false);
if (this->getReady()) { this->setTime(t);
setReady(false); }
this->setTime(t); return accessCopy();
}
return accessCopy();
}; };
} }
...@@ -211,23 +218,23 @@ template <class T, class Time> ...@@ -211,23 +218,23 @@ template <class T, class Time>
std::ostream &Signal<T, Time>::display(std::ostream &os) const { std::ostream &Signal<T, Time>::display(std::ostream &os) const {
os << "Sig:" << this->name << " (Type "; os << "Sig:" << this->name << " (Type ";
switch (this->signalType) { switch (this->signalType) {
case Signal<T, Time>::CONSTANT: case Signal<T, Time>::CONSTANT:
os << "Cst"; os << "Cst";
break; break;
case Signal<T, Time>::REFERENCE: case Signal<T, Time>::REFERENCE:
os << "Ref"; os << "Ref";
break; break;
case Signal<T, Time>::REFERENCE_NON_CONST: case Signal<T, Time>::REFERENCE_NON_CONST:
os << "RefNonCst"; os << "RefNonCst";
break; break;
case Signal<T, Time>::FUNCTION: case Signal<T, Time>::FUNCTION:
os << "Fun"; os << "Fun";
break; break;
} }
return os << ")"; return os << ")";
} }
} // end of namespace dynamicgraph. } // end of namespace dynamicgraph.
#undef __SIGNAL_INIT #undef __SIGNAL_INIT
#endif //! DYNAMIC_GRAPH_SIGNAL_T_CPP #endif //! DYNAMIC_GRAPH_SIGNAL_T_CPP
...@@ -5,23 +5,24 @@ ...@@ -5,23 +5,24 @@
#ifndef DYNAMIC_GRAPH_TIME_DEPENDENCY_H #ifndef DYNAMIC_GRAPH_TIME_DEPENDENCY_H
#define DYNAMIC_GRAPH_TIME_DEPENDENCY_H #define DYNAMIC_GRAPH_TIME_DEPENDENCY_H
#include <list>
#include <dynamic-graph/fwd.hh>
#include <dynamic-graph/signal-array.h> #include <dynamic-graph/signal-array.h>
#include <dynamic-graph/signal-base.h> #include <dynamic-graph/signal-base.h>
#include <dynamic-graph/fwd.hh>
#include <list>
namespace dynamicgraph { namespace dynamicgraph {
/** \brief A helper class for setting and specifying dependencies /** \brief A helper class for setting and specifying dependencies
between signals. between signals.
*/ */
template <class Time> class TimeDependency { template <class Time>
public: class TimeDependency {
public:
enum DependencyType { TIME_DEPENDENT, BOOL_DEPENDENT, ALWAYS_READY }; enum DependencyType { TIME_DEPENDENT, BOOL_DEPENDENT, ALWAYS_READY };
mutable Time lastAskForUpdate; mutable Time lastAskForUpdate;
public: public:
SignalBase<Time> &leader; SignalBase<Time> &leader;
typedef std::list<const SignalBase<Time> *> Dependencies; typedef std::list<const SignalBase<Time> *> Dependencies;
...@@ -36,7 +37,7 @@ public: ...@@ -36,7 +37,7 @@ public:
Time periodTime; Time periodTime;
static const Time PERIOD_TIME_DEFAULT = 1; static const Time PERIOD_TIME_DEFAULT = 1;
public: public:
TimeDependency(SignalBase<Time> *sig, TimeDependency(SignalBase<Time> *sig,
const DependencyType dep = DEPENDENCY_TYPE_DEFAULT); const DependencyType dep = DEPENDENCY_TYPE_DEFAULT);
TimeDependency(SignalBase<Time> *sig, const SignalArray_const<Time> &arr, TimeDependency(SignalBase<Time> *sig, const SignalArray_const<Time> &arr,
...@@ -67,7 +68,7 @@ public: ...@@ -67,7 +68,7 @@ public:
Time getPeriodTime() const { return periodTime; } Time getPeriodTime() const { return periodTime; }
}; };
} // end of namespace dynamicgraph } // end of namespace dynamicgraph
#include <dynamic-graph/time-dependency.t.cpp> #include <dynamic-graph/time-dependency.t.cpp>
#endif //! DYNAMIC_GRAPH_TIME_DEPENDENCY_H #endif //! DYNAMIC_GRAPH_TIME_DEPENDENCY_H
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
#define VP_TEMPLATE_DEBUG_MODE 0 #define VP_TEMPLATE_DEBUG_MODE 0
#include <dynamic-graph/debug.h> #include <dynamic-graph/debug.h>
#define __TIME_DEPENDENCY_INIT(sig, dep) \ #define __TIME_DEPENDENCY_INIT(sig, dep) \
leader(*sig), dependencies(), updateFromAllChildren(ALL_READY_DEFAULT), \ leader(*sig), dependencies(), updateFromAllChildren(ALL_READY_DEFAULT), \
dependencyType(dep), periodTime(PERIOD_TIME_DEFAULT) dependencyType(dep), periodTime(PERIOD_TIME_DEFAULT)
namespace dynamicgraph { namespace dynamicgraph {
...@@ -49,7 +49,8 @@ void TimeDependency<Time>::removeDependency(const SignalBase<Time> &sig) { ...@@ -49,7 +49,8 @@ void TimeDependency<Time>::removeDependency(const SignalBase<Time> &sig) {
dependencies.remove(&sig); dependencies.remove(&sig);
} }
template <class Time> void TimeDependency<Time>::clearDependency() { template <class Time>
void TimeDependency<Time>::clearDependency() {
dependencies.clear(); dependencies.clear();
} }
...@@ -68,19 +69,19 @@ bool TimeDependency<Time>::needUpdate(const Time &t1) const { ...@@ -68,19 +69,19 @@ bool TimeDependency<Time>::needUpdate(const Time &t1) const {
} }
switch (dependencyType) { switch (dependencyType) {
case ALWAYS_READY: { case ALWAYS_READY: {
dgTDEBUGOUT(15);
return true;
}
case BOOL_DEPENDENT:
break;
case TIME_DEPENDENT: {
if (t1 < leader.getTime() + periodTime) {
dgTDEBUGOUT(15); dgTDEBUGOUT(15);
return false; return true;
}
case BOOL_DEPENDENT:
break;
case TIME_DEPENDENT: {
if (t1 < leader.getTime() + periodTime) {
dgTDEBUGOUT(15);
return false;
}
break;
} }
break;
}
}; };
bool res = updateFromAllChildren; bool res = updateFromAllChildren;
...@@ -117,24 +118,23 @@ std::ostream &TimeDependency<Time>::writeGraph(std::ostream &os) const { ...@@ -117,24 +118,23 @@ std::ostream &TimeDependency<Time>::writeGraph(std::ostream &os) const {
} }
template <class Time> template <class Time>
std::ostream & std::ostream &TimeDependency<Time>::displayDependencies(
TimeDependency<Time>::displayDependencies(std::ostream &os, const int depth, std::ostream &os, const int depth, std::string space, std::string next1,
std::string space, std::string next1, std::string next2) const {
std::string next2) const {
leader.SignalBase<Time>::displayDependencies(os, depth, space, next1, next2) leader.SignalBase<Time>::displayDependencies(os, depth, space, next1, next2)
<< " ("; << " (";
switch (dependencyType) { switch (dependencyType) {
case ALWAYS_READY: case ALWAYS_READY:
os << "A"; os << "A";
break; break;
case BOOL_DEPENDENT: case BOOL_DEPENDENT:
os << "ready=" << ((leader.getReady()) ? "TRUE" : "FALSE"); os << "ready=" << ((leader.getReady()) ? "TRUE" : "FALSE");
break; break;
case TIME_DEPENDENT: case TIME_DEPENDENT:
os << "t=" << leader.getTime() << " (/" << periodTime << ") "; os << "t=" << leader.getTime() << " (/" << periodTime << ") ";
break; break;
}; };
os << ")"; //<<std::endl; os << ")"; //<<std::endl;
{ {
const typename Dependencies::const_iterator itend = dependencies.end(); const typename Dependencies::const_iterator itend = dependencies.end();
for (typename Dependencies::const_iterator it = dependencies.begin(); for (typename Dependencies::const_iterator it = dependencies.begin();
...@@ -159,7 +159,7 @@ TimeDependency<Time>::displayDependencies(std::ostream &os, const int depth, ...@@ -159,7 +159,7 @@ TimeDependency<Time>::displayDependencies(std::ostream &os, const int depth,
return os; return os;
} }
} // end of namespace dynamicgraph } // end of namespace dynamicgraph
#undef __TIME_DEPENDENCY_INIT #undef __TIME_DEPENDENCY_INIT
#endif //! DYNAMIC_GRAPH_TIME_DEPENDENCY_T_CPP #endif //! DYNAMIC_GRAPH_TIME_DEPENDENCY_T_CPP
...@@ -5,25 +5,25 @@ ...@@ -5,25 +5,25 @@
#ifndef DYNAMIC_GRAPH_TRACER_REAL_TIME_H #ifndef DYNAMIC_GRAPH_TRACER_REAL_TIME_H
#define DYNAMIC_GRAPH_TRACER_REAL_TIME_H #define DYNAMIC_GRAPH_TRACER_REAL_TIME_H
#include <sstream> #include <dynamic-graph/tracer.h>
#include <dynamic-graph/config-tracer-real-time.hh> #include <dynamic-graph/config-tracer-real-time.hh>
#include <dynamic-graph/fwd.hh> #include <dynamic-graph/fwd.hh>
#include <dynamic-graph/tracer.h> #include <sstream>
namespace dynamicgraph { namespace dynamicgraph {
/// \ingroup plugin /// \ingroup plugin
/// ///
/// \brief Stream for the tracer real-time. /// \brief Stream for the tracer real-time.
class DG_TRACERREALTIME_DLLAPI OutStringStream : public std::ostringstream { class DG_TRACERREALTIME_DLLAPI OutStringStream : public std::ostringstream {
public: public:
char *buffer; char *buffer;
std::streamsize index; std::streamsize index;
std::streamsize bufferSize; std::streamsize bufferSize;
bool full; bool full;
std::string givenname; std::string givenname;
public: public:
OutStringStream(); OutStringStream();
~OutStringStream(); ~OutStringStream();
...@@ -39,7 +39,7 @@ public: ...@@ -39,7 +39,7 @@ public:
class DG_TRACERREALTIME_DLLAPI TracerRealTime : public Tracer { class DG_TRACERREALTIME_DLLAPI TracerRealTime : public Tracer {
DYNAMIC_GRAPH_ENTITY_DECL(); DYNAMIC_GRAPH_ENTITY_DECL();
public: public:
TracerRealTime(const std::string &n); TracerRealTime(const std::string &n);
virtual ~TracerRealTime() {} virtual ~TracerRealTime() {}
...@@ -47,8 +47,8 @@ public: ...@@ -47,8 +47,8 @@ public:
virtual void trace(); virtual void trace();
void display(std::ostream &os) const; void display(std::ostream &os) const;
DG_TRACERREALTIME_DLLAPI friend std::ostream & DG_TRACERREALTIME_DLLAPI friend std::ostream &operator<<(
operator<<(std::ostream &os, const TracerRealTime &t); std::ostream &os, const TracerRealTime &t);
void emptyBuffers(); void emptyBuffers();
...@@ -56,18 +56,18 @@ public: ...@@ -56,18 +56,18 @@ public:
const int &getBufferSize() { return bufferSize; } const int &getBufferSize() { return bufferSize; }
protected: protected:
virtual void openFile(const SignalBase<int> &sig, virtual void openFile(const SignalBase<int> &sig,
const std::string &filename); const std::string &filename);
virtual void recordSignal(std::ostream &os, const SignalBase<int> &sig); virtual void recordSignal(std::ostream &os, const SignalBase<int> &sig);
typedef std::list<std::ofstream *> HardFileList; typedef std::list<std::ofstream *> HardFileList;
static const int BUFFER_SIZE_DEFAULT = 1048576; // 1Mo static const int BUFFER_SIZE_DEFAULT = 1048576; // 1Mo
int bufferSize; int bufferSize;
HardFileList hardFiles; HardFileList hardFiles;
}; };
} // end of namespace dynamicgraph } // end of namespace dynamicgraph
#endif //! DYNAMIC_GRAPH_TRACER_REAL_TIME_H #endif //! DYNAMIC_GRAPH_TRACER_REAL_TIME_H
...@@ -5,18 +5,17 @@ ...@@ -5,18 +5,17 @@
#ifndef DYNAMIC_GRAPH_TRACER_H #ifndef DYNAMIC_GRAPH_TRACER_H
#define DYNAMIC_GRAPH_TRACER_H #define DYNAMIC_GRAPH_TRACER_H
#include <boost/function.hpp>
#include <list>
#include <mutex>
#include <string>
#include <dynamic-graph/entity.h> #include <dynamic-graph/entity.h>
#include <dynamic-graph/exception-traces.h> #include <dynamic-graph/exception-traces.h>
#include <dynamic-graph/signal-base.h> #include <dynamic-graph/signal-base.h>
#include <dynamic-graph/signal-time-dependent.h> #include <dynamic-graph/signal-time-dependent.h>
#include <dynamic-graph/time-dependency.h> #include <dynamic-graph/time-dependency.h>
#include <boost/function.hpp>
#include <dynamic-graph/config-tracer.hh> #include <dynamic-graph/config-tracer.hh>
#include <list>
#include <mutex>
#include <string>
namespace dynamicgraph { namespace dynamicgraph {
/// \ingroup plugin /// \ingroup plugin
...@@ -25,12 +24,12 @@ namespace dynamicgraph { ...@@ -25,12 +24,12 @@ namespace dynamicgraph {
class DG_TRACER_DLLAPI Tracer : public Entity { class DG_TRACER_DLLAPI Tracer : public Entity {
DYNAMIC_GRAPH_ENTITY_DECL(); DYNAMIC_GRAPH_ENTITY_DECL();
protected: protected:
typedef std::list<const SignalBase<int> *> SignalList; typedef std::list<const SignalBase<int> *> SignalList;
SignalList toTraceSignals; SignalList toTraceSignals;
std::mutex files_mtx; std::mutex files_mtx;
public: public:
enum TraceStyle { enum TraceStyle {
WHEN_SAID WHEN_SAID
/// Record, then trace to file only when said to. /// Record, then trace to file only when said to.
...@@ -56,7 +55,7 @@ public: ...@@ -56,7 +55,7 @@ public:
bool play; bool play;
int timeStart; int timeStart;
public: public:
Tracer(const std::string n); Tracer(const std::string n);
virtual ~Tracer() { closeFiles(); } virtual ~Tracer() { closeFiles(); }
...@@ -70,11 +69,11 @@ public: ...@@ -70,11 +69,11 @@ public:
const std::string &suffix); const std::string &suffix);
virtual void closeFiles(); virtual void closeFiles();
protected: protected:
virtual void openFile(const SignalBase<int> &sig, virtual void openFile(const SignalBase<int> &sig,
const std::string &filename); const std::string &filename);
public: public:
void setTraceStyle(const TraceStyle &style) { traceStyle = style; } void setTraceStyle(const TraceStyle &style) { traceStyle = style; }
TraceStyle getTraceStyle() { return traceStyle; } TraceStyle getTraceStyle() { return traceStyle; }
...@@ -89,7 +88,7 @@ public: ...@@ -89,7 +88,7 @@ public:
void start() { play = true; } void start() { play = true; }
void stop() { play = false; } void stop() { play = false; }
public: public:
// SignalTrigerer<int> triger; // SignalTrigerer<int> triger;
SignalTimeDependent<int, int> triger; SignalTimeDependent<int, int> triger;
...@@ -101,6 +100,6 @@ public: ...@@ -101,6 +100,6 @@ public:
void display(std::ostream &os) const; void display(std::ostream &os) const;
}; };
} // end of namespace dynamicgraph } // end of namespace dynamicgraph
#endif //! DYNAMIC_GRAPH_TRACER_H #endif //! DYNAMIC_GRAPH_TRACER_H
...@@ -7,25 +7,29 @@ ...@@ -7,25 +7,29 @@
#ifndef DYNAMIC_GRAPH_VALUE_H #ifndef DYNAMIC_GRAPH_VALUE_H
#define DYNAMIC_GRAPH_VALUE_H #define DYNAMIC_GRAPH_VALUE_H
#include "dynamic-graph/dynamic-graph-api.h"
#include <cassert>
#include <dynamic-graph/linear-algebra.h> #include <dynamic-graph/linear-algebra.h>
#include <cassert>
#include <string> #include <string>
#include <typeinfo> #include <typeinfo>
#include <vector> #include <vector>
#include "dynamic-graph/dynamic-graph-api.h"
namespace dynamicgraph { namespace dynamicgraph {
namespace command { namespace command {
class Value; class Value;
typedef std::vector<Value> Values; typedef std::vector<Value> Values;
class DYNAMIC_GRAPH_DLLAPI EitherType { class DYNAMIC_GRAPH_DLLAPI EitherType {
public: public:
EitherType(const Value &value); EitherType(const Value &value);
~EitherType(); ~EitherType();
operator bool() const; operator bool() const;
operator unsigned() const; operator unsigned() const;
operator unsigned long int() const;
operator int() const; operator int() const;
operator long int() const;
operator float() const; operator float() const;
operator double() const; operator double() const;
operator std::string() const; operator std::string() const;
...@@ -34,7 +38,7 @@ public: ...@@ -34,7 +38,7 @@ public:
operator Eigen::Matrix4d() const; operator Eigen::Matrix4d() const;
operator Values() const; operator Values() const;
private: private:
const Value *value_; const Value *value_;
}; };
...@@ -44,12 +48,14 @@ private: ...@@ -44,12 +48,14 @@ private:
*/ */
class DYNAMIC_GRAPH_DLLAPI Value { class DYNAMIC_GRAPH_DLLAPI Value {
public: public:
enum Type { enum Type {
NONE, NONE,
BOOL, BOOL,
UNSIGNED, UNSIGNED,
UNSIGNEDLONGINT,
INT, INT,
LONGINT,
FLOAT, FLOAT,
DOUBLE, DOUBLE,
STRING, STRING,
...@@ -63,7 +69,9 @@ public: ...@@ -63,7 +69,9 @@ public:
void deleteValue(); void deleteValue();
explicit Value(const bool &value); explicit Value(const bool &value);
explicit Value(const unsigned &value); explicit Value(const unsigned &value);
explicit Value(const unsigned long int &value);
explicit Value(const int &value); explicit Value(const int &value);
explicit Value(const long int &value);
explicit Value(const float &value); explicit Value(const float &value);
explicit Value(const double &value); explicit Value(const double &value);
explicit Value(const std::string &value); explicit Value(const std::string &value);
...@@ -101,11 +109,13 @@ public: ...@@ -101,11 +109,13 @@ public:
DYNAMIC_GRAPH_DLLAPI friend std::ostream &operator<<(std::ostream &os, DYNAMIC_GRAPH_DLLAPI friend std::ostream &operator<<(std::ostream &os,
const Value &value); const Value &value);
public: public:
friend class EitherType; friend class EitherType;
bool boolValue() const; bool boolValue() const;
unsigned unsignedValue() const; unsigned unsignedValue() const;
unsigned long int unsignedlongintValue() const;
int intValue() const; int intValue() const;
long int longintValue() const;
float floatValue() const; float floatValue() const;
double doubleValue() const; double doubleValue() const;
std::string stringValue() const; std::string stringValue() const;
...@@ -122,10 +132,11 @@ public: ...@@ -122,10 +132,11 @@ public:
// Note: to ensure the WIN32 compatibility, it is necessary to export // Note: to ensure the WIN32 compatibility, it is necessary to export
// the template specialization. Also, it is forbidden to do the template // the template specialization. Also, it is forbidden to do the template
// specialization declaration in the header file, for the same reason. // specialization declaration in the header file, for the same reason.
template <typename T> struct DYNAMIC_GRAPH_DLLAPI ValueHelper { template <typename T>
struct DYNAMIC_GRAPH_DLLAPI ValueHelper {
static const Value::Type TypeID; static const Value::Type TypeID;
}; };
} // namespace command } // namespace command
} // namespace dynamicgraph } // namespace dynamicgraph
#endif // DYNAMIC_GRAPH_VALUE_H #endif // DYNAMIC_GRAPH_VALUE_H
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<script> <script>
function renderDOTFile() { function renderDOTFile() {
var fileInputElement = document.getElementById("fileInputElement"); var fileInputElement = document.getElementById("fileInputElement");
var reader = new FileReader(); var reader = new FileReader();
var graphtextres = "" var graphtextres = ""
reader.onloadend = function(e) { reader.onloadend = function(e) {
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
.catch(error => { .catch(error => {
// Create a new Viz instance (@see Caveats page for more info) // Create a new Viz instance (@see Caveats page for more info)
viz = new Viz(); viz = new Viz();
// Possibly display the error // Possibly display the error
console.error(error); console.error(error);
}); });
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
</script> </script>
<input type="file" id="fileInputElement"> <input type="file" id="fileInputElement">
<input id="Rendering" type="button" value="Rendering" onclick="renderDOTFile();" /> <input id="Rendering" type="button" value="Rendering" onclick="renderDOTFile();" />
<script> <script>
var el = document.getElementById("Rendering"); var el = document.getElementById("Rendering");
...@@ -49,4 +49,3 @@ ...@@ -49,4 +49,3 @@
</body> </body>
</html> </html>
<?xml version="1.0"?> <?xml version="1.0"?>
<package format="3"> <package format="3">
<name>dynamic-graph</name> <name>dynamic-graph</name>
<version>4.4.0</version> <version>4.4.1</version>
<description> <description>
Dynamic graph library Dynamic graph library
</description> </description>
......
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
// //
#include "dynamic-graph/command.h" #include "dynamic-graph/command.h"
#include "dynamic-graph/exception-abstract.h"
#include <sstream> #include <sstream>
#include "dynamic-graph/exception-abstract.h"
namespace dynamicgraph { namespace dynamicgraph {
namespace command { namespace command {
...@@ -51,5 +53,5 @@ Value Command::execute() { return doExecute(); } ...@@ -51,5 +53,5 @@ Value Command::execute() { return doExecute(); }
Entity &Command::owner() { return owner_; } Entity &Command::owner() { return owner_; }
std::string Command::getDocstring() const { return docstring_; } std::string Command::getDocstring() const { return docstring_; }
} // namespace command } // namespace command
} // namespace dynamicgraph } // namespace dynamicgraph
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
// //
#include "dynamic-graph/value.h" #include "dynamic-graph/value.h"
#include "dynamic-graph/exception-abstract.h" #include "dynamic-graph/exception-abstract.h"
namespace dynamicgraph { namespace dynamicgraph {
...@@ -21,7 +22,11 @@ EitherType::~EitherType() { ...@@ -21,7 +22,11 @@ EitherType::~EitherType() {
EitherType::operator bool() const { return value_->boolValue(); } EitherType::operator bool() const { return value_->boolValue(); }
EitherType::operator unsigned() const { return value_->unsignedValue(); } EitherType::operator unsigned() const { return value_->unsignedValue(); }
EitherType::operator unsigned long int() const {
return value_->unsignedlongintValue();
}
EitherType::operator int() const { return value_->intValue(); } EitherType::operator int() const { return value_->intValue(); }
EitherType::operator long int() const { return value_->longintValue(); }
EitherType::operator float() const { return value_->floatValue(); } EitherType::operator float() const { return value_->floatValue(); }
EitherType::operator double() const { return value_->doubleValue(); } EitherType::operator double() const { return value_->doubleValue(); }
EitherType::operator std::string() const { return value_->stringValue(); } EitherType::operator std::string() const { return value_->stringValue(); }
...@@ -33,37 +38,47 @@ EitherType::operator Values() const { return value_->valuesValue(); } ...@@ -33,37 +38,47 @@ EitherType::operator Values() const { return value_->valuesValue(); }
void Value::deleteValue() { void Value::deleteValue() {
switch (type_) { switch (type_) {
case BOOL: case BOOL:
delete (const bool *)value_; delete (const bool *)value_;
break; break;
case UNSIGNED: case UNSIGNED:
delete (const unsigned *)value_; delete (const unsigned *)value_;
break; break;
case INT: case UNSIGNEDLONGINT:
delete (const int *)value_; delete (const unsigned long int *)value_;
break; break;
case FLOAT: case INT:
delete (const float *)value_; delete (const int *)value_;
break; break;
case DOUBLE: case LONGINT:
delete (const double *)value_; delete (const long int *)value_;
break; break;
case STRING: case FLOAT:
delete (const std::string *)value_; delete (const float *)value_;
break; break;
case VECTOR: case DOUBLE:
delete (const Vector *)value_; delete (const double *)value_;
break; break;
case MATRIX: case STRING:
delete (const Eigen::MatrixXd *)value_; delete (const std::string *)value_;
break; break;
case MATRIX4D: case VECTOR:
delete (const Eigen::Matrix4d *)value_; delete (const Vector *)value_;
break; break;
case VALUES: case MATRIX:
delete (const Values *)value_; delete (const Eigen::MatrixXd *)value_;
break; break;
default:; case MATRIX4D:
delete (const Eigen::Matrix4d *)value_;
break;
case VALUES:
delete (const Values *)value_;
break;
case NONE: /* Equivalent to void */
break;
default:
throw "Value::deleteValue : Undefined type";
;
} }
} }
...@@ -72,6 +87,8 @@ Value::~Value() { deleteValue(); } ...@@ -72,6 +87,8 @@ Value::~Value() { deleteValue(); }
Value::Value(const bool &value) : type_(BOOL), value_(new bool(value)) {} Value::Value(const bool &value) : type_(BOOL), value_(new bool(value)) {}
Value::Value(const unsigned &value) Value::Value(const unsigned &value)
: type_(UNSIGNED), value_(new unsigned(value)) {} : type_(UNSIGNED), value_(new unsigned(value)) {}
Value::Value(const unsigned long int &value)
: type_(UNSIGNEDLONGINT), value_(new unsigned long int(value)) {}
Value::Value(const int &value) : type_(INT), value_(new int(value)) {} Value::Value(const int &value) : type_(INT), value_(new int(value)) {}
Value::Value(const float &value) : type_(FLOAT), value_(new float(value)) {} Value::Value(const float &value) : type_(FLOAT), value_(new float(value)) {}
Value::Value(const double &value) : type_(DOUBLE), value_(new double(value)) {} Value::Value(const double &value) : type_(DOUBLE), value_(new double(value)) {}
...@@ -90,42 +107,47 @@ Value::Value(const Value &value) ...@@ -90,42 +107,47 @@ Value::Value(const Value &value)
void *copyValue(const Value &value) { void *copyValue(const Value &value) {
void *copy; void *copy;
switch (value.type()) { switch (value.type()) {
case Value::NONE:
case Value::NONE: copy = NULL;
copy = NULL; break;
break; case Value::BOOL:
case Value::BOOL: copy = new bool(value.boolValue());
copy = new bool(value.boolValue()); break;
break; case Value::UNSIGNED:
case Value::UNSIGNED: copy = new unsigned(value.unsignedValue());
copy = new unsigned(value.unsignedValue()); break;
break; case Value::UNSIGNEDLONGINT:
case Value::INT: copy = new unsigned long int(value.unsignedlongintValue());
copy = new int(value.intValue()); break;
break; case Value::INT:
case Value::FLOAT: copy = new int(value.intValue());
copy = new float(value.floatValue()); break;
break; case Value::LONGINT:
case Value::DOUBLE: copy = new long int(value.longintValue());
copy = new double(value.doubleValue()); break;
break; case Value::FLOAT:
case Value::STRING: copy = new float(value.floatValue());
copy = new std::string(value.stringValue()); break;
break; case Value::DOUBLE:
case Value::VECTOR: copy = new double(value.doubleValue());
copy = new Vector(value.vectorValue()); break;
break; case Value::STRING:
case Value::MATRIX: copy = new std::string(value.stringValue());
copy = new Eigen::MatrixXd(value.matrixXdValue()); break;
break; case Value::VECTOR:
case Value::MATRIX4D: copy = new Vector(value.vectorValue());
copy = new Eigen::Matrix4d(value.matrix4dValue()); break;
break; case Value::MATRIX:
case Value::VALUES: copy = new Eigen::MatrixXd(value.matrixXdValue());
copy = new Values(value.valuesValue()); break;
break; case Value::MATRIX4D:
default: copy = new Eigen::Matrix4d(value.matrix4dValue());
abort(); break;
case Value::VALUES:
copy = new Values(value.valuesValue());
break;
default:
abort();
} }
return copy; return copy;
} }
...@@ -134,8 +156,7 @@ Value::Value() : type_(NONE), value_(NULL) {} ...@@ -134,8 +156,7 @@ Value::Value() : type_(NONE), value_(NULL) {}
Value Value::operator=(const Value &value) { Value Value::operator=(const Value &value) {
if (&value != this) { if (&value != this) {
if (value_ != 0x0) if (value_ != 0x0) deleteValue();
deleteValue();
type_ = value.type_; type_ = value.type_;
void **ptValue = const_cast<void **>(&value_); void **ptValue = const_cast<void **>(&value_);
*ptValue = copyValue(value); *ptValue = copyValue(value);
...@@ -144,33 +165,34 @@ Value Value::operator=(const Value &value) { ...@@ -144,33 +165,34 @@ Value Value::operator=(const Value &value) {
} }
bool Value::operator==(const Value &other) const { bool Value::operator==(const Value &other) const {
if (type_ != other.type_) if (type_ != other.type_) return false;
return false;
switch (type_) { switch (type_) {
case Value::BOOL: case Value::BOOL:
return boolValue() == other.boolValue(); return boolValue() == other.boolValue();
case Value::UNSIGNED: case Value::UNSIGNED:
return unsignedValue() == other.unsignedValue(); return unsignedValue() == other.unsignedValue();
case Value::INT: case Value::UNSIGNEDLONGINT:
return intValue() == other.intValue(); return unsignedlongintValue() == other.unsignedlongintValue();
case Value::DOUBLE: case Value::INT:
return doubleValue() == other.doubleValue(); return intValue() == other.intValue();
case Value::FLOAT: case Value::DOUBLE:
return floatValue() == other.floatValue(); return doubleValue() == other.doubleValue();
case Value::STRING: case Value::FLOAT:
return stringValue() == other.stringValue(); return floatValue() == other.floatValue();
case Value::VECTOR: case Value::STRING:
return vectorValue() == other.vectorValue(); return stringValue() == other.stringValue();
case Value::MATRIX: case Value::VECTOR:
return matrixXdValue() == other.matrixXdValue(); return vectorValue() == other.vectorValue();
case Value::MATRIX4D: case Value::MATRIX:
return matrix4dValue() == other.matrix4dValue(); return matrixXdValue() == other.matrixXdValue();
case Value::VALUES: case Value::MATRIX4D:
return constValuesValue() == other.constValuesValue(); return matrix4dValue() == other.matrix4dValue();
case Value::NONE: case Value::VALUES:
break; return constValuesValue() == other.constValuesValue();
default: case Value::NONE:
break; break;
default:
break;
} }
return false; return false;
} }
...@@ -180,22 +202,30 @@ const EitherType Value::value() const { return EitherType(*this); } ...@@ -180,22 +202,30 @@ const EitherType Value::value() const { return EitherType(*this); }
Value::Type Value::type() const { return type_; } Value::Type Value::type() const { return type_; }
bool Value::boolValue() const { bool Value::boolValue() const {
if (type_ == BOOL) if (type_ == BOOL) return *((const bool *)value_);
return *((const bool *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an bool"); throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an bool");
} }
unsigned Value::unsignedValue() const { unsigned Value::unsignedValue() const {
if (type_ == UNSIGNED) if (type_ == UNSIGNED) return *((const unsigned *)value_);
return *((const unsigned *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, throw ExceptionAbstract(ExceptionAbstract::TOOLS,
"value is not an unsigned int"); "value is not an unsigned int");
} }
unsigned long int Value::unsignedlongintValue() const {
if (type_ == UNSIGNEDLONGINT) return *((const unsigned long int *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS,
"value is not an unsigned long int");
}
long int Value::longintValue() const {
if (type_ == LONGINT) return *((const long int *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an long int");
}
int Value::intValue() const { int Value::intValue() const {
if (type_ == INT) if (type_ == INT) return *((const int *)value_);
return *((const int *)value_); throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an int");
throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an int int");
} }
float Value::floatValue() const { float Value::floatValue() const {
...@@ -215,127 +245,138 @@ double Value::doubleValue() const { ...@@ -215,127 +245,138 @@ double Value::doubleValue() const {
} }
std::string Value::stringValue() const { std::string Value::stringValue() const {
if (type_ == STRING) if (type_ == STRING) return *((const std::string *)value_);
return *((const std::string *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an string"); throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an string");
} }
Vector Value::vectorValue() const { Vector Value::vectorValue() const {
if (type_ == VECTOR) if (type_ == VECTOR) return *((const Vector *)value_);
return *((const Vector *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an vector"); throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an vector");
} }
Eigen::MatrixXd Value::matrixXdValue() const { Eigen::MatrixXd Value::matrixXdValue() const {
if (type_ == MATRIX) if (type_ == MATRIX) return *((const Eigen::MatrixXd *)value_);
return *((const Eigen::MatrixXd *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, throw ExceptionAbstract(ExceptionAbstract::TOOLS,
"value is not a Eigen matrixXd"); "value is not a Eigen matrixXd");
} }
Eigen::Matrix4d Value::matrix4dValue() const { Eigen::Matrix4d Value::matrix4dValue() const {
if (type_ == MATRIX4D) if (type_ == MATRIX4D) return *((const Eigen::Matrix4d *)value_);
return *((const Eigen::Matrix4d *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, throw ExceptionAbstract(ExceptionAbstract::TOOLS,
"value is not a Eigen matrix4d"); "value is not a Eigen matrix4d");
} }
Values Value::valuesValue() const { Values Value::valuesValue() const {
if (type_ == VALUES) if (type_ == VALUES) return *((const Values *)value_);
return *((const Values *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, throw ExceptionAbstract(ExceptionAbstract::TOOLS,
"value is not a vector of Value"); "value is not a vector of Value");
} }
const Values &Value::constValuesValue() const { const Values &Value::constValuesValue() const {
if (type_ == VALUES) if (type_ == VALUES) return *((const Values *)value_);
return *((const Values *)value_);
throw ExceptionAbstract(ExceptionAbstract::TOOLS, throw ExceptionAbstract(ExceptionAbstract::TOOLS,
"value is not a vector of Value"); "value is not a vector of Value");
} }
std::string Value::typeName(Type type) { std::string Value::typeName(Type type) {
switch (type) { switch (type) {
case BOOL: case BOOL:
return std::string("bool"); return std::string("bool");
case UNSIGNED: case UNSIGNED:
return std::string("unsigned int"); return std::string("unsigned int");
case INT: case UNSIGNEDLONGINT:
return std::string("int"); return std::string("unsigned long int");
case FLOAT: case INT:
return std::string("float"); return std::string("int");
case DOUBLE: case FLOAT:
return std::string("double"); return std::string("float");
case STRING: case DOUBLE:
return std::string("string"); return std::string("double");
case VECTOR: case STRING:
return std::string("vector"); return std::string("string");
case MATRIX: case VECTOR:
return std::string("matrixXd"); return std::string("vector");
case MATRIX4D: case MATRIX:
return std::string("matrix4d"); return std::string("matrixXd");
case VALUES: case MATRIX4D:
return std::string("values"); return std::string("matrix4d");
default: case VALUES:
return std::string("unknown"); return std::string("values");
default:
return std::string("unknown");
} }
} }
std::ostream &operator<<(std::ostream &os, const Value &value) { std::ostream &operator<<(std::ostream &os, const Value &value) {
os << "Type=" << Value::typeName(value.type_) << ", value="; os << "Type=" << Value::typeName(value.type_) << ", value=";
switch (value.type_) { switch (value.type_) {
case Value::BOOL: case Value::BOOL:
os << value.boolValue(); os << value.boolValue();
break; break;
case Value::UNSIGNED: case Value::UNSIGNED:
os << value.unsignedValue(); os << value.unsignedValue();
break; break;
case Value::INT: case Value::UNSIGNEDLONGINT:
os << value.intValue(); os << value.unsignedlongintValue();
break; break;
case Value::DOUBLE: case Value::INT:
os << value.doubleValue(); os << value.intValue();
break; break;
case Value::FLOAT: case Value::DOUBLE:
os << value.floatValue(); os << value.doubleValue();
break; break;
case Value::STRING: case Value::FLOAT:
os << value.stringValue(); os << value.floatValue();
break; break;
case Value::VECTOR: case Value::STRING:
os << value.vectorValue(); os << value.stringValue();
break; break;
case Value::MATRIX: case Value::VECTOR:
os << value.matrixXdValue(); os << value.vectorValue();
break; break;
case Value::MATRIX4D: case Value::MATRIX:
os << value.matrix4dValue(); os << value.matrixXdValue();
break; break;
case Value::VALUES: { case Value::MATRIX4D:
const std::vector<Value> &vals = value.constValuesValue(); os << value.matrix4dValue();
os << "[ "; break;
for (std::size_t i = 0; i < vals.size(); ++i) case Value::VALUES: {
os << "Value(" << vals[i] << "), "; const std::vector<Value> &vals = value.constValuesValue();
os << "]"; os << "[ ";
} break; for (std::size_t i = 0; i < vals.size(); ++i)
default: os << "Value(" << vals[i] << "), ";
return os; os << "]";
} break;
default:
return os;
} }
return os; return os;
} }
template <> const Value::Type ValueHelper<bool>::TypeID = Value::BOOL; template <>
template <> const Value::Type ValueHelper<unsigned>::TypeID = Value::UNSIGNED; const Value::Type ValueHelper<bool>::TypeID = Value::BOOL;
template <> const Value::Type ValueHelper<int>::TypeID = Value::INT; template <>
template <> const Value::Type ValueHelper<float>::TypeID = Value::FLOAT; const Value::Type ValueHelper<unsigned>::TypeID = Value::UNSIGNED;
template <> const Value::Type ValueHelper<double>::TypeID = Value::DOUBLE; template <>
template <> const Value::Type ValueHelper<std::string>::TypeID = Value::STRING; const Value::Type ValueHelper<unsigned long int>::TypeID =
template <> const Value::Type ValueHelper<Vector>::TypeID = Value::VECTOR; Value::UNSIGNEDLONGINT;
template <>
const Value::Type ValueHelper<int>::TypeID = Value::INT;
template <>
const Value::Type ValueHelper<float>::TypeID = Value::FLOAT;
template <>
const Value::Type ValueHelper<double>::TypeID = Value::DOUBLE;
template <>
const Value::Type ValueHelper<std::string>::TypeID = Value::STRING;
template <>
const Value::Type ValueHelper<Vector>::TypeID = Value::VECTOR;
template <> template <>
const Value::Type ValueHelper<Eigen::MatrixXd>::TypeID = Value::MATRIX; const Value::Type ValueHelper<Eigen::MatrixXd>::TypeID = Value::MATRIX;
template <> template <>
const Value::Type ValueHelper<Eigen::Matrix4d>::TypeID = Value::MATRIX4D; const Value::Type ValueHelper<Eigen::Matrix4d>::TypeID = Value::MATRIX4D;
template <> const Value::Type ValueHelper<Values>::TypeID = Value::VALUES; template <>
const Value::Type ValueHelper<Values>::TypeID = Value::VALUES;
} // namespace command } // namespace command
} // namespace dynamicgraph } // namespace dynamicgraph
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
*/ */
#include <dynamic-graph/debug.h> #include <dynamic-graph/debug.h>
#include <fstream> #include <fstream>
#include <ios> #include <ios>
...@@ -32,7 +33,7 @@ std::ofstream dg_debugfile("/tmp/dynamic-graph-traces.txt", ...@@ -32,7 +33,7 @@ std::ofstream dg_debugfile("/tmp/dynamic-graph-traces.txt",
#else #else
std::ofstream dg_debugfile; std::ofstream dg_debugfile;
class dgDebug_init { class dgDebug_init {
public: public:
dgDebug_init() { dg_debugfile.setstate(std::ios::failbit); } dgDebug_init() { dg_debugfile.setstate(std::ios::failbit); }
}; };
dgDebug_init dgDebug_initialisator; dgDebug_init dgDebug_initialisator;
...@@ -42,11 +43,10 @@ dgDebug_init dgDebug_initialisator; ...@@ -42,11 +43,10 @@ dgDebug_init dgDebug_initialisator;
namespace dynamicgraph { namespace dynamicgraph {
DebugTrace dgDEBUGFLOW(dg_debugfile); DebugTrace dgDEBUGFLOW(dg_debugfile);
DebugTrace dgERRORFLOW(dg_debugfile); DebugTrace dgERRORFLOW(dg_debugfile);
} // namespace dynamicgraph } // namespace dynamicgraph
void DebugTrace::openFile(const char *filename) { void DebugTrace::openFile(const char *filename) {
if (dg_debugfile.good() && dg_debugfile.is_open()) if (dg_debugfile.good() && dg_debugfile.is_open()) dg_debugfile.close();
dg_debugfile.close();
dg_debugfile.clear(); dg_debugfile.clear();
dg_debugfile.open(filename, std::ios::trunc & std::ios::out); dg_debugfile.open(filename, std::ios::trunc & std::ios::out);
} }
......