Browse Source

Deprecate templated [Compressed]Image{,View,Data}::data().

This one returned a raw pointer, losing all size information, One should
instead use the non-templated data() along with Containers::arrayCast()
for a properly type-checked conversion.

There's *a lot* of tests using the deprecated functionality. I need to
change one more thing before updating those.
pull/362/head
Vladimír Vondruš 7 years ago
parent
commit
1c25bdba7a
  1. 6
      doc/changelog.dox
  2. 40
      src/Magnum/Image.h
  3. 22
      src/Magnum/ImageView.h
  4. 20
      src/Magnum/Trade/ImageData.h

6
doc/changelog.dox

@ -489,6 +489,12 @@ See also:
is deprecated for doing too many things at once and being too tied to one is deprecated for doing too many things at once and being too tied to one
particular STL container, use @ref MeshTools::generateFlatNormals(const Containers::StridedArrayView1D<const Vector3>&) particular STL container, use @ref MeshTools::generateFlatNormals(const Containers::StridedArrayView1D<const Vector3>&)
instead instead
- Templated versions of @ref Image::data(), @ref ImageView::data(),
@ref CompressedImage::data(), @ref CompressedImageView::data() and
@ref Trade::ImageData::data() that returned a raw pointer are deprecated,
use the non-templated version together with
@ref Corrade::Containers::arrayCast() instead for properly bounds-checked
type conversion
@subsection changelog-latest-compatibility Potential compatibility breakages, removed APIs @subsection changelog-latest-compatibility Potential compatibility breakages, removed APIs

40
src/Magnum/Image.h

@ -364,15 +364,27 @@ template<UnsignedInt dimensions> class Image {
Containers::ArrayView<const char> data() const & { return _data; } Containers::ArrayView<const char> data() const & { return _data; }
Containers::ArrayView<const char> data() const && = delete; /**< @overload */ Containers::ArrayView<const char> data() const && = delete; /**< @overload */
/** @overload */ #ifdef MAGNUM_BUILD_DEPRECATED
template<class T = char> T* data() { /**
* @brief Image data in a particular type
* @deprecated Use non-templated @ref data() together with
* @ref Corrade::Containers::arrayCast() instead for properly
* bounds-checked type conversion.
*/
template<class T> CORRADE_DEPRECATED("use data() together with Containers::arrayCast() instead") T* data() {
return reinterpret_cast<T*>(_data.data()); return reinterpret_cast<T*>(_data.data());
} }
/** @overload */ /**
template<class T = char> const T* data() const { * @brief Image data in a particular type
* @deprecated Use non-templated @ref data() together with
* @ref Corrade::Containers::arrayCast() instead for properly
* bounds-checked type conversion.
*/
template<class T> CORRADE_DEPRECATED("use data() together with Containers::arrayCast() instead") const T* data() const {
return reinterpret_cast<const T*>(_data.data()); return reinterpret_cast<const T*>(_data.data());
} }
#endif
/** /**
* @brief View on pixel data * @brief View on pixel data
@ -580,15 +592,27 @@ template<UnsignedInt dimensions> class CompressedImage {
/** @overload */ /** @overload */
Containers::ArrayView<const char> data() const { return _data; } Containers::ArrayView<const char> data() const { return _data; }
/** @overload */ #ifdef MAGNUM_BUILD_DEPRECATED
template<class T> T* data() { /**
* @brief Image data in a particular type
* @deprecated Use non-templated @ref data() together with
* @ref Corrade::Containers::arrayCast() instead for properly
* bounds-checked type conversion.
*/
template<class T> CORRADE_DEPRECATED("use data() together with Containers::arrayCast() instead") T* data() {
return reinterpret_cast<T*>(_data.data()); return reinterpret_cast<T*>(_data.data());
} }
/** @overload */ /**
template<class T> const T* data() const { * @brief Image data in a particular type
* @deprecated Use non-templated @ref data() together with
* @ref Corrade::Containers::arrayCast() instead for properly
* bounds-checked type conversion.
*/
template<class T> CORRADE_DEPRECATED("use data() together with Containers::arrayCast() instead") const T* data() const {
return reinterpret_cast<const T*>(_data.data()); return reinterpret_cast<const T*>(_data.data());
} }
#endif
/** /**
* @brief Release data storage * @brief Release data storage

22
src/Magnum/ImageView.h

@ -373,10 +373,17 @@ template<UnsignedInt dimensions> class ImageView {
*/ */
Containers::ArrayView<const char> data() const { return _data; } Containers::ArrayView<const char> data() const { return _data; }
/** @overload */ #ifdef MAGNUM_BUILD_DEPRECATED
template<class T> const T* data() const { /**
* @brief Image data in a particular type
* @deprecated Use non-templated @ref data() together with
* @ref Corrade::Containers::arrayCast() instead for properly
* bounds-checked type conversion.
*/
template<class T> CORRADE_DEPRECATED("use data() together with Containers::arrayCast() instead") const T* data() const {
return reinterpret_cast<const T*>(_data.data()); return reinterpret_cast<const T*>(_data.data());
} }
#endif
/** /**
* @brief Set image data * @brief Set image data
@ -612,10 +619,17 @@ template<UnsignedInt dimensions> class CompressedImageView {
/** @brief Image data */ /** @brief Image data */
Containers::ArrayView<const char> data() const { return _data; } Containers::ArrayView<const char> data() const { return _data; }
/** @overload */ #ifdef MAGNUM_BUILD_DEPRECATED
template<class T> const T* data() const { /**
* @brief Image data in a particular type
* @deprecated Use non-templated @ref data() together with
* @ref Corrade::Containers::arrayCast() instead for properly
* bounds-checked type conversion.
*/
template<class T> CORRADE_DEPRECATED("use data() together with Containers::arrayCast() instead") const T* data() const {
return reinterpret_cast<const T*>(_data.data()); return reinterpret_cast<const T*>(_data.data());
} }
#endif
/** /**
* @brief Set image data * @brief Set image data

20
src/Magnum/Trade/ImageData.h

@ -340,15 +340,27 @@ template<UnsignedInt dimensions> class ImageData {
Containers::ArrayView<const char> data() const & { return _data; } Containers::ArrayView<const char> data() const & { return _data; }
Containers::ArrayView<const char> data() const && = delete; /**< @overload */ Containers::ArrayView<const char> data() const && = delete; /**< @overload */
/** @overload */ #ifdef MAGNUM_BUILD_DEPRECATED
template<class T> T* data() { /**
* @brief Image data in a particular type
* @deprecated Use non-templated @ref data() together with
* @ref Corrade::Containers::arrayCast() instead for properly
* bounds-checked type conversion.
*/
template<class T> CORRADE_DEPRECATED("use data() together with Containers::arrayCast() instead") T* data() {
return reinterpret_cast<T*>(_data.data()); return reinterpret_cast<T*>(_data.data());
} }
/** @overload */ /**
template<class T> const T* data() const { * @brief Image data in a particular type
* @deprecated Use non-templated @ref data() together with
* @ref Corrade::Containers::arrayCast() instead for properly
* bounds-checked type conversion.
*/
template<class T> CORRADE_DEPRECATED("use data() together with Containers::arrayCast() instead") const T* data() const {
return reinterpret_cast<const T*>(_data.data()); return reinterpret_cast<const T*>(_data.data());
} }
#endif
/** /**
* @brief View on pixel data * @brief View on pixel data

Loading…
Cancel
Save