Bug 1039924 part 3 - Templatize TimeDuration so it can support different behaviors...
commit9d4bf99681d3f0197a2f4b87184c005b03cff387
authorBrian Birtles <birtles@gmail.com>
Thu, 25 Sep 2014 05:25:49 +0000 (25 14:25 +0900)
committerBrian Birtles <birtles@gmail.com>
Thu, 25 Sep 2014 05:25:49 +0000 (25 14:25 +0900)
treec620666f5a7e63518d992d34e2fdaab76f629692
parent924730126ae75b08c67c117904bea49a3547a331
Bug 1039924 part 3 - Templatize TimeDuration so it can support different behaviors with regards to tick count arithmetic; r=froydnj

This patch prepares the way for having a separate StickyTimeDuration class
by factoring TimeDuration into a templated base class: BaseTimeDuration.
BaseTimeDuration takes a templated parameter, ValueCalculator, which is a helper
object that defines how various arithmetic operations are performed on its
mValue member (an int64_t count of ticks).

This patch does not actually define or use the ValueCalculator parameter yet but
simply performs the renaming and templatization.

With regards to the templatization, arithmetic operators are defined to take
objects with the same ValueCalculator template parameter (so that we don't, for
example, apply non-safe arithmetic to a StickyTimeDuration).
However, comparison operators are defined to also operate on objects with
a different ValueCalculator template parameter since comparison should be
independent of the type of arithmetic used.

Likewise, the constructor and assignment operator are defined to operate on
objects with a different ValueCalculator template parameter so that objects can
be converted from TimeDuration to StickyTimeDuration and vice-versa.
The constructor is marked as explicit, however, so that we don't silently
convert a StickyTimeDuration to a TimeDuration and unwittingly apply
non-safe arithmetic to a StickyTimeDuration.

TimeDuration is defined as a specialization of BaseTimeDuration that uses
TimeDurationValueCalculator as its ValueCalculator type.
TimeDurationValueCalculator is filled-in in a subsequent patch.
xpcom/ds/TimeStamp.h
xpcom/ds/TimeStamp_darwin.cpp
xpcom/ds/TimeStamp_posix.cpp
xpcom/ds/TimeStamp_windows.cpp