Browse Source

Removed Math::TypeTraits to MathTypeTraits to avoid name clash.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
4cd1ee140e
  1. 38
      src/Math/MathTypeTraits.h
  2. 2
      src/Math/Matrix.h
  3. 2
      src/Math/Test/CMakeLists.txt
  4. 24
      src/Math/Test/MathTypeTraitsTest.cpp
  5. 6
      src/Math/Test/MathTypeTraitsTest.h
  6. 4
      src/Math/Vector.h
  7. 24
      src/TypeTraits.h

38
src/Math/TypeTraits.h → src/Math/MathTypeTraits.h

@ -1,5 +1,5 @@
#ifndef Magnum_Math_TypeTraits_h #ifndef Magnum_Math_MathTypeTraits_h
#define Magnum_Math_TypeTraits_h #define Magnum_Math_MathTypeTraits_h
/* /*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz> Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
@ -16,7 +16,7 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Math::TypeTraits * @brief Class Magnum::Math::MathTypeTraits
*/ */
#include <cmath> #include <cmath>
@ -44,7 +44,7 @@ This class and class methods are specialized only for types where it makes
sense, it has empty implementation for unknown types or types which don't sense, it has empty implementation for unknown types or types which don't
support given feature, thus forcing the compilation stop with an error. support given feature, thus forcing the compilation stop with an error.
*/ */
template<class T> struct TypeTraits { template<class T> struct MathTypeTraits {
#ifdef DOXYGEN_GENERATING_OUTPUT #ifdef DOXYGEN_GENERATING_OUTPUT
/* Development note: the following values are implemented as inline /* Development note: the following values are implemented as inline
functions, not as static const variables, because the compiler will functions, not as static const variables, because the compiler will
@ -79,39 +79,39 @@ template<class T> struct TypeTraits {
*/ */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template<class T> struct _TypeTraitsIntegral { template<class T> struct _MathTypeTraitsIntegral {
constexpr inline static T epsilon() { return 1; } constexpr inline static T epsilon() { return 1; }
inline constexpr static bool equals(T a, T b) { inline constexpr static bool equals(T a, T b) {
return a == b; return a == b;
} }
}; };
template<> struct TypeTraits<unsigned char>: public _TypeTraitsIntegral<unsigned char> {}; template<> struct MathTypeTraits<unsigned char>: public _MathTypeTraitsIntegral<unsigned char> {};
template<> struct TypeTraits<char>: public _TypeTraitsIntegral<char> {}; template<> struct MathTypeTraits<char>: public _MathTypeTraitsIntegral<char> {};
template<> struct TypeTraits<unsigned short>: public _TypeTraitsIntegral<unsigned short> {}; template<> struct MathTypeTraits<unsigned short>: public _MathTypeTraitsIntegral<unsigned short> {};
template<> struct TypeTraits<short>: public _TypeTraitsIntegral<short> {}; template<> struct MathTypeTraits<short>: public _MathTypeTraitsIntegral<short> {};
template<> struct TypeTraits<unsigned int>: public _TypeTraitsIntegral<unsigned int> {}; template<> struct MathTypeTraits<unsigned int>: public _MathTypeTraitsIntegral<unsigned int> {};
template<> struct TypeTraits<int>: public _TypeTraitsIntegral<int> {}; template<> struct MathTypeTraits<int>: public _MathTypeTraitsIntegral<int> {};
/* long is 32 bits somewhere and 64 bits elsewhere, so it cannot be mapped to /* long is 32 bits somewhere and 64 bits elsewhere, so it cannot be mapped to
any of them */ any of them */
template<> struct TypeTraits<long unsigned int>: public _TypeTraitsIntegral<long unsigned int> {}; template<> struct MathTypeTraits<long unsigned int>: public _MathTypeTraitsIntegral<long unsigned int> {};
template<> struct TypeTraits<long int>: public _TypeTraitsIntegral<long int> {}; template<> struct MathTypeTraits<long int>: public _MathTypeTraitsIntegral<long int> {};
template<> struct TypeTraits<unsigned long long>: public _TypeTraitsIntegral<unsigned long long> {}; template<> struct MathTypeTraits<unsigned long long>: public _MathTypeTraitsIntegral<unsigned long long> {};
template<> struct TypeTraits<long long>: public _TypeTraitsIntegral<long long> {}; template<> struct MathTypeTraits<long long>: public _MathTypeTraitsIntegral<long long> {};
template<class T> struct _TypeTraitsFloatingPoint { template<class T> struct _MathTypeTraitsFloatingPoint {
inline static bool equals(T a, T b) { inline static bool equals(T a, T b) {
return std::abs(a - b) < TypeTraits<T>::epsilon(); return std::abs(a - b) < MathTypeTraits<T>::epsilon();
} }
}; };
template<> struct TypeTraits<float>: public _TypeTraitsFloatingPoint<float> { template<> struct MathTypeTraits<float>: public _MathTypeTraitsFloatingPoint<float> {
constexpr inline static float epsilon() { return FLOAT_EQUALITY_PRECISION; } constexpr inline static float epsilon() { return FLOAT_EQUALITY_PRECISION; }
}; };
template<> struct TypeTraits<double>: public _TypeTraitsFloatingPoint<double> { template<> struct MathTypeTraits<double>: public _MathTypeTraitsFloatingPoint<double> {
constexpr inline static double epsilon() { return DOUBLE_EQUALITY_PRECISION; } constexpr inline static double epsilon() { return DOUBLE_EQUALITY_PRECISION; }
}; };
#endif #endif

2
src/Math/Matrix.h

@ -158,7 +158,7 @@ template<size_t size, class T> class Matrix {
/** @brief Equality operator */ /** @brief Equality operator */
inline bool operator==(const Matrix<size, T>& other) const { inline bool operator==(const Matrix<size, T>& other) const {
for(size_t i = 0; i != size*size; ++i) for(size_t i = 0; i != size*size; ++i)
if(!TypeTraits<T>::equals(_data[i], other._data[i])) return false; if(!MathTypeTraits<T>::equals(_data[i], other._data[i])) return false;
return true; return true;
} }

2
src/Math/Test/CMakeLists.txt

@ -1,4 +1,4 @@
corrade_add_test(MathTypeTraitsTest TypeTraitsTest.h TypeTraitsTest.cpp) corrade_add_test(MathMathTypeTraitsTest MathTypeTraitsTest.h MathTypeTraitsTest.cpp)
corrade_add_test(MathVectorTest VectorTest.h VectorTest.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test(MathVectorTest VectorTest.h VectorTest.cpp ${CORRADE_UTILITY_LIBRARY})
corrade_add_test(MathVector2Test Vector2Test.h Vector2Test.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test(MathVector2Test Vector2Test.h Vector2Test.cpp ${CORRADE_UTILITY_LIBRARY})

24
src/Math/Test/TypeTraitsTest.cpp → src/Math/Test/MathTypeTraitsTest.cpp

@ -13,17 +13,17 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include "TypeTraitsTest.h" #include "MathTypeTraitsTest.h"
#include <QtTest/QTest> #include <QtTest/QTest>
#include "TypeTraits.h" #include "MathTypeTraits.h"
QTEST_APPLESS_MAIN(Magnum::Math::Test::TypeTraitsTest) QTEST_APPLESS_MAIN(Magnum::Math::Test::MathTypeTraitsTest)
namespace Magnum { namespace Math { namespace Test { namespace Magnum { namespace Math { namespace Test {
void TypeTraitsTest::equalsIntegral() { void MathTypeTraitsTest::equalsIntegral() {
_equalsIntegral<unsigned char>(); _equalsIntegral<unsigned char>();
_equalsIntegral<char>(); _equalsIntegral<char>();
_equalsIntegral<unsigned short>(); _equalsIntegral<unsigned short>();
@ -36,23 +36,23 @@ void TypeTraitsTest::equalsIntegral() {
_equalsIntegral<long long>(); _equalsIntegral<long long>();
} }
void TypeTraitsTest::equalsFloatingPoint() { void MathTypeTraitsTest::equalsFloatingPoint() {
_equalsFloatingPoint<float>(); _equalsFloatingPoint<float>();
_equalsFloatingPoint<double>(); _equalsFloatingPoint<double>();
} }
template<class T> void TypeTraitsTest::_equalsIntegral() { template<class T> void MathTypeTraitsTest::_equalsIntegral() {
QVERIFY(!TypeTraits<T>::equals(1, 1+TypeTraits<T>::epsilon())); QVERIFY(!MathTypeTraits<T>::equals(1, 1+MathTypeTraits<T>::epsilon()));
} }
template<class T> void TypeTraitsTest::_equalsFloatingPoint() { template<class T> void MathTypeTraitsTest::_equalsFloatingPoint() {
QVERIFY(TypeTraits<T>::equals(1.0f+TypeTraits<T>::epsilon()/2, 1.0f)); QVERIFY(MathTypeTraits<T>::equals(1.0f+MathTypeTraits<T>::epsilon()/2, 1.0f));
QVERIFY(!TypeTraits<T>::equals(1.0f+TypeTraits<T>::epsilon()*2, 1.0f)); QVERIFY(!MathTypeTraits<T>::equals(1.0f+MathTypeTraits<T>::epsilon()*2, 1.0f));
QEXPECT_FAIL(0, "Comparing to infinity is broken", Continue); QEXPECT_FAIL(0, "Comparing to infinity is broken", Continue);
QVERIFY(TypeTraits<T>::equals(std::numeric_limits<T>::infinity(), QVERIFY(MathTypeTraits<T>::equals(std::numeric_limits<T>::infinity(),
std::numeric_limits<T>::infinity())); std::numeric_limits<T>::infinity()));
QVERIFY(!TypeTraits<T>::equals(std::numeric_limits<T>::quiet_NaN(), QVERIFY(!MathTypeTraits<T>::equals(std::numeric_limits<T>::quiet_NaN(),
std::numeric_limits<T>::quiet_NaN())); std::numeric_limits<T>::quiet_NaN()));
} }

6
src/Math/Test/TypeTraitsTest.h → src/Math/Test/MathTypeTraitsTest.h

@ -1,5 +1,5 @@
#ifndef Magnum_Math_Test_TypeTraitsTest_h #ifndef Magnum_Math_Test_MathTypeTraitsTest_h
#define Magnum_Math_Test_TypeTraitsTest_h #define Magnum_Math_Test_MathTypeTraitsTest_h
/* /*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz> Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
@ -19,7 +19,7 @@
namespace Magnum { namespace Math { namespace Test { namespace Magnum { namespace Math { namespace Test {
class TypeTraitsTest: public QObject { class MathTypeTraitsTest: public QObject {
Q_OBJECT Q_OBJECT
private slots: private slots:

4
src/Math/Vector.h

@ -22,7 +22,7 @@
#include <cmath> #include <cmath>
#include "Utility/Debug.h" #include "Utility/Debug.h"
#include "TypeTraits.h" #include "MathTypeTraits.h"
namespace Magnum { namespace Math { namespace Magnum { namespace Math {
@ -145,7 +145,7 @@ template<size_t size, class T> class Vector {
/** @brief Equality operator */ /** @brief Equality operator */
inline bool operator==(const Vector<size, T>& other) const { inline bool operator==(const Vector<size, T>& other) const {
for(size_t pos = 0; pos != size; ++pos) for(size_t pos = 0; pos != size; ++pos)
if(!TypeTraits<T>::equals((*this)[pos], other[pos])) return false; if(!MathTypeTraits<T>::equals((*this)[pos], other[pos])) return false;
return true; return true;
} }

24
src/TypeTraits.h

@ -26,13 +26,13 @@ namespace Magnum {
/** /**
@brief Traits class for plain OpenGL types @brief Traits class for plain OpenGL types
@copydetails Math::TypeTraits @copydetails Math::MathTypeTraits
Where it makes sense, this class extends Math::TypeTraits with OpenGL-specific Where it makes sense, this class extends Math::MathTypeTraits with
traits. OpenGL-specific traits.
*/ */
#ifdef DOXYGEN_GENERATING_OUTPUT #ifdef DOXYGEN_GENERATING_OUTPUT
template<class T> struct TypeTraits: public Math::TypeTraits<T> { template<class T> struct TypeTraits: public Math::MathTypeTraits<T> {
/** /**
* @brief OpenGL plain type ID * @brief OpenGL plain type ID
* *
@ -146,7 +146,7 @@ template<> struct TypeOf<Type::Int> { typedef GLint Type; };
template<> struct TypeOf<Type::Float> { typedef GLfloat Type; }; template<> struct TypeOf<Type::Float> { typedef GLfloat Type; };
template<> struct TypeOf<Type::Double> { typedef GLdouble Type; }; template<> struct TypeOf<Type::Double> { typedef GLdouble Type; };
template<> struct TypeTraits<GLubyte>: public Math::TypeTraits<unsigned char> { template<> struct TypeTraits<GLubyte>: public Math::MathTypeTraits<unsigned char> {
inline constexpr static Type type() { return Type::UnsignedByte; } inline constexpr static Type type() { return Type::UnsignedByte; }
inline constexpr static Type indexType() { return Type::UnsignedByte; } inline constexpr static Type indexType() { return Type::UnsignedByte; }
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedByte; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedByte; }
@ -154,7 +154,7 @@ template<> struct TypeTraits<GLubyte>: public Math::TypeTraits<unsigned char> {
inline constexpr static size_t count() { return 1; } inline constexpr static size_t count() { return 1; }
}; };
template<> struct TypeTraits<GLbyte>: public Math::TypeTraits<char> { template<> struct TypeTraits<GLbyte>: public Math::MathTypeTraits<char> {
inline constexpr static Type type() { return Type::Byte; } inline constexpr static Type type() { return Type::Byte; }
/* Can not be used for indices */ /* Can not be used for indices */
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Byte; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Byte; }
@ -162,7 +162,7 @@ template<> struct TypeTraits<GLbyte>: public Math::TypeTraits<char> {
inline constexpr static size_t count() { return 1; } inline constexpr static size_t count() { return 1; }
}; };
template<> struct TypeTraits<GLushort>: public Math::TypeTraits<unsigned short> { template<> struct TypeTraits<GLushort>: public Math::MathTypeTraits<unsigned short> {
inline constexpr static Type type() { return Type::UnsignedShort; } inline constexpr static Type type() { return Type::UnsignedShort; }
inline constexpr static Type indexType() { return Type::UnsignedShort; } inline constexpr static Type indexType() { return Type::UnsignedShort; }
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedShort; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedShort; }
@ -170,7 +170,7 @@ template<> struct TypeTraits<GLushort>: public Math::TypeTraits<unsigned short>
inline constexpr static size_t count() { return 1; } inline constexpr static size_t count() { return 1; }
}; };
template<> struct TypeTraits<GLshort>: public Math::TypeTraits<short> { template<> struct TypeTraits<GLshort>: public Math::MathTypeTraits<short> {
inline constexpr static Type type() { return Type::Short; } inline constexpr static Type type() { return Type::Short; }
/* Can not be used for indices */ /* Can not be used for indices */
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Short; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Short; }
@ -178,7 +178,7 @@ template<> struct TypeTraits<GLshort>: public Math::TypeTraits<short> {
inline constexpr static size_t count() { return 1; } inline constexpr static size_t count() { return 1; }
}; };
template<> struct TypeTraits<GLuint>: public Math::TypeTraits<unsigned int> { template<> struct TypeTraits<GLuint>: public Math::MathTypeTraits<unsigned int> {
inline constexpr static Type type() { return Type::UnsignedInt; } inline constexpr static Type type() { return Type::UnsignedInt; }
inline constexpr static Type indexType() { return Type::UnsignedInt; } inline constexpr static Type indexType() { return Type::UnsignedInt; }
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedInt; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedInt; }
@ -186,7 +186,7 @@ template<> struct TypeTraits<GLuint>: public Math::TypeTraits<unsigned int> {
inline constexpr static size_t count() { return 1; } inline constexpr static size_t count() { return 1; }
}; };
template<> struct TypeTraits<GLint>: public Math::TypeTraits<int> { template<> struct TypeTraits<GLint>: public Math::MathTypeTraits<int> {
inline constexpr static Type type() { return Type::Int; } inline constexpr static Type type() { return Type::Int; }
/* Can not be used for indices */ /* Can not be used for indices */
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Int; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Int; }
@ -194,7 +194,7 @@ template<> struct TypeTraits<GLint>: public Math::TypeTraits<int> {
inline constexpr static size_t count() { return 1; } inline constexpr static size_t count() { return 1; }
}; };
template<> struct TypeTraits<GLfloat>: public Math::TypeTraits<float> { template<> struct TypeTraits<GLfloat>: public Math::MathTypeTraits<float> {
inline constexpr static Type type() { return Type::Float; } inline constexpr static Type type() { return Type::Float; }
/* Can not be used for indices */ /* Can not be used for indices */
inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Float; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Float; }
@ -202,7 +202,7 @@ template<> struct TypeTraits<GLfloat>: public Math::TypeTraits<float> {
inline constexpr static size_t count() { return 1; } inline constexpr static size_t count() { return 1; }
}; };
template<> struct TypeTraits<GLdouble>: public Math::TypeTraits<double> { template<> struct TypeTraits<GLdouble>: public Math::MathTypeTraits<double> {
inline constexpr static Type type() { return Type::Double; } inline constexpr static Type type() { return Type::Double; }
/* Can not be used for indices */ /* Can not be used for indices */
/* Can not be used for images */ /* Can not be used for images */

Loading…
Cancel
Save