diff --git a/src/Magnum/Trade/AnimationData.cpp b/src/Magnum/Trade/AnimationData.cpp index 18fbdf1d0..5208ac45a 100644 --- a/src/Magnum/Trade/AnimationData.cpp +++ b/src/Magnum/Trade/AnimationData.cpp @@ -70,6 +70,11 @@ UnsignedInt AnimationData::trackTargetId(UnsignedInt id) const { return _tracks[id]._targetId; } +const Animation::TrackViewStorage& 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 auto animationInterpolatorFor(Animation::Interpolation interpolation) -> R(*)(const V&, const V&, Float) { return Animation::interpolatorFor(interpolation); } diff --git a/src/Magnum/Trade/AnimationData.h b/src/Magnum/Trade/AnimationData.h index d0e7d11a7..f12bb5ea4 100644 --- a/src/Magnum/Trade/AnimationData.h +++ b/src/Magnum/Trade/AnimationData.h @@ -326,6 +326,16 @@ class MAGNUM_TRADE_EXPORT AnimationData { */ 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& track(UnsignedInt id) const; + /** * @brief Track data * @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 * @ref release() and manage its lifetime yourself. */ - template> Animation::TrackView track(UnsignedInt id) const; + template> const Animation::TrackView& track(UnsignedInt id) const; /** * @brief Release data storage @@ -401,11 +411,11 @@ namespace Implementation { } #endif -template Animation::TrackView AnimationData::track(UnsignedInt id) const { - CORRADE_ASSERT(id < _tracks.size(), "Trade::AnimationData::track(): index out of range", (Animation::TrackView{})); - CORRADE_ASSERT(Implementation::animationTypeFor() == _tracks[id]._type, "Trade::AnimationData::track(): improper type requested for" << _tracks[id]._type, (Animation::TrackView{})); - CORRADE_ASSERT(Implementation::animationTypeFor() == _tracks[id]._resultType, "Trade::AnimationData::track(): improper result type requested for" << _tracks[id]._resultType, (Animation::TrackView{})); - return static_cast&>(_tracks[id]._view); +template const Animation::TrackView& AnimationData::track(UnsignedInt id) const { + const Animation::TrackViewStorage& storage = track(id); + CORRADE_ASSERT(Implementation::animationTypeFor() == _tracks[id]._type, "Trade::AnimationData::track(): improper type requested for" << _tracks[id]._type, (static_cast&>(storage))); + CORRADE_ASSERT(Implementation::animationTypeFor() == _tracks[id]._resultType, "Trade::AnimationData::track(): improper result type requested for" << _tracks[id]._resultType, (static_cast&>(storage))); + return static_cast&>(storage); } }} diff --git a/src/Magnum/Trade/Test/AnimationDataTest.cpp b/src/Magnum/Trade/Test/AnimationDataTest.cpp index 06ff6b2dd..006ae5b38 100644 --- a/src/Magnum/Trade/Test/AnimationDataTest.cpp +++ b/src/Magnum/Trade/Test/AnimationDataTest.cpp @@ -342,7 +342,7 @@ void AnimationDataTest::trackWrongIndex() { data.trackResultType(0); data.trackTarget(0); data.trackTargetId(0); - data.track(0); + data.track(0); CORRADE_COMPARE(out.str(), "Trade::AnimationData::trackType(): index out of range\n"