Skip to content

Commit 9b21dae

Browse files
Florent Lamirauxflorent-lamiraux
authored andcommitted
Define a specific type for signal time.
1 parent 52e9aea commit 9b21dae

File tree

16 files changed

+95
-104
lines changed

16 files changed

+95
-104
lines changed

include/dynamic-graph/entity.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace dynamicgraph {
5151
/// DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN macro in factory.h.
5252
class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable {
5353
public:
54-
typedef std::map<std::string, SignalBase<int> *> SignalMap;
54+
typedef std::map<std::string, SignalBase<sigtime_t> *> SignalMap;
5555
typedef std::map<const std::string, command::Command *> CommandMap_t;
5656

5757
explicit Entity(const std::string &name);
@@ -76,13 +76,13 @@ class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable {
7676
\param signalName: Name of the signal
7777
\return A reference to the signal with a temporal dependency.
7878
*/
79-
SignalBase<int> &getSignal(const std::string &signalName);
79+
SignalBase<sigtime_t> &getSignal(const std::string &signalName);
8080

8181
/** \brief Provides a const reference to the signal named signalName.
8282
\param signalName: Name of the signal
8383
\return A const reference to the signal with a temporal dependency.
8484
*/
85-
const SignalBase<int> &getSignal(const std::string &signalName) const;
85+
const SignalBase<sigtime_t> &getSignal(const std::string &signalName) const;
8686

8787
/** \brief Display the list of signals of this entity in output stream os.
8888
\param os: the output stream where to display the list of signals.
@@ -108,9 +108,9 @@ class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable {
108108
*/
109109
virtual void display(std::ostream &os) const;
110110

111-
virtual SignalBase<int> *test() { return 0; }
111+
virtual SignalBase<sigtime_t> *test() { return 0; }
112112

113-
virtual void test2(SignalBase<int> *) { return; }
113+
virtual void test2(SignalBase<sigtime_t> *) { return; }
114114

115115
const std::string &getCommandList() const;
116116

@@ -168,7 +168,7 @@ class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable {
168168
void entityRegistration();
169169
void entityDeregistration();
170170

171-
void signalRegistration(const SignalArray<int> &signals);
171+
void signalRegistration(const SignalArray<sigtime_t> &signals);
172172
void signalDeregistration(const std::string &name);
173173

174174
std::string name;

include/dynamic-graph/fwd.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <boost/smart_ptr.hpp>
99

1010
namespace dynamicgraph {
11+
// Set a typedef for signal time type
12+
typedef int sigtime_t;
1113

1214
// to be replace by std:: when we switch to C++11 and later
1315
using boost::const_pointer_cast;

include/dynamic-graph/pool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class DYNAMIC_GRAPH_DLLAPI PoolStorage {
9191
/// \brief Get a signal by name
9292
///
9393
/// \param sigpath stream containing a string of the form "entity.signal"
94-
SignalBase<int> &getSignal(std::istringstream &sigpath);
94+
SignalBase<sigtime_t> &getSignal(std::istringstream &sigpath);
9595

9696
/*! \brief This method write a graph description on the file named
9797
FileName. */

include/dynamic-graph/signal-array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ SignalArray<Time> operator<<(SignalBase<Time> &sig1, SignalBase<Time> &sig2) {
147147
return res;
148148
}
149149

150-
DYNAMIC_GRAPH_DLLAPI extern SignalArray<int> sotNOSIGNAL;
150+
DYNAMIC_GRAPH_DLLAPI extern SignalArray<sigtime_t> sotNOSIGNAL;
151151

152152
} // end of namespace dynamicgraph.
153153

include/dynamic-graph/signal-helper.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#define SIGNAL_OUT_FUNCTION_NAME(name) name##SOUT_function
2121

2222
#define DECLARE_SIGNAL(name, IO, type) \
23-
::dynamicgraph::Signal<type, int> m_##name##S##IO
23+
::dynamicgraph::Signal<type, sigtime_t> m_##name##S##IO
2424
#define CONSTRUCT_SIGNAL(name, IO, type) \
2525
m_##name##S##IO(getClassName() + "(" + getName() + ")::" + #IO + "put(" + \
2626
#type + ")::" + #name)
@@ -31,27 +31,27 @@
3131
/**/
3232

3333
#define DECLARE_SIGNAL_IN(name, type) \
34-
::dynamicgraph::SignalPtr<type, int> m_##name##SIN
34+
::dynamicgraph::SignalPtr<type, sigtime_t> m_##name##SIN
3535
#define CONSTRUCT_SIGNAL_IN(name, type) \
3636
m_##name##SIN(NULL, getClassName() + "(" + getName() + ")::input(" + #type + \
3737
")::" + #name)
3838

3939
/**/
4040

4141
#define DECLARE_SIGNAL_OUT_FUNCTION(name, type) \
42-
type &SIGNAL_OUT_FUNCTION_NAME(name)(type &, int)
42+
type &SIGNAL_OUT_FUNCTION_NAME(name)(type &, sigtime_t)
4343

4444
#define DEFINE_SIGNAL_OUT_FUNCTION(name, type) \
45-
type &EntityClassName::SIGNAL_OUT_FUNCTION_NAME(name)(type & s, int iter)
45+
type &EntityClassName::SIGNAL_OUT_FUNCTION_NAME(name)(type & s, sigtime_t iter)
4646

4747
#define SIGNAL_OUT_FUNCTION(name) name##SOUT_function
4848

4949
#define DECLARE_SIGNAL_OUT(name, type) \
5050
public: \
51-
::dynamicgraph::SignalTimeDependent<type, int> m_##name##SOUT; \
51+
::dynamicgraph::SignalTimeDependent<type, sigtime_t> m_##name##SOUT; \
5252
\
5353
protected: \
54-
type &SIGNAL_OUT_FUNCTION(name)(type &, int)
54+
type &SIGNAL_OUT_FUNCTION(name)(type &, sigtime_t)
5555

5656
#define CONSTRUCT_SIGNAL_OUT(name, type, dep) \
5757
m_##name##SOUT( \
@@ -62,14 +62,14 @@
6262
#define SIGNAL_INNER_FUNCTION_NAME(name) name##SINNER_function
6363

6464
#define DECLARE_SIGNAL_INNER_FUNCTION(name, type) \
65-
type &SIGNAL_INNER_FUNCTION_NAME(name)(type &, int)
65+
type &SIGNAL_INNER_FUNCTION_NAME(name)(type &, sigtime_t)
6666

6767
#define DEFINE_SIGNAL_INNER_FUNCTION(name, type) \
68-
type &EntityClassName::SIGNAL_INNER_FUNCTION_NAME(name)(type & s, int iter)
68+
type &EntityClassName::SIGNAL_INNER_FUNCTION_NAME(name)(type & s, sigtime_t iter)
6969

7070
#define DECLARE_SIGNAL_INNER(name, type) \
7171
public: \
72-
::dynamicgraph::SignalTimeDependent<type, int> m_##name##SINNER; \
72+
::dynamicgraph::SignalTimeDependent<type, sigtime_t> m_##name##SINNER; \
7373
\
7474
protected: \
7575
DECLARE_SIGNAL_INNER_FUNCTION(name, type)

include/dynamic-graph/tracer-real-time.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ class DG_TRACERREALTIME_DLLAPI TracerRealTime : public Tracer {
5757
const int &getBufferSize() { return bufferSize; }
5858

5959
protected:
60-
virtual void openFile(const SignalBase<int> &sig,
60+
virtual void openFile(const SignalBase<sigtime_t> &sig,
6161
const std::string &filename);
6262

63-
virtual void recordSignal(std::ostream &os, const SignalBase<int> &sig);
63+
virtual void recordSignal(std::ostream &os, const SignalBase<sigtime_t> &sig);
6464

6565
typedef std::list<std::ofstream *> HardFileList;
6666
static const int BUFFER_SIZE_DEFAULT = 1048576; // 1Mo

include/dynamic-graph/tracer.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DG_TRACER_DLLAPI Tracer : public Entity {
2525
DYNAMIC_GRAPH_ENTITY_DECL();
2626

2727
protected:
28-
typedef std::list<const SignalBase<int> *> SignalList;
28+
typedef std::list<const SignalBase<sigtime_t> *> SignalList;
2929
SignalList toTraceSignals;
3030
std::mutex files_mtx;
3131

@@ -53,13 +53,13 @@ class DG_TRACER_DLLAPI Tracer : public Entity {
5353
typedef std::list<std::string> NameList;
5454
NameList names;
5555
bool play;
56-
int timeStart;
56+
sigtime_t timeStart;
5757

5858
public:
5959
Tracer(const std::string n);
6060
virtual ~Tracer() { closeFiles(); }
6161

62-
void addSignalToTrace(const SignalBase<int> &sig,
62+
void addSignalToTrace(const SignalBase<sigtime_t> &sig,
6363
const std::string &filename = "");
6464
void addSignalToTraceByName(const std::string &signame,
6565
const std::string &filename = "");
@@ -70,7 +70,7 @@ class DG_TRACER_DLLAPI Tracer : public Entity {
7070
virtual void closeFiles();
7171

7272
protected:
73-
virtual void openFile(const SignalBase<int> &sig,
73+
virtual void openFile(const SignalBase<sigtime_t> &sig,
7474
const std::string &filename);
7575

7676
public:
@@ -81,16 +81,16 @@ class DG_TRACER_DLLAPI Tracer : public Entity {
8181
double getFrequency() { return frequency; }
8282

8383
void record();
84-
virtual void recordSignal(std::ostream &os, const SignalBase<int> &sig);
85-
int &recordTrigger(int &dummy, const int &time);
84+
virtual void recordSignal(std::ostream &os, const SignalBase<sigtime_t> &sig);
85+
sigtime_t &recordTrigger(sigtime_t &dummy, const sigtime_t &time);
8686

8787
virtual void trace();
8888
void start() { play = true; }
8989
void stop() { play = false; }
9090

9191
public:
9292
// SignalTrigerer<int> triger;
93-
SignalTimeDependent<int, int> triger;
93+
SignalTimeDependent<sigtime_t, sigtime_t> triger;
9494

9595
/* --- DISPLAY --------------------------------------------------------- */
9696
DG_TRACER_DLLAPI friend std::ostream &operator<<(std::ostream &os,

src/dgraph/entity.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ Entity::~Entity() {
5656
/* -------------------------------------------------------------------------- */
5757
/* --- SIGNALS -------------------------------------------------------------- */
5858
/* -------------------------------------------------------------------------- */
59-
void Entity::signalRegistration(const SignalArray<int> &signals) {
59+
void Entity::signalRegistration(const SignalArray<sigtime_t> &signals) {
6060
for (unsigned int i = 0; i < signals.getSize(); ++i) {
61-
SignalBase<int> &sig = signals[i];
61+
SignalBase<sigtime_t> &sig = signals[i];
6262
// const string& signame = sig.getName ();
6363
istringstream iss(sig.getName());
6464
const int SIZE = 4096;
@@ -106,26 +106,30 @@ std::string Entity::getDocString() const {
106106
return docString;
107107
}
108108

109-
#define __DG_ENTITY_GET_SIGNAL__(ITER_TYPE) \
110-
SignalMap::ITER_TYPE sigkey = signalMap.find(signame); \
111-
if (sigkey == signalMap.end()) /* key does NOT exist */ \
112-
{ \
113-
throw ExceptionFactory(ExceptionFactory::UNREFERED_SIGNAL, \
114-
"The requested signal is not registered", ": %s", \
115-
signame.c_str()); \
116-
} \
117-
return *(sigkey->second);
118-
119109
bool Entity::hasSignal(const string &signame) const {
120110
return (!(signalMap.find(signame) == signalMap.end()));
121111
}
122112

123-
SignalBase<int> &Entity::getSignal(const string &signame) {
124-
__DG_ENTITY_GET_SIGNAL__(iterator);
113+
SignalBase<sigtime_t> &Entity::getSignal(const string &signame) {
114+
SignalMap::iterator sigkey = signalMap.find(signame);
115+
if (sigkey == signalMap.end()) /* key does NOT exist */
116+
{
117+
throw ExceptionFactory(ExceptionFactory::UNREFERED_SIGNAL,
118+
"The requested signal is not registered", ": %s",
119+
signame.c_str());
120+
}
121+
return *(sigkey->second);
125122
}
126123

127-
const SignalBase<int> &Entity::getSignal(const string &signame) const {
128-
__DG_ENTITY_GET_SIGNAL__(const_iterator);
124+
const SignalBase<sigtime_t> &Entity::getSignal(const string &signame) const {
125+
SignalMap::const_iterator sigkey = signalMap.find(signame);
126+
if (sigkey == signalMap.end()) /* key does NOT exist */
127+
{
128+
throw ExceptionFactory(ExceptionFactory::UNREFERED_SIGNAL,
129+
"The requested signal is not registered", ": %s",
130+
signame.c_str());
131+
}
132+
return *(sigkey->second);
129133
}
130134

131135
std::ostream &Entity::displaySignalList(std::ostream &os) const {

src/dgraph/pool.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ void PoolStorage::clearPlugin(const std::string &name) {
138138

139139
#include <dynamic-graph/entity.h>
140140

141-
#ifdef WIN32
142-
#include <time.h>
143-
#endif /*WIN32*/
144-
145141
void PoolStorage::writeGraph(const std::string &aFileName) {
146142
size_t IdxPointFound = aFileName.rfind(".");
147143
std::string tmp1 = aFileName.substr(0, IdxPointFound);
@@ -152,24 +148,9 @@ void PoolStorage::writeGraph(const std::string &aFileName) {
152148
else
153149
GenericName = tmp1;
154150

155-
/* Reading local time */
156-
time_t ltime;
157-
ltime = time(NULL);
158-
struct tm ltimeformatted;
159-
#ifdef WIN32
160-
localtime_s(&ltimeformatted, &ltime);
161-
#else
162-
localtime_r(&ltime, &ltimeformatted);
163-
#endif /*WIN32*/
164-
165151
/* Opening the file and writing the first comment. */
166152
std::ofstream GraphFile(aFileName.c_str(), std::ofstream::out);
167153
GraphFile << "/* This graph has been automatically generated. " << std::endl;
168-
GraphFile << " " << 1900 + ltimeformatted.tm_year
169-
<< " Month: " << 1 + ltimeformatted.tm_mon
170-
<< " Day: " << ltimeformatted.tm_mday
171-
<< " Time: " << ltimeformatted.tm_hour << ":"
172-
<< ltimeformatted.tm_min;
173154
GraphFile << " */" << std::endl;
174155
GraphFile << "digraph \"" << GenericName << "\" { ";
175156
GraphFile << "\t graph [ label=\"" << GenericName
@@ -219,7 +200,7 @@ static bool objectNameParser(std::istringstream &cmdparse, std::string &objName,
219200
return true;
220201
}
221202

222-
SignalBase<int> &PoolStorage::getSignal(std::istringstream &sigpath) {
203+
SignalBase<sigtime_t> &PoolStorage::getSignal(std::istringstream &sigpath) {
223204
std::string objname, signame;
224205
if (!objectNameParser(sigpath, objname, signame)) {
225206
DG_THROW ExceptionFactory(ExceptionFactory::UNREFERED_SIGNAL,

src/signal/signal-array.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
#include <dynamic-graph/signal-array.h>
1111

1212
namespace dynamicgraph {
13-
SignalArray<int> sotNOSIGNAL(0);
13+
SignalArray<sigtime_t> sotNOSIGNAL(0);
1414
}

0 commit comments

Comments
 (0)