From 2f2d4a4dfd9cf127f3f57cb3591f2a0ff82cdccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 15 Jan 2013 18:59:37 +0100 Subject: [PATCH] Removed Magnum::Type and related functionality. The enum is finally completely reimplemented for specific cases with proper values (Mesh attribute types, index types, pixel types, ...). The rest currently remaining in TypeTraits.h is used only in Mesh and AbstractShaderProgram, probably will be moved there. --- src/Test/CMakeLists.txt | 1 - src/Test/TypeTraitsTest.cpp | 55 ------------- src/TypeTraits.cpp | 94 ---------------------- src/TypeTraits.h | 151 +----------------------------------- 4 files changed, 1 insertion(+), 300 deletions(-) delete mode 100644 src/Test/TypeTraitsTest.cpp diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 6ae07e8d8..0bd72dd47 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -4,6 +4,5 @@ corrade_add_test(MeshTest MeshTest.cpp LIBRARIES Magnum) corrade_add_test(IndexedMeshTest IndexedMeshTest.cpp LIBRARIES Magnum) corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib) corrade_add_test(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test(TypeTraitsTest TypeTraitsTest.cpp LIBRARIES Magnum) set_target_properties(ResourceManagerTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Test/TypeTraitsTest.cpp b/src/Test/TypeTraitsTest.cpp deleted file mode 100644 index a6da165a7..000000000 --- a/src/Test/TypeTraitsTest.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include -#include -#include - -#include "TypeTraits.h" - -using namespace Corrade::Utility; - -namespace Magnum { namespace Test { - -class TypeTraitsTest: public Corrade::TestSuite::Tester { - public: - TypeTraitsTest(); - - void debug(); - void configuration(); -}; - -TypeTraitsTest::TypeTraitsTest() { - addTests(&TypeTraitsTest::debug, - &TypeTraitsTest::configuration); -} - -void TypeTraitsTest::debug() { - std::ostringstream o; - Debug(&o) << Type::UnsignedShort; - CORRADE_COMPARE(o.str(), "Type::UnsignedShort\n"); -} - -void TypeTraitsTest::configuration() { - Configuration c; - - c.setValue("type", Type::Byte); - CORRADE_COMPARE(c.value("type"), "Byte"); - CORRADE_COMPARE(c.value("type"), Type::Byte); -} - -}} - -CORRADE_TEST_MAIN(Magnum::Test::TypeTraitsTest) diff --git a/src/TypeTraits.cpp b/src/TypeTraits.cpp index bf764d21d..d8312a764 100644 --- a/src/TypeTraits.cpp +++ b/src/TypeTraits.cpp @@ -16,7 +16,6 @@ #include "TypeTraits.h" #include -#include namespace Magnum { @@ -34,97 +33,4 @@ static_assert(std::is_same::value, "GLdouble is not the same a #endif #endif -std::size_t TypeInfo::sizeOf(Type type) { - switch(type) { - #define val(type) case Type::type: return TypeTraits::Type>::size(); - val(UnsignedByte) - val(Byte) - val(UnsignedShort) - val(Short) - val(UnsignedInt) - val(Int) - #ifndef MAGNUM_TARGET_GLES - val(Double) - #endif - val(Float) - #undef val - - default: return 0; - } -} - -bool TypeInfo::isIntegral(Type type) { - switch(type) { - case Type::UnsignedByte: - case Type::Byte: - case Type::UnsignedShort: - case Type::Short: - case Type::UnsignedInt: - case Type::Int: - return true; - default: - return false; - } -} - -#ifndef DOXYGEN_GENERATING_OUTPUT -Debug operator<<(Debug debug, Type value) { - switch(value) { - #define _c(value) case Type::value: return debug << "Type::" #value; - _c(UnsignedByte) - _c(Byte) - _c(UnsignedShort) - _c(Short) - _c(UnsignedInt) - _c(Int) - _c(Float) - #ifndef MAGNUM_TARGET_GLES - _c(Double) - #endif - #undef _c - } - - return debug << "Type::(invalid)"; -} -#endif - -} - -namespace Corrade { namespace Utility { - -std::string ConfigurationValue::toString(Magnum::Type value, ConfigurationValueFlags) { - switch(value) { - #define _c(value) case Magnum::Type::value: return #value; - _c(UnsignedByte) - _c(Byte) - _c(UnsignedShort) - _c(Short) - _c(UnsignedInt) - _c(Int) - _c(Float) - #ifndef MAGNUM_TARGET_GLES - _c(Double) - #endif - #undef _c - } - - return ""; } - -Magnum::Type ConfigurationValue::fromString(const std::string& stringValue, ConfigurationValueFlags) { - #define _c(value) if(stringValue == #value) return Magnum::Type::value; - _c(UnsignedByte) - _c(Byte) - _c(UnsignedShort) - _c(Short) - _c(UnsignedInt) - _c(Int) - #ifndef MAGNUM_TARGET_GLES - _c(Double) - #endif - #undef _c - - return Magnum::Type::Float; -} - -}} diff --git a/src/TypeTraits.h b/src/TypeTraits.h index f92c89577..0770db5dd 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -16,7 +16,7 @@ */ /** @file /TypeTraits.h - * @brief Enum Magnum::Type, class Magnum::TypeOf, Magnum::TypeInfo, Magnum::TypeTraits + * @brief Class Magnum::TypeTraits */ #include @@ -48,13 +48,6 @@ template struct TypeTraits: Math::MathTypeTraits { */ typedef U AttributeType; - /** - * @brief OpenGL plain type ID - * - * Returns e.g. Type::UnsignedInt for GLuint. - */ - inline constexpr static Type type(); - /** * @brief Size of plain OpenGL type * @@ -76,161 +69,45 @@ template struct TypeTraits { }; #endif -/** @brief OpenGL plain types */ -enum class Type: GLenum { - UnsignedByte = GL_UNSIGNED_BYTE, /**< Unsigned byte (char) */ - Byte = GL_BYTE, /**< Byte (char) */ - UnsignedShort = GL_UNSIGNED_SHORT, /**< Unsigned short */ - Short = GL_SHORT, /**< Short */ - UnsignedInt = GL_UNSIGNED_INT, /**< Unsigned int */ - Int = GL_INT, /**< Int */ - Float = GL_FLOAT /**< Float */ - - #ifndef MAGNUM_TARGET_GLES - , - /** - * Double - * @requires_gl Only floats are available in OpenGL ES. - */ - Double = GL_DOUBLE - #endif -}; - -/** @debugoperator{Magnum::TypeInfo} */ -Debug MAGNUM_EXPORT operator<<(Debug debug, Type value); - -/** -@brief Class for converting Type enum values to types - -When you want to use TypeTraits on type specified only as enum value, you can -use this class to convert it into type, for example these two statements -are equivalent: -@code -type = TypeTraits::Type>::imageType(); -type = TypeTraits::imageType(); -@endcode -*/ -template class TypeOf { - TypeOf() = delete; - - #ifdef DOXYGEN_GENERATING_OUTPUT - typedef U Type; /**< @brief Type */ - #endif -}; - -/** -@brief Functor for runtime information about given type - -TypeTraits alone allows to get information about given type only at compile -time, this class alows to get some information also at runtime with tiny -performance loss. -*/ -struct MAGNUM_EXPORT TypeInfo { - TypeInfo() = delete; - - /** - * @brief Size of given type - * - * These two lines provide the same information, one at compile time, - * one at runtime: - * @code - * std::size_t size = TypeTraits::size(); - * std::size_t size = TypeInfo::sizeOf(Type::UnsignedByte); - * @endcode - */ - static std::size_t sizeOf(Type type); - - /** - * @brief Whether the type is integral - * @return true for (un)signed byte, short and integer, false otherwise. - */ - static bool isIntegral(Type type); -}; - -/** @todo Other texture types, referenced in glTexImage2D function manual */ -/** @todo Using Vector3 for textures? */ - #ifndef DOXYGEN_GENERATING_OUTPUT -template<> struct TypeOf { - TypeOf() = delete; - typedef GLubyte Type; -}; -template<> struct TypeOf { - TypeOf() = delete; - typedef GLbyte Type; -}; -template<> struct TypeOf { - TypeOf() = delete; - typedef GLushort Type; -}; -template<> struct TypeOf { - TypeOf() = delete; - typedef GLshort Type; -}; -template<> struct TypeOf { - TypeOf() = delete; - typedef GLuint Type; -}; -template<> struct TypeOf { - TypeOf() = delete; - typedef GLint Type; -}; -template<> struct TypeOf { - TypeOf() = delete; - typedef GLfloat Type; -}; -#ifndef MAGNUM_TARGET_GLES -template<> struct TypeOf { - TypeOf() = delete; - typedef GLdouble Type; -}; -#endif - template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ - inline constexpr static Type type() { return Type::UnsignedByte; } inline constexpr static std::size_t size() { return sizeof(GLubyte); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ - inline constexpr static Type type() { return Type::Byte; } inline constexpr static std::size_t size() { return sizeof(GLbyte); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ - inline constexpr static Type type() { return Type::UnsignedShort; } inline constexpr static std::size_t size() { return sizeof(GLushort); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ - inline constexpr static Type type() { return Type::Short; } inline constexpr static std::size_t size() { return sizeof(GLshort); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { typedef GLuint AttributeType; - inline constexpr static Type type() { return Type::UnsignedInt; } inline constexpr static std::size_t size() { return sizeof(GLuint); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { typedef GLint AttributeType; - inline constexpr static Type type() { return Type::Int; } inline constexpr static std::size_t size() { return sizeof(GLint); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { typedef GLfloat AttributeType; - inline constexpr static Type type() { return Type::Float; } inline constexpr static std::size_t size() { return sizeof(GLfloat); } inline constexpr static std::size_t count() { return 1; } }; @@ -238,7 +115,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { #ifndef MAGNUM_TARGET_GLES template<> struct TypeTraits: Math::MathTypeTraits { typedef GLdouble AttributeType; - inline constexpr static Type type() { return Type::Double; } inline constexpr static std::size_t size() { return sizeof(GLdouble); } inline constexpr static std::size_t count() { return 1; } }; @@ -249,7 +125,6 @@ namespace Implementation { VectorTypeTraits() = delete; /* Might be used for attributes, see below */ - inline constexpr static Type type() { return TypeTraits::type(); } inline constexpr static std::size_t size() { return sizeof(T); } inline constexpr static std::size_t count() { return vectorSize; } }; @@ -296,7 +171,6 @@ namespace Implementation { MatrixTypeTraits() = delete; /* Might be used for attributes, see below */ - inline constexpr static Type type() { return TypeTraits::type(); } inline constexpr static std::size_t size() { return sizeof(T); } inline constexpr static std::size_t count() { return rows; } inline constexpr static std::size_t vectors() { return cols; } @@ -336,27 +210,4 @@ template struct TypeTraits>: TypeTraits struct MAGNUM_EXPORT ConfigurationValue { - ConfigurationValue() = delete; - - /** - * @brief Writes enum value as string - * - * If the value is invalid, returns empty string. - */ - static std::string toString(Magnum::Type value, ConfigurationValueFlags); - - /** - * @brief Reads enum value as string - * - * If the value is invalid, returns @ref Magnum::Type "Magnum::Type::Float". - */ - static Magnum::Type fromString(const std::string& stringValue, ConfigurationValueFlags); -}; - -}} - #endif