From 3b03da5d5ed195f0ae37055359bd9c29afbd83f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 6 Dec 2013 14:00:05 +0100 Subject: [PATCH] Made ImageReference data pointer constant. ImageReference is supposed to be wrapper around existing data array of some type which is passed to Magnum functions. Thus modifying the original data array (which must be kept somewhere for proper deletion) is much better option than casting the pointer returned by data() to some proper type and then operating on that. Hopefully this won't break any existing code. --- src/ImageReference.h | 12 +++++------- .../TgaImageConverter/Test/TgaImageConverterTest.cpp | 3 +-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/ImageReference.h b/src/ImageReference.h index f41007d2c..7532c103e 100644 --- a/src/ImageReference.h +++ b/src/ImageReference.h @@ -48,7 +48,6 @@ to change image properties, only data pointer. Interchangeable with Image, BufferImage or Trade::ImageData. @see ImageReference1D, ImageReference2D, ImageReference3D -@todo Provide const version somewhat */ template class ImageReference: public AbstractImage { public: @@ -61,7 +60,7 @@ template class ImageReference: public AbstractImage { * @param size %Image size * @param data %Image data */ - constexpr explicit ImageReference(ColorFormat format, ColorType type, const typename DimensionTraits::VectorType& size, void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} + constexpr explicit ImageReference(ColorFormat format, ColorType type, const typename DimensionTraits::VectorType& size, const void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor @@ -78,8 +77,7 @@ template class ImageReference: public AbstractImage { constexpr typename DimensionTraits::VectorType size() const { return _size; } /** @brief Pointer to raw data */ - unsigned char* data() { return _data; } - constexpr const unsigned char* data() const { return _data; } /**< @overload */ + constexpr const unsigned char* data() const { return _data; } /** * @brief Set image data @@ -89,13 +87,13 @@ template class ImageReference: public AbstractImage { * passed in constructor. The data are not copied nor deleted on * destruction. */ - void setData(void* data) { - _data = reinterpret_cast(data); + void setData(const void* data) { + _data = reinterpret_cast(data); } private: Math::Vector _size; - unsigned char* _data; + const unsigned char* _data; }; /** @brief One-dimensional image wrapper */ diff --git a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index a63aa1c14..0a03fcd45 100644 --- a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -49,8 +49,7 @@ class TgaImageConverterTest: public TestSuite::Tester { }; namespace { - /** @todo `const` when ImageReference is sane */ - char originalData[] = { + constexpr const char originalData[] = { 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8