Browse Source

Trade: provide untyped access to tracks in AnimationData.

This reduces the templated code a bit, as I moved the index assertion to
the *.cpp file. Also the function now returns a reference to avoid
needless copies -- it's a view, but still quite a heavy view.
pull/191/head
Vladimír Vondruš 8 years ago
parent
commit
aa2e888bed
  1. 5
      src/Magnum/Trade/AnimationData.cpp
  2. 22
      src/Magnum/Trade/AnimationData.h
  3. 2
      src/Magnum/Trade/Test/AnimationDataTest.cpp

5
src/Magnum/Trade/AnimationData.cpp

@ -70,6 +70,11 @@ UnsignedInt AnimationData::trackTargetId(UnsignedInt id) const {
return _tracks[id]._targetId; return _tracks[id]._targetId;
} }
const Animation::TrackViewStorage<Float>& AnimationData::track(UnsignedInt id) const {
CORRADE_ASSERT(id < _tracks.size(), "Trade::AnimationData::track(): index out of range", _tracks[id]._view);
return _tracks[id]._view;
}
template<class V, class R> auto animationInterpolatorFor(Animation::Interpolation interpolation) -> R(*)(const V&, const V&, Float) { template<class V, class R> auto animationInterpolatorFor(Animation::Interpolation interpolation) -> R(*)(const V&, const V&, Float) {
return Animation::interpolatorFor<V, R>(interpolation); return Animation::interpolatorFor<V, R>(interpolation);
} }

22
src/Magnum/Trade/AnimationData.h

@ -326,6 +326,16 @@ class MAGNUM_TRADE_EXPORT AnimationData {
*/ */
UnsignedInt trackTargetId(UnsignedInt id) const; UnsignedInt trackTargetId(UnsignedInt id) const;
/**
* @brief Track data storage
*
* Returns the untyped base of a @ref Animation::TrackView, which
* allows access only to some track properties. Use the templated and
* checked version below to access a concrete @ref Animation::TrackView
* type.
*/
const Animation::TrackViewStorage<Float>& track(UnsignedInt id) const;
/** /**
* @brief Track data * @brief Track data
* @tparam V Track value type * @tparam V Track value type
@ -338,7 +348,7 @@ class MAGNUM_TRADE_EXPORT AnimationData {
* use the view or you need to release the data array using * use the view or you need to release the data array using
* @ref release() and manage its lifetime yourself. * @ref release() and manage its lifetime yourself.
*/ */
template<class V, class R = Animation::ResultOf<V>> Animation::TrackView<Float, V, R> track(UnsignedInt id) const; template<class V, class R = Animation::ResultOf<V>> const Animation::TrackView<Float, V, R>& track(UnsignedInt id) const;
/** /**
* @brief Release data storage * @brief Release data storage
@ -401,11 +411,11 @@ namespace Implementation {
} }
#endif #endif
template<class V, class R> Animation::TrackView<Float, V, R> AnimationData::track(UnsignedInt id) const { template<class V, class R> const Animation::TrackView<Float, V, R>& AnimationData::track(UnsignedInt id) const {
CORRADE_ASSERT(id < _tracks.size(), "Trade::AnimationData::track(): index out of range", (Animation::TrackView<Float, V, R>{})); const Animation::TrackViewStorage<Float>& storage = track(id);
CORRADE_ASSERT(Implementation::animationTypeFor<V>() == _tracks[id]._type, "Trade::AnimationData::track(): improper type requested for" << _tracks[id]._type, (Animation::TrackView<Float, V, R>{})); CORRADE_ASSERT(Implementation::animationTypeFor<V>() == _tracks[id]._type, "Trade::AnimationData::track(): improper type requested for" << _tracks[id]._type, (static_cast<const Animation::TrackView<Float, V, R>&>(storage)));
CORRADE_ASSERT(Implementation::animationTypeFor<R>() == _tracks[id]._resultType, "Trade::AnimationData::track(): improper result type requested for" << _tracks[id]._resultType, (Animation::TrackView<Float, V, R>{})); CORRADE_ASSERT(Implementation::animationTypeFor<R>() == _tracks[id]._resultType, "Trade::AnimationData::track(): improper result type requested for" << _tracks[id]._resultType, (static_cast<const Animation::TrackView<Float, V, R>&>(storage)));
return static_cast<const Animation::TrackView<Float, V, R>&>(_tracks[id]._view); return static_cast<const Animation::TrackView<Float, V, R>&>(storage);
} }
}} }}

2
src/Magnum/Trade/Test/AnimationDataTest.cpp

@ -342,7 +342,7 @@ void AnimationDataTest::trackWrongIndex() {
data.trackResultType(0); data.trackResultType(0);
data.trackTarget(0); data.trackTarget(0);
data.trackTargetId(0); data.trackTargetId(0);
data.track<Float>(0); data.track(0);
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"Trade::AnimationData::trackType(): index out of range\n" "Trade::AnimationData::trackType(): index out of range\n"

Loading…
Cancel
Save