102 #ifndef LIB_TIME_TIMEVALUE_H 103 #define LIB_TIME_TIMEVALUE_H 107 #include <boost/operators.hpp> 108 #include <boost/rational.hpp> 114 #include <gavl/gavltime.h> 143 : boost::totally_ordered<TimeValue,
144 boost::totally_ordered<TimeValue, gavl_time_t>>
167 static gavl_time_t
limitedDelta (gavl_time_t origin, gavl_time_t target);
195 operator std::string ()
const;
199 friend bool operator< (
TimeValue const& t1, gavl_time_t t2) {
return t1.
t_ < t2 ; }
200 friend bool operator> (
TimeValue const& t1, gavl_time_t t2) {
return t1.
t_ > t2 ; }
202 friend bool operator== (
TimeValue const& t1, gavl_time_t t2) {
return t1.
t_ == t2 ; }
226 using FSecs = boost::rational<int64_t>;
240 , boost::additive<TimeVar,
241 boost::additive<TimeVar, TimeValue,
242 boost::multipliable<TimeVar, int>
267 operator gavl_time_t()
const {
return t_; }
276 TimeVar& operator*= (int64_t fact) {
t_ *= fact;
return *
this; }
316 static const Time MIN ;
317 static const Time ZERO;
341 operator std::string ()
const;
398 Offset stretchedByRationalFactor (boost::rational<int64_t>)
const;
399 Offset stretchedByFloatFactor (
double)
const;
402 operator std::string ()
const;
405 Offset operator- ()
const;
419 operator- (
Offset const& start,
Offset const& toSubtract)
422 distance -= toSubtract;
426 template<
typename FAC>
428 operator* (
Offset const& distance, FAC factor)
430 return factor*distance;
433 template<
typename INT>
435 operator* (INT factor,
Offset const& o)
442 template<
typename INTX>
444 operator* (boost::rational<INTX> factor,
Offset const& offset)
450 operator* (
double factor,
Offset const& offset)
452 return offset.stretchedByFloatFactor (factor);
509 REQUIRE (
t_ >= 0,
"Copy rejected: negative Duration %lu", o.
t_);
519 operator std::string ()
const;
522 Offset operator- ()
const;
541 template<
typename INT>
543 operator* (INT factor,
Duration const& dur)
545 return factor *
Offset(dur);
548 template<
typename INT>
550 operator* (
Duration const& dur, INT factor)
581 , boost::totally_ordered<TimeSpan>
593 , dur_(duration_in_secs)
597 :
Time(start<=end? start:end)
648 operator std::string ()
const;
653 (t1.
t_==t2.
t_ && t1.dur_< t2.dur_);}
662 :
public boost::rational<uint>
667 FrameRate (boost::rational<uint>
const& fractionalRate);
671 double asDouble()
const;
681 operator std::string()
const;
688 return FSecs{ n*rate.denominator(), rate.numerator()};
698 template<
typename NUM>
700 __ensure_nonzero (NUM n)
703 throw error::Logic (
"Degenerated frame grid not allowed" 704 , error::LERR_(BOTTOM_VALUE));
709 symmetricLimit (gavl_time_t raw,
TimeValue lim)
711 return raw > lim?
_raw(lim)
712 : -raw > lim? -
_raw(lim)
729 const uint width =
sizeof(
HashVal) * CHAR_BIT;
730 const uint mask = width-1;
731 const uint n = width / 2;
733 static_assert (0 < n and n <= mask);
734 return (x<<n) | (x>>((-n)&mask ));
753 if (0 > (origin^target))
758 gavl_time_t res = target - origin;
773 TimeVar::TimeVar (
FSecs const& fractionalSeconds)
778 Offset::Offset (
TimeValue const& distance)
784 Duration::Duration (
TimeSpan const& interval)
789 FrameRate::FrameRate (uint fps)
790 : boost::rational<uint> (__ensure_nonzero(fps))
794 FrameRate::FrameRate (uint num, uint denom)
795 : boost::rational<uint> (__ensure_nonzero(num), denom)
799 FrameRate::FrameRate (boost::rational<uint>
const& fractionalRate)
800 : boost::rational<uint> (__ensure_nonzero(fractionalRate))
804 FrameRate::asDouble()
const 806 return boost::rational_cast<
double> (*this);
829 template<
typename X,
typename COND>
static const Time ANYTIME
border condition marker value. ANYTIME <= any time value
TimeValue(TimeValue const &o)
copy initialisation allowed
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
TimeValue & operator=(TimeValue const &o)
Assigning of time values is not allowed, but derived classed might allow that.
static const Duration MAX
maximum possible temporal extension
TimeValue(gavl_time_t val)
Framerate specified as frames per second.
static const gavl_time_t SCALE
Number of micro ticks (µs) per second as basic time scale.
Offset stretchedByRationalFactor(boost::rational< int64_t >) const
Duration(FrameCnt count, FrameRate const &fps)
duration of the given number of frames.
Interface: an opaque change imposed onto some time value.
static const Duration NIL
constant to indicate "no duration"
Implementation namespace for support and library code.
Lumiera's internal time value datatype.
std::string operator+(std::string str, Literal const &sym)
string concatenation
Derived specific exceptions within Lumiera's exception hierarchy.
TimeSpan conform() const
<
Duration abs() const
interpret the distance given by this offset as a time duration
TimeValue(TimeValue const &origin, TimeValue const &target)
static TimeValue buildRaw_(gavl_time_t)
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Offset operator-() const
Supporting backwards use as offset.
friend HashVal hash_value(TimeValue const &)
derive a hash from the µ-tick value
Lumiera error handling (C++ interface).
size_t HashVal
a STL compatible hash value
static const Time NEVER
border condition marker value. NEVER >= any time value
Offset measures a distance in time.
static gavl_time_t limitedTime(gavl_time_t raw)
explicit limit of allowed time range
Duration is the internal Lumiera time metric.
static gavl_time_t limitedDelta(gavl_time_t origin, gavl_time_t target)
safe calculation of explicitly limited time offset
abstract entry, not yet allocated
A time interval anchored at a specific point in time.
int64_t FrameCnt
relative framecount or frame number.
Offset operator-() const
flip offset direction
basic constant internal time value.
failsafe invocation of custom string conversion.
gavl_time_t t_
the raw (internal) time value used to implement the time types
friend gavl_time_t _raw(TimeValue const &time)
static const FrameRate PAL
predefined constant for PAL framerate
TimeVar(TimeVar const &o)
Allowing copy and assignment.