Browse Source

Pedantic: first inline, then constexpr, then static.

Moreover all constexpr functions are meant to be inline here, mark them
as such.
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
9d31231471
  1. 8
      src/Math/MathTypeTraits.h
  2. 4
      src/Math/Matrix4.h
  3. 2
      src/Math/Vector3.h
  4. 16
      src/Set.h
  5. 10
      src/TypeTraits.h

8
src/Math/MathTypeTraits.h

@ -58,7 +58,7 @@ template<class T> struct MathTypeTraits {
* inequal. Returns 1 for integer types and reasonably small value for * inequal. Returns 1 for integer types and reasonably small value for
* floating-point types. * floating-point types.
*/ */
constexpr inline static T epsilon(); inline constexpr static T epsilon();
/** /**
* @brief Fuzzy compare * @brief Fuzzy compare
@ -80,7 +80,7 @@ template<class T> struct MathTypeTraits {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template<class T> struct _MathTypeTraitsIntegral { template<class T> struct _MathTypeTraitsIntegral {
constexpr inline static T epsilon() { return 1; } inline constexpr 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;
@ -109,10 +109,10 @@ template<class T> struct _MathTypeTraitsFloatingPoint {
} }
}; };
template<> struct MathTypeTraits<float>: public _MathTypeTraitsFloatingPoint<float> { template<> struct MathTypeTraits<float>: public _MathTypeTraitsFloatingPoint<float> {
constexpr inline static float epsilon() { return FLOAT_EQUALITY_PRECISION; } inline constexpr static float epsilon() { return FLOAT_EQUALITY_PRECISION; }
}; };
template<> struct MathTypeTraits<double>: public _MathTypeTraitsFloatingPoint<double> { template<> struct MathTypeTraits<double>: public _MathTypeTraitsFloatingPoint<double> {
constexpr inline static double epsilon() { return DOUBLE_EQUALITY_PRECISION; } inline constexpr static double epsilon() { return DOUBLE_EQUALITY_PRECISION; }
}; };
#endif #endif

4
src/Math/Matrix4.h

@ -36,7 +36,7 @@ template<class T> class Matrix4: public Matrix<4, T> {
* @brief Translation matrix * @brief Translation matrix
* @param vec Translation vector * @param vec Translation vector
*/ */
static constexpr Matrix4<T> translation(const Vector3<T>& vec) { inline constexpr static Matrix4<T> translation(const Vector3<T>& vec) {
return Matrix4( /* Column-major! */ return Matrix4( /* Column-major! */
1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
@ -49,7 +49,7 @@ template<class T> class Matrix4: public Matrix<4, T> {
* @brief Scaling matrix * @brief Scaling matrix
* @param vec Scaling vector * @param vec Scaling vector
*/ */
static constexpr Matrix4 scaling(const Vector3<T>& vec) { inline constexpr static Matrix4 scaling(const Vector3<T>& vec) {
return Matrix4( /* Column-major! */ return Matrix4( /* Column-major! */
vec.x(), 0.0f, 0.0f, 0.0f, vec.x(), 0.0f, 0.0f, 0.0f,
0.0f, vec.y(), 0.0f, 0.0f, 0.0f, vec.y(), 0.0f, 0.0f,

2
src/Math/Vector3.h

@ -43,7 +43,7 @@ template<class T> class Vector3: public Vector<3, T> {
* \begin{pmatrix}a_1b_2 - a_2b_1 \\ a_2b_0 - a_0b_2 \\ a_0b_1 - a_1b_0 \end{pmatrix} * \begin{pmatrix}a_1b_2 - a_2b_1 \\ a_2b_0 - a_0b_2 \\ a_0b_1 - a_1b_0 \end{pmatrix}
* @f] * @f]
*/ */
constexpr static Vector3<T> cross(const Vector3<T>& a, const Vector3<T>& b) { inline constexpr static Vector3<T> cross(const Vector3<T>& a, const Vector3<T>& b) {
return Vector3<T>(a[1]*b[2]-a[2]*b[1], return Vector3<T>(a[1]*b[2]-a[2]*b[1],
a[2]*b[0]-a[0]*b[2], a[2]*b[0]-a[0]*b[2],
a[0]*b[1]-a[1]*b[0]); a[0]*b[1]-a[1]*b[0]);

16
src/Set.h

@ -49,18 +49,18 @@ template<class T, class U> class Set {
typedef U UnderlyingType; /**< @brief Underlying type of the enum */ typedef U UnderlyingType; /**< @brief Underlying type of the enum */
/** @brief Create empty set */ /** @brief Create empty set */
constexpr inline Set(): value() {} inline constexpr Set(): value() {}
/** @brief Create set from one value */ /** @brief Create set from one value */
constexpr inline Set(T value): value(static_cast<UnderlyingType>(value)) {} inline constexpr Set(T value): value(static_cast<UnderlyingType>(value)) {}
/** @brief Add value to the set */ /** @brief Add value to the set */
constexpr inline Set<T, U> operator|(T other) const { inline constexpr Set<T, U> operator|(T other) const {
return Set<T, U>(value | static_cast<UnderlyingType>(other)); return Set<T, U>(value | static_cast<UnderlyingType>(other));
} }
/** @brief Union of two sets */ /** @brief Union of two sets */
constexpr inline Set<T, U> operator|(Set<T, U> other) const { inline constexpr Set<T, U> operator|(Set<T, U> other) const {
return Set<T, U>(value | other.value); return Set<T, U>(value | other.value);
} }
@ -77,12 +77,12 @@ template<class T, class U> class Set {
} }
/** @brief Check if given value is in the set */ /** @brief Check if given value is in the set */
constexpr inline T operator&(T other) const { inline constexpr T operator&(T other) const {
return static_cast<T>(value & static_cast<UnderlyingType>(other)); return static_cast<T>(value & static_cast<UnderlyingType>(other));
} }
/** @brief Intersection of two sets */ /** @brief Intersection of two sets */
constexpr inline Set<T, U> operator&(Set<T, U> other) const { inline constexpr Set<T, U> operator&(Set<T, U> other) const {
return Set<T, U>(value & other.value); return Set<T, U>(value & other.value);
} }
@ -93,12 +93,12 @@ template<class T, class U> class Set {
} }
/** @brief Value in underlying type */ /** @brief Value in underlying type */
constexpr inline UnderlyingType toUnderlyingType() const { inline constexpr UnderlyingType toUnderlyingType() const {
return value; return value;
} }
private: private:
constexpr inline explicit Set(UnderlyingType type): value(type) {} inline constexpr explicit Set(UnderlyingType type): value(type) {}
UnderlyingType value; UnderlyingType value;
}; };

10
src/TypeTraits.h

@ -42,7 +42,7 @@ template<class T> struct TypeTraits: public Math::MathTypeTraits<T> {
* *
* Returns e.g. Type::UnsignedInt for GLuint. * Returns e.g. Type::UnsignedInt for GLuint.
*/ */
constexpr inline static Type type(); inline constexpr static Type type();
/** /**
* @brief OpenGL type ID for indices * @brief OpenGL type ID for indices
@ -51,7 +51,7 @@ template<class T> struct TypeTraits: public Math::MathTypeTraits<T> {
* unsigned types). This function is not present for types unusable for * unsigned types). This function is not present for types unusable for
* vertex indices, like GLfloat or GLint. * vertex indices, like GLfloat or GLint.
*/ */
constexpr inline static Type indexType(); inline constexpr static Type indexType();
/** /**
* @brief OpenGL type ID for images * @brief OpenGL type ID for images
@ -60,7 +60,7 @@ template<class T> struct TypeTraits: public Math::MathTypeTraits<T> {
* GLubyte. This function is not present for types unusable for image data, * GLubyte. This function is not present for types unusable for image data,
* like GLdouble and Matrix3. * like GLdouble and Matrix3.
*/ */
constexpr inline static AbstractImage::ComponentType imageType(); inline constexpr static AbstractImage::ComponentType imageType();
/** /**
* @brief Size of plain OpenGL type * @brief Size of plain OpenGL type
@ -68,14 +68,14 @@ template<class T> struct TypeTraits: public Math::MathTypeTraits<T> {
* Returns sizeof(GLfloat) for GLfloat, but also sizeof(GLfloat) for * Returns sizeof(GLfloat) for GLfloat, but also sizeof(GLfloat) for
* Vector3. See count(). * Vector3. See count().
*/ */
constexpr inline static size_t size(); inline constexpr static size_t size();
/** /**
* @brief Count of plain elements in this type * @brief Count of plain elements in this type
* *
* Returns 1 for plain OpenGL types like GLint, but e.g. 3 for Vector3. * Returns 1 for plain OpenGL types like GLint, but e.g. 3 for Vector3.
*/ */
constexpr inline static size_t count(); inline constexpr static size_t count();
}; };
#else #else
template<class T> struct TypeTraits {}; template<class T> struct TypeTraits {};

Loading…
Cancel
Save