00001 #ifndef PROTON_TIMESTAMP_HPP
00002 #define PROTON_TIMESTAMP_HPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "./duration.hpp"
00024
00025 #include <proton/type_compat.h>
00026
00029
00030 namespace proton {
00031
00035 class timestamp : private internal::comparable<timestamp> {
00036 public:
00038 typedef int64_t numeric_type;
00039
00041 PN_CPP_EXTERN static timestamp now();
00042
00044 explicit timestamp(numeric_type ms = 0) : ms_(ms) {}
00045
00047 timestamp& operator=(numeric_type ms) { ms_ = ms; return *this; }
00048
00050 numeric_type milliseconds() const { return ms_; }
00051
00052 private:
00053 numeric_type ms_;
00054 };
00055
00058 inline bool operator==(timestamp x, timestamp y) { return x.milliseconds() == y.milliseconds(); }
00059 inline bool operator<(timestamp x, timestamp y) { return x.milliseconds() < y.milliseconds(); }
00060
00061 inline timestamp operator+(timestamp ts, duration d) { return timestamp(ts.milliseconds() + d.milliseconds()); }
00062 inline timestamp operator-(timestamp ts, duration d) { return timestamp(ts.milliseconds() - d.milliseconds()); }
00063 inline duration operator-(timestamp t0, timestamp t1) { return duration(t0.milliseconds() - t1.milliseconds()); }
00064 inline timestamp operator+(duration d, timestamp ts) { return ts + d; }
00066
00068 PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, timestamp);
00069
00070 }
00071
00072 #endif // PROTON_TIMESTAMP_HPP