From faf579c4c5fe5680a5942595895d8722b7df7442 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 22 Jan 2011 23:20:12 +0100 Subject: [PATCH] enforce generally imutable time values --- src/lib/time/timevalue.hpp | 15 ++++++++++++++- src/proc/asset/meta/time-grid.hpp | 3 ++- tests/lib/time/time-formats-test.cpp | 6 +++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/lib/time/timevalue.hpp b/src/lib/time/timevalue.hpp index f8407717f..f0d7fc9c8 100644 --- a/src/lib/time/timevalue.hpp +++ b/src/lib/time/timevalue.hpp @@ -169,7 +169,14 @@ namespace time { class Offset : public TimeValue { - + protected: + Offset& + operator= (Offset const& o) ///< derived classes allow mutation + { + TimeValue::operator= (o); + return *this; + } + public: explicit Offset (TimeValue const& distance) @@ -246,6 +253,9 @@ namespace time { class Time : public TimeValue { + /// direct assignment prohibited + Time& operator= (Time const); + public: static const Time MAX ; static const Time MIN ; @@ -291,6 +301,9 @@ namespace time { class Duration : public Offset { + /// direct assignment prohibited + Duration& operator= (Duration const&); + public: Duration (Offset const& distance) : Offset(distance.abs()) diff --git a/src/proc/asset/meta/time-grid.hpp b/src/proc/asset/meta/time-grid.hpp index b8e768326..5b1f0486b 100644 --- a/src/proc/asset/meta/time-grid.hpp +++ b/src/proc/asset/meta/time-grid.hpp @@ -59,6 +59,7 @@ namespace meta { using lib::Symbol; using lib::time::Time; + using lib::time::TimeVar; using lib::time::TimeValue; using lib::time::FrameRate; using lib::time::FSecs; @@ -102,7 +103,7 @@ namespace meta { string id_; FrameRate fps_; - Time origin_; + TimeVar origin_; /** when building a compound or variable grid, * the predecessor is the grid active \em before diff --git a/tests/lib/time/time-formats-test.cpp b/tests/lib/time/time-formats-test.cpp index beda7e5af..daf7f6ca1 100644 --- a/tests/lib/time/time-formats-test.cpp +++ b/tests/lib/time/time-formats-test.cpp @@ -142,7 +142,7 @@ namespace test{ CHECK (--smpte.mins == 38); CHECK (" 5:38:00:01" == string(smpte)); - Time tx = smpte.getTime(); + TimeVar tx = smpte.getTime(); CHECK (tx == Time(0,0,38,5) + Time(FSecs(1,25))); // Extended SMPTE: extension of the axis beyond origin towards negative values @@ -157,7 +157,7 @@ namespace test{ tx = smpte.getTime(); ++smpte.frames; // now *increasing* the frame value CHECK ("- 0:22:00:00"== string(smpte)); // means decreasing the resulting time - CHECK (tx - Time(1000/25,0,0,0) == smpte.getTime()); + CHECK (smpte.getTime() == tx - Time(1000/25,0,0,0)); ++smpte; // but the orientation of the increment on the *whole* TC values is unaltered CHECK ("- 0:21:59:24"== string(smpte)); // so this actually *advanced* time by one frame CHECK (tx == smpte.getTime()); @@ -204,7 +204,7 @@ namespace test{ CHECK (tx == smpte.getTime()); // applying invertOrientation() doesn't change the value smpte.frames.setValueRaw(-1); - tx = tx - Time(FSecs(2,25)); + tx -= Time(FSecs(2,25)); CHECK (tx == smpte.getTime()); CHECK (" 1:00:00:-1"== string(smpte)); smpte.invertOrientation(); // invoking on positive should create double negated representation