summaryrefslogtreecommitdiff
path: root/ACE/ace/Time_Value.inl
diff options
context:
space:
mode:
authorMarcel Smit <msmit@remedy.nl>2015-02-23 14:08:37 +0100
committerMarcel Smit <msmit@remedy.nl>2015-02-23 14:08:37 +0100
commiteb9f76436224250d20bf6b8088ef330cbcb593f3 (patch)
treebfdf3cb1ef360fdbc429039cdc37b9fab885e6d5 /ACE/ace/Time_Value.inl
parent959b3362da669ca3cde5f100604be3d7d90c8277 (diff)
downloadATCD-eb9f76436224250d20bf6b8088ef330cbcb593f3.tar.gz
Added more operators to and from chrono. Added tests for this.
* ACE/ace/Time_Value.h: * ACE/ace/Time_Value.inl: * ACE/tests/Chrono_Test.cpp:
Diffstat (limited to 'ACE/ace/Time_Value.inl')
-rw-r--r--ACE/ace/Time_Value.inl123
1 files changed, 108 insertions, 15 deletions
diff --git a/ACE/ace/Time_Value.inl b/ACE/ace/Time_Value.inl
index 72da7c25a28..ed31b14fd42 100644
--- a/ACE/ace/Time_Value.inl
+++ b/ACE/ace/Time_Value.inl
@@ -96,21 +96,6 @@ ACE_Time_Value::ACE_Time_Value (void)
this->set (0, 0);
}
-#if defined (ACE_HAS_CPP11)
-template< class Rep, class Period >
-ACE_INLINE
-ACE_Time_Value::ACE_Time_Value (const std::chrono::duration<Rep, Period>& duration)
-{
- std::chrono::seconds const s {
- std::chrono::duration_cast<std::chrono::seconds> (duration)};
-
- std::chrono::microseconds const usec {
- std::chrono::duration_cast<std::chrono::microseconds>(
- duration % std::chrono::seconds (1))};
- this->set (s.count (), usec.count ());
-}
-#endif /* ACE_HAS_CPP11 */
-
ACE_INLINE
ACE_Time_Value::ACE_Time_Value (time_t sec, suseconds_t usec)
{
@@ -147,6 +132,16 @@ ACE_Time_Value::msec (void) const
return ACE_Utils::truncate_cast<unsigned long> (secs);
}
+#if defined (ACE_HAS_CPP11)
+ACE_INLINE std::chrono::milliseconds
+ACE_Time_Value::get_chrono_msec (void) const
+{
+ return std::chrono::milliseconds (
+ std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::seconds (this->sec ()))+
+ std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::microseconds (this->usec ())));
+}
+#endif
+
ACE_INLINE ACE_UINT64
ACE_Time_Value::get_msec () const
{
@@ -464,6 +459,104 @@ namespace std
duration_cast<hours>(microseconds{tv.usec()});
return h;
}
+
+
+ ACE_INLINE nanoseconds&
+ operator +=(nanoseconds &ns, ACE_Time_Value const &tv)
+ {
+ ns += duration_cast<nanoseconds>(seconds{tv.sec ()}) +
+ duration_cast<nanoseconds>(microseconds{tv.usec()});
+ return ns;
+ }
+
+ ACE_INLINE microseconds&
+ operator +=(microseconds &us, ACE_Time_Value const &tv)
+ {
+ us += duration_cast<microseconds>(seconds{tv.sec ()}) +
+ microseconds{tv.usec()};
+ return us;
+ }
+
+ ACE_INLINE milliseconds&
+ operator +=(milliseconds &ms, ACE_Time_Value const &tv)
+ {
+ ms += duration_cast<milliseconds>(seconds{tv.sec ()}) +
+ duration_cast<milliseconds>(microseconds{tv.usec()});
+ return ms;
+ }
+
+ ACE_INLINE seconds&
+ operator +=(seconds &s, ACE_Time_Value const &tv)
+ {
+ s += seconds{tv.sec ()} +
+ duration_cast<seconds>(microseconds{tv.usec()});
+ return s;
+ }
+
+ ACE_INLINE minutes&
+ operator +=(minutes &m, ACE_Time_Value const &tv)
+ {
+ m += duration_cast<minutes>(seconds{tv.sec ()}) +
+ duration_cast<minutes>(microseconds{tv.usec()});
+ return m;
+ }
+
+ ACE_INLINE hours&
+ operator +=(hours &h, ACE_Time_Value const &tv)
+ {
+ h += duration_cast<hours>(seconds{tv.sec ()}) +
+ duration_cast<hours>(microseconds{tv.usec()});
+ return h;
+ }
+
+
+ ACE_INLINE nanoseconds&
+ operator -=(nanoseconds &ns, ACE_Time_Value const &tv)
+ {
+ ns -= duration_cast<nanoseconds>(seconds{tv.sec ()}) +
+ duration_cast<nanoseconds>(microseconds{tv.usec()});
+ return ns;
+ }
+
+ ACE_INLINE microseconds&
+ operator -=(microseconds &us, ACE_Time_Value const &tv)
+ {
+ us -= duration_cast<microseconds>(seconds{tv.sec ()}) +
+ microseconds{tv.usec()};
+ return us;
+ }
+
+ ACE_INLINE milliseconds&
+ operator -=(milliseconds &ms, ACE_Time_Value const &tv)
+ {
+ ms -= duration_cast<milliseconds>(seconds{tv.sec ()}) +
+ duration_cast<milliseconds>(microseconds{tv.usec()});
+ return ms;
+ }
+
+ ACE_INLINE seconds&
+ operator -=(seconds &s, ACE_Time_Value const &tv)
+ {
+ s -= seconds{tv.sec ()} +
+ duration_cast<seconds>(microseconds{tv.usec()});
+ return s;
+ }
+
+ ACE_INLINE minutes&
+ operator -=(minutes &m, ACE_Time_Value const &tv)
+ {
+ m -= duration_cast<minutes>(seconds{tv.sec ()}) +
+ duration_cast<minutes>(microseconds{tv.usec()});
+ return m;
+ }
+
+ ACE_INLINE hours&
+ operator -=(hours &h, ACE_Time_Value const &tv)
+ {
+ h -= duration_cast<hours>(seconds{tv.sec ()}) +
+ duration_cast<hours>(microseconds{tv.usec()});
+ return h;
+ }
}
}