diff --git a/src/lib/time/control.hpp b/src/lib/time/control.hpp index 69ae4ec02..01f5295cc 100644 --- a/src/lib/time/control.hpp +++ b/src/lib/time/control.hpp @@ -162,12 +162,53 @@ namespace time { }; + + namespace { // metaprogramming helpers to pick the suitable Instantiation... + + template + struct isDurationZ + { + static const bool value = is_sameType::value; + }; + template + struct isTimeSpanZ + { + static const bool value = is_sameType::value; + }; + template + struct isQuTime + { + static const bool value = is_sameType::value; + }; + + template + struct isSpecialCase + { + static const bool value = isDurationZ::value; + }; + + template + inline bool + isDuration() + { + return is_sameType::value; + } + + template + inline bool + isTimeSpan() + { + return is_sameType::value; + } + } + + template struct Builder { static TI - buildChangedValue (TAR& target) + buildChangedValue (TAR const& target) { return TI(target); } @@ -176,12 +217,21 @@ namespace time { struct Builder { static TimeSpan - buildChangedValue (TAR& target) + buildChangedValue (TAR const& target) { return TimeSpan (target, Duration::NIL); /////////////TODO how to feed the "new value" duration???? } }; template<> + struct Builder + { + static TimeSpan + buildChangedValue (Duration const& targetDuration) + { + return TimeSpan (Time::ZERO, targetDuration); + } + }; + template<> struct Builder { static TimeSpan @@ -219,41 +269,112 @@ namespace time { , Builder { + template static TI - imposeValueChange (TAR& target, TI const& newVal) + processValueChange (TAR& target, SRC const& change) { - imposeChange (target,newVal); + imposeChange (target,change); return buildChangedValue(target); } static TI - imposeOffset (TAR& target, Offset const& off) + useLengthAsChange (TAR& target, TimeSpan const& change) { - imposeChange (target,off); - return buildChangedValue(target); + return processValueChange(target, change.duration()); } static TI - imposeNudge (TAR& target, int off_by_steps) + mutateLength (TimeSpan& target, Duration const& change) { - imposeChange (target,off_by_steps); + Mutator::imposeChange (target.duration(), change); + return Builder::buildChangedValue(target); + } + + static TimeSpan + mutateTimeSpan (TimeSpan& target, TimeSpan const& change) + { + Mutator::imposeChange (target.duration(), change.duration()); + Mutator::imposeChange (target,change.start()); + return Builder::buildChangedValue(target); + } + + static TI + dontChange (TAR& target) + { + // note: not touching the target return buildChangedValue(target); } }; + + template - struct Policy; - - template - struct Policy + struct Policy { - static function + static function buildChangeHandler (TAR& target) { - return bind (Adap::imposeValueChange, ref(target), _1 ); + return bind (Adap::template processValueChange, ref(target), _1 ); } }; + + // special treatment of Durations as target... + + template + struct Policy + { + static function + buildChangeHandler (Duration& target) + { + return bind (Adap::dontChange, ref(target) ); + } + }; + + template + struct Policy + { + static function + buildChangeHandler (Duration& target) + { + return bind (Adap::template processValueChange, ref(target), _1 ); + } + }; + + template + struct Policy + { + static function + buildChangeHandler (Duration& target) + { + return bind (Adap::useLengthAsChange, ref(target), _1 ); + } + }; + + // special treatment for TimeSpan values... + + template + struct Policy + { + static function + buildChangeHandler (TimeSpan& target) + { + return bind (Adap::mutateLength, ref(target), _1 ); + } + }; + + template<> + struct Policy + { + static function + buildChangeHandler (TimeSpan& target) + { + return bind (Adap::mutateTimeSpan, ref(target), _1 ); + } + }; + + +/* template struct Policy { @@ -273,7 +394,7 @@ namespace time { return bind (Adap::imposeNudge, ref(target), _1 ); } }; - +*/ template TI @@ -371,33 +492,6 @@ namespace time { } #endif //(End)quantisation special case - - namespace { // metaprogramming helpers to pick the suitable Instantiation... - - template - struct isDuration - { - static const bool value = is_sameType::value; - }; - template - struct isTimeSpan - { - static const bool value = is_sameType::value; - }; - template - struct isQuTime - { - static const bool value = is_sameType::value; - }; - - template - struct isSpecialCase - { - static const bool value = isDuration::value; - }; - - } - template template struct Mutator::MutationPolicy< typename disable_if< isSpecialCase, @@ -437,7 +531,7 @@ namespace time { template template - struct Mutator::MutationPolicy< typename enable_if< isDuration, + struct Mutator::MutationPolicy< typename enable_if< isDurationZ, TI>::type, TAR> { static function diff --git a/tests/lib/time/time-control-test.cpp b/tests/lib/time/time-control-test.cpp index 1b5cb2dd7..e309fabaa 100644 --- a/tests/lib/time/time-control-test.cpp +++ b/tests/lib/time/time-control-test.cpp @@ -260,10 +260,17 @@ namespace test{ CHECK (target == otherDuration); } void - verify_wasChanged (Duration const& target, TimeValue const& org, TimeSpan const& span) + verify_wasChanged (Duration const& target, TimeValue const& org, TimeSpan const& span_as_change) { CHECK (target != org); - CHECK (target == span.duration()); + CHECK (target == span_as_change.duration()); + } + void + verify_wasChanged (TimeSpan const& target, TimeValue const& org, Duration const& changedDur) + { + CHECK (target == org, "Logic error: Duration was used as start point of the target TimeSpan"); + CHECK (target.duration() != Time(FSecs(3,2)), "length of the timespan should have been changed"); + CHECK (target.duration() == changedDur); }