diff --git a/src/lib/time/timevalue.hpp b/src/lib/time/timevalue.hpp index 8a0b1f5fe..0778022a7 100644 --- a/src/lib/time/timevalue.hpp +++ b/src/lib/time/timevalue.hpp @@ -148,7 +148,7 @@ namespace time { // Supporting multiplication with integral factor TimeVar& operator*= (int fact) { t_ *= fact; return *this; } - // Supporting flip sign + // Supporting sign flip TimeVar operator- () const { return TimeVar(*this)*=-1; } // baseclass TimeValue is already totally_ordered @@ -185,16 +185,32 @@ namespace time { { return TimeValue(std::llabs (t_)); } - - Offset - operator+ (Offset const& toChain) const - { - TimeVar distance(*this); - distance += toChain; - return Offset(distance); - } }; + //-- support linear offset chaining --------------- + + inline Offset + operator+ (Offset const& start, Offset const& toChain) + { + TimeVar distance(start); + distance += toChain; + return Offset(distance); + } + + inline Offset + operator* (int factor, Offset const& o) + { + TimeVar distance(o); + distance *= factor; + return Offset(distance); + } + + inline Offset + operator* (Offset const& distance, int factor) + { + return factor*distance; + } + diff --git a/tests/lib/time/time-value-test.cpp b/tests/lib/time/time-value-test.cpp index ddc026b9d..a25d22b0c 100644 --- a/tests/lib/time/time-value-test.cpp +++ b/tests/lib/time/time-value-test.cpp @@ -230,6 +230,8 @@ namespace test{ // chaining and copy construction Offset off9 (off5 + Offset(four)); CHECK (9 == off9); + // simple linear combinations + CHECK (7 == -2*off9 + off5*5); }