Browse Source

Trade: return TrackView with const types from AnimationData.

Follows the change done in 954798a9ba.
pull/371/head
Vladimír Vondruš 7 years ago
parent
commit
a3ab27f7b9
  1. 2
      doc/changelog.dox
  2. 2
      src/Magnum/Trade/AnimationData.cpp
  3. 20
      src/Magnum/Trade/AnimationData.h
  4. 30
      src/Magnum/Trade/Test/AnimationDataTest.cpp

2
doc/changelog.dox

@ -390,6 +390,8 @@ See also:
@ref Animation library was changed to allow mutable access to the keys &
values it references. Existing code needs to be changed to say
@cpp TrackView<const K, const V> @ce instead of @cpp TrackView<K, V> @ce.
Following this change, @ref Trade::AnimationData now also return instances
with @cpp const @ce types.
- The 4-argument @ref GL::DynamicAttribute constructor was not marked as
@cpp explicit @ce by mistake, it's done now to enforce readability in long
expressions.

2
src/Magnum/Trade/AnimationData.cpp

@ -70,7 +70,7 @@ UnsignedInt AnimationData::trackTarget(UnsignedInt id) const {
return _tracks[id]._target;
}
const Animation::TrackViewStorage<Float>& AnimationData::track(UnsignedInt id) const {
const Animation::TrackViewStorage<const 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;
}

20
src/Magnum/Trade/AnimationData.h

@ -237,14 +237,14 @@ class AnimationTrackData {
* @param target Track target
* @param view Type-erased @ref Animation::TrackView instance
*/
/*implicit*/ AnimationTrackData(AnimationTrackType type, AnimationTrackType resultType, AnimationTrackTargetType targetType, UnsignedInt target, Animation::TrackViewStorage<Float> view) noexcept: _type{type}, _resultType{resultType}, _targetType{targetType}, _target{target}, _view{view} {}
/*implicit*/ AnimationTrackData(AnimationTrackType type, AnimationTrackType resultType, AnimationTrackTargetType targetType, UnsignedInt target, Animation::TrackViewStorage<const Float> view) noexcept: _type{type}, _resultType{resultType}, _targetType{targetType}, _target{target}, _view{view} {}
/** @overload
*
* Equivalent to the above with @p type used as both value type and
* result type.
*/
/*implicit*/ AnimationTrackData(AnimationTrackType type, AnimationTrackTargetType targetType, UnsignedInt target, Animation::TrackViewStorage<Float> view) noexcept: _type{type}, _resultType{type}, _targetType{targetType}, _target{target}, _view{view} {}
/*implicit*/ AnimationTrackData(AnimationTrackType type, AnimationTrackTargetType targetType, UnsignedInt target, Animation::TrackViewStorage<const Float> view) noexcept: _type{type}, _resultType{type}, _targetType{targetType}, _target{target}, _view{view} {}
private:
friend AnimationData;
@ -252,7 +252,7 @@ class AnimationTrackData {
AnimationTrackType _type, _resultType;
AnimationTrackTargetType _targetType;
UnsignedInt _target;
Animation::TrackViewStorage<Float> _view;
Animation::TrackViewStorage<const Float> _view;
};
/**
@ -400,7 +400,7 @@ class MAGNUM_TRADE_EXPORT AnimationData {
* checked version below to access a concrete @ref Animation::TrackView
* type.
*/
const Animation::TrackViewStorage<Float>& track(UnsignedInt id) const;
const Animation::TrackViewStorage<const Float>& track(UnsignedInt id) const;
/**
* @brief Track data
@ -414,7 +414,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<class V, class R = Animation::ResultOf<V>> const Animation::TrackView<Float, V, R>& track(UnsignedInt id) const;
template<class V, class R = Animation::ResultOf<V>> const Animation::TrackView<const Float, const V, R>& track(UnsignedInt id) const;
/**
* @brief Release data storage
@ -505,11 +505,11 @@ namespace Implementation {
}
#endif
template<class V, class R> const Animation::TrackView<Float, V, R>& AnimationData::track(UnsignedInt id) const {
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, (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, (static_cast<const Animation::TrackView<Float, V, R>&>(storage)));
return static_cast<const Animation::TrackView<Float, V, R>&>(storage);
template<class V, class R> const Animation::TrackView<const Float, const V, R>& AnimationData::track(UnsignedInt id) const {
const Animation::TrackViewStorage<const Float>& storage = track(id);
CORRADE_ASSERT(Implementation::animationTypeFor<V>() == _tracks[id]._type, "Trade::AnimationData::track(): improper type requested for" << _tracks[id]._type, (static_cast<const Animation::TrackView<const Float, const V, R>&>(storage)));
CORRADE_ASSERT(Implementation::animationTypeFor<R>() == _tracks[id]._resultType, "Trade::AnimationData::track(): improper result type requested for" << _tracks[id]._resultType, (static_cast<const Animation::TrackView<const Float, const V, R>&>(storage)));
return static_cast<const Animation::TrackView<const Float, const V, R>&>(storage);
}
}}

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

@ -92,14 +92,14 @@ void AnimationDataTest::construct() {
AnimationData data{std::move(buffer), Containers::Array<AnimationTrackData>{Containers::InPlaceInit, {
{AnimationTrackType::Vector3,
AnimationTrackTargetType::Translation3D, 42,
Animation::TrackView<Float, Vector3>{
Animation::TrackView<const Float, const Vector3>{
{view, &view[0].time, view.size(), sizeof(Data)},
{view, &view[0].position, view.size(), sizeof(Data)},
Animation::Interpolation::Constant,
animationInterpolatorFor<Vector3>(Animation::Interpolation::Constant)}},
{AnimationTrackType::Quaternion,
AnimationTrackTargetType::Rotation3D, 1337,
Animation::TrackView<Float, Quaternion>{
Animation::TrackView<const Float, const Quaternion>{
{view, &view[0].time, view.size(), sizeof(Data)},
{view, &view[0].rotation, view.size(), sizeof(Data)},
Animation::Interpolation::Linear,
@ -117,7 +117,7 @@ void AnimationDataTest::construct() {
CORRADE_COMPARE(data.trackTargetType(0), AnimationTrackTargetType::Translation3D);
CORRADE_COMPARE(data.trackTarget(0), 42);
Animation::TrackView<Float, Vector3> track = data.track<Vector3>(0);
Animation::TrackView<const Float, const Vector3> track = data.track<Vector3>(0);
CORRADE_COMPARE(track.keys().size(), 3);
CORRADE_COMPARE(track.values().size(), 3);
CORRADE_COMPARE(track.interpolation(), Animation::Interpolation::Constant);
@ -128,7 +128,7 @@ void AnimationDataTest::construct() {
CORRADE_COMPARE(data.trackTargetType(1), AnimationTrackTargetType::Rotation3D);
CORRADE_COMPARE(data.trackTarget(1), 1337);
Animation::TrackView<Float, Quaternion> track = data.track<Quaternion>(1);
Animation::TrackView<const Float, const Quaternion> track = data.track<Quaternion>(1);
CORRADE_COMPARE(track.keys().size(), 3);
CORRADE_COMPARE(track.values().size(), 3);
CORRADE_COMPARE(track.interpolation(), Animation::Interpolation::Linear);
@ -154,13 +154,13 @@ void AnimationDataTest::constructImplicitDuration() {
AnimationData data{std::move(buffer), Containers::Array<AnimationTrackData>{Containers::InPlaceInit, {
{AnimationTrackType::Bool,
AnimationTrackTargetType(129), 0,
Animation::TrackView<Float, bool>{
Animation::TrackView<const Float, const bool>{
{view, &view[0].time, 2, sizeof(Data)},
{view, &view[0].value, 2, sizeof(Data)},
Animation::Interpolation::Constant}},
{AnimationTrackType::Bool,
AnimationTrackTargetType(130), 1,
Animation::TrackView<Float, bool>{
Animation::TrackView<const Float, const bool>{
{view, &view[2].time, 2, sizeof(Data)},
{view, &view[2].value, 2, sizeof(Data)},
Animation::Interpolation::Linear}}
@ -175,7 +175,7 @@ void AnimationDataTest::constructImplicitDuration() {
CORRADE_COMPARE(data.trackTargetType(0), AnimationTrackTargetType(129));
CORRADE_COMPARE(data.trackTarget(0), 0);
Animation::TrackView<Float, bool> track = data.track<bool>(0);
Animation::TrackView<const Float, const bool> track = data.track<bool>(0);
CORRADE_COMPARE(track.duration(), (Range1D{1.0f, 5.0f}));
CORRADE_COMPARE(track.keys().size(), 2);
CORRADE_COMPARE(track.values().size(), 2);
@ -187,7 +187,7 @@ void AnimationDataTest::constructImplicitDuration() {
CORRADE_COMPARE(data.trackTargetType(1), AnimationTrackTargetType(130));
CORRADE_COMPARE(data.trackTarget(1), 1);
Animation::TrackView<Float, bool> track = data.track<bool>(1);
Animation::TrackView<const Float, const bool> track = data.track<bool>(1);
CORRADE_COMPARE(track.duration(), (Range1D{3.0f, 7.0f}));
CORRADE_COMPARE(track.keys().size(), 2);
CORRADE_COMPARE(track.values().size(), 2);
@ -223,14 +223,14 @@ void AnimationDataTest::constructMove() {
AnimationData a{std::move(buffer), Containers::Array<AnimationTrackData>{Containers::InPlaceInit, {
{AnimationTrackType::Vector3,
AnimationTrackTargetType::Translation3D, 42,
Animation::TrackView<Float, Vector3>{
Animation::TrackView<const Float, const Vector3>{
{view, &view[0].time, view.size(), sizeof(Data)},
{view, &view[0].position, view.size(), sizeof(Data)},
Animation::Interpolation::Constant,
animationInterpolatorFor<Vector3>(Animation::Interpolation::Constant)}},
{AnimationTrackType::Quaternion,
AnimationTrackTargetType::Rotation3D, 1337,
Animation::TrackView<Float, Quaternion>{
Animation::TrackView<const Float, const Quaternion>{
{view, &view[0].time, view.size(), sizeof(Data)},
{view, &view[0].rotation, view.size(), sizeof(Data)},
Animation::Interpolation::Linear,
@ -250,7 +250,7 @@ void AnimationDataTest::constructMove() {
CORRADE_COMPARE(b.trackTargetType(0), AnimationTrackTargetType::Translation3D);
CORRADE_COMPARE(b.trackTarget(0), 42);
Animation::TrackView<Float, Vector3> track = b.track<Vector3>(0);
Animation::TrackView<const Float, const Vector3> track = b.track<Vector3>(0);
CORRADE_COMPARE(track.keys().size(), 3);
CORRADE_COMPARE(track.values().size(), 3);
CORRADE_COMPARE(track.interpolation(), Animation::Interpolation::Constant);
@ -261,7 +261,7 @@ void AnimationDataTest::constructMove() {
CORRADE_COMPARE(b.trackTargetType(1), AnimationTrackTargetType::Rotation3D);
CORRADE_COMPARE(b.trackTarget(1), 1337);
Animation::TrackView<Float, Quaternion> track = b.track<Quaternion>(1);
Animation::TrackView<const Float, const Quaternion> track = b.track<Quaternion>(1);
CORRADE_COMPARE(track.keys().size(), 3);
CORRADE_COMPARE(track.values().size(), 3);
CORRADE_COMPARE(track.interpolation(), Animation::Interpolation::Linear);
@ -283,7 +283,7 @@ void AnimationDataTest::constructMove() {
CORRADE_COMPARE(c.trackTargetType(0), AnimationTrackTargetType::Translation3D);
CORRADE_COMPARE(c.trackTarget(0), 42);
Animation::TrackView<Float, Vector3> track = c.track<Vector3>(0);
Animation::TrackView<const Float, const Vector3> track = c.track<Vector3>(0);
CORRADE_COMPARE(track.keys().size(), 3);
CORRADE_COMPARE(track.values().size(), 3);
CORRADE_COMPARE(track.interpolation(), Animation::Interpolation::Constant);
@ -294,7 +294,7 @@ void AnimationDataTest::constructMove() {
CORRADE_COMPARE(c.trackTargetType(1), AnimationTrackTargetType::Rotation3D);
CORRADE_COMPARE(c.trackTarget(1), 1337);
Animation::TrackView<Float, Quaternion> track = c.track<Quaternion>(1);
Animation::TrackView<const Float, const Quaternion> track = c.track<Quaternion>(1);
CORRADE_COMPARE(track.keys().size(), 3);
CORRADE_COMPARE(track.values().size(), 3);
CORRADE_COMPARE(track.interpolation(), Animation::Interpolation::Linear);
@ -326,7 +326,7 @@ void AnimationDataTest::trackCustomResultType() {
{AnimationTrackType::Vector3i,
AnimationTrackType::Vector3,
AnimationTrackTargetType::Scaling3D, 0,
Animation::TrackView<Float, Vector3i, Vector3>{
Animation::TrackView<const Float, const Vector3i, Vector3>{
{view, &view[0].time, view.size(), sizeof(Data)},
{view, &view[0].position, view.size(), sizeof(Data)},
[](const Vector3i& a, const Vector3i& b, Float t) -> Vector3 {

Loading…
Cancel
Save