From eb733df1bb781449d4ef1f3e81a7c2c1b4977f1a Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 4 Apr 2011 02:43:01 +0200 Subject: [PATCH] proof-of-concept: implement simple mutation --- src/lib/time/mutation.cpp | 82 ++++++++++++++++++++++++++++++++++++++ src/lib/time/mutation.hpp | 6 +++ src/lib/time/timevalue.hpp | 3 ++ 3 files changed, 91 insertions(+) diff --git a/src/lib/time/mutation.cpp b/src/lib/time/mutation.cpp index e2f5b1ae4..070386c62 100644 --- a/src/lib/time/mutation.cpp +++ b/src/lib/time/mutation.cpp @@ -21,7 +21,9 @@ * *****************************************************/ +#include "lib/error.hpp" #include "lib/time/timevalue.hpp" +#include "lib/time/timequant.hpp" #include "lib/time/mutation.hpp" //#include "lib/time.h" //#include "lib/util.hpp" @@ -32,15 +34,95 @@ //using util::unConst; //using util::floorwrap; +namespace error = lumiera::error; namespace lib { namespace time { + LUMIERA_ERROR_DEFINE (INVALID_MUTATION, "Changing a time value in this way was not designated"); + + Mutation::~Mutation() { } // emit VTable here.... + /** @internal actually force a change + * into a target time entity to mutate. + * Mutation is declared fried to TimeValue + * and thus is allowed to influence the basic + * value stored in each time entity + */ + void + Mutation::imposeChange (TimeValue& target, TimeValue valueToSet) + { + target = valueToSet; + } + + + + + /** + * concrete time value mutation: + * impose fixed new start time. + */ + class SetNewStartTime + : public Mutation + { + TimeValue newTime_; + + virtual void + change (Duration&) const + { + throw error::Logic ("mutating the start point of a pure Duration doesn't make sense" + , LUMIERA_ERROR_INVALID_MUTATION); + } + + + virtual void + change (TimeSpan& target) const + { + imposeChange (target, newTime_); + } + + + /** @note the re-quantisation happens automatically + * when the (changed) QuTime is materialised */ + virtual void + change (QuTime& target) const + { + imposeChange (target, newTime_); + } + + + public: + explicit + SetNewStartTime (TimeValue t) + : newTime_(t) + { } + }; + + + /** */ + void + Mutation::changeTime (Time newStartTime) + { + UNIMPLEMENTED ("perform a trivial mutation to set a new fixed time value"); + } + + + void + Mutation::changeDuration (Duration) + { + UNIMPLEMENTED ("perform a trivial mutation to set a new Duration"); + } + + + void + Mutation::nudge (int adjustment) + { + UNIMPLEMENTED ("Nudge by a predefined nudge amount"); + } diff --git a/src/lib/time/mutation.hpp b/src/lib/time/mutation.hpp index b4d6961df..bbb325911 100644 --- a/src/lib/time/mutation.hpp +++ b/src/lib/time/mutation.hpp @@ -53,6 +53,7 @@ #ifndef LIB_TIME_MUTATION_H #define LIB_TIME_MUTATION_H +#include "lib/error.hpp" #include "lib/time/timevalue.hpp" //#include "lib/symbol.hpp" @@ -68,6 +69,8 @@ namespace time { //using std::string; //using lib::Literal; + LUMIERA_ERROR_DECLARE (INVALID_MUTATION); ///< Changing a time value in this way was not designated + class QuTime; /** @@ -91,6 +94,9 @@ namespace time { static void changeTime (Time); static void changeDuration (Duration); static void nudge (int adjustment); + + protected: + static void imposeChange (TimeValue&, TimeValue); }; diff --git a/src/lib/time/timevalue.hpp b/src/lib/time/timevalue.hpp index 7fd185a62..b6fc7d28f 100644 --- a/src/lib/time/timevalue.hpp +++ b/src/lib/time/timevalue.hpp @@ -74,6 +74,9 @@ namespace time { return *this; } + /** some subclasses may receive modification messages */ + friend class Mutation; + public: /** explicit limit of allowed time range */ static gavl_time_t limited (gavl_time_t raw);