diff --git a/src/lib/time/control.hpp b/src/lib/time/control.hpp index 398d2c172..6d7b3ad73 100644 --- a/src/lib/time/control.hpp +++ b/src/lib/time/control.hpp @@ -94,6 +94,9 @@ namespace time { using std::tr1::ref; + template + struct Mutabor; + /** * Implementation building block: impose changes to a Time element. @@ -120,6 +123,8 @@ namespace time { template struct MutationPolicy; + + friend class Mutabor; protected: mutable ValueSetter setVal_; @@ -145,7 +150,75 @@ namespace time { }; + template + struct Mutabor + { + + static void + imposeChange (TimeValue& target, TI const& newVal) + { + Mutator::imposeChange (target,newVal); + } + }; + template + struct Builder + { + + static TI + buildChangedValue (TAR& target, TI const&) + { + return TI(target); + } + }; + template + struct Builder + { + static TimeSpan + buildChangedValue (TAR& target, TimeSpan const& newVal) + { + return TimeSpan (target, newVal.duration()); + } + }; +#ifdef LIB_TIME_TIMEQUQNT_H + template + struct Builder + { + static QuTime + buildChangedValue (TAR& target, QuTime const&) + { + return QuTime (target + ,getDefaultGridFallback() //////////////////TICKET #810 + ); + } + }; +#endif + + template + struct Adap + : Mutabor + , Builder + { + + static TI + imposeValueChange (TAR& target, TI const& newVal) + { + imposeChange (target,newVal); + return buildChangedValue(target,newVal); + } + }; + + template + struct Policy + { + static function + buildChangeHandler (TAR& target) + { + return bind (Adap::imposeValueChange, ref(target), _1 ); + } + }; + + template TI Mutator::imposeValueChange (TimeValue& target, TI const& newVal) @@ -243,10 +316,36 @@ 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, TI>::type, TAR> + struct Mutator::MutationPolicy< typename disable_if< isSpecialCase, + TI>::type, TAR> { static function buildChangeHandler (TAR& target) @@ -282,7 +381,8 @@ namespace time { template template - struct Mutator::MutationPolicy, TI>::type, TAR> + struct Mutator::MutationPolicy< typename enable_if< isDuration, + TI>::type, TAR> { static function buildChangeHandler (Duration& target) @@ -323,7 +423,7 @@ namespace time { void Mutator::bind_to (TAR& target) const { - setVal_ = MutationPolicy ::buildChangeHandler (target); + setVal_ = Policy::buildChangeHandler(target); //MutationPolicy ::buildChangeHandler (target); offset_ = MutationPolicy::buildChangeHandler (target); nudge_ = MutationPolicy ::buildChangeHandler (target); }