From 1d9e6210d8d6be4534121ab84d29d703a94ce134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 5 Jul 2015 15:29:08 +0200 Subject: [PATCH] Use anonymous typed enum instead of static const member variable. The reason behind this is that it's not possible to take address of the enum value -- the generated code can be simpler and no symbol is exported. --- src/Magnum/Array.h | 7 ++++-- src/Magnum/BufferImage.h | 4 +++- src/Magnum/Image.h | 4 +++- src/Magnum/ImageReference.h | 4 +++- src/Magnum/Implementation/BufferState.h | 20 +++++++++-------- src/Magnum/Math/BoolVector.h | 6 +++-- src/Magnum/Math/Matrix.h | 4 +++- src/Magnum/Math/RectangularMatrix.h | 22 ++++++++++--------- src/Magnum/Math/Vector.h | 7 ++++-- src/Magnum/MultisampleTexture.h | 4 +++- .../SceneGraph/AbstractTransformation.h | 5 +++-- src/Magnum/Texture.h | 4 +++- src/Magnum/TextureArray.h | 4 +++- src/Magnum/Trade/ImageData.h | 4 +++- 14 files changed, 64 insertions(+), 35 deletions(-) diff --git a/src/Magnum/Array.h b/src/Magnum/Array.h index 0beb5bb5e..0001b2107 100644 --- a/src/Magnum/Array.h +++ b/src/Magnum/Array.h @@ -48,8 +48,11 @@ don't need any math operations and fuzzy comparison (e.g. enum values). Unlike */ template class Array { public: - typedef T Type; /**< @brief Data type */ - const static UnsignedInt Dimensions = dimensions; /**< @brief Dimension count */ + typedef T Type; /**< @brief Data type */ + + enum: UnsignedInt { + Dimensions = dimensions /**< Dimension count */ + }; /** * @brief Default constructor diff --git a/src/Magnum/BufferImage.h b/src/Magnum/BufferImage.h index 75098ee92..eedb32651 100644 --- a/src/Magnum/BufferImage.h +++ b/src/Magnum/BufferImage.h @@ -50,7 +50,9 @@ Stores image data in GPU memory. Interchangeable with @ref Image, */ template class BufferImage: public AbstractImage { public: - const static UnsignedInt Dimensions = dimensions; /**< @brief Image dimension count */ + enum: UnsignedInt { + Dimensions = dimensions /**< Image dimension count */ + }; /** * @brief Constructor diff --git a/src/Magnum/Image.h b/src/Magnum/Image.h index a3da46395..0a41dc0d0 100644 --- a/src/Magnum/Image.h +++ b/src/Magnum/Image.h @@ -42,7 +42,9 @@ Stores image data on client memory. Interchangeable with @ref ImageReference, */ template class Image: public AbstractImage { public: - const static UnsignedInt Dimensions = dimensions; /**< @brief Image dimension count */ + enum: UnsignedInt { + Dimensions = dimensions /**< Image dimension count */ + }; /** * @brief Constructor diff --git a/src/Magnum/ImageReference.h b/src/Magnum/ImageReference.h index 1fac76b59..b48960e4c 100644 --- a/src/Magnum/ImageReference.h +++ b/src/Magnum/ImageReference.h @@ -52,7 +52,9 @@ Interchangeable with @ref Image, @ref BufferImage or @ref Trade::ImageData. */ template class ImageReference: public AbstractImage { public: - const static UnsignedInt Dimensions = dimensions; /**< @brief Image dimension count */ + enum: UnsignedInt { + Dimensions = dimensions /**< Image dimension count */ + }; /** * @brief Constructor diff --git a/src/Magnum/Implementation/BufferState.h b/src/Magnum/Implementation/BufferState.h index 7b0190edd..78501d8a6 100644 --- a/src/Magnum/Implementation/BufferState.h +++ b/src/Magnum/Implementation/BufferState.h @@ -30,15 +30,17 @@ namespace Magnum { namespace Implementation { struct BufferState { - #ifndef MAGNUM_TARGET_GLES - static const std::size_t TargetCount = 13+1; - #elif !defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL) - static const std::size_t TargetCount = 8+1; - #elif !defined(MAGNUM_TARGET_GLES2) - static const std::size_t TargetCount = 12+1; - #else - static const std::size_t TargetCount = 2+1; - #endif + enum: std::size_t { + #ifndef MAGNUM_TARGET_GLES + TargetCount = 13+1 + #elif !defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL) + TargetCount = 8+1 + #elif !defined(MAGNUM_TARGET_GLES2) + TargetCount = 12+1 + #else + TargetCount = 2+1 + #endif + }; /* Target <-> index mapping */ static std::size_t indexForTarget(Buffer::TargetHint target); diff --git a/src/Magnum/Math/BoolVector.h b/src/Magnum/Math/BoolVector.h index cecbef921..d70ba6b43 100644 --- a/src/Magnum/Math/BoolVector.h +++ b/src/Magnum/Math/BoolVector.h @@ -67,8 +67,10 @@ template class BoolVector { static_assert(size != 0, "BoolVector cannot have zero elements"); public: - static const std::size_t Size = size; /**< @brief Vector size */ - static const std::size_t DataSize = (size-1)/8+1; /**< @brief Vector storage size */ + enum: std::size_t { + Size = size, /**< Vector size */ + DataSize = (size-1)/8+1 /**< Vector storage size */ + }; /** @brief Construct zero-filled boolean vector */ constexpr /*implicit*/ BoolVector(ZeroInitT = ZeroInit): _data{} {} diff --git a/src/Magnum/Math/Matrix.h b/src/Magnum/Math/Matrix.h index cde459028..884b69534 100644 --- a/src/Magnum/Math/Matrix.h +++ b/src/Magnum/Math/Matrix.h @@ -49,7 +49,9 @@ See @ref matrix-vector for brief introduction. */ template class Matrix: public RectangularMatrix { public: - const static std::size_t Size = size; /**< @brief Matrix size */ + enum: std::size_t { + Size = size /**< Matrix size */ + }; #ifdef MAGNUM_BUILD_DEPRECATED /** diff --git a/src/Magnum/Math/RectangularMatrix.h b/src/Magnum/Math/RectangularMatrix.h index 2b8a6a12d..a8814b781 100644 --- a/src/Magnum/Math/RectangularMatrix.h +++ b/src/Magnum/Math/RectangularMatrix.h @@ -58,16 +58,18 @@ template class RectangularMatrix { template friend class RectangularMatrix; public: - typedef T Type; /**< @brief Underlying data type */ - const static std::size_t Cols = cols; /**< @brief Matrix column count */ - const static std::size_t Rows = rows; /**< @brief Matrix row count */ - - /** - * @brief Size of matrix diagonal - * - * @see @ref fromDiagonal(), @ref diagonal() - */ - const static std::size_t DiagonalSize = (cols < rows ? cols : rows); + typedef T Type; /**< @brief Underlying data type */ + + enum: std::size_t { + Cols = cols, /**< Matrix column count */ + Rows = rows, /**< Matrix row count */ + + /** + * Size of matrix diagonal + * @see @ref fromDiagonal(), @ref diagonal() + */ + DiagonalSize = (cols < rows ? cols : rows) + }; /** * @brief Matrix from array diff --git a/src/Magnum/Math/Vector.h b/src/Magnum/Math/Vector.h index 4bc5c3013..99ab690e3 100644 --- a/src/Magnum/Math/Vector.h +++ b/src/Magnum/Math/Vector.h @@ -89,8 +89,11 @@ template class Vector { template friend class Vector; public: - typedef T Type; /**< @brief Underlying data type */ - const static std::size_t Size = size; /**< @brief Vector size */ + typedef T Type; /**< @brief Underlying data type */ + + enum: std::size_t { + Size = size /**< Vector size */ + }; /** * @brief Vector from array diff --git a/src/Magnum/MultisampleTexture.h b/src/Magnum/MultisampleTexture.h index 40b3643ba..b57cdf0bc 100644 --- a/src/Magnum/MultisampleTexture.h +++ b/src/Magnum/MultisampleTexture.h @@ -95,7 +95,9 @@ shaders. */ template class MultisampleTexture: public AbstractTexture { public: - static const UnsignedInt Dimensions = dimensions; /**< @brief Texture dimension count */ + enum: UnsignedInt { + Dimensions = dimensions /**< Texture dimension count */ + }; /** * @brief Max supported multisample texture size diff --git a/src/Magnum/SceneGraph/AbstractTransformation.h b/src/Magnum/SceneGraph/AbstractTransformation.h index ba468f7b9..fcc2ea2ce 100644 --- a/src/Magnum/SceneGraph/AbstractTransformation.h +++ b/src/Magnum/SceneGraph/AbstractTransformation.h @@ -62,8 +62,9 @@ template class AbstractTransformation { /** @brief Underlying floating-point type */ typedef T Type; - /** @brief Dimension count */ - static const UnsignedInt Dimensions = dimensions; + enum: UnsignedInt { + Dimensions = dimensions /**< Dimension count */ + }; explicit AbstractTransformation(); diff --git a/src/Magnum/Texture.h b/src/Magnum/Texture.h index f2b1ded3c..45cf1b60f 100644 --- a/src/Magnum/Texture.h +++ b/src/Magnum/Texture.h @@ -105,7 +105,9 @@ in shaders. */ template class Texture: public AbstractTexture { public: - static const UnsignedInt Dimensions = dimensions; /**< @brief Texture dimension count */ + enum: UnsignedInt { + Dimensions = dimensions /**< Texture dimension count */ + }; /** * @brief Max supported texture size diff --git a/src/Magnum/TextureArray.h b/src/Magnum/TextureArray.h index b78b669ff..9673b7737 100644 --- a/src/Magnum/TextureArray.h +++ b/src/Magnum/TextureArray.h @@ -96,7 +96,9 @@ documentation for more information about usage in shaders. */ template class TextureArray: public AbstractTexture { public: - static const UnsignedInt Dimensions = dimensions; /**< @brief Texture dimension count */ + enum: UnsignedInt { + Dimensions = dimensions /**< Texture dimension count */ + }; /** * @brief Max supported texture array size diff --git a/src/Magnum/Trade/ImageData.h b/src/Magnum/Trade/ImageData.h index 79c6cb4ba..3b0e6f449 100644 --- a/src/Magnum/Trade/ImageData.h +++ b/src/Magnum/Trade/ImageData.h @@ -42,7 +42,9 @@ Interchangeable with @ref Image, @ref ImageReference or @ref BufferImage. */ template class ImageData: public AbstractImage { public: - const static UnsignedInt Dimensions = dimensions; /**< @brief Image dimension count */ + enum: UnsignedInt { + Dimensions = dimensions /**< Image dimension count */ + }; /** * @brief Constructor