95#ifndef LIB_TIME_TIMEVALUE_H
96#define LIB_TIME_TIMEVALUE_H
100#include <boost/operators.hpp>
101#include <boost/rational.hpp>
193 explicit operator std::string()
const;
227 using FSecs = boost::rational<int64_t>;
241 , boost::additive<TimeVar,
242 boost::additive<TimeVar, TimeValue,
243 boost::multipliable<TimeVar, int>
342 explicit operator std::string()
const;
405 explicit operator std::string()
const;
425 distance -= toSubtract;
429 template<
typename FAC>
433 return factor*distance;
436 template<
typename INT>
445 template<
typename INTX>
512 REQUIRE (
t_ >= 0,
"Copy rejected: negative Duration %lu", o.
t_);
522 explicit operator std::string()
const;
544 template<
typename NUM>
548 return factor *
Offset(dur);
551 template<
typename NUM>
595 ,
dur_(duration_in_secs)
650 explicit operator std::string()
const;
656 auto ord{ t_ <=> ts.
t_ };
669 :
public boost::rational<uint>
676 FrameRate (boost::rational<uint> fractionalRate);
696 explicit operator std::string()
const;
713 template<
typename NUM>
718 throw error::Logic (
"Degenerated frame grid not allowed"
719 ,
LERR_(BOTTOM_VALUE));
726 return raw > lim? _raw(lim)
727 : -raw > lim? -_raw(lim)
745 const uint mask = width-1;
746 const uint n = width / 2;
748 static_assert (0 < n and n <= mask);
749 return (x<<n) | (x>>((-n)&mask ));
768 if (0 > (origin^target))
801 :
TimeValue{buildRaw_(symmetricLimit(_raw(distance)
812 :
boost::rational<
uint> (__ensure_nonzero(fps))
817 :
boost::rational<
uint> (__ensure_nonzero(num), denom)
822 :
boost::rational<
uint> (__ensure_nonzero(fractionalRate))
843 return boost::rational_cast<double> (*
this);
866 template<
typename X,
typename COND>
Duration is the internal Lumiera time metric.
static const Duration MAX
maximum possible temporal extension
Duration(FrameCnt count, FrameRate const &fps)
duration of the given number of frames.
Duration(FSecs const &timeSpan_in_secs)
Offset operator-() const
Supporting backwards use as offset.
Duration(Duration const &o)
Duration(TimeValue const &timeSpec)
static const Duration NIL
constant to indicate "no duration"
Duration & operator=(Duration const &)
direct assignment prohibited
void accept(Mutation const &)
Duration(Offset const &distance)
Framerate specified as frames per second.
static const FrameRate STEP
1 frame per second
Duration duration() const
duration of one frame
static const FrameRate PAL
predefined constant for PAL framerate
std::strong_ordering operator<=>(FrameRate const &) const =default
derive total ordering from base class
static FrameRate approx(double fps)
static const FrameRate NTSC
static const FrameRate HALTED
Interface: an opaque change imposed onto some time value.
Offset measures a distance in time.
Offset stretchedByFloatFactor(double) const
Offset(TimeValue const &distance=Time::ZERO)
Offset & operator=(Offset const &o)
generally immutable, but derived classes allow some limited mutation through special API calls
Duration abs() const
interpret the distance given by this offset as a time duration
Offset operator-() const
flip offset direction
Offset(TimeValue const &origin, TimeValue const &target)
Offset(Offset const &)=default
Offset stretchedByRationalFactor(boost::rational< int64_t >) const
A time interval anchored at a specific point in time.
static const TimeSpan ALL
bool contains(TimeValue const &tp) const
TimeSpan(TimeValue const &start, Duration const &length)
Duration duration() const
TimeSpan(TimeValue const &start, FSecs(duration_in_secs))
TimeSpan conform() const
<
TimeSpan(TimeValue const &start, TimeValue const &end)
bool operator==(TimeSpan const &ts) const =default
std::strong_ordering operator<=>(TimeSpan const &ts) const
Supporting extended strong total ordering, based on start and interval length.
TimeSpan(TimeValue const &start, Offset const &reference_distance)
basic constant internal time value.
static const raw_time_64 SCALE
Number of micro ticks (µs) per second as basic time scale.
TimeValue & operator=(TimeValue const &o)
Assigning of time values is not allowed, but derived classed might allow that.
std::strong_ordering operator<=>(TimeValue const &) const =default
static raw_time_64 limitedTime(raw_time_64 raw)
explicit limit of allowed time range
static TimeValue buildRaw_(raw_time_64)
raw_time_64 t_
the raw (internal) time value used to implement the time types
static raw_time_64 limitedDelta(raw_time_64 origin, raw_time_64 target)
safe calculation of explicitly limited time offset
TimeValue(raw_time_64 val)
friend raw_time_64 _raw(TimeValue const &time)
TimeValue(TimeValue const &o)
copy initialisation allowed
bool operator==(TimeValue const &) const =default
TimeValue(TimeValue const &origin, TimeValue const &target)
friend HashVal hash_value(TimeValue const &)
derive a hash from the µ-tick value
a mutable time value, behaving like a plain number, allowing copy and re-accessing
TimeVar & operator=(TimeVar const &)=default
TimeVar & operator-=(TimeVar const &tx)
TimeVar(TimeValue const &time=TimeValue(0))
TimeVar(TimeVar const &o)
Allowing copy and assignment.
TimeVar & operator*=(int64_t fact)
Supporting multiplication with integral factor.
TimeVar operator-() const
Supporting sign flip.
TimeVar & operator+=(TimeVar const &tx)
Supporting additive.
Lumiera's internal time value datatype.
static const Time NEVER
border condition marker value. NEVER >= any time value
TimeVar operator+(TimeValue const &tval) const
convenience start for time calculations
static const Time ANYTIME
border condition marker value. ANYTIME <= any time value
Time & operator=(Time const)
direct assignment prohibited
Time(Time const &)=default
Time(TimeValue const &val=TimeValue(0))
TimeVar operator-() const
Time(TimeVar const &calcResult)
Time(int)
suppress possible direct conversions
Lumiera error handling (C++ interface).
raw_time_64 symmetricLimit(raw_time_64 raw, TimeValue lim)
NUM __ensure_nonzero(NUM n)
HashVal hash_value(TimeValue const &time)
derive a hash from the µ-tick value
int64_t FrameCnt
relative framecount or frame number.
FSecs operator/(int n, FrameRate rate)
convenient conversion to duration in fractional seconds
Offset operator+(Offset const &start, Offset const &toChain)
int64_t raw_time_64
Raw µ-tick time representation used in Lumiera.
Offset operator*(Offset const &distance, FAC factor)
Offset operator-(Offset const &start, Offset const &toSubtract)
boost::rational< int64_t > FSecs
rational representation of fractional seconds
boost::rational< uint > __framerate_approximation(double fps)
Implementation namespace for support and library code.
size_t HashVal
a STL compatible hash value
LumieraError< LERR_(LOGIC)> Logic
bool isnil(lib::time::Duration const &dur)
failsafe invocation of custom string conversion.
static std::string invoke(X const &x) noexcept
#define MAX(A, B)
the inevitable MAX macro, sometimes still necessary in template code