add internal / diagnostic display for low-level time values and time spans
Initially I've deliberately omitted those, to nudge towards using time quantisation and TCode formatting for any external representation of time values. While this recommendation is still valid, the overloaded string conversion turns out to be helpful for unit testing and diagnostics in compound data structures. See Record<GenNode>
This commit is contained in:
parent
6da0785d0a
commit
7b7d12d99e
4 changed files with 42 additions and 26 deletions
|
|
@ -121,7 +121,7 @@ namespace time {
|
|||
{ }
|
||||
|
||||
|
||||
/** displaying an internal Lumiera Time value
|
||||
/** display an internal Lumiera Time value
|
||||
* for diagnostic purposes or internal reporting.
|
||||
* @warning internal Lumiera time values refer to an
|
||||
* implementation dependent time origin/scale.
|
||||
|
|
@ -133,9 +133,28 @@ namespace time {
|
|||
return string (lumiera_tmpbuf_print_time (t_));
|
||||
}
|
||||
|
||||
TimeVar::operator string() const
|
||||
/** @note recommendation to use TCode for external representation */
|
||||
TimeValue::operator string() const
|
||||
{
|
||||
return string (lumiera_tmpbuf_print_time (t_));
|
||||
gavl_time_t time = t_;
|
||||
int millis, seconds;
|
||||
bool negative = (time < 0);
|
||||
|
||||
if (negative) time = -time;
|
||||
time /= GAVL_TIME_SCALE_MS;
|
||||
millis = time % 1000;
|
||||
seconds = time / 1000;
|
||||
|
||||
return string (negative ? "-" : "")
|
||||
+ (seconds>0 or time==0? lexical_cast<string> (seconds)+"s" : "")
|
||||
+ (millis>0? lexical_cast<string> (millis)+"ms" : "")
|
||||
;
|
||||
}
|
||||
|
||||
TimeSpan::operator string() const
|
||||
{
|
||||
return string (lumiera_tmpbuf_print_time (t_))
|
||||
+ "["+string(dur_)+"]";
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -224,14 +243,10 @@ char*
|
|||
lumiera_tmpbuf_print_time (gavl_time_t time)
|
||||
{
|
||||
int milliseconds, seconds, minutes, hours;
|
||||
int negative;
|
||||
bool negative = (time < 0);
|
||||
|
||||
if(time < 0)
|
||||
{
|
||||
negative = 1;
|
||||
if (negative)
|
||||
time = -time;
|
||||
}
|
||||
else negative = 0;
|
||||
|
||||
time /= GAVL_TIME_SCALE_MS;
|
||||
milliseconds = time % 1000;
|
||||
|
|
|
|||
|
|
@ -118,6 +118,9 @@ namespace time {
|
|||
friend gavl_time_t _raw (TimeValue const& time) { return time.t_; }
|
||||
static TimeValue buildRaw_(gavl_time_t);
|
||||
|
||||
/** @internal diagnostics */
|
||||
operator std::string () const;
|
||||
|
||||
// Supporting totally_ordered
|
||||
friend bool operator< (TimeValue const& t1, TimeValue const& t2) { return t1.t_ < t2.t_; }
|
||||
friend bool operator< (TimeValue const& t1, gavl_time_t t2) { return t1.t_ < t2 ; }
|
||||
|
|
@ -160,10 +163,7 @@ namespace time {
|
|||
return *this;
|
||||
}
|
||||
|
||||
/** @internal diagnostics */
|
||||
operator std::string () const;
|
||||
|
||||
// Supporting mixing with plain long int arithmetics
|
||||
// Support mixing with plain long int arithmetics
|
||||
operator gavl_time_t () const { return t_; }
|
||||
|
||||
// Supporting additive
|
||||
|
|
@ -515,6 +515,8 @@ namespace time {
|
|||
/** may change start / duration */
|
||||
void accept (Mutation const&);
|
||||
|
||||
/** @internal diagnostics */
|
||||
operator std::string () const;
|
||||
|
||||
/// Supporting extended total order, based on start and interval length
|
||||
friend bool operator== (TimeSpan const& t1, TimeSpan const& t2) { return t1.t_==t2.t_ && t1.dur_==t2.dur_; }
|
||||
|
|
|
|||
|
|
@ -12,26 +12,26 @@ out: Command-State. arguments=unbound, ·noUNDO·.
|
|||
out: capture state...
|
||||
out: Command-State. arguments=Closure\(\), ·noUNDO·.
|
||||
out: Command-State. arguments=Closure\(.\), ·noUNDO·.
|
||||
out: Command-State. arguments=Closure\(.,0:..:....00\), ·noUNDO·.
|
||||
out: Command-State. arguments=Closure\(0:..:....00,glorious,..\), <mem: destruction>.
|
||||
out: Command-State. arguments=Closure\(.,.+s.*\), ·noUNDO·.
|
||||
out: Command-State. arguments=Closure\(.+s.*,glorious,..\), <mem: destruction>.
|
||||
out: would be serialised.....Command-State. arguments=Closure\(\), ·noUNDO·.
|
||||
out: would be serialised.....Command-State. arguments=Closure\(.\), ·noUNDO·.
|
||||
out: would be serialised.....Command-State. arguments=Closure\(.,0:..:....00\), ·noUNDO·.
|
||||
out: would be serialised.....Command-State. arguments=Closure\(0:..:....00,glorious,..\), <mem: destruction>.
|
||||
out: would be serialised.....Command-State. arguments=Closure\(.,.+s.*\), ·noUNDO·.
|
||||
out: would be serialised.....Command-State. arguments=Closure\(.+s.*,glorious,..\), <mem: destruction>.
|
||||
out: sizeof\( .+control1.ArgumentHolder.+ \) = .+
|
||||
out: Command-State. arguments=Closure\(0:..:....00,Lumiera rocks,..\), ·noUNDO·.
|
||||
out: Command-State. arguments=Closure\(.+s.*,Lumiera rocks,..\), ·noUNDO·.
|
||||
out: capture state...
|
||||
out: captured state: START...Lumiera rocks
|
||||
out: Command-State. arguments=Closure\(0:..:....00,Lumiera rocks,..\), <mem: START...Lumiera rocks>.
|
||||
out: Command-State. arguments=Closure\(.+s.*,Lumiera rocks,..\), <mem: START...Lumiera rocks>.
|
||||
out: invoke operation...
|
||||
out: START...doIt\( Time=0:..:....00 "Lumiera rocks" rand=.. \)
|
||||
out: START...doIt\( Time=.+s.* "Lumiera rocks" rand=.. \)
|
||||
out: undo... memento=START...Lumiera rocks
|
||||
out: START...doIt\( Time=0:..:....00 "Lumiera rocks" rand=.. \)undoIt\(time=0:..:....00\)----memento-:START...Lumiera rocks
|
||||
out: START...doIt\( Time=.+s.* "Lumiera rocks" rand=.. \)undoIt\(time=0:..:....00\)----memento-:START...Lumiera rocks
|
||||
out: capture state...
|
||||
out: modified: Command-State. arguments=Closure\(0:00:00.123,unbelievable,..\), <mem: START...doIt\( Time=0:..:....00 "Lumiera rocks" rand=.. \)undoIt\(time=0:..:....00\)----memento-:START...Lumiera rocksLumiera rocks>.
|
||||
out: copied : Command-State. arguments=Closure\(0:..:....00,Lumiera rocks,..\), <mem: START...Lumiera rocks>.
|
||||
out: undo... memento=START...doIt\( Time=0:..:....00 "Lumiera rocks" rand=.. \)undoIt\(time=0:..:....00\)----memento-:START...Lumiera rocksLumiera rocks
|
||||
out: RESET...undoIt\(time=0:..:....00\)----memento-:START...doIt\( Time=0:..:....00 "Lumiera rocks" rand=.. \)undoIt\(time=0:..:....00\)----memento-:START...Lumiera rocksLumiera rocks
|
||||
out: modified: Command-State. arguments=Closure\(123ms,unbelievable,..\), <mem: START...doIt\( Time=.+s.* "Lumiera rocks" rand=.. \)undoIt\(time=0:..:....00\)----memento-:START...Lumiera rocksLumiera rocks>.
|
||||
out: copied : Command-State. arguments=Closure\(.+s.*,Lumiera rocks,..\), <mem: START...Lumiera rocks>.
|
||||
out: undo... memento=START...doIt\( Time=.+s.* "Lumiera rocks" rand=.. \)undoIt\(time=0:..:....00\)----memento-:START...Lumiera rocksLumiera rocks
|
||||
out: RESET...undoIt\(time=0:..:....00\)----memento-:START...doIt\( Time=.+s.* "Lumiera rocks" rand=.. \)undoIt\(time=0:..:....00\)----memento-:START...Lumiera rocksLumiera rocks
|
||||
END
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -319,7 +319,6 @@ namespace test{
|
|||
|
||||
// the time span behaves like a time
|
||||
CHECK (org == interval);
|
||||
CHECK (string(Time(org)) == string(interval));
|
||||
|
||||
// can get the length by direct conversion
|
||||
Duration theLength(interval);
|
||||
|
|
|
|||
Loading…
Reference in a new issue