add a mutable time value with full arithmetics
This commit is contained in:
parent
0c45fc47f3
commit
643859f6b8
3 changed files with 64 additions and 19 deletions
|
|
@ -38,9 +38,16 @@ namespace time {
|
|||
|
||||
|
||||
/**
|
||||
* fixed format time specification.
|
||||
*
|
||||
* @todo WIP-WIP-WIP
|
||||
* basic constant internal time value.
|
||||
* These time values provide the implementation base
|
||||
* for all further time types. They can be created by
|
||||
* wrapping up a raw micro tick value (gavl_time_t),
|
||||
* are totally ordered, but besides that,
|
||||
* they are opaque and non-mutable.
|
||||
* @note clients should prefer to use Time instances,
|
||||
* which explicitly denote an Lumiera internal
|
||||
* time value and are easier to use.
|
||||
* @see TimeVar when full arithmetics are required
|
||||
*/
|
||||
class TimeValue
|
||||
: boost::totally_ordered<TimeValue,
|
||||
|
|
@ -83,16 +90,19 @@ namespace time {
|
|||
|
||||
|
||||
/** a mutable time value,
|
||||
* behaving like a plain number
|
||||
* and allowing copying and re-accessing
|
||||
* behaving like a plain number,
|
||||
* allowing copy and re-accessing
|
||||
*/
|
||||
class TimeVar
|
||||
: public TimeValue
|
||||
, boost::additive<TimeVar>
|
||||
, boost::additive<TimeVar,
|
||||
boost::additive<TimeVar, TimeValue,
|
||||
boost::multipliable<TimeVar, int>
|
||||
> >
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
TimeVar (TimeValue time)
|
||||
TimeVar (TimeValue time = TimeValue())
|
||||
: TimeValue(time)
|
||||
{ }
|
||||
|
||||
|
|
@ -117,13 +127,13 @@ namespace time {
|
|||
TimeVar& operator-= (TimeVar const& tx) { t_ -= tx.t_; return *this; }
|
||||
|
||||
// Supporting multiplication with integral factor
|
||||
TimeVar& operator*= (int64_t fact) { t_ *= fact; return *this; }
|
||||
TimeVar& operator*= (int fact) { t_ *= fact; return *this; }
|
||||
|
||||
// baseclass TimeValue is already totally_ordered
|
||||
};
|
||||
|
||||
|
||||
class Offset;
|
||||
class Offset;
|
||||
|
||||
/**
|
||||
* Lumiera's internal time value datatype
|
||||
|
|
@ -158,14 +168,17 @@ namespace time {
|
|||
: TimeValue(distance)
|
||||
{ }
|
||||
};
|
||||
|
||||
inline Offset
|
||||
operator- (TimeValue const& end, TimeValue const& start)
|
||||
{
|
||||
TimeVar distance(end);
|
||||
distance -= start;
|
||||
return Offset(distance);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////TODO this seems rather like a bad idea,
|
||||
// because it opens a lot of implicit conversions which we don't want!
|
||||
//inline Offset
|
||||
//operator- (TimeValue const& end, TimeValue const& start)
|
||||
//{
|
||||
// TimeVar distance(end);
|
||||
// distance -= start;
|
||||
// return Offset(distance);
|
||||
//}
|
||||
|
||||
typedef const Offset TimeDistance;
|
||||
|
||||
|
|
|
|||
|
|
@ -633,7 +633,7 @@ return: 0
|
|||
END
|
||||
|
||||
|
||||
PLANNED "Times and time intervals" TimeValue_test <<END
|
||||
TEST "Times and time intervals" TimeValue_test <<END
|
||||
return: 0
|
||||
END
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ namespace test{
|
|||
TimeValue ref (random_or_get(arg));
|
||||
|
||||
checkBasicTimeValues (ref);
|
||||
checkMutableTime (ref);
|
||||
checkComparisons (ref);
|
||||
checkComponentAccess();
|
||||
}
|
||||
|
|
@ -105,6 +106,37 @@ namespace test{
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
checkMutableTime (TimeValue org)
|
||||
{
|
||||
TimeVar zero;
|
||||
TimeVar one = TimeValue(1);
|
||||
TimeVar two = TimeValue(2);
|
||||
|
||||
TimeVar var (org);
|
||||
|
||||
var += two;
|
||||
var *= 2;
|
||||
CHECK (zero == (var - 2*(org + two)) );
|
||||
|
||||
// the transient vars caused no side-effects
|
||||
CHECK (var == 2*two + org + org);
|
||||
CHECK (two == TimeValue(2));
|
||||
|
||||
var = org; // assign new value
|
||||
CHECK (zero == (var - org));
|
||||
|
||||
CHECK (zero < one);
|
||||
CHECK (one < two);
|
||||
CHECK (var < Time::MAX);
|
||||
CHECK (var > Time::MIN);
|
||||
|
||||
gavl_time_t raw (var);
|
||||
CHECK (raw == org);
|
||||
CHECK (raw > org - two);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
checkComparisons (TimeValue org)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue