Skip to content

Commit 561e2ad

Browse files
Forward declaration of << operator for dynamicgraph::timestamp_t
GCC accept this but according to C++ standard this is not correct. CLANG does not accept it.
1 parent 6949b0e commit 561e2ad

File tree

4 files changed

+50
-26
lines changed

4 files changed

+50
-26
lines changed

src/fwd.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* @file
3+
* @license BSD 3-clause
4+
* @copyright Copyright (c) 2023, LAAS/CNRS
5+
* @copyright Copyright (c) 2020, New York University and Max Planck
6+
* Gesellschaft
7+
*
8+
* @brief Define the time stamp signal.
9+
*/
10+
11+
#pragma once
12+
13+
#include <ostream>
14+
#include <chrono>
15+
16+
namespace dynamic_graph_bridge
17+
{
18+
/** @brief Time stamp type. */
19+
typedef std::chrono::time_point<std::chrono::high_resolution_clock> timestamp_t;
20+
21+
} // namespace dynamic_graph_bridge
22+
23+
namespace dynamicgraph
24+
{
25+
/**
26+
* @brief out stream the time stamp data.
27+
*
28+
* @param os
29+
* @param time_stamp
30+
* @return std::ostream&
31+
*
32+
* For clang this function needs to be forward declared before the template using it.
33+
* This is more in accordance to the standard.
34+
*/
35+
inline std::ostream &operator<<(
36+
std::ostream &os, const dynamic_graph_bridge::timestamp_t &time_stamp)
37+
{
38+
std::chrono::time_point<std::chrono::high_resolution_clock,
39+
std::chrono::milliseconds>
40+
time_stamp_nanosec =
41+
std::chrono::time_point_cast<std::chrono::milliseconds>(time_stamp);
42+
os << time_stamp_nanosec.time_since_epoch().count();
43+
return os;
44+
}
45+
}

src/ros_subscribe.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @date 2019-05-22
88
*/
99

10+
#include "fwd.hpp"
1011
#include <dynamic-graph/factory.h>
1112
#include "ros_subscribe.hpp"
1213

@@ -163,6 +164,7 @@ Add::Add(RosSubscribe& entity, const std::string& doc_string)
163164

164165
Value Add::doExecute()
165166
{
167+
using namespace dynamicgraph;
166168
RosSubscribe& entity = static_cast<RosSubscribe&>(owner());
167169
std::vector<Value> values = getParameterValues();
168170

src/ros_subscribe.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#pragma once
1212

13+
#include "fwd.hpp"
1314
#include <dynamic-graph/command.h>
1415
#include <dynamic-graph/entity.h>
1516
#include <dynamic-graph/signal-ptr.h>

src/time_point_io.hpp

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,12 @@
99

1010
#pragma once
1111

12-
#include <dynamic-graph/signal-caster.h>
13-
14-
#include <chrono>
12+
#include "fwd.hpp"
1513

16-
namespace dynamic_graph_bridge
17-
{
18-
/** @brief Time stamp type. */
19-
typedef std::chrono::time_point<std::chrono::high_resolution_clock> timestamp_t;
20-
21-
} // namespace dynamic_graph_bridge
14+
#include <dynamic-graph/signal-caster.h>
2215

2316
namespace dynamicgraph
2417
{
25-
/**
26-
* @brief out stream the time stamp data.
27-
*
28-
* @param os
29-
* @param time_stamp
30-
* @return std::ostream&
31-
*/
32-
inline std::ostream &operator<<(
33-
std::ostream &os, const dynamic_graph_bridge::timestamp_t &time_stamp)
34-
{
35-
std::chrono::time_point<std::chrono::high_resolution_clock,
36-
std::chrono::milliseconds>
37-
time_stamp_nanosec =
38-
std::chrono::time_point_cast<std::chrono::milliseconds>(time_stamp);
39-
os << time_stamp_nanosec.time_since_epoch().count();
40-
return os;
41-
}
4218

4319
/**
4420
* @brief Structure used to serialize/deserialize the time stamp.

0 commit comments

Comments
 (0)