From 3cf9974211928f07bf338d9fa500ee32cb0a702b Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 8 Jan 2011 19:11:42 +0100 Subject: [PATCH] provide unary minus to flip a TimeVar around origin --- src/lib/time/timevalue.hpp | 3 +++ tests/lib/time/time-value-test.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/lib/time/timevalue.hpp b/src/lib/time/timevalue.hpp index 08ed06f02..a19c806be 100644 --- a/src/lib/time/timevalue.hpp +++ b/src/lib/time/timevalue.hpp @@ -138,6 +138,9 @@ namespace time { // Supporting multiplication with integral factor TimeVar& operator*= (int fact) { t_ *= fact; return *this; } + + // Supporting flip sign + TimeVar operator- () const { return TimeVar(*this)*=-1; } // baseclass TimeValue is already totally_ordered }; diff --git a/tests/lib/time/time-value-test.cpp b/tests/lib/time/time-value-test.cpp index 67d9feb9c..342697b8f 100644 --- a/tests/lib/time/time-value-test.cpp +++ b/tests/lib/time/time-value-test.cpp @@ -144,6 +144,11 @@ namespace test{ gavl_time_t raw (var); CHECK (raw == org); CHECK (raw > org - two); + + // unary minus will flip around origin + CHECK (zero == -var + var); + CHECK (zero != -var); + CHECK (var == org); // unaltered }