Browse Source

Fix dependency of Image headers on StridedArrayView.

mousecapture
Vladimír Vondruš 6 years ago
parent
commit
fc0ceac99e
  1. 5
      doc/changelog.dox
  2. 14
      src/Magnum/Image.h
  3. 14
      src/Magnum/ImageView.h
  4. 3
      src/Magnum/Test/ImageTest.cpp
  5. 3
      src/Magnum/Test/ImageViewTest.cpp
  6. 14
      src/Magnum/Trade/ImageData.h
  7. 3
      src/Magnum/Trade/Test/ImageDataTest.cpp

5
doc/changelog.dox

@ -220,6 +220,11 @@ See also:
- With @ref Corrade/Utility/DebugStl.h not being included, @ref std::string - With @ref Corrade/Utility/DebugStl.h not being included, @ref std::string
instances could get accidentally printed as @ref ResourceKey instances. instances could get accidentally printed as @ref ResourceKey instances.
Added and explicit header dependency to avoid such cases. Added and explicit header dependency to avoid such cases.
- The @ref Magnum/Image.h, @ref Magnum/ImageView.h and
@ref Magnum/Trade/ImageData.h headers required
@ref Corrade/Containers/StridedArrayView.h to be included *before* in order
to use the @ref ImageView::pixels() "pixels()" function. Now it's enough
to just include it at any point, with no order dependency anymore.
@subsection changelog-latest-deprecated Deprecated APIs @subsection changelog-latest-deprecated Deprecated APIs

14
src/Magnum/Image.h

@ -34,6 +34,17 @@
#include "Magnum/DimensionTraits.h" #include "Magnum/DimensionTraits.h"
#include "Magnum/PixelStorage.h" #include "Magnum/PixelStorage.h"
#ifndef DOXYGEN_GENERATING_OUTPUT
namespace Corrade { namespace Containers {
/* Forward declaration of an utility used in pixels() to avoid forcing users to
include the relatively large StridedArrayView header *before* the Image
class definition. */
template<unsigned newDimensions, class U, unsigned dimensions, class T> StridedArrayView<newDimensions, U> arrayCast(const StridedArrayView<dimensions, T>& view);
}}
#endif
namespace Magnum { namespace Magnum {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
@ -437,7 +448,8 @@ template<UnsignedInt dimensions> class Image {
*/ */
template<class T> Containers::StridedArrayView<dimensions, T> pixels() { template<class T> Containers::StridedArrayView<dimensions, T> pixels() {
/* Deliberately not adding a StridedArrayView include, it should /* Deliberately not adding a StridedArrayView include, it should
work without since this is a templated function */ work without since this is a templated function and we declare
arrayCast() above to satisfy two-phase lookup. */
return Containers::arrayCast<dimensions, T>(pixels()); return Containers::arrayCast<dimensions, T>(pixels());
} }

14
src/Magnum/ImageView.h

@ -35,6 +35,17 @@
#include "Magnum/PixelStorage.h" #include "Magnum/PixelStorage.h"
#include "Magnum/Math/Vector3.h" #include "Magnum/Math/Vector3.h"
#ifndef DOXYGEN_GENERATING_OUTPUT
namespace Corrade { namespace Containers {
/* Forward declaration of an utility used in pixels() to avoid forcing users to
include the relatively large StridedArrayView header *before* the Image
class definition. */
template<unsigned newDimensions, class U, unsigned dimensions, class T> StridedArrayView<newDimensions, U> arrayCast(const StridedArrayView<dimensions, T>& view);
}}
#endif
namespace Magnum { namespace Magnum {
/** /**
@ -460,7 +471,8 @@ template<UnsignedInt dimensions, class T> class ImageView {
template<class U> Containers::StridedArrayView<dimensions, typename std::conditional<std::is_const<Type>::value, typename std::add_const<U>::type, U>::type> pixels() const { template<class U> Containers::StridedArrayView<dimensions, typename std::conditional<std::is_const<Type>::value, typename std::add_const<U>::type, U>::type> pixels() const {
if(!_data && !_data.size()) return {}; if(!_data && !_data.size()) return {};
/* Deliberately not adding a StridedArrayView include, it should /* Deliberately not adding a StridedArrayView include, it should
work without since this is a templated function */ work without since this is a templated function and we declare
arrayCast() above to satisfy two-phase lookup. */
return Containers::arrayCast<dimensions, typename std::conditional<std::is_const<Type>::value, typename std::add_const<U>::type, U>::type>(pixels()); return Containers::arrayCast<dimensions, typename std::conditional<std::is_const<Type>::value, typename std::add_const<U>::type, U>::type>(pixels());
} }

3
src/Magnum/Test/ImageTest.cpp

@ -24,7 +24,8 @@
*/ */
/* Included as first to check that we *really* don't need the StridedArrayView /* Included as first to check that we *really* don't need the StridedArrayView
header for definition of pixels() */ header for definition of pixels(). We actually need, but just for the
arrayCast() template, which is forward-declared. */
#include "Magnum/Image.h" #include "Magnum/Image.h"
#include <sstream> #include <sstream>

3
src/Magnum/Test/ImageViewTest.cpp

@ -24,7 +24,8 @@
*/ */
/* Included as first to check that we *really* don't need the StridedArrayView /* Included as first to check that we *really* don't need the StridedArrayView
header for definition of pixels() */ header for definition of pixels(). We actually need, but just for the
arrayCast() template, which is forward-declared. */
#include "Magnum/ImageView.h" #include "Magnum/ImageView.h"
#include <sstream> #include <sstream>

14
src/Magnum/Trade/ImageData.h

@ -36,6 +36,17 @@
#include "Magnum/Trade/Trade.h" #include "Magnum/Trade/Trade.h"
#include "Magnum/Trade/visibility.h" #include "Magnum/Trade/visibility.h"
#ifndef DOXYGEN_GENERATING_OUTPUT
namespace Corrade { namespace Containers {
/* Forward declaration of an utility used in pixels() to avoid forcing users to
include the relatively large StridedArrayView header *before* the Image
class definition. */
template<unsigned newDimensions, class U, unsigned dimensions, class T> StridedArrayView<newDimensions, U> arrayCast(const StridedArrayView<dimensions, T>& view);
}}
#endif
namespace Magnum { namespace Trade { namespace Magnum { namespace Trade {
/** /**
@ -417,7 +428,8 @@ template<UnsignedInt dimensions> class ImageData {
*/ */
template<class T> Containers::StridedArrayView<dimensions, T> pixels() { template<class T> Containers::StridedArrayView<dimensions, T> pixels() {
/* Deliberately not adding a StridedArrayView include, it should /* Deliberately not adding a StridedArrayView include, it should
work without since this is a templated function */ work without since this is a templated function and we declare
arrayCast() above to satisfy two-phase lookup. */
return Containers::arrayCast<dimensions, T>(pixels()); return Containers::arrayCast<dimensions, T>(pixels());
} }

3
src/Magnum/Trade/Test/ImageDataTest.cpp

@ -24,7 +24,8 @@
*/ */
/* Included as first to check that we *really* don't need the StridedArrayView /* Included as first to check that we *really* don't need the StridedArrayView
header for definition of pixels() */ header for definition of pixels(). We actually need, but just for the
arrayCast() template, which is forward-declared. */
#include "Magnum/Trade/ImageData.h" #include "Magnum/Trade/ImageData.h"
#include <sstream> #include <sstream>

Loading…
Cancel
Save