From 7c5f18643b264247da67bdf32448d272f553df77 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 6 Jun 2011 03:17:42 +0200 Subject: [PATCH] cont. reworking based on that idea; refactor mutation base cases --- src/lib/time/control.hpp | 76 +++++++++++++++++++++++++++++++++------ src/lib/time/mutation.cpp | 38 ++++++-------------- src/lib/time/mutation.hpp | 51 ++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 38 deletions(-) diff --git a/src/lib/time/control.hpp b/src/lib/time/control.hpp index 6d7b3ad73..7f257880b 100644 --- a/src/lib/time/control.hpp +++ b/src/lib/time/control.hpp @@ -161,12 +161,13 @@ namespace time { } }; + template struct Builder { static TI - buildChangedValue (TAR& target, TI const&) + buildChangedValue (TAR& target) { return TI(target); } @@ -175,9 +176,18 @@ namespace time { struct Builder { static TimeSpan - buildChangedValue (TAR& target, TimeSpan const& newVal) + buildChangedValue (TAR& target) { - return TimeSpan (target, newVal.duration()); + return TimeSpan (target, Duration::ZERO); /////////////TODO how to feed the "new value" duration???? + } + }; + template<> + struct Builder + { + static TimeSpan + buildChangedValue (TimeSpan& target) + { + return target; } }; #ifdef LIB_TIME_TIMEQUQNT_H @@ -185,18 +195,27 @@ namespace time { struct Builder { static QuTime - buildChangedValue (TAR& target, QuTime const&) + buildChangedValue (TAR& target) { return QuTime (target ,getDefaultGridFallback() //////////////////TICKET #810 ); } }; + template<> + struct Builder + { + static QuTime + buildChangedValue (QuTime& target) + { + return target; + } + }; #endif template struct Adap - : Mutabor + : Mutator , Builder { @@ -204,12 +223,29 @@ namespace time { imposeValueChange (TAR& target, TI const& newVal) { imposeChange (target,newVal); - return buildChangedValue(target,newVal); + return buildChangedValue(target); + } + + static TI + imposeOffset (TAR& target, Offset const& off) + { + imposeChange (target,off); + return buildChangedValue(target); + } + + static TI + imposeNudge (TAR& target, int off_by_steps) + { + imposeChange (target,off_by_steps); + return buildChangedValue(target); } }; template - struct Policy + struct Policy; + + template + struct Policy { static function buildChangeHandler (TAR& target) @@ -218,6 +254,26 @@ namespace time { } }; + template + struct Policy + { + static function + buildChangeHandler (TAR& target) + { + return bind (Adap::imposeOffset, ref(target), _1 ); + } + }; + + template + struct Policy + { + static function + buildChangeHandler (TAR& target) + { + return bind (Adap::imposeNudge, ref(target), _1 ); + } + }; + template TI @@ -423,9 +479,9 @@ namespace time { void Mutator::bind_to (TAR& target) const { - setVal_ = Policy::buildChangeHandler(target); //MutationPolicy ::buildChangeHandler (target); - offset_ = MutationPolicy::buildChangeHandler (target); - nudge_ = MutationPolicy ::buildChangeHandler (target); + setVal_ = Policy ::buildChangeHandler (target); + offset_ = Policy::buildChangeHandler (target); + nudge_ = Policy ::buildChangeHandler (target); } template diff --git a/src/lib/time/mutation.cpp b/src/lib/time/mutation.cpp index d96c96419..a6fd96e50 100644 --- a/src/lib/time/mutation.cpp +++ b/src/lib/time/mutation.cpp @@ -48,17 +48,6 @@ namespace time { 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 - */ - TimeValue& - Mutation::imposeChange (TimeValue& target, TimeValue const& valueToSet) - { - return target = valueToSet; - } @@ -157,14 +146,14 @@ namespace time { virtual void change (Duration& target) const { - imposeChange (target, TimeVar(target)+=adjustment_); + imposeChange (target, adjustment_); } virtual void change (TimeSpan& target) const { - imposeChange (target, TimeVar(target)+=adjustment_); + imposeChange (target, adjustment_); } @@ -173,7 +162,7 @@ namespace time { virtual void change (QuTime& target) const { - imposeChange (target, TimeVar(target)+=adjustment_); + imposeChange (target, adjustment_); } @@ -205,7 +194,7 @@ namespace time { /** * concrete time value mutation: * nudge target value by the given number of 'steps', - * relative to either the given grid. + * relative to the given grid. */ class NudgeMutation : public ImposeOffsetMutation @@ -234,6 +223,8 @@ namespace time { * @note currently the natural grid is hard wired, * just interpreting the step parameter as * offset in seconds. + * @see mutation#imposeChange (TimeValue, int) + * @see mutation#imposeChange (QuTime, int) */ class NaturalNudgeMutation : public ClonableMutation @@ -243,31 +234,22 @@ namespace time { virtual void change (Duration& target) const { - imposeChange (target, TimeVar(target)+=Time(FSecs(steps_))); + imposeChange (target, steps_); } virtual void change (TimeSpan& target) const { - imposeChange (target, TimeVar(target)+=Time(FSecs(steps_))); + imposeChange (target, steps_); } - /** Special treatment: use the quantised time's own grid; - * retrieve the corresponding grid point, offset it by the step-parameter, - * then retrieve the corresponding time from the quantised time's - * underlying quantiser (grid). - * @note when the #steps_ parameter is zero, what happens here effectively - * is the materialisation of the quantised target time, i.e. making - * the quantisation explicit and storing the resulting value. */ + /** @note special treatment: use the quantised time's own grid */ virtual void change (QuTime& target) const { - PQuant const& grid (target); - int64_t originalGridPoint = grid->gridPoint(target); - int64_t adjustedGridPoint = originalGridPoint + steps_; - imposeChange (target, grid->timeOf (adjustedGridPoint)); + imposeChange (target, steps_); } diff --git a/src/lib/time/mutation.hpp b/src/lib/time/mutation.hpp index bbd3f9fe9..f6e2f3f5f 100644 --- a/src/lib/time/mutation.hpp +++ b/src/lib/time/mutation.hpp @@ -113,6 +113,9 @@ namespace time { protected: static TimeValue& imposeChange (TimeValue&, TimeValue const&); + static TimeValue& imposeChange (TimeValue&, Offset const&); + static TimeValue& imposeChange (TimeValue&, int); + static TimeValue& imposeChange (QuTime&, int); }; @@ -126,5 +129,53 @@ namespace time { #endif + + /* === implementing the actual changes === */ + + /** @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 + */ + inline TimeValue& + Mutation::imposeChange (TimeValue& target, TimeValue const& valueToSet) + { + return target = valueToSet; + } + + /** @internal variation to mutate a target time value by applying an offset */ + inline TimeValue& + Mutation::imposeChange (TimeValue& target, Offset const& offset) + { + return imposeChange (target, TimeVar(target) += offset); + } + + /** @internal nudge a target time value by a step wise offset. + * The standard case uses a fixed offset of 1 second per step //////////////////TICKET #810 + */ + inline TimeValue& + Mutation::imposeChange (TimeValue& target, int steps) + { + return imposeChange (target, TimeVar(target) += Time(FSecs(steps))); + } + +#ifdef LIB_TIME_TIMEQUQNT_H + /** @internal Special treatment for quantised target values: + * use the quantised time's own grid; retrieve the corresponding grid point, + * offset it by the step-parameter, then retrieve the corresponding time from + * the quantised time's underlying quantiser (grid) and impose that as change. + * @note when the #steps parameter is zero, what happens here effectively + * is the materialisation of the quantised target time, i.e. making + * the quantisation explicit and storing the resulting value. */ + inline TimeValue& + Mutation::imposeChange (QuTime& target, int steps) + { + PQuant const& grid (target); + int64_t originalGridPoint = grid->gridPoint(target); + int64_t adjustedGridPoint = originalGridPoint + steps; + return imposeChange (target, grid->timeOf (adjustedGridPoint)); + } +#endif + + }} // lib::time #endif