diff options
author | Mark Salyzyn <salyzyn@google.com> | 2014-10-13 14:13:18 -0700 |
---|---|---|
committer | Mark Salyzyn <salyzyn@google.com> | 2015-01-05 16:27:54 +0000 |
commit | decd92945fa8692b384a99da786bd43f6bc1ef3e (patch) | |
tree | 54cbc3d20d850906e713889de90f6be79a422a7e | |
parent | 69159ba0b70178a24e6f592dfb9d903629c23a09 (diff) | |
download | system_core-decd92945fa8692b384a99da786bd43f6bc1ef3e.zip system_core-decd92945fa8692b384a99da786bd43f6bc1ef3e.tar.gz system_core-decd92945fa8692b384a99da786bd43f6bc1ef3e.tar.bz2 |
liblog: Add log_time += operator
Change-Id: I1d2987b6cb333fc344d4fee1b7bb25f32a4143c6
-rw-r--r-- | include/log/log_read.h | 12 | ||||
-rw-r--r-- | liblog/log_time.cpp | 22 |
2 files changed, 34 insertions, 0 deletions
diff --git a/include/log/log_read.h b/include/log/log_read.h index 946711a..1b70aff 100644 --- a/include/log/log_read.h +++ b/include/log/log_read.h @@ -100,6 +100,12 @@ public: log_time local(*this); return local -= T; } + log_time operator+= (const timespec &T); + log_time operator+ (const timespec &T) const + { + log_time local(*this); + return local += T; + } // log_time bool operator== (const log_time &T) const @@ -134,6 +140,12 @@ public: log_time local(*this); return local -= T; } + log_time operator+= (const log_time &T); + log_time operator+ (const log_time &T) const + { + log_time local(*this); + return local += T; + } uint64_t nsec() const { diff --git a/liblog/log_time.cpp b/liblog/log_time.cpp index 209a9da..50742df 100644 --- a/liblog/log_time.cpp +++ b/liblog/log_time.cpp @@ -150,6 +150,17 @@ log_time log_time::operator-= (const timespec &T) { return *this; } +log_time log_time::operator+= (const timespec &T) { + this->tv_nsec += (unsigned long int)T.tv_nsec; + if (this->tv_nsec >= NS_PER_SEC) { + this->tv_nsec -= NS_PER_SEC; + ++this->tv_sec; + } + this->tv_sec += T.tv_sec; + + return *this; +} + log_time log_time::operator-= (const log_time &T) { // No concept of negative time, clamp to EPOCH if (*this <= T) { @@ -166,3 +177,14 @@ log_time log_time::operator-= (const log_time &T) { return *this; } + +log_time log_time::operator+= (const log_time &T) { + this->tv_nsec += T.tv_nsec; + if (this->tv_nsec >= NS_PER_SEC) { + this->tv_nsec -= NS_PER_SEC; + ++this->tv_sec; + } + this->tv_sec += T.tv_sec; + + return *this; +} |