Vanetza
 
Loading...
Searching...
No Matches
timestamp.hpp
1#ifndef TIMESTAMP_HPP_SFETMZJI
2#define TIMESTAMP_HPP_SFETMZJI
3
4#include <vanetza/common/clock.hpp>
5#include <vanetza/geonet/serialization.hpp>
6#include <cstdint>
7#include <boost/operators.hpp>
8#include <boost/date_time/posix_time/posix_time.hpp>
9#include <boost/units/absolute.hpp>
10#include <boost/units/quantity.hpp>
11#include <boost/units/systems/si/time.hpp>
12#include <boost/units/make_scaled_unit.hpp>
13
14namespace vanetza
15{
16namespace geonet
17{
18
19class Timestamp : public boost::totally_ordered<Timestamp>
20{
21public:
22 typedef uint32_t value_type;
23 typedef boost::units::make_scaled_unit<
24 boost::units::si::time,
25 boost::units::scale<10, boost::units::static_rational<-3>>
26 >::type unit_type;
27 typedef boost::units::absolute<unit_type> absolute_unit_type;
28 typedef boost::units::quantity<absolute_unit_type, value_type> time_type;
29 typedef boost::units::quantity<unit_type, value_type> duration_type;
30
31 static unit_type millisecond();
32 static boost::posix_time::ptime start_time();
33
34 Timestamp() : m_timestamp(0) {}
35 Timestamp(time_type t) : m_timestamp(t) {}
36 Timestamp(const Clock::time_point&);
37 Timestamp(const boost::posix_time::ptime&);
38 value_type raw() const { return m_timestamp.value(); }
39 time_type quantity() const { return m_timestamp; }
40 Timestamp& operator+=(duration_type);
41 Timestamp& operator-=(duration_type);
42
43 /**
44 * Timestamp is before other one
45 * \param other time stamp
46 * \return true if other timestamp is later
47 */
48 bool before(const Timestamp& other) const;
49
50 /**
51 * Timestamp is after other one
52 * \param other time stamp
53 * \return true is other timestamp is before
54 */
55 bool after(const Timestamp& other) const;
56
57private:
58 time_type m_timestamp; // since 01-01-2004 00:00:00.0
59};
60
61// timestamp calculus
62Timestamp operator+(Timestamp lhs, Timestamp::duration_type rhs);
63Timestamp operator-(Timestamp lhs, Timestamp::duration_type rhs);
64Timestamp::duration_type operator-(Timestamp lhs, Timestamp rhs);
65
66// timestamp comparison according to ETSI GeoNet
67bool is_greater(Timestamp lhs, Timestamp rhs);
68
69// operators required for boost::totally_ordered
70bool operator<(Timestamp lhs, Timestamp rhs);
71bool operator==(Timestamp lhs, Timestamp rhs);
72
73// serialization
74void serialize(const Timestamp&, OutputArchive&);
75void deserialize(Timestamp&, InputArchive&);
76
77} // namespace geonet
78} // namespace vanetza
79
80#endif /* TIMESTAMP_HPP_SFETMZJI */
81
bool after(const Timestamp &other) const
Definition: timestamp.cpp:76
bool before(const Timestamp &other) const
Definition: timestamp.cpp:71