Browse Source

Trade: make AnimationTrackData constructors explicit.

There's a ton of parameters and it's just unreadable without.
pull/371/head
Vladimír Vondruš 7 years ago
parent
commit
93e6dc2c54
  1. 2
      doc/changelog.dox
  2. 8
      src/Magnum/Trade/AnimationData.h
  3. 2
      src/Magnum/Trade/Test/AbstractImporterTest.cpp
  4. 26
      src/Magnum/Trade/Test/AnimationDataTest.cpp

2
doc/changelog.dox

@ -412,6 +412,8 @@ See also:
- The @ref Magnum/Math/FunctionsBatch.h header is no longer included from
@ref Magnum/Math/Functions.h for backwards compatibility in order to speed
up compile times.
- @ref Trade::AnimationTrackData constructors are now explicit as that
enforces better readability in long initializer expressions
- Non-const @ref Trade::ImageData::data() and @ref Trade::ImageData::pixels()
were renamed to @ref Trade::ImageData::mutableData() and
@ref Trade::ImageData::mutablePixels() to follow the new

8
src/Magnum/Trade/AnimationData.h

@ -228,7 +228,7 @@ class AnimationTrackData {
* initialization of the track array for @ref AnimationData, expected
* to be replaced with concrete values later.
*/
/*implicit*/ AnimationTrackData() noexcept: _type{}, _resultType{}, _targetType{}, _target{}, _view{} {}
explicit AnimationTrackData() noexcept: _type{}, _resultType{}, _targetType{}, _target{}, _view{} {}
/**
* @brief Type-erased constructor
@ -238,14 +238,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<const Float> view) noexcept: _type{type}, _resultType{resultType}, _targetType{targetType}, _target{target}, _view{view} {}
explicit 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<const Float> view) noexcept: _type{type}, _resultType{type}, _targetType{targetType}, _target{target}, _view{view} {}
explicit AnimationTrackData(AnimationTrackType type, AnimationTrackTargetType targetType, UnsignedInt target, Animation::TrackViewStorage<const Float> view) noexcept: _type{type}, _resultType{type}, _targetType{targetType}, _target{target}, _view{view} {}
/**
* @brief Constructor
@ -257,7 +257,7 @@ class AnimationTrackData {
* Detects @ref AnimationTrackType from @p view type and delegates to
* @ref AnimationTrackData(AnimationTrackType, AnimationTrackType, AnimationTrackTargetType, UnsignedInt, Animation::TrackViewStorage<const Float>).
*/
template<class V, class R> /*implicit*/ AnimationTrackData(AnimationTrackTargetType targetType, UnsignedInt target, Animation::TrackView<const Float, const V, R> view) noexcept;
template<class V, class R> explicit AnimationTrackData(AnimationTrackTargetType targetType, UnsignedInt target, Animation::TrackView<const Float, const V, R> view) noexcept;
private:
friend AnimationData;

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

@ -1231,7 +1231,7 @@ void AbstractImporterTest::animation() {
/* Verify that initializer list is converted to an array with
the default deleter and not something disallowed */
if(id == 7) return AnimationData{nullptr, {
{AnimationTrackType::Vector3,
AnimationTrackData{AnimationTrackType::Vector3,
AnimationTrackTargetType::Scaling3D, 0, {}}
}, &state};
else return AnimationData{{}, {}};

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

@ -177,13 +177,13 @@ void AnimationDataTest::construct() {
const int state = 5;
AnimationData data{std::move(buffer), {
{AnimationTrackTargetType::Translation3D, 42,
AnimationTrackData{AnimationTrackTargetType::Translation3D, 42,
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)}},
{AnimationTrackTargetType::Rotation3D, 1337,
AnimationTrackData{AnimationTrackTargetType::Rotation3D, 1337,
Animation::TrackView<const Float, const Quaternion>{
{view, &view[0].time, view.size(), sizeof(Data)},
{view, &view[0].rotation, view.size(), sizeof(Data)},
@ -245,12 +245,12 @@ void AnimationDataTest::constructImplicitDuration() {
const int state = 5;
AnimationData data{std::move(buffer), {
{AnimationTrackTargetType(129), 0,
AnimationTrackData{AnimationTrackTargetType(129), 0,
Animation::TrackView<const Float, const bool>{
{view, &view[0].time, 2, sizeof(Data)},
{view, &view[0].value, 2, sizeof(Data)},
Animation::Interpolation::Constant}},
{AnimationTrackTargetType(130), 1,
AnimationTrackData{AnimationTrackTargetType(130), 1,
Animation::TrackView<const Float, const bool>{
{view, &view[2].time, 2, sizeof(Data)},
{view, &view[2].value, 2, sizeof(Data)},
@ -313,7 +313,7 @@ void AnimationDataTest::constructNotOwned() {
const int state = 5;
AnimationData data{instanceData.dataFlags, keyframes, {
{AnimationTrackTargetType::Translation3D, 42,
AnimationTrackData{AnimationTrackTargetType::Translation3D, 42,
Animation::TrackView<const Float, const Vector3>{
keyframes,
Animation::Interpolation::Constant,
@ -361,7 +361,7 @@ void AnimationDataTest::constructImplicitDurationNotOwned() {
const int state = 5;
AnimationData data{instanceData.dataFlags, keyframes, {
{AnimationTrackTargetType(129), 0,
AnimationTrackData{AnimationTrackTargetType(129), 0,
Animation::TrackView<const Float, const bool>{keyframes, Animation::Interpolation::Constant}},
}, &state};
@ -433,13 +433,13 @@ void AnimationDataTest::constructMove() {
const int state = 5;
AnimationData a{std::move(buffer), {
{AnimationTrackTargetType::Translation3D, 42,
AnimationTrackData{AnimationTrackTargetType::Translation3D, 42,
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)}},
{AnimationTrackTargetType::Rotation3D, 1337,
AnimationTrackData{AnimationTrackTargetType::Rotation3D, 1337,
Animation::TrackView<const Float, const Quaternion>{
{view, &view[0].time, view.size(), sizeof(Data)},
{view, &view[0].rotation, view.size(), sizeof(Data)},
@ -522,7 +522,7 @@ void AnimationDataTest::mutableAccessNotAllowed() {
};
AnimationData data{{}, keyframes, {
{AnimationTrackTargetType(129), 0,
AnimationTrackData{AnimationTrackTargetType(129), 0,
Animation::TrackView<const Float, const bool>{keyframes, Animation::Interpolation::Constant}},
}};
CORRADE_COMPARE(data.dataFlags(), DataFlags{});
@ -551,7 +551,7 @@ void AnimationDataTest::trackCustomResultType() {
view[1] = {5.0f, {30, 60, 100}};
AnimationData data{std::move(buffer), {
{AnimationTrackTargetType::Scaling3D, 0,
AnimationTrackData{AnimationTrackTargetType::Scaling3D, 0,
Animation::TrackView<const Float, const Vector3i, Vector3>{
{view, &view[0].time, view.size(), sizeof(Data)},
{view, &view[0].position, view.size(), sizeof(Data)},
@ -587,7 +587,7 @@ void AnimationDataTest::trackWrongType() {
Error redirectError{&out};
AnimationData data{nullptr, {
{AnimationTrackType::Vector3i,
AnimationTrackData{AnimationTrackType::Vector3i,
AnimationTrackType::Vector3,
AnimationTrackTargetType::Scaling3D, 0, {}}
}};
@ -602,7 +602,7 @@ void AnimationDataTest::trackWrongResultType() {
Error redirectError{&out};
AnimationData data{nullptr, {
{AnimationTrackType::Vector3i,
AnimationTrackData{AnimationTrackType::Vector3i,
AnimationTrackType::Vector3,
AnimationTrackTargetType::Scaling3D, 0, {}}
}};
@ -619,7 +619,7 @@ void AnimationDataTest::release() {
};
AnimationData data{{}, keyframes, {
{AnimationTrackTargetType(129), 0,
AnimationTrackData{AnimationTrackTargetType(129), 0,
Animation::TrackView<const Float, const bool>{keyframes, Animation::Interpolation::Constant}},
}};
CORRADE_COMPARE(data.trackCount(), 1);

Loading…
Cancel
Save