Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use long int fot signal time type. #117

Merged
merged 8 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions include/dynamic-graph/command-setter.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,41 @@ Value Setter<E, unsigned>::doExecute() {
return Value();
}

//
// Template specialization: unsigned long
//
template <class E>
class Setter<E, unsigned long> : public Command {
public:
/// Pointer to method that sets parameter of type unsigned long
typedef void (E::*SetterMethod)(const unsigned long &);
/// Constructor
Setter(E &entity, SetterMethod setterMethod, const std::string &docString);

protected:
virtual Value doExecute();

private:
SetterMethod setterMethod_;
}; // Class Setter

template <class E>
Setter<E, unsigned long>::Setter(E &entity, SetterMethod setterMethod,
const std::string &docString)
: Command(entity, boost::assign::list_of(Value::UNSIGNEDLONGINT),
docString),
setterMethod_(setterMethod) {}

template <class E>
Value Setter<E, unsigned long>::doExecute() {
const std::vector<Value> &values = getParameterValues();
// Get parameter
unsigned long value = values[0].value();
E &entity = static_cast<E &>(owner());
(entity.*setterMethod_)(value);
return Value();
}

//
// Template specialization: int
//
Expand Down Expand Up @@ -120,6 +155,40 @@ Value Setter<E, int>::doExecute() {
return Value();
}

//
// Template specialization: int64_t
//
template <class E>
class Setter<E, int64_t> : public Command {
public:
/// Pointer to method that sets parameter of type int64_t
typedef void (E::*SetterMethod)(const int64_t &);
/// Constructor
Setter(E &entity, SetterMethod setterMethod, const std::string &docString);

protected:
virtual Value doExecute();

private:
SetterMethod setterMethod_;
}; // Class Setter

template <class E>
Setter<E, int64_t>::Setter(E &entity, SetterMethod setterMethod,
const std::string &docString)
: Command(entity, boost::assign::list_of(Value::LONGINT), docString),
setterMethod_(setterMethod) {}

template <class E>
Value Setter<E, int64_t>::doExecute() {
const std::vector<Value> &values = getParameterValues();
// Get parameter
int64_t value = values[0].value();
E &entity = static_cast<E &>(owner());
(entity.*setterMethod_)(value);
return Value();
}

//
// Template specialization: float
//
Expand Down
12 changes: 6 additions & 6 deletions include/dynamic-graph/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ 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<std::string, SignalBase<sigtime_t> *> SignalMap;
typedef std::map<const std::string, command::Command *> CommandMap_t;

explicit Entity(const std::string &name);
Expand All @@ -76,13 +76,13 @@ class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable {
\param signalName: Name of the signal
\return A reference to the signal with a temporal dependency.
*/
SignalBase<int> &getSignal(const std::string &signalName);
SignalBase<sigtime_t> &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;
const SignalBase<sigtime_t> &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.
Expand All @@ -108,9 +108,9 @@ class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable {
*/
virtual void display(std::ostream &os) const;

virtual SignalBase<int> *test() { return 0; }
virtual SignalBase<sigtime_t> *test() { return 0; }

virtual void test2(SignalBase<int> *) { return; }
virtual void test2(SignalBase<sigtime_t> *) { return; }

const std::string &getCommandList() const;

Expand Down Expand Up @@ -168,7 +168,7 @@ class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable {
void entityRegistration();
void entityDeregistration();

void signalRegistration(const SignalArray<int> &signals);
void signalRegistration(const SignalArray<sigtime_t> &signals);
void signalDeregistration(const std::string &name);

std::string name;
Expand Down
2 changes: 2 additions & 0 deletions include/dynamic-graph/fwd.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <boost/smart_ptr.hpp>

namespace dynamicgraph {
// Set a typedef for signal time type
typedef int64_t sigtime_t;

// to be replace by std:: when we switch to C++11 and later
using boost::const_pointer_cast;
Expand Down
1 change: 1 addition & 0 deletions include/dynamic-graph/linear-algebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace dynamicgraph {
typedef Eigen::MatrixXd Matrix;
typedef Eigen::VectorXd Vector;
typedef Matrix::Index size_type;
} // namespace dynamicgraph

#endif // DYNAMIC_GRAPH_LINEAR_ALGEBRA_H
2 changes: 1 addition & 1 deletion include/dynamic-graph/pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class DYNAMIC_GRAPH_DLLAPI PoolStorage {
/// \brief Get a signal by name
///
/// \param sigpath stream containing a string of the form "entity.signal"
SignalBase<int> &getSignal(std::istringstream &sigpath);
SignalBase<sigtime_t> &getSignal(std::istringstream &sigpath);

/*! \brief This method write a graph description on the file named
FileName. */
Expand Down
2 changes: 1 addition & 1 deletion include/dynamic-graph/signal-array.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ SignalArray<Time> operator<<(SignalBase<Time> &sig1, SignalBase<Time> &sig2) {
return res;
}

DYNAMIC_GRAPH_DLLAPI extern SignalArray<int> sotNOSIGNAL;
DYNAMIC_GRAPH_DLLAPI extern SignalArray<sigtime_t> sotNOSIGNAL;

} // end of namespace dynamicgraph.

Expand Down
10 changes: 0 additions & 10 deletions include/dynamic-graph/signal-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,6 @@ class SignalBase : public boost::noncopyable {

/// \}

/// \name Test
/// \{
virtual void checkCompatibility() {
DG_THROW ExceptionSignal(ExceptionSignal::PLUG_IMPOSSIBLE,
"Abstract signal not compatible with anything.",
"(while trying to plug <%s>).",
this->getName().c_str());
}
/// \}

protected:
std::string name;
Time signalTime;
Expand Down
40 changes: 21 additions & 19 deletions include/dynamic-graph/signal-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define SIGNAL_OUT_FUNCTION_NAME(name) name##SOUT_function

#define DECLARE_SIGNAL(name, IO, type) \
::dynamicgraph::Signal<type, int> m_##name##S##IO
::dynamicgraph::Signal<type, sigtime_t> m_##name##S##IO
#define CONSTRUCT_SIGNAL(name, IO, type) \
m_##name##S##IO(getClassName() + "(" + getName() + ")::" + #IO + "put(" + \
#type + ")::" + #name)
Expand All @@ -31,27 +31,28 @@
/**/

#define DECLARE_SIGNAL_IN(name, type) \
::dynamicgraph::SignalPtr<type, int> m_##name##SIN
::dynamicgraph::SignalPtr<type, sigtime_t> m_##name##SIN
#define CONSTRUCT_SIGNAL_IN(name, type) \
m_##name##SIN(NULL, getClassName() + "(" + getName() + ")::input(" + #type + \
")::" + #name)

/**/

#define DECLARE_SIGNAL_OUT_FUNCTION(name, type) \
type &SIGNAL_OUT_FUNCTION_NAME(name)(type &, int)
type &SIGNAL_OUT_FUNCTION_NAME(name)(type &, sigtime_t)

#define DEFINE_SIGNAL_OUT_FUNCTION(name, type) \
type &EntityClassName::SIGNAL_OUT_FUNCTION_NAME(name)(type & s, int iter)
#define DEFINE_SIGNAL_OUT_FUNCTION(name, type) \
type &EntityClassName::SIGNAL_OUT_FUNCTION_NAME(name)(type & s, \
sigtime_t iter)

#define SIGNAL_OUT_FUNCTION(name) name##SOUT_function

#define DECLARE_SIGNAL_OUT(name, type) \
public: \
::dynamicgraph::SignalTimeDependent<type, int> m_##name##SOUT; \
\
protected: \
type &SIGNAL_OUT_FUNCTION(name)(type &, int)
#define DECLARE_SIGNAL_OUT(name, type) \
public: \
::dynamicgraph::SignalTimeDependent<type, sigtime_t> m_##name##SOUT; \
\
protected: \
type &SIGNAL_OUT_FUNCTION(name)(type &, sigtime_t)

#define CONSTRUCT_SIGNAL_OUT(name, type, dep) \
m_##name##SOUT( \
Expand All @@ -62,16 +63,17 @@
#define SIGNAL_INNER_FUNCTION_NAME(name) name##SINNER_function

#define DECLARE_SIGNAL_INNER_FUNCTION(name, type) \
type &SIGNAL_INNER_FUNCTION_NAME(name)(type &, int)
type &SIGNAL_INNER_FUNCTION_NAME(name)(type &, sigtime_t)

#define DEFINE_SIGNAL_INNER_FUNCTION(name, type) \
type &EntityClassName::SIGNAL_INNER_FUNCTION_NAME(name)(type & s, int iter)
#define DEFINE_SIGNAL_INNER_FUNCTION(name, type) \
type &EntityClassName::SIGNAL_INNER_FUNCTION_NAME(name)(type & s, \
sigtime_t iter)

#define DECLARE_SIGNAL_INNER(name, type) \
public: \
::dynamicgraph::SignalTimeDependent<type, int> m_##name##SINNER; \
\
protected: \
#define DECLARE_SIGNAL_INNER(name, type) \
public: \
::dynamicgraph::SignalTimeDependent<type, sigtime_t> m_##name##SINNER; \
\
protected: \
DECLARE_SIGNAL_INNER_FUNCTION(name, type)

#define CONSTRUCT_SIGNAL_INNER(name, type, dep) \
Expand Down
11 changes: 2 additions & 9 deletions include/dynamic-graph/signal-ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class SignalPtr : public virtual Signal<T, Time> {
protected:
Signal<T, Time> *signalPtr;
bool modeNoThrow;
bool transmitAbstract;
SignalBase<Time> *abstractTransmitter;
T *transmitAbstractData;

Expand All @@ -42,24 +41,20 @@ class SignalPtr : public virtual Signal<T, Time> {
: Signal<T, Time>(name),
signalPtr(ptr),
modeNoThrow(false),
transmitAbstract(false),
abstractTransmitter(NULL) {}

virtual ~SignalPtr() { signalPtr = NULL; }

public:
/* --- PLUG-IN OPERATION --- */
Signal<T, Time> *getPtr(); // throw
const Signal<T, Time> *getPtr() const; // throw
SignalBase<Time> *getAbstractPtr(); // throw
const SignalBase<Time> *getAbstractPtr() const; // throw
Signal<T, Time> *getPtr(); // throw
const Signal<T, Time> *getPtr() const; // throw
virtual void plug(SignalBase<Time> *ref);

virtual void unplug() { plug(NULL); }

virtual bool isPlugged() const { return (NULL != signalPtr); }
virtual SignalBase<Time> *getPluged() const { return signalPtr; }
virtual bool isAbstractPluged() const;
virtual const Time &getTime() const;

/* Equivalent operator-like definitions. */
Expand Down Expand Up @@ -91,8 +86,6 @@ class SignalPtr : public virtual Signal<T, Time> {
virtual inline void setConstantDefault() { setConstantDefault(accessCopy()); }
inline void unsetConstantDefault() { modeNoThrow = false; }

virtual void checkCompatibility();

public: /* --- INHERITANCE --- */
/* SignalPtr could be used as a classical signal, through the normal
* setting functions. The behavior is to plugged the signalPtr on
Expand Down
Loading