Browse Source

Pedantic: using std::size_t instead of size_t from C compat headers.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
0145343d59
  1. 2
      src/AbstractImage.cpp
  2. 2
      src/AbstractImage.h
  3. 8
      src/Buffer.h
  4. 4
      src/Context.h
  5. 2
      src/DimensionTraits.h
  6. 2
      src/Extensions.h
  7. 18
      src/Math/Algorithms/GaussJordan.h
  8. 2
      src/Math/MathTypeTraits.h
  9. 40
      src/Math/Matrix.h
  10. 82
      src/Math/RectangularMatrix.h
  11. 38
      src/Math/Vector.h
  12. 32
      src/MeshTools/Clean.h
  13. 18
      src/MeshTools/CombineIndexedArrays.h
  14. 2
      src/MeshTools/CompressIndices.cpp
  15. 10
      src/MeshTools/CompressIndices.h
  16. 24
      src/MeshTools/Interleave.h
  17. 6
      src/MeshTools/Subdivide.h
  18. 6
      src/MeshTools/Test/CleanTest.h
  19. 6
      src/MeshTools/Test/SubdivideTest.h
  20. 2
      src/MeshTools/Test/TipsifyTest.h
  21. 4
      src/MeshTools/Tipsify.h
  22. 2
      src/MeshTools/Transform.h
  23. 8
      src/Primitives/Icosphere.h
  24. 4
      src/Profiler.h
  25. 24
      src/ResourceManager.h
  26. 10
      src/SizeTraits.h
  27. 34
      src/Swizzle.h
  28. 2
      src/Test/ResourceManagerTest.h
  29. 58
      src/TypeTraits.h

2
src/AbstractImage.cpp

@ -16,6 +16,8 @@
#include "AbstractImage.h" #include "AbstractImage.h"
#include "TypeTraits.h" #include "TypeTraits.h"
using namespace std;
namespace Magnum { namespace Magnum {
size_t AbstractImage::pixelSize(Components format, ComponentType type) { size_t AbstractImage::pixelSize(Components format, ComponentType type) {

2
src/AbstractImage.h

@ -268,7 +268,7 @@ class MAGNUM_EXPORT AbstractImage {
* @param components Color components * @param components Color components
* @param type Data type * @param type Data type
*/ */
static size_t pixelSize(Components components, ComponentType type); static std::size_t pixelSize(Components components, ComponentType type);
/** /**
* @brief Constructor * @brief Constructor

8
src/Buffer.h

@ -250,7 +250,7 @@ class Buffer {
* setData(GLsizeiptr, const GLvoid*, Usage). * setData(GLsizeiptr, const GLvoid*, Usage).
* @see setData(Target, GLsizeiptr, const GLvoid*, Usage) * @see setData(Target, GLsizeiptr, const GLvoid*, Usage)
*/ */
template<size_t size, class T> inline void setData(const T(&data)[size], Usage usage) { template<std::size_t size, class T> inline void setData(const T(&data)[size], Usage usage) {
setData(_defaultTarget, data, usage); setData(_defaultTarget, data, usage);
} }
@ -291,7 +291,7 @@ class Buffer {
* *
* @see setData(Target, GLsizeiptr, const GLvoid*, Usage) * @see setData(Target, GLsizeiptr, const GLvoid*, Usage)
*/ */
template<size_t size, class T> inline void setData(Target target, const T(&data)[size], Usage usage) { template<std::size_t size, class T> inline void setData(Target target, const T(&data)[size], Usage usage) {
setData(target, size*sizeof(T), data, usage); setData(target, size*sizeof(T), data, usage);
} }
@ -330,7 +330,7 @@ class Buffer {
* setSubData(GLintptr, GLsizeiptr, const GLvoid*). * setSubData(GLintptr, GLsizeiptr, const GLvoid*).
* @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*)
*/ */
template<size_t size, class T> inline void setSubData(GLintptr offset, const T(&data)[size]) { template<std::size_t size, class T> inline void setSubData(GLintptr offset, const T(&data)[size]) {
setSubData(_defaultTarget, offset, data); setSubData(_defaultTarget, offset, data);
} }
@ -370,7 +370,7 @@ class Buffer {
* setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*). * setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*).
* @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*) * @see setSubData(Target, GLintptr, GLsizeiptr, const GLvoid*)
*/ */
template<size_t size, class T> inline void setSubData(Target target, GLintptr offset, const T(&data)[size]) { template<std::size_t size, class T> inline void setSubData(Target target, GLintptr offset, const T(&data)[size]) {
setSubData(target, offset, size*sizeof(T), data); setSubData(target, offset, size*sizeof(T), data);
} }

4
src/Context.h

@ -76,12 +76,12 @@ class MAGNUM_EXPORT Extension {
private: private:
/* GCC 4.6 doesn't like const members, as std::vector doesn't have /* GCC 4.6 doesn't like const members, as std::vector doesn't have
proper move semantic yet */ proper move semantic yet */
size_t _index; std::size_t _index;
Version _requiredVersion; Version _requiredVersion;
Version _coreVersion; Version _coreVersion;
const char* _string; const char* _string;
inline constexpr Extension(size_t index, Version requiredVersion, Version coreVersion, const char* string): _index(index), _requiredVersion(requiredVersion), _coreVersion(coreVersion), _string(string) {} inline constexpr Extension(std::size_t index, Version requiredVersion, Version coreVersion, const char* string): _index(index), _requiredVersion(requiredVersion), _coreVersion(coreVersion), _string(string) {}
}; };
/** /**

2
src/DimensionTraits.h

@ -24,7 +24,7 @@
namespace Magnum { namespace Magnum {
namespace Math { namespace Math {
template<size_t, class> class Vector; template<std::size_t, class> class Vector;
template<class> class Vector2; template<class> class Vector2;
template<class> class Vector3; template<class> class Vector3;

2
src/Extensions.h

@ -38,7 +38,7 @@ namespace Extensions {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
#define _extension(prefix, vendor, extension, _requiredVersion, _coreVersion) \ #define _extension(prefix, vendor, extension, _requiredVersion, _coreVersion) \
struct extension { \ struct extension { \
enum: size_t { Index = __LINE__-1 }; \ enum: std::size_t { Index = __LINE__-1 }; \
constexpr static Version requiredVersion() { return Version::_requiredVersion; } \ constexpr static Version requiredVersion() { return Version::_requiredVersion; } \
constexpr static Version coreVersion() { return Version::_coreVersion; } \ constexpr static Version coreVersion() { return Version::_coreVersion; } \
constexpr static const char* string() { return #prefix "_" #vendor "_" #extension; } \ constexpr static const char* string() { return #prefix "_" #vendor "_" #extension; } \

18
src/Math/Algorithms/GaussJordan.h

@ -48,7 +48,7 @@ class GaussJordan {
* and the final backsubstitution is done only on @p t, as @p a would * and the final backsubstitution is done only on @p t, as @p a would
* always end with identity matrix anyway. * always end with identity matrix anyway.
*/ */
template<size_t size, size_t rows, class T> static bool inPlaceTransposed(RectangularMatrix<size, size, T>& a, RectangularMatrix<size, rows, T>& t); template<std::size_t size, std::size_t rows, class T> static bool inPlaceTransposed(RectangularMatrix<size, size, T>& a, RectangularMatrix<size, rows, T>& t);
/** /**
* @brief Eliminate in place * @brief Eliminate in place
@ -56,7 +56,7 @@ class GaussJordan {
* Transposes the matrices, calls inPlaceTransposed() on them and then * Transposes the matrices, calls inPlaceTransposed() on them and then
* transposes them back. * transposes them back.
*/ */
template<size_t size, size_t cols, class T> static bool inPlace(RectangularMatrix<size, size, T>& a, RectangularMatrix<cols, size, T>& t) { template<std::size_t size, std::size_t cols, class T> static bool inPlace(RectangularMatrix<size, size, T>& a, RectangularMatrix<cols, size, T>& t) {
a = a.transposed(); a = a.transposed();
RectangularMatrix<size, cols, T> tTransposed = t.transposed(); RectangularMatrix<size, cols, T> tTransposed = t.transposed();
@ -69,11 +69,11 @@ class GaussJordan {
} }
}; };
template<size_t size, size_t cols, class T> bool GaussJordan::inPlaceTransposed(RectangularMatrix<size, size, T>& a, RectangularMatrix<size, cols, T>& t) { template<std::size_t size, std::size_t cols, class T> bool GaussJordan::inPlaceTransposed(RectangularMatrix<size, size, T>& a, RectangularMatrix<size, cols, T>& t) {
for(size_t row = 0; row != size; ++row) { for(std::size_t row = 0; row != size; ++row) {
/* Find max pivot */ /* Find max pivot */
size_t rowMax = row; std::size_t rowMax = row;
for(size_t row2 = row+1; row2 != size; ++row2) for(std::size_t row2 = row+1; row2 != size; ++row2)
if(std::abs(a(row2, row)) > std::abs(a(rowMax, row))) if(std::abs(a(row2, row)) > std::abs(a(rowMax, row)))
rowMax = row2; rowMax = row2;
@ -86,7 +86,7 @@ template<size_t size, size_t cols, class T> bool GaussJordan::inPlaceTransposed(
return false; return false;
/* Eliminate column */ /* Eliminate column */
for(size_t row2 = row+1; row2 != size; ++row2) { for(std::size_t row2 = row+1; row2 != size; ++row2) {
T c = a(row2, row)/a(row, row); T c = a(row2, row)/a(row, row);
a[row2] -= a[row]*c; a[row2] -= a[row]*c;
@ -95,10 +95,10 @@ template<size_t size, size_t cols, class T> bool GaussJordan::inPlaceTransposed(
} }
/* Backsubstitute */ /* Backsubstitute */
for(size_t row = size; row != 0; --row) { for(std::size_t row = size; row != 0; --row) {
T c = T(1)/a(row-1, row-1); T c = T(1)/a(row-1, row-1);
for(size_t row2 = 0; row2 != row-1; ++row2) for(std::size_t row2 = 0; row2 != row-1; ++row2)
t[row2] -= t[row-1]*a(row2, row-1)*c; t[row2] -= t[row-1]*a(row2, row-1)*c;
/* Normalize the row */ /* Normalize the row */

2
src/Math/MathTypeTraits.h

@ -112,7 +112,7 @@ template<class T> struct MathTypeTraitsFloatingPoint {
} }
}; };
template<size_t> struct MathTypeTraitsLong {}; template<std::size_t> struct MathTypeTraitsLong {};
template<> struct MathTypeTraitsLong<sizeof(int)> { template<> struct MathTypeTraitsLong<sizeof(int)> {
typedef unsigned int UnsignedType; typedef unsigned int UnsignedType;

40
src/Math/Matrix.h

@ -25,7 +25,7 @@ namespace Magnum { namespace Math {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
namespace Implementation { namespace Implementation {
template<size_t size, class T> class MatrixDeterminant; template<std::size_t size, class T> class MatrixDeterminant;
} }
#endif #endif
@ -38,9 +38,9 @@ See @ref matrix-vector for brief introduction.
@configurationvalueref{Magnum::Math::Matrix} @configurationvalueref{Magnum::Math::Matrix}
*/ */
template<size_t size, class T> class Matrix: public RectangularMatrix<size, size, T> { template<std::size_t size, class T> class Matrix: public RectangularMatrix<size, size, T> {
public: public:
const static size_t Size = size; /**< @brief %Matrix size */ const static std::size_t Size = size; /**< @brief %Matrix size */
/** @brief Pass to constructor to create zero-filled matrix */ /** @brief Pass to constructor to create zero-filled matrix */
enum ZeroType { Zero }; enum ZeroType { Zero };
@ -63,7 +63,7 @@ template<size_t size, class T> class Matrix: public RectangularMatrix<size, size
* you to specify value on diagonal. * you to specify value on diagonal.
*/ */
inline Matrix(IdentityType = Identity, T value = T(1)) { inline Matrix(IdentityType = Identity, T value = T(1)) {
for(size_t i = 0; i != size; ++i) for(std::size_t i = 0; i != size; ++i)
(*this)(i, i) = value; (*this)(i, i) = value;
} }
@ -92,18 +92,18 @@ template<size_t size, class T> class Matrix: public RectangularMatrix<size, size
T trace() const { T trace() const {
T out(0); T out(0);
for(size_t i = 0; i != size; ++i) for(std::size_t i = 0; i != size; ++i)
out += (*this)(i, i); out += (*this)(i, i);
return out; return out;
} }
/** @brief %Matrix without given column and row */ /** @brief %Matrix without given column and row */
Matrix<size-1, T> ij(size_t skipCol, size_t skipRow) const { Matrix<size-1, T> ij(std::size_t skipCol, std::size_t skipRow) const {
Matrix<size-1, T> out(Matrix<size-1, T>::Zero); Matrix<size-1, T> out(Matrix<size-1, T>::Zero);
for(size_t col = 0; col != size-1; ++col) for(std::size_t col = 0; col != size-1; ++col)
for(size_t row = 0; row != size-1; ++row) for(std::size_t row = 0; row != size-1; ++row)
out(col, row) = (*this)(col + (col >= skipCol), out(col, row) = (*this)(col + (col >= skipCol),
row + (row >= skipRow)); row + (row >= skipRow));
@ -135,8 +135,8 @@ template<size_t size, class T> class Matrix: public RectangularMatrix<size, size
T _determinant = determinant(); T _determinant = determinant();
for(size_t col = 0; col != size; ++col) for(std::size_t col = 0; col != size; ++col)
for(size_t row = 0; row != size; ++row) for(std::size_t row = 0; row != size; ++row)
out(col, row) = (((row+col) & 1) ? -1 : 1)*ij(row, col).determinant()/_determinant; out(col, row) = (((row+col) & 1) ? -1 : 1)*ij(row, col).determinant()/_determinant;
return out; return out;
@ -147,7 +147,7 @@ template<size_t size, class T> class Matrix: public RectangularMatrix<size, size
inline Matrix<size, T> operator*(const Matrix<size, T>& other) const { inline Matrix<size, T> operator*(const Matrix<size, T>& other) const {
return RectangularMatrix<size, size, T>::operator*(other); return RectangularMatrix<size, size, T>::operator*(other);
} }
template<size_t otherCols> inline RectangularMatrix<otherCols, size, T> operator*(const RectangularMatrix<otherCols, size, T>& other) const { template<std::size_t otherCols> inline RectangularMatrix<otherCols, size, T> operator*(const RectangularMatrix<otherCols, size, T>& other) const {
return RectangularMatrix<size, size, T>::operator*(other); return RectangularMatrix<size, size, T>::operator*(other);
} }
inline Vector<size, T> operator*(const Vector<size, T>& other) const { inline Vector<size, T> operator*(const Vector<size, T>& other) const {
@ -159,16 +159,16 @@ template<size_t size, class T> class Matrix: public RectangularMatrix<size, size
}; };
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template<size_t size, class T, class U> inline typename std::enable_if<std::is_arithmetic<U>::value, Matrix<size, T>>::type operator*(U number, const Matrix<size, T>& matrix) { template<std::size_t size, class T, class U> inline typename std::enable_if<std::is_arithmetic<U>::value, Matrix<size, T>>::type operator*(U number, const Matrix<size, T>& matrix) {
return number*RectangularMatrix<size, size, T>(matrix); return number*RectangularMatrix<size, size, T>(matrix);
} }
template<size_t size, class T, class U> inline typename std::enable_if<std::is_arithmetic<U>::value, Matrix<size, T>>::type operator/(U number, const Matrix<size, T>& matrix) { template<std::size_t size, class T, class U> inline typename std::enable_if<std::is_arithmetic<U>::value, Matrix<size, T>>::type operator/(U number, const Matrix<size, T>& matrix) {
return number/RectangularMatrix<size, size, T>(matrix); return number/RectangularMatrix<size, size, T>(matrix);
} }
#endif #endif
/** @debugoperator{Magnum::Math::Matrix} */ /** @debugoperator{Magnum::Math::Matrix} */
template<size_t size, class T> inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Matrix<size, T>& value) { template<std::size_t size, class T> inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Matrix<size, T>& value) {
return debug << static_cast<const RectangularMatrix<size, size, T>&>(value); return debug << static_cast<const RectangularMatrix<size, size, T>&>(value);
} }
@ -189,10 +189,10 @@ template<size_t size, class T> inline Corrade::Utility::Debug operator<<(Corrade
return *this; \ return *this; \
} \ } \
\ \
inline VectorType<T>& operator[](size_t col) { \ inline VectorType<T>& operator[](std::size_t col) { \
return VectorType<T>::from(Matrix<size, T>::data()+col*size); \ return VectorType<T>::from(Matrix<size, T>::data()+col*size); \
} \ } \
inline constexpr const VectorType<T>& operator[](size_t col) const { \ inline constexpr const VectorType<T>& operator[](std::size_t col) const { \
return VectorType<T>::from(Matrix<size, T>::data()+col*size); \ return VectorType<T>::from(Matrix<size, T>::data()+col*size); \
} \ } \
\ \
@ -203,7 +203,7 @@ template<size_t size, class T> inline Corrade::Utility::Debug operator<<(Corrade
Matrix<size, T>::operator*=(other); \ Matrix<size, T>::operator*=(other); \
return *this; \ return *this; \
} \ } \
template<size_t otherCols> inline RectangularMatrix<otherCols, size, T> operator*(const RectangularMatrix<otherCols, size, T>& other) const { \ template<std::size_t otherCols> inline RectangularMatrix<otherCols, size, T> operator*(const RectangularMatrix<otherCols, size, T>& other) const { \
return Matrix<size, T>::operator*(other); \ return Matrix<size, T>::operator*(other); \
} \ } \
inline VectorType<T> operator*(const Vector<size, T>& other) const { \ inline VectorType<T> operator*(const Vector<size, T>& other) const { \
@ -223,12 +223,12 @@ template<size_t size, class T> inline Corrade::Utility::Debug operator<<(Corrade
namespace Implementation { namespace Implementation {
template<size_t size, class T> class MatrixDeterminant { template<std::size_t size, class T> class MatrixDeterminant {
public: public:
T operator()(const Matrix<size, T>& m) { T operator()(const Matrix<size, T>& m) {
T out(0); T out(0);
for(size_t col = 0; col != size; ++col) for(std::size_t col = 0; col != size; ++col)
out += ((col & 1) ? -1 : 1)*m(col, 0)*m.ij(col, 0).determinant(); out += ((col & 1) ? -1 : 1)*m(col, 0)*m.ij(col, 0).determinant();
return out; return out;
@ -256,7 +256,7 @@ template<class T> class MatrixDeterminant<1, T> {
namespace Corrade { namespace Utility { namespace Corrade { namespace Utility {
/** @configurationvalue{Magnum::Math::Matrix} */ /** @configurationvalue{Magnum::Math::Matrix} */
template<size_t size, class T> struct ConfigurationValue<Magnum::Math::Matrix<size, T>>: public ConfigurationValue<Magnum::Math::RectangularMatrix<size, size, T>> {}; template<std::size_t size, class T> struct ConfigurationValue<Magnum::Math::Matrix<size, T>>: public ConfigurationValue<Magnum::Math::RectangularMatrix<size, size, T>> {};
}} }}
#endif #endif

82
src/Math/RectangularMatrix.h

@ -28,28 +28,28 @@
namespace Magnum { namespace Math { namespace Magnum { namespace Math {
template<size_t, size_t, class> class RectangularMatrix; template<std::size_t, std::size_t, class> class RectangularMatrix;
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
namespace Implementation { namespace Implementation {
template<size_t ...> struct Sequence {}; template<std::size_t ...> struct Sequence {};
/* E.g. GenerateSequence<3>::Type is Sequence<0, 1, 2> */ /* E.g. GenerateSequence<3>::Type is Sequence<0, 1, 2> */
template<size_t N, size_t ...sequence> struct GenerateSequence: template<std::size_t N, std::size_t ...sequence> struct GenerateSequence:
GenerateSequence<N-1, N-1, sequence...> {}; GenerateSequence<N-1, N-1, sequence...> {};
template<size_t ...sequence> struct GenerateSequence<0, sequence...> { template<std::size_t ...sequence> struct GenerateSequence<0, sequence...> {
typedef Sequence<sequence...> Type; typedef Sequence<sequence...> Type;
}; };
/* Implementation for RectangularMatrix<cols, rows, T>::from(const RectangularMatrix<cols, rows, U>&) */ /* Implementation for RectangularMatrix<cols, rows, T>::from(const RectangularMatrix<cols, rows, U>&) */
template<class T, class U, size_t c, size_t ...sequence> inline constexpr Math::RectangularMatrix<c, sizeof...(sequence)/c, T> rectangularMatrixFrom(Sequence<sequence...>, const Math::RectangularMatrix<c, sizeof...(sequence)/c, U>& matrix) { template<class T, class U, std::size_t c, std::size_t ...sequence> inline constexpr Math::RectangularMatrix<c, sizeof...(sequence)/c, T> rectangularMatrixFrom(Sequence<sequence...>, const Math::RectangularMatrix<c, sizeof...(sequence)/c, U>& matrix) {
return {T(matrix.data()[sequence])...}; return {T(matrix.data()[sequence])...};
} }
} }
#endif #endif
template<size_t size, class T> class Vector; template<std::size_t size, class T> class Vector;
/** /**
@brief Rectangular matrix @brief Rectangular matrix
@ -60,13 +60,13 @@ template<size_t size, class T> class Vector;
See @ref matrix-vector for brief introduction. See also Matrix (square) and See @ref matrix-vector for brief introduction. See also Matrix (square) and
Vector. Vector.
*/ */
template<size_t cols, size_t rows, class T> class RectangularMatrix { template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
static_assert(cols != 0 && rows != 0, "Matrix cannot have zero elements"); static_assert(cols != 0 && rows != 0, "Matrix cannot have zero elements");
public: public:
typedef T Type; /**< @brief Data type */ typedef T Type; /**< @brief Data type */
const static size_t Cols = cols; /**< @brief %Matrix column count */ const static std::size_t Cols = cols; /**< @brief %Matrix column count */
const static size_t Rows = rows; /**< @brief %Matrix row count */ const static std::size_t Rows = rows; /**< @brief %Matrix row count */
/** /**
* @brief %Matrix from array * @brief %Matrix from array
@ -148,11 +148,11 @@ template<size_t cols, size_t rows, class T> class RectangularMatrix {
* For accessing individual elements prefer to use operator(), as it * For accessing individual elements prefer to use operator(), as it
* is guaranteed to not involve unnecessary conversions. * is guaranteed to not involve unnecessary conversions.
*/ */
inline Vector<rows, T>& operator[](size_t col) { inline Vector<rows, T>& operator[](std::size_t col) {
return Vector<rows, T>::from(_data+col*rows); return Vector<rows, T>::from(_data+col*rows);
} }
/** @overload */ /** @overload */
inline constexpr const Vector<rows, T>& operator[](size_t col) const { inline constexpr const Vector<rows, T>& operator[](std::size_t col) const {
return Vector<rows, T>::from(_data+col*rows); return Vector<rows, T>::from(_data+col*rows);
} }
@ -162,17 +162,17 @@ template<size_t cols, size_t rows, class T> class RectangularMatrix {
* Prefer this instead of using `[][]`. * Prefer this instead of using `[][]`.
* @see operator[] * @see operator[]
*/ */
inline T& operator()(size_t col, size_t row) { inline T& operator()(std::size_t col, std::size_t row) {
return _data[col*rows+row]; return _data[col*rows+row];
} }
/** @overload */ /** @overload */
inline constexpr const T& operator()(size_t col, size_t row) const { inline constexpr const T& operator()(std::size_t col, std::size_t row) const {
return _data[col*rows+row]; return _data[col*rows+row];
} }
/** @brief Equality operator */ /** @brief Equality operator */
inline bool operator==(const RectangularMatrix<cols, rows, T>& other) const { inline bool operator==(const RectangularMatrix<cols, rows, T>& other) const {
for(size_t i = 0; i != cols*rows; ++i) for(std::size_t i = 0; i != cols*rows; ++i)
if(!MathTypeTraits<T>::equals(_data[i], other._data[i])) return false; if(!MathTypeTraits<T>::equals(_data[i], other._data[i])) return false;
return true; return true;
@ -199,7 +199,7 @@ template<size_t cols, size_t rows, class T> class RectangularMatrix {
* in-place. * in-place.
*/ */
RectangularMatrix<cols, rows, T>& operator+=(const RectangularMatrix<cols, rows, T>& other) { RectangularMatrix<cols, rows, T>& operator+=(const RectangularMatrix<cols, rows, T>& other) {
for(size_t i = 0; i != cols*rows; ++i) for(std::size_t i = 0; i != cols*rows; ++i)
_data[i] += other._data[i]; _data[i] += other._data[i];
return *this; return *this;
@ -209,7 +209,7 @@ template<size_t cols, size_t rows, class T> class RectangularMatrix {
RectangularMatrix<cols, rows, T> operator-() const { RectangularMatrix<cols, rows, T> operator-() const {
RectangularMatrix<cols, rows, T> out; RectangularMatrix<cols, rows, T> out;
for(size_t i = 0; i != cols*rows; ++i) for(std::size_t i = 0; i != cols*rows; ++i)
out._data[i] = -_data[i]; out._data[i] = -_data[i];
return out; return out;
@ -231,7 +231,7 @@ template<size_t cols, size_t rows, class T> class RectangularMatrix {
* in-place. * in-place.
*/ */
RectangularMatrix<cols, rows, T>& operator-=(const RectangularMatrix<cols, rows, T>& other) { RectangularMatrix<cols, rows, T>& operator-=(const RectangularMatrix<cols, rows, T>& other) {
for(size_t i = 0; i != cols*rows; ++i) for(std::size_t i = 0; i != cols*rows; ++i)
_data[i] -= other._data[i]; _data[i] -= other._data[i];
return *this; return *this;
@ -261,7 +261,7 @@ template<size_t cols, size_t rows, class T> class RectangularMatrix {
#else #else
template<class U> RectangularMatrix<cols, rows, T>& operator*=(U number) { template<class U> RectangularMatrix<cols, rows, T>& operator*=(U number) {
#endif #endif
for(size_t i = 0; i != cols*rows; ++i) for(std::size_t i = 0; i != cols*rows; ++i)
_data[i] *= number; _data[i] *= number;
return *this; return *this;
@ -291,19 +291,19 @@ template<size_t cols, size_t rows, class T> class RectangularMatrix {
#else #else
template<class U> RectangularMatrix<cols, rows, T>& operator/=(U number) { template<class U> RectangularMatrix<cols, rows, T>& operator/=(U number) {
#endif #endif
for(size_t i = 0; i != cols*rows; ++i) for(std::size_t i = 0; i != cols*rows; ++i)
_data[i] /= number; _data[i] /= number;
return *this; return *this;
} }
/** @brief Multiply matrix */ /** @brief Multiply matrix */
template<size_t size> RectangularMatrix<size, rows, T> operator*(const RectangularMatrix<size, cols, T>& other) const { template<std::size_t size> RectangularMatrix<size, rows, T> operator*(const RectangularMatrix<size, cols, T>& other) const {
RectangularMatrix<size, rows, T> out; RectangularMatrix<size, rows, T> out;
for(size_t col = 0; col != size; ++col) for(std::size_t col = 0; col != size; ++col)
for(size_t row = 0; row != rows; ++row) for(std::size_t row = 0; row != rows; ++row)
for(size_t pos = 0; pos != cols; ++pos) for(std::size_t pos = 0; pos != cols; ++pos)
out(col, row) += (*this)(pos, row)*other(col, pos); out(col, row) += (*this)(pos, row)*other(col, pos);
return out; return out;
@ -323,8 +323,8 @@ template<size_t cols, size_t rows, class T> class RectangularMatrix {
RectangularMatrix<rows, cols, T> transposed() const { RectangularMatrix<rows, cols, T> transposed() const {
RectangularMatrix<rows, cols, T> out; RectangularMatrix<rows, cols, T> out;
for(size_t col = 0; col != cols; ++col) for(std::size_t col = 0; col != cols; ++col)
for(size_t row = 0; row != rows; ++row) for(std::size_t row = 0; row != rows; ++row)
out(row, col) = (*this)(col, row); out(row, col) = (*this)(col, row);
return out; return out;
@ -336,10 +336,10 @@ template<size_t cols, size_t rows, class T> class RectangularMatrix {
#endif #endif
private: private:
template<size_t ...sequence, class ...U> inline constexpr static RectangularMatrix<cols, rows, T> from(Implementation::Sequence<sequence...> s, const Vector<rows, T>& first, U... next) { template<std::size_t ...sequence, class ...U> inline constexpr static RectangularMatrix<cols, rows, T> from(Implementation::Sequence<sequence...> s, const Vector<rows, T>& first, U... next) {
return from(s, next..., first[sequence]...); return from(s, next..., first[sequence]...);
} }
template<size_t ...sequence, class ...U> inline constexpr static RectangularMatrix<cols, rows, T> from(Implementation::Sequence<sequence...>, T first, U... next) { template<std::size_t ...sequence, class ...U> inline constexpr static RectangularMatrix<cols, rows, T> from(Implementation::Sequence<sequence...>, T first, U... next) {
return RectangularMatrix<cols, rows, T>(first, next...); return RectangularMatrix<cols, rows, T>(first, next...);
} }
}; };
@ -350,9 +350,9 @@ template<size_t cols, size_t rows, class T> class RectangularMatrix {
@see RectangularMatrix::operator*(U) const @see RectangularMatrix::operator*(U) const
*/ */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template<size_t cols, size_t rows, class T, class U> inline typename std::enable_if<std::is_arithmetic<U>::value, RectangularMatrix<cols, rows, T>>::type operator*(U number, const RectangularMatrix<cols, rows, T>& matrix) { template<std::size_t cols, std::size_t rows, class T, class U> inline typename std::enable_if<std::is_arithmetic<U>::value, RectangularMatrix<cols, rows, T>>::type operator*(U number, const RectangularMatrix<cols, rows, T>& matrix) {
#else #else
template<size_t cols, size_t rows, class T, class U> inline RectangularMatrix<cols, rows, T> operator*(U number, const RectangularMatrix<cols, rows, T>& matrix) { template<std::size_t cols, std::size_t rows, class T, class U> inline RectangularMatrix<cols, rows, T> operator*(U number, const RectangularMatrix<cols, rows, T>& matrix) {
#endif #endif
return matrix*number; return matrix*number;
} }
@ -368,25 +368,25 @@ RectangularMatrix<2, 3, float> another = 1.0f/mat; // {1.0f, 0.5f, -0.25f, 0.128
@see RectangularMatrix::operator/() @see RectangularMatrix::operator/()
*/ */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template<size_t cols, size_t rows, class T, class U> typename std::enable_if<std::is_arithmetic<U>::value, RectangularMatrix<cols, rows, T>>::type operator/(U number, const RectangularMatrix<cols, rows, T>& matrix) { template<std::size_t cols, std::size_t rows, class T, class U> typename std::enable_if<std::is_arithmetic<U>::value, RectangularMatrix<cols, rows, T>>::type operator/(U number, const RectangularMatrix<cols, rows, T>& matrix) {
#else #else
template<size_t cols, size_t rows, class T, class U> RectangularMatrix<cols, rows, T> operator/(U number, const RectangularMatrix<cols, rows, T>& matrix) { template<std::size_t cols, std::size_t rows, class T, class U> RectangularMatrix<cols, rows, T> operator/(U number, const RectangularMatrix<cols, rows, T>& matrix) {
#endif #endif
RectangularMatrix<cols, rows, T> out; RectangularMatrix<cols, rows, T> out;
for(size_t i = 0; i != cols*rows; ++i) for(std::size_t i = 0; i != cols*rows; ++i)
out.data()[i] = number/matrix.data()[i]; out.data()[i] = number/matrix.data()[i];
return out; return out;
} }
/** @debugoperator{Magnum::Math::RectangularMatrix} */ /** @debugoperator{Magnum::Math::RectangularMatrix} */
template<size_t cols, size_t rows, class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::RectangularMatrix<cols, rows, T>& value) { template<std::size_t cols, std::size_t rows, class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::RectangularMatrix<cols, rows, T>& value) {
debug << "Matrix("; debug << "Matrix(";
debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false);
for(size_t row = 0; row != rows; ++row) { for(std::size_t row = 0; row != rows; ++row) {
if(row != 0) debug << ",\n "; if(row != 0) debug << ",\n ";
for(size_t col = 0; col != cols; ++col) { for(std::size_t col = 0; col != cols; ++col) {
if(col != 0) debug << ", "; if(col != 0) debug << ", ";
debug << typename MathTypeTraits<T>::NumericType(value[col][row]); debug << typename MathTypeTraits<T>::NumericType(value[col][row]);
} }
@ -455,13 +455,13 @@ template<size_t cols, size_t rows, class T> Corrade::Utility::Debug operator<<(C
namespace Corrade { namespace Utility { namespace Corrade { namespace Utility {
/** @configurationvalue{Magnum::Math::RectangularMatrix} */ /** @configurationvalue{Magnum::Math::RectangularMatrix} */
template<size_t cols, size_t rows, class T> struct ConfigurationValue<Magnum::Math::RectangularMatrix<cols, rows, T>> { template<std::size_t cols, std::size_t rows, class T> struct ConfigurationValue<Magnum::Math::RectangularMatrix<cols, rows, T>> {
/** @brief Writes elements separated with spaces */ /** @brief Writes elements separated with spaces */
static std::string toString(const Magnum::Math::RectangularMatrix<cols, rows, T>& value, int flags = 0) { static std::string toString(const Magnum::Math::RectangularMatrix<cols, rows, T>& value, int flags = 0) {
std::string output; std::string output;
for(size_t row = 0; row != rows; ++row) { for(std::size_t row = 0; row != rows; ++row) {
for(size_t col = 0; col != cols; ++col) { for(std::size_t col = 0; col != cols; ++col) {
if(!output.empty()) output += ' '; if(!output.empty()) output += ' ';
output += ConfigurationValue<T>::toString(value(col, row), flags); output += ConfigurationValue<T>::toString(value(col, row), flags);
} }
@ -475,8 +475,8 @@ template<size_t cols, size_t rows, class T> struct ConfigurationValue<Magnum::Ma
Magnum::Math::RectangularMatrix<cols, rows, T> result; Magnum::Math::RectangularMatrix<cols, rows, T> result;
std::istringstream in(stringValue); std::istringstream in(stringValue);
for(size_t row = 0; row != rows; ++row) { for(std::size_t row = 0; row != rows; ++row) {
for(size_t col = 0; col != cols; ++col) { for(std::size_t col = 0; col != cols; ++col) {
std::string num; std::string num;
in >> num; in >> num;
result(col, row) = ConfigurationValue<T>::fromString(num, flags); result(col, row) = ConfigurationValue<T>::fromString(num, flags);

38
src/Math/Vector.h

@ -31,9 +31,9 @@ namespace Magnum { namespace Math {
See @ref matrix-vector for brief introduction. See @ref matrix-vector for brief introduction.
@configurationvalueref{Magnum::Math::Vector} @configurationvalueref{Magnum::Math::Vector}
*/ */
template<size_t size, class T> class Vector: public RectangularMatrix<1, size, T> { template<std::size_t size, class T> class Vector: public RectangularMatrix<1, size, T> {
public: public:
const static size_t Size = size; /**< @brief %Vector size */ const static std::size_t Size = size; /**< @brief %Vector size */
/** /**
* @brief Dot product * @brief Dot product
@ -46,7 +46,7 @@ template<size_t size, class T> class Vector: public RectangularMatrix<1, size, T
static T dot(const Vector<size, T>& a, const Vector<size, T>& b) { static T dot(const Vector<size, T>& a, const Vector<size, T>& b) {
T out(0); T out(0);
for(size_t i = 0; i != size; ++i) for(std::size_t i = 0; i != size; ++i)
out += a[i]*b[i]; out += a[i]*b[i];
return out; return out;
@ -90,7 +90,7 @@ template<size_t size, class T> class Vector: public RectangularMatrix<1, size, T
#else #else
inline explicit Vector(T value) { inline explicit Vector(T value) {
#endif #endif
for(size_t i = 0; i != size; ++i) for(std::size_t i = 0; i != size; ++i)
(*this)[i] = value; (*this)[i] = value;
} }
@ -98,8 +98,8 @@ template<size_t size, class T> class Vector: public RectangularMatrix<1, size, T
inline constexpr Vector(const RectangularMatrix<1, size, T>& other): RectangularMatrix<1, size, T>(other) {} inline constexpr Vector(const RectangularMatrix<1, size, T>& other): RectangularMatrix<1, size, T>(other) {}
/** @brief Value at given position */ /** @brief Value at given position */
inline T& operator[](size_t pos) { return RectangularMatrix<1, size, T>::_data[pos]; } inline T& operator[](std::size_t pos) { return RectangularMatrix<1, size, T>::_data[pos]; }
inline constexpr T operator[](size_t pos) const { return RectangularMatrix<1, size, T>::_data[pos]; } /**< @overload */ inline constexpr T operator[](std::size_t pos) const { return RectangularMatrix<1, size, T>::_data[pos]; } /**< @overload */
/** /**
* @brief Multiply vector component-wise * @brief Multiply vector component-wise
@ -117,7 +117,7 @@ template<size_t size, class T> class Vector: public RectangularMatrix<1, size, T
* because it does the computation in-place. * because it does the computation in-place.
*/ */
Vector<size, T>& operator*=(const Vector<size, T>& other) { Vector<size, T>& operator*=(const Vector<size, T>& other) {
for(size_t i = 0; i != size; ++i) for(std::size_t i = 0; i != size; ++i)
(*this)[i] *= other[i]; (*this)[i] *= other[i];
return *this; return *this;
@ -139,7 +139,7 @@ template<size_t size, class T> class Vector: public RectangularMatrix<1, size, T
* because it does the computation in-place. * because it does the computation in-place.
*/ */
Vector<size, T>& operator/=(const Vector<size, T>& other) { Vector<size, T>& operator/=(const Vector<size, T>& other) {
for(size_t i = 0; i != size; ++i) for(std::size_t i = 0; i != size; ++i)
(*this)[i] /= other[i]; (*this)[i] /= other[i];
return *this; return *this;
@ -177,7 +177,7 @@ template<size_t size, class T> class Vector: public RectangularMatrix<1, size, T
T sum() const { T sum() const {
T out(0); T out(0);
for(size_t i = 0; i != size; ++i) for(std::size_t i = 0; i != size; ++i)
out += (*this)[i]; out += (*this)[i];
return out; return out;
@ -187,7 +187,7 @@ template<size_t size, class T> class Vector: public RectangularMatrix<1, size, T
T product() const { T product() const {
T out(1); T out(1);
for(size_t i = 0; i != size; ++i) for(std::size_t i = 0; i != size; ++i)
out *= (*this)[i]; out *= (*this)[i];
return out; return out;
@ -197,7 +197,7 @@ template<size_t size, class T> class Vector: public RectangularMatrix<1, size, T
T min() const { T min() const {
T out((*this)[0]); T out((*this)[0]);
for(size_t i = 1; i != size; ++i) for(std::size_t i = 1; i != size; ++i)
out = std::min(out, (*this)[i]); out = std::min(out, (*this)[i]);
return out; return out;
@ -207,7 +207,7 @@ template<size_t size, class T> class Vector: public RectangularMatrix<1, size, T
T max() const { T max() const {
T out((*this)[0]); T out((*this)[0]);
for(size_t i = 1; i != size; ++i) for(std::size_t i = 1; i != size; ++i)
out = std::max(out, (*this)[i]); out = std::max(out, (*this)[i]);
return out; return out;
@ -215,7 +215,7 @@ template<size_t size, class T> class Vector: public RectangularMatrix<1, size, T
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
/* Reimplementation of functions to return correct type */ /* Reimplementation of functions to return correct type */
template<size_t otherCols> inline RectangularMatrix<otherCols, size, T> operator*(const RectangularMatrix<otherCols, 1, T>& other) const { template<std::size_t otherCols> inline RectangularMatrix<otherCols, size, T> operator*(const RectangularMatrix<otherCols, 1, T>& other) const {
return RectangularMatrix<1, size, T>::operator*(other); return RectangularMatrix<1, size, T>::operator*(other);
} }
MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(1, size, Vector<size, T>) MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(1, size, Vector<size, T>)
@ -231,19 +231,19 @@ template<size_t size, class T> class Vector: public RectangularMatrix<1, size, T
}; };
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template<size_t size, class T, class U> inline typename std::enable_if<std::is_arithmetic<U>::value, Vector<size, T>>::type operator*(U number, const Vector<size, T>& vector) { template<std::size_t size, class T, class U> inline typename std::enable_if<std::is_arithmetic<U>::value, Vector<size, T>>::type operator*(U number, const Vector<size, T>& vector) {
return number*RectangularMatrix<1, size, T>(vector); return number*RectangularMatrix<1, size, T>(vector);
} }
template<size_t size, class T, class U> inline typename std::enable_if<std::is_arithmetic<U>::value, Vector<size, T>>::type operator/(U number, const Vector<size, T>& vector) { template<std::size_t size, class T, class U> inline typename std::enable_if<std::is_arithmetic<U>::value, Vector<size, T>>::type operator/(U number, const Vector<size, T>& vector) {
return number/RectangularMatrix<1, size, T>(vector); return number/RectangularMatrix<1, size, T>(vector);
} }
#endif #endif
/** @debugoperator{Magnum::Math::Vector} */ /** @debugoperator{Magnum::Math::Vector} */
template<size_t size, class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Vector<size, T>& value) { template<std::size_t size, class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Vector<size, T>& value) {
debug << "Vector("; debug << "Vector(";
debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false);
for(size_t i = 0; i != size; ++i) { for(std::size_t i = 0; i != size; ++i) {
if(i != 0) debug << ", "; if(i != 0) debug << ", ";
debug << typename MathTypeTraits<T>::NumericType(value[i]); debug << typename MathTypeTraits<T>::NumericType(value[i]);
} }
@ -269,7 +269,7 @@ template<size_t size, class T> Corrade::Utility::Debug operator<<(Corrade::Utili
return *this; \ return *this; \
} \ } \
\ \
template<size_t otherCols> inline Math::RectangularMatrix<otherCols, size, T> operator*(const Math::RectangularMatrix<otherCols, 1, T>& other) const { \ template<std::size_t otherCols> inline Math::RectangularMatrix<otherCols, size, T> operator*(const Math::RectangularMatrix<otherCols, 1, T>& other) const { \
return Math::Vector<size, T>::operator*(other); \ return Math::Vector<size, T>::operator*(other); \
} \ } \
inline Type<T> operator*(const Math::Vector<size, T>& other) const { \ inline Type<T> operator*(const Math::Vector<size, T>& other) const { \
@ -303,7 +303,7 @@ template<size_t size, class T> Corrade::Utility::Debug operator<<(Corrade::Utili
namespace Corrade { namespace Utility { namespace Corrade { namespace Utility {
/** @configurationvalue{Magnum::Math::Vector} */ /** @configurationvalue{Magnum::Math::Vector} */
template<size_t size, class T> struct ConfigurationValue<Magnum::Math::Vector<size, T>>: public ConfigurationValue<Magnum::Math::RectangularMatrix<1, size, T>> {}; template<std::size_t size, class T> struct ConfigurationValue<Magnum::Math::Vector<size, T>>: public ConfigurationValue<Magnum::Math::RectangularMatrix<1, size, T>> {};
}} }}

32
src/MeshTools/Clean.h

@ -31,7 +31,7 @@ namespace Magnum { namespace MeshTools {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
namespace Implementation { namespace Implementation {
template<class Vertex, size_t vertexSize = Vertex::Size> class Clean { template<class Vertex, std::size_t vertexSize = Vertex::Size> class Clean {
public: public:
inline Clean(std::vector<unsigned int>& indices, std::vector<Vertex>& vertices): indices(indices), vertices(vertices) {} inline Clean(std::vector<unsigned int>& indices, std::vector<Vertex>& vertices): indices(indices), vertices(vertices) {}
@ -40,32 +40,32 @@ template<class Vertex, size_t vertexSize = Vertex::Size> class Clean {
/* Get mesh bounds */ /* Get mesh bounds */
Vertex min, max; Vertex min, max;
for(size_t i = 0; i != Vertex::Size; ++i) { for(std::size_t i = 0; i != Vertex::Size; ++i) {
min[i] = std::numeric_limits<typename Vertex::Type>::max(); min[i] = std::numeric_limits<typename Vertex::Type>::max();
max[i] = std::numeric_limits<typename Vertex::Type>::min(); max[i] = std::numeric_limits<typename Vertex::Type>::min();
} }
for(auto it = vertices.cbegin(); it != vertices.cend(); ++it) for(auto it = vertices.cbegin(); it != vertices.cend(); ++it)
for(size_t i = 0; i != vertexSize; ++i) for(std::size_t i = 0; i != vertexSize; ++i)
if((*it)[i] < min[i]) if((*it)[i] < min[i])
min[i] = (*it)[i]; min[i] = (*it)[i];
else if((*it)[i] > max[i]) else if((*it)[i] > max[i])
max[i] = (*it)[i]; max[i] = (*it)[i];
/* Make epsilon so large that size_t can index all vertices inside /* Make epsilon so large that std::size_t can index all vertices
mesh bounds. */ inside mesh bounds. */
Vertex size = max-min; Vertex size = max-min;
for(size_t i = 0; i != Vertex::Size; ++i) for(std::size_t i = 0; i != Vertex::Size; ++i)
if(static_cast<typename Vertex::Type>(size[i]/std::numeric_limits<size_t>::max()) > epsilon) if(static_cast<typename Vertex::Type>(size[i]/std::numeric_limits<std::size_t>::max()) > epsilon)
epsilon = static_cast<typename Vertex::Type>(size[i]/std::numeric_limits<size_t>::max()); epsilon = static_cast<typename Vertex::Type>(size[i]/std::numeric_limits<std::size_t>::max());
/* First go with original vertex coordinates, then move them by /* First go with original vertex coordinates, then move them by
epsilon/2 in each direction. */ epsilon/2 in each direction. */
Vertex moved; Vertex moved;
for(size_t moving = 0; moving <= vertexSize; ++moving) { for(std::size_t moving = 0; moving <= vertexSize; ++moving) {
/* Under each index is pointer to face which contains given vertex /* Under each index is pointer to face which contains given vertex
and index of vertex in the face. */ and index of vertex in the face. */
std::unordered_map<Math::Vector<vertexSize, size_t>, HashedVertex, IndexHash> table; std::unordered_map<Math::Vector<vertexSize, std::size_t>, HashedVertex, IndexHash> table;
/* Reserve space for all vertices */ /* Reserve space for all vertices */
table.reserve(vertices.size()); table.reserve(vertices.size());
@ -73,15 +73,15 @@ template<class Vertex, size_t vertexSize = Vertex::Size> class Clean {
/* Go through all faces' vertices */ /* Go through all faces' vertices */
for(auto it = indices.begin(); it != indices.end(); ++it) { for(auto it = indices.begin(); it != indices.end(); ++it) {
/* Index of a vertex in vertexSize-dimensional table */ /* Index of a vertex in vertexSize-dimensional table */
size_t index[vertexSize]; std::size_t index[vertexSize];
for(size_t ii = 0; ii != vertexSize; ++ii) for(std::size_t ii = 0; ii != vertexSize; ++ii)
index[ii] = (vertices[*it][ii]+moved[ii]-min[ii])/epsilon; index[ii] = (vertices[*it][ii]+moved[ii]-min[ii])/epsilon;
/* Try inserting the vertex into table, if it already /* Try inserting the vertex into table, if it already
exists, change vertex pointer of the face to already exists, change vertex pointer of the face to already
existing vertex */ existing vertex */
HashedVertex v(*it, table.size()); HashedVertex v(*it, table.size());
auto result = table.insert(std::pair<Math::Vector<vertexSize, size_t>, HashedVertex>(Math::Vector<vertexSize, size_t>::from(index), v)); auto result = table.insert(std::pair<Math::Vector<vertexSize, std::size_t>, HashedVertex>(Math::Vector<vertexSize, std::size_t>::from(index), v));
*it = result.first->second.newIndex; *it = result.first->second.newIndex;
} }
@ -102,8 +102,8 @@ template<class Vertex, size_t vertexSize = Vertex::Size> class Clean {
private: private:
class IndexHash { class IndexHash {
public: public:
inline size_t operator()(const Math::Vector<vertexSize, size_t>& data) const { inline std::size_t operator()(const Math::Vector<vertexSize, std::size_t>& data) const {
return *reinterpret_cast<const size_t*>(Corrade::Utility::MurmurHash2()(reinterpret_cast<const char*>(&data), sizeof(data)).byteArray()); return *reinterpret_cast<const std::size_t*>(Corrade::Utility::MurmurHash2()(reinterpret_cast<const char*>(&data), sizeof(data)).byteArray());
} }
}; };
@ -137,7 +137,7 @@ Removes duplicate vertices from the mesh.
@todo Interpolate vertices, not collapse them to first in the cell @todo Interpolate vertices, not collapse them to first in the cell
@todo Ability to specify other attributes for interpolation @todo Ability to specify other attributes for interpolation
*/ */
template<class Vertex, size_t vertexSize = Vertex::Size> inline void clean(std::vector<unsigned int>& indices, std::vector<Vertex>& vertices, typename Vertex::Type epsilon = TypeTraits<typename Vertex::Type>::epsilon()) { template<class Vertex, std::size_t vertexSize = Vertex::Size> inline void clean(std::vector<unsigned int>& indices, std::vector<Vertex>& vertices, typename Vertex::Type epsilon = TypeTraits<typename Vertex::Type>::epsilon()) {
Implementation::Clean<Vertex, vertexSize>(indices, vertices)(epsilon); Implementation::Clean<Vertex, vertexSize>(indices, vertices)(epsilon);
} }

18
src/MeshTools/CombineIndexedArrays.h

@ -35,7 +35,7 @@ class CombineIndexedArrays {
public: public:
template<class ...T> std::vector<unsigned int> operator()(const std::tuple<const std::vector<unsigned int>&, std::vector<T>&>&... indexedArrays) { template<class ...T> std::vector<unsigned int> operator()(const std::tuple<const std::vector<unsigned int>&, std::vector<T>&>&... indexedArrays) {
/* Compute index count */ /* Compute index count */
size_t _indexCount = indexCount(std::get<0>(indexedArrays)...); std::size_t _indexCount = indexCount(std::get<0>(indexedArrays)...);
/* Resulting index array */ /* Resulting index array */
std::vector<unsigned int> result; std::vector<unsigned int> result;
@ -56,24 +56,24 @@ class CombineIndexedArrays {
} }
private: private:
template<class ...T> inline static size_t indexCount(const std::vector<unsigned int>& first, const std::vector<T>&... next) { template<class ...T> inline static std::size_t indexCount(const std::vector<unsigned int>& first, const std::vector<T>&... next) {
CORRADE_ASSERT(sizeof...(next) == 0 || indexCount(next...) == first.size(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.", 0); CORRADE_ASSERT(sizeof...(next) == 0 || indexCount(next...) == first.size(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.", 0);
return first.size(); return first.size();
} }
template<size_t size, class ...T> static void writeCombinedIndices(std::vector<Math::Vector<size, unsigned int>>& output, const std::vector<unsigned int>& first, const std::vector<T>&... next) { template<std::size_t size, class ...T> static void writeCombinedIndices(std::vector<Math::Vector<size, unsigned int>>& output, const std::vector<unsigned int>& first, const std::vector<T>&... next) {
/* Copy the data to output */ /* Copy the data to output */
for(size_t i = 0; i != output.size(); ++i) for(std::size_t i = 0; i != output.size(); ++i)
output[i][size-sizeof...(next)-1] = first[i]; output[i][size-sizeof...(next)-1] = first[i];
writeCombinedIndices(output, next...); writeCombinedIndices(output, next...);
} }
template<size_t size, class T, class ...U> static void writeCombinedArrays(const std::vector<Math::Vector<size, unsigned int>>& combinedIndices, std::vector<T>& first, std::vector<U>&... next) { template<std::size_t size, class T, class ...U> static void writeCombinedArrays(const std::vector<Math::Vector<size, unsigned int>>& combinedIndices, std::vector<T>& first, std::vector<U>&... next) {
/* Rewrite output array */ /* Rewrite output array */
std::vector<T> output; std::vector<T> output;
for(size_t i = 0; i != combinedIndices.size(); ++i) for(std::size_t i = 0; i != combinedIndices.size(); ++i)
output.push_back(first[combinedIndices[i][size-sizeof...(next)-1]]); output.push_back(first[combinedIndices[i][size-sizeof...(next)-1]]);
std::swap(output, first); std::swap(output, first);
@ -81,9 +81,9 @@ class CombineIndexedArrays {
} }
/* Terminator functions for recursive calls */ /* Terminator functions for recursive calls */
inline static size_t indexCount() { return 0; } inline static std::size_t indexCount() { return 0; }
template<size_t size> inline static void writeCombinedIndices(std::vector<Math::Vector<size, unsigned int>>&) {} template<std::size_t size> inline static void writeCombinedIndices(std::vector<Math::Vector<size, unsigned int>>&) {}
template<size_t size> inline static void writeCombinedArrays(const std::vector<Math::Vector<size, unsigned int>>&) {} template<std::size_t size> inline static void writeCombinedArrays(const std::vector<Math::Vector<size, unsigned int>>&) {}
}; };
} }

2
src/MeshTools/CompressIndices.cpp

@ -22,6 +22,8 @@
#include "IndexedMesh.h" #include "IndexedMesh.h"
#include "SizeTraits.h" #include "SizeTraits.h"
using namespace std;
namespace Magnum { namespace MeshTools { namespace Magnum { namespace MeshTools {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT

10
src/MeshTools/CompressIndices.h

@ -39,13 +39,13 @@ class MESHTOOLS_EXPORT CompressIndices {
public: public:
CompressIndices(const std::vector<unsigned int>& indices): indices(indices) {} CompressIndices(const std::vector<unsigned int>& indices): indices(indices) {}
std::tuple<size_t, Type, char*> operator()() const; std::tuple<std::size_t, Type, char*> operator()() const;
void operator()(IndexedMesh* mesh, Buffer::Usage usage) const; void operator()(IndexedMesh* mesh, Buffer::Usage usage) const;
private: private:
struct Compressor { struct Compressor {
template<class IndexType> static std::tuple<size_t, Type, char*> run(const std::vector<unsigned int>& indices); template<class IndexType> static std::tuple<std::size_t, Type, char*> run(const std::vector<unsigned int>& indices);
}; };
const std::vector<unsigned int>& indices; const std::vector<unsigned int>& indices;
@ -66,11 +66,11 @@ wasteful to store them in array of `unsigned int`s, array of `unsigned short`s
is sufficient. Size of the buffer can be computed from index count and type, is sufficient. Size of the buffer can be computed from index count and type,
as shown below. Example usage: as shown below. Example usage:
@code @code
size_t indexCount; std::size_t indexCount;
Type indexType; Type indexType;
char* data; char* data;
std::tie(indexCount, indexType, data) = MeshTools::compressIndices(indices); std::tie(indexCount, indexType, data) = MeshTools::compressIndices(indices);
size_t dataSize = indexCount*TypeInfo::sizeOf(indexType); std::size_t dataSize = indexCount*TypeInfo::sizeOf(indexType);
// ... // ...
delete[] data; delete[] data;
@endcode @endcode
@ -78,7 +78,7 @@ delete[] data;
See also compressIndices(IndexedMesh*, Buffer::Usage, const std::vector<unsigned int>&), See also compressIndices(IndexedMesh*, Buffer::Usage, const std::vector<unsigned int>&),
which writes the compressed data directly into index buffer of given mesh. which writes the compressed data directly into index buffer of given mesh.
*/ */
inline std::tuple<size_t, Type, char*> compressIndices(const std::vector<unsigned int>& indices) { inline std::tuple<std::size_t, Type, char*> compressIndices(const std::vector<std::unsigned int>& indices) {
return Implementation::CompressIndices{indices}(); return Implementation::CompressIndices{indices}();
} }

24
src/MeshTools/Interleave.h

@ -36,7 +36,7 @@ class Interleave {
public: public:
inline Interleave(): _attributeCount(0), _stride(0), _data(nullptr) {} inline Interleave(): _attributeCount(0), _stride(0), _data(nullptr) {}
template<class ...T> std::tuple<size_t, size_t, char*> operator()(const T&... attributes) { template<class ...T> std::tuple<std::size_t, std::size_t, char*> operator()(const T&... attributes) {
/* Compute buffer size and stride */ /* Compute buffer size and stride */
_attributeCount = attributeCount(attributes...); _attributeCount = attributeCount(attributes...);
if(_attributeCount) { if(_attributeCount) {
@ -69,13 +69,13 @@ class Interleave {
buffer->setData(attribute, usage); buffer->setData(attribute, usage);
} }
template<class T, class ...U> inline static size_t attributeCount(const T& first, const U&... next) { template<class T, class ...U> inline static std::size_t attributeCount(const T& first, const U&... next) {
CORRADE_ASSERT(sizeof...(next) == 0 || attributeCount(next...) == first.size(), "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.", 0); CORRADE_ASSERT(sizeof...(next) == 0 || attributeCount(next...) == first.size(), "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.", 0);
return first.size(); return first.size();
} }
template<class T, class ...U> inline static size_t stride(const T&, const U&... next) { template<class T, class ...U> inline static std::size_t stride(const T&, const U&... next) {
return sizeof(typename T::value_type) + stride(next...); return sizeof(typename T::value_type) + stride(next...);
} }
@ -83,19 +83,19 @@ class Interleave {
template<class T, class ...U> void write(char* startingOffset, const T& first, const U&... next) { template<class T, class ...U> void write(char* startingOffset, const T& first, const U&... next) {
/* Copy the data to the buffer */ /* Copy the data to the buffer */
auto it = first.begin(); auto it = first.begin();
for(size_t i = 0; i != _attributeCount; ++i, ++it) for(std::size_t i = 0; i != _attributeCount; ++i, ++it)
memcpy(startingOffset+i*_stride, reinterpret_cast<const char*>(&*it), sizeof(typename T::value_type)); memcpy(startingOffset+i*_stride, reinterpret_cast<const char*>(&*it), sizeof(typename T::value_type));
write(startingOffset+sizeof(typename T::value_type), next...); write(startingOffset+sizeof(typename T::value_type), next...);
} }
/* Terminator functions for recursive calls */ /* Terminator functions for recursive calls */
inline static size_t attributeCount() { return 0; } inline static std::size_t attributeCount() { return 0; }
inline static size_t stride() { return 0; } inline static std::size_t stride() { return 0; }
inline void write(char*) {} inline void write(char*) {}
size_t _attributeCount; std::size_t _attributeCount;
size_t _stride; std::size_t _stride;
char* _data; char* _data;
}; };
@ -116,11 +116,11 @@ usage:
@code @code
std::vector<Vector4> positions; std::vector<Vector4> positions;
std::vector<Vector2> textureCoordinates; std::vector<Vector2> textureCoordinates;
size_t attributeCount; std::size_t attributeCount;
size_t stride; std::size_t stride;
char* data; char* data;
std::tie(attributeCount, stride, data) = MeshTools::interleave(positions, textureCoordinates); std::tie(attributeCount, stride, data) = MeshTools::interleave(positions, textureCoordinates);
size_t dataSize = attributeCount*stride; std::size_t dataSize = attributeCount*stride;
// ... // ...
delete[] data; delete[] data;
@endcode @endcode
@ -137,7 +137,7 @@ which writes the interleaved array directly into buffer of given mesh.
array has zero length. array has zero length.
*/ */
/* enable_if to avoid clash with overloaded function below */ /* enable_if to avoid clash with overloaded function below */
template<class T, class ...U> inline typename std::enable_if<!std::is_convertible<T, Mesh*>::value, std::tuple<size_t, size_t, char*>>::type interleave(const T& attribute, const U&... attributes) { template<class T, class ...U> inline typename std::enable_if<!std::is_convertible<T, Mesh*>::value, std::tuple<std::size_t, std::size_t, char*>>::type interleave(const T& attribute, const U&... attributes) {
return Implementation::Interleave()(attribute, attributes...); return Implementation::Interleave()(attribute, attributes...);
} }

6
src/MeshTools/Subdivide.h

@ -34,11 +34,11 @@ template<class Vertex, class Interpolator> class Subdivide {
void operator()(Interpolator interpolator) { void operator()(Interpolator interpolator) {
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::subdivide(): index count is not divisible by 3!", ); CORRADE_ASSERT(!(indices.size()%3), "MeshTools::subdivide(): index count is not divisible by 3!", );
size_t indexCount = indices.size(); std::size_t indexCount = indices.size();
indices.reserve(indices.size()*4); indices.reserve(indices.size()*4);
/* Subdivide each face to four new */ /* Subdivide each face to four new */
for(size_t i = 0; i != indexCount; i += 3) { for(std::size_t i = 0; i != indexCount; i += 3) {
/* Interpolate each side */ /* Interpolate each side */
unsigned int newVertices[3]; unsigned int newVertices[3];
for(int j = 0; j != 3; ++j) for(int j = 0; j != 3; ++j)
@ -60,7 +60,7 @@ template<class Vertex, class Interpolator> class Subdivide {
addFace(indices[i], newVertices[0], newVertices[2]); addFace(indices[i], newVertices[0], newVertices[2]);
addFace(newVertices[0], indices[i+1], newVertices[1]); addFace(newVertices[0], indices[i+1], newVertices[1]);
addFace(newVertices[2], newVertices[1], indices[i+2]); addFace(newVertices[2], newVertices[1], indices[i+2]);
for(size_t j = 0; j != 3; ++j) for(std::size_t j = 0; j != 3; ++j)
indices[i+j] = newVertices[j]; indices[i+j] = newVertices[j];
} }
} }

6
src/MeshTools/Test/CleanTest.h

@ -28,13 +28,13 @@ class CleanTest: public Corrade::TestSuite::Tester<CleanTest> {
private: private:
class Vector1 { class Vector1 {
public: public:
static const size_t Size = 1; static const std::size_t Size = 1;
typedef int Type; typedef int Type;
Vector1(): data(0) {} Vector1(): data(0) {}
Vector1(int i): data(i) {} Vector1(int i): data(i) {}
int operator[](size_t) const { return data; } int operator[](std::size_t) const { return data; }
int& operator[](size_t) { return data; } int& operator[](std::size_t) { return data; }
bool operator==(Vector1 i) const { return i.data == data; } bool operator==(Vector1 i) const { return i.data == data; }
Vector1 operator-(Vector1 i) const { return data-i.data; } Vector1 operator-(Vector1 i) const { return data-i.data; }

6
src/MeshTools/Test/SubdivideTest.h

@ -29,13 +29,13 @@ class SubdivideTest: public Corrade::TestSuite::Tester<SubdivideTest> {
private: private:
class Vector1 { class Vector1 {
public: public:
static const size_t Size = 1; static const std::size_t Size = 1;
typedef int Type; typedef int Type;
Vector1(): data(0) {} Vector1(): data(0) {}
Vector1(int i): data(i) {} Vector1(int i): data(i) {}
int operator[](size_t) const { return data; } int operator[](std::size_t) const { return data; }
int& operator[](size_t) { return data; } int& operator[](std::size_t) { return data; }
bool operator==(Vector1 i) const { return i.data == data; } bool operator==(Vector1 i) const { return i.data == data; }
Vector1 operator-(Vector1 i) const { return data-i.data; } Vector1 operator-(Vector1 i) const { return data-i.data; }

2
src/MeshTools/Test/TipsifyTest.h

@ -28,7 +28,7 @@ class TipsifyTest: public Corrade::TestSuite::Tester<TipsifyTest> {
private: private:
std::vector<unsigned int> indices; std::vector<unsigned int> indices;
size_t vertexCount; std::size_t vertexCount;
}; };
}}} }}}

4
src/MeshTools/Tipsify.h

@ -33,7 +33,7 @@ class MESHTOOLS_EXPORT Tipsify {
public: public:
inline Tipsify(std::vector<unsigned int>& indices, unsigned int vertexCount): indices(indices), vertexCount(vertexCount) {} inline Tipsify(std::vector<unsigned int>& indices, unsigned int vertexCount): indices(indices), vertexCount(vertexCount) {}
void operator()(size_t cacheSize); void operator()(std::size_t cacheSize);
/** /**
* @brief Build vertex-triangle adjacency * @brief Build vertex-triangle adjacency
@ -63,7 +63,7 @@ array for beter usage of post-transform vertex cache. Algorithm used:
for Vertex Locality and Reduced Overdraw, SIGGRAPH 2007, for Vertex Locality and Reduced Overdraw, SIGGRAPH 2007,
http://gfx.cs.princeton.edu/pubs/Sander_2007_%3ETR/index.php*. http://gfx.cs.princeton.edu/pubs/Sander_2007_%3ETR/index.php*.
*/ */
inline void tipsify(std::vector<unsigned int>& indices, unsigned int vertexCount, size_t cacheSize) { inline void tipsify(std::vector<unsigned int>& indices, unsigned int vertexCount, std::size_t cacheSize) {
Implementation::Tipsify(indices, vertexCount)(cacheSize); Implementation::Tipsify(indices, vertexCount)(cacheSize);
} }

2
src/MeshTools/Transform.h

@ -34,7 +34,7 @@ std::vector<Point3D> vertices;
MeshTools::transform(Matrix4::scaling({2.0f, 0.5f, 0.0f}), vertices); MeshTools::transform(Matrix4::scaling({2.0f, 0.5f, 0.0f}), vertices);
@endcode @endcode
*/ */
template<size_t size, class T, class U> inline void transform(const Math::Matrix<size, T>& matrix, U& vertices) { template<std::size_t size, class T, class U> inline void transform(const Math::Matrix<size, T>& matrix, U& vertices) {
for(Math::Vector<size, T>& vertex: vertices) for(Math::Vector<size, T>& vertex: vertices)
vertex = matrix*vertex; vertex = matrix*vertex;
} }

8
src/Primitives/Icosphere.h

@ -26,7 +26,7 @@
namespace Magnum { namespace Primitives { namespace Magnum { namespace Primitives {
template<size_t subdivisions> class Icosphere; template<std::size_t subdivisions> class Icosphere;
/** /**
@brief 3D icosphere primitive with zero subdivisions @brief 3D icosphere primitive with zero subdivisions
@ -48,14 +48,14 @@ template<> class Icosphere<0>: public Trade::MeshData3D {
Indexed triangle mesh with normals. Indexed triangle mesh with normals.
*/ */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template<size_t subdivisions> class Icosphere: public Icosphere<0> { template<std::size_t subdivisions> class Icosphere: public Icosphere<0> {
#else #else
template<size_t subdivisions> class Icosphere { template<std::size_t subdivisions> class Icosphere {
#endif #endif
public: public:
/** @brief Constructor */ /** @brief Constructor */
Icosphere() { Icosphere() {
for(size_t i = 0; i != subdivisions; ++i) for(std::size_t i = 0; i != subdivisions; ++i)
MeshTools::subdivide(*indices(), *normals(0), [](const Vector3& a, const Vector3& b) { MeshTools::subdivide(*indices(), *normals(0), [](const Vector3& a, const Vector3& b) {
return (a+b).normalized(); return (a+b).normalized();
}); });

4
src/Profiler.h

@ -115,7 +115,7 @@ class MAGNUM_EXPORT Profiler {
* is 60. * is 60.
* @attention This function cannot be called if profiling is enabled. * @attention This function cannot be called if profiling is enabled.
*/ */
void setMeasureDuration(size_t frames); void setMeasureDuration(std::size_t frames);
/** /**
* @brief Add named section * @brief Add named section
@ -193,7 +193,7 @@ class MAGNUM_EXPORT Profiler {
void save(); void save();
bool enabled; bool enabled;
size_t measureDuration, currentFrame, frameCount; std::size_t measureDuration, currentFrame, frameCount;
std::vector<std::string> sections; std::vector<std::string> sections;
std::vector<std::chrono::high_resolution_clock::duration> frameData; std::vector<std::chrono::high_resolution_clock::duration> frameData;
std::vector<std::chrono::high_resolution_clock::duration> totalData; std::vector<std::chrono::high_resolution_clock::duration> totalData;

24
src/ResourceManager.h

@ -106,7 +106,7 @@ class ResourceKey: public Corrade::Utility::MurmurHash2::Digest {
* @brief Constructor * @brief Constructor
* @todo constexpr * @todo constexpr
*/ */
template<size_t size> inline constexpr ResourceKey(const char(&key)[size]): Corrade::Utility::MurmurHash2::Digest(Corrade::Utility::MurmurHash2()(key)) {} template<std::size_t size> inline constexpr ResourceKey(const char(&key)[size]): Corrade::Utility::MurmurHash2::Digest(Corrade::Utility::MurmurHash2()(key)) {}
}; };
template<class T, class U> class Resource; template<class T, class U> class Resource;
@ -114,8 +114,8 @@ template<class T, class U> class Resource;
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
namespace Implementation { namespace Implementation {
struct ResourceKeyHash { struct ResourceKeyHash {
inline size_t operator()(ResourceKey key) const { inline std::size_t operator()(ResourceKey key) const {
return *reinterpret_cast<const size_t*>(key.byteArray()); return *reinterpret_cast<const std::size_t*>(key.byteArray());
} }
}; };
@ -146,18 +146,18 @@ namespace Implementation {
T* data; T* data;
ResourceDataState state; ResourceDataState state;
ResourcePolicy policy; ResourcePolicy policy;
size_t referenceCount; std::size_t referenceCount;
}; };
inline virtual ~ResourceManagerData() { inline virtual ~ResourceManagerData() {
delete _fallback; delete _fallback;
} }
inline size_t lastChange() const { return _lastChange; } inline std::size_t lastChange() const { return _lastChange; }
inline size_t count() const { return _data.size(); } inline std::size_t count() const { return _data.size(); }
size_t referenceCount(ResourceKey key) const { std::size_t referenceCount(ResourceKey key) const {
auto it = _data.find(key); auto it = _data.find(key);
if(it == _data.end()) return 0; if(it == _data.end()) return 0;
return it->second.referenceCount; return it->second.referenceCount;
@ -243,7 +243,7 @@ namespace Implementation {
private: private:
std::unordered_map<ResourceKey, Data, ResourceKeyHash> _data; std::unordered_map<ResourceKey, Data, ResourceKeyHash> _data;
T* _fallback; T* _fallback;
size_t _lastChange; std::size_t _lastChange;
}; };
} }
#endif #endif
@ -372,7 +372,7 @@ template<class T, class U = T> class Resource {
Implementation::ResourceManagerData<T>* manager; Implementation::ResourceManagerData<T>* manager;
ResourceKey _key; ResourceKey _key;
size_t lastCheck; std::size_t lastCheck;
ResourceState _state; ResourceState _state;
T* data; T* data;
}; };
@ -465,7 +465,7 @@ template<class... Types> class ResourceManager: protected Implementation::Resour
inline ~ResourceManager() { _instance = nullptr; } inline ~ResourceManager() { _instance = nullptr; }
/** @brief Count of resources of given type */ /** @brief Count of resources of given type */
template<class T> inline size_t count() { template<class T> inline std::size_t count() {
return this->Implementation::ResourceManagerData<T>::count(); return this->Implementation::ResourceManagerData<T>::count();
} }
@ -490,7 +490,7 @@ template<class... Types> class ResourceManager: protected Implementation::Resour
* *
* @see set() * @see set()
*/ */
template<class T> inline size_t referenceCount(ResourceKey key) const { template<class T> inline std::size_t referenceCount(ResourceKey key) const {
return this->Implementation::ResourceManagerData<T>::referenceCount(key); return this->Implementation::ResourceManagerData<T>::referenceCount(key);
} }
@ -552,7 +552,7 @@ template<class... Types> class ResourceManager: protected Implementation::Resour
/** @debugoperator{Magnum::ResourceKey} */ /** @debugoperator{Magnum::ResourceKey} */
template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const ResourceKey& value) { template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const ResourceKey& value) {
return debug << static_cast<const Corrade::Utility::HashDigest<sizeof(size_t)>&>(value); return debug << static_cast<const Corrade::Utility::HashDigest<sizeof(std::size_t)>&>(value);
} }
template<class ...Types> ResourceManager<Types...>* ResourceManager<Types...>::_instance(nullptr); template<class ...Types> ResourceManager<Types...>* ResourceManager<Types...>::_instance(nullptr);

10
src/SizeTraits.h

@ -39,7 +39,7 @@ to compute logarithms at compile time, e.g.
`SizeTraits<Log<256, 289>::%value>::%SizeType`. `SizeTraits<Log<256, 289>::%value>::%SizeType`.
*/ */
#ifdef DOXYGEN_GENERATING_OUTPUT #ifdef DOXYGEN_GENERATING_OUTPUT
template<size_t byte> struct SizeTraits { template<std::size_t byte> struct SizeTraits {
/** /**
* @brief (Unsigned) type able to index the data * @brief (Unsigned) type able to index the data
* *
@ -49,7 +49,7 @@ template<size_t byte> struct SizeTraits {
typedef T SizeType; typedef T SizeType;
}; };
#else #else
template<size_t byte> struct SizeTraits: public SizeTraits<byte - 1> {}; template<std::size_t byte> struct SizeTraits: public SizeTraits<byte - 1> {};
#endif #endif
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
@ -75,7 +75,7 @@ template<> struct SizeTraits<4> {
If you have templated function which you want to call with type suitable for If you have templated function which you want to call with type suitable for
indexing data of some size, you will probably use cascade of IFs, like this: indexing data of some size, you will probably use cascade of IFs, like this:
@code @code
size_t dataSize; std::size_t dataSize;
template<class IndexType> Bar foo(Arg1 arg1, Arg2 arg2, ...); template<class IndexType> Bar foo(Arg1 arg1, Arg2 arg2, ...);
Bar bar; Bar bar;
@ -105,7 +105,7 @@ template<class Base> struct SizeBasedCall: public Base {
* @brief Constructor * @brief Constructor
* @param size Data size * @param size Data size
*/ */
SizeBasedCall(size_t size): size(size) {} SizeBasedCall(std::size_t size): size(size) {}
/** /**
* @brief Functor * @brief Functor
@ -132,7 +132,7 @@ template<class Base> struct SizeBasedCall: public Base {
} }
private: private:
size_t size; std::size_t size;
}; };
/** /**

34
src/Swizzle.h

@ -28,29 +28,29 @@ namespace Implementation {
using Math::Implementation::Sequence; using Math::Implementation::Sequence;
using Math::Implementation::GenerateSequence; using Math::Implementation::GenerateSequence;
template<size_t size, size_t position> struct ComponentAtPosition { template<std::size_t size, std::size_t position> struct ComponentAtPosition {
static_assert(size > position, "Swizzle parameter out of range of base vector"); static_assert(size > position, "Swizzle parameter out of range of base vector");
template<class T> inline constexpr static T value(const Math::Vector<size, T>& vector) { return vector[position]; } template<class T> inline constexpr static T value(const Math::Vector<size, T>& vector) { return vector[position]; }
}; };
template<size_t size, char component> struct Component {}; template<std::size_t size, char component> struct Component {};
template<size_t size> struct Component<size, 'x'>: public ComponentAtPosition<size, 0> {}; template<std::size_t size> struct Component<size, 'x'>: public ComponentAtPosition<size, 0> {};
template<size_t size> struct Component<size, 'y'>: public ComponentAtPosition<size, 1> {}; template<std::size_t size> struct Component<size, 'y'>: public ComponentAtPosition<size, 1> {};
template<size_t size> struct Component<size, 'z'>: public ComponentAtPosition<size, 2> {}; template<std::size_t size> struct Component<size, 'z'>: public ComponentAtPosition<size, 2> {};
template<size_t size> struct Component<size, 'w'>: public ComponentAtPosition<size, 3> {}; template<std::size_t size> struct Component<size, 'w'>: public ComponentAtPosition<size, 3> {};
template<size_t size> struct Component<size, 'r'>: public ComponentAtPosition<size, 0> {}; template<std::size_t size> struct Component<size, 'r'>: public ComponentAtPosition<size, 0> {};
template<size_t size> struct Component<size, 'g'>: public ComponentAtPosition<size, 1> {}; template<std::size_t size> struct Component<size, 'g'>: public ComponentAtPosition<size, 1> {};
template<size_t size> struct Component<size, 'b'>: public ComponentAtPosition<size, 2> {}; template<std::size_t size> struct Component<size, 'b'>: public ComponentAtPosition<size, 2> {};
template<size_t size> struct Component<size, 'a'>: public ComponentAtPosition<size, 3> {}; template<std::size_t size> struct Component<size, 'a'>: public ComponentAtPosition<size, 3> {};
template<size_t size> struct Component<size, '0'> { template<std::size_t size> struct Component<size, '0'> {
template<class T> inline constexpr static T value(const Math::Vector<size, T>&) { return T(0); } template<class T> inline constexpr static T value(const Math::Vector<size, T>&) { return T(0); }
}; };
template<size_t size> struct Component<size, '1'> { template<std::size_t size> struct Component<size, '1'> {
template<class T> inline constexpr static T value(const Math::Vector<size, T>&) { return T(1); } template<class T> inline constexpr static T value(const Math::Vector<size, T>&) { return T(1); }
}; };
template<size_t size, class T> struct TypeForSize { template<std::size_t size, class T> struct TypeForSize {
typedef Math::Vector<size, typename T::Type> Type; typedef Math::Vector<size, typename T::Type> Type;
}; };
template<class T> struct TypeForSize<2, T> { typedef Math::Vector2<typename T::Type> Type; }; template<class T> struct TypeForSize<2, T> { typedef Math::Vector2<typename T::Type> Type; };
@ -61,11 +61,11 @@ namespace Implementation {
template<class T> struct TypeForSize<4, Color3<T>> { typedef Color4<T> Type; }; template<class T> struct TypeForSize<4, Color3<T>> { typedef Color4<T> Type; };
template<class T> struct TypeForSize<4, Color4<T>> { typedef Color4<T> Type; }; template<class T> struct TypeForSize<4, Color4<T>> { typedef Color4<T> Type; };
template<size_t size, class T> inline constexpr T componentAtPosition(const Math::Vector<size, T>& vector, size_t position) { template<std::size_t size, class T> inline constexpr T componentAtPosition(const Math::Vector<size, T>& vector, std::size_t position) {
return size > position ? vector[position] : throw; return size > position ? vector[position] : throw;
} }
template<size_t size, class T> inline constexpr T component(const Math::Vector<size, T>& vector, char component) { template<std::size_t size, class T> inline constexpr T component(const Math::Vector<size, T>& vector, char component) {
return component == 'x' ? componentAtPosition(vector, 0) : return component == 'x' ? componentAtPosition(vector, 0) :
component == 'y' ? componentAtPosition(vector, 1) : component == 'y' ? componentAtPosition(vector, 1) :
component == 'z' ? componentAtPosition(vector, 2) : component == 'z' ? componentAtPosition(vector, 2) :
@ -79,7 +79,7 @@ namespace Implementation {
throw; throw;
} }
template<size_t size, class T, size_t ...sequence> inline constexpr Math::Vector<sizeof...(sequence), T> swizzleFrom(Sequence<sequence...>, const Math::Vector<size, T>& vector, const char(&components)[sizeof...(sequence)+1]) { template<std::size_t size, class T, std::size_t ...sequence> inline constexpr Math::Vector<sizeof...(sequence), T> swizzleFrom(Sequence<sequence...>, const Math::Vector<size, T>& vector, const char(&components)[sizeof...(sequence)+1]) {
return {component<size>(vector, components[sequence])...}; return {component<size>(vector, components[sequence])...};
} }
} }
@ -137,7 +137,7 @@ evaluated at compile time, but at runtime.
@see @ref matrix-vector-component-access, Vector4::xyz(), Color4::rgb(), @see @ref matrix-vector-component-access, Vector4::xyz(), Color4::rgb(),
Vector4::xy(), Vector3::xy() Vector4::xy(), Vector3::xy()
*/ */
template<class T, size_t newSize> inline constexpr typename Implementation::TypeForSize<newSize-1, T>::Type swizzle(const T& vector, const char(&components)[newSize]) { template<class T, std::size_t newSize> inline constexpr typename Implementation::TypeForSize<newSize-1, T>::Type swizzle(const T& vector, const char(&components)[newSize]) {
return Implementation::swizzleFrom(typename Implementation::GenerateSequence<newSize-1>::Type(), vector, components); return Implementation::swizzleFrom(typename Implementation::GenerateSequence<newSize-1>::Type(), vector, components);
} }

2
src/Test/ResourceManagerTest.h

@ -25,7 +25,7 @@ namespace Test {
class Data { class Data {
public: public:
static size_t count; static std::size_t count;
inline Data() { ++count; } inline Data() { ++count; }
inline ~Data() { --count; } inline ~Data() { --count; }

58
src/TypeTraits.h

@ -25,8 +25,8 @@
namespace Magnum { namespace Magnum {
namespace Math { namespace Math {
template<size_t, class> class Vector; template<std::size_t, class> class Vector;
template<size_t, class> class Matrix; template<std::size_t, class> class Matrix;
} }
template<class> class Color3; template<class> class Color3;
@ -73,14 +73,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().
*/ */
inline constexpr static size_t size(); inline constexpr static std::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.
*/ */
inline constexpr static size_t count(); inline constexpr static std::size_t count();
}; };
#else #else
template<class T> struct TypeTraits {}; template<class T> struct TypeTraits {};
@ -137,11 +137,11 @@ struct MAGNUM_EXPORT TypeInfo {
* These two lines provide the same information, one at compile time, * These two lines provide the same information, one at compile time,
* one at runtime: * one at runtime:
* @code * @code
* size_t size = TypeTraits<TypeOf<Type::UnsignedByte>::size(); * std::size_t size = TypeTraits<TypeOf<Type::UnsignedByte>::size();
* size_t size = TypeInfo::sizeOf(Type::UnsignedByte); * std::size_t size = TypeInfo::sizeOf(Type::UnsignedByte);
* @endcode * @endcode
*/ */
static size_t sizeOf(Type type); static std::size_t sizeOf(Type type);
/** /**
* @brief Whether the type is integral * @brief Whether the type is integral
@ -169,56 +169,56 @@ 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; }
inline constexpr static size_t size() { return sizeof(GLubyte); } inline constexpr static std::size_t size() { return sizeof(GLubyte); }
inline constexpr static size_t count() { return 1; } inline constexpr static std::size_t count() { return 1; }
}; };
template<> struct TypeTraits<GLbyte>: public Math::MathTypeTraits<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; }
inline constexpr static size_t size() { return sizeof(GLbyte); } inline constexpr static std::size_t size() { return sizeof(GLbyte); }
inline constexpr static size_t count() { return 1; } inline constexpr static std::size_t count() { return 1; }
}; };
template<> struct TypeTraits<GLushort>: public Math::MathTypeTraits<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; }
inline constexpr static size_t size() { return sizeof(GLushort); } inline constexpr static std::size_t size() { return sizeof(GLushort); }
inline constexpr static size_t count() { return 1; } inline constexpr static std::size_t count() { return 1; }
}; };
template<> struct TypeTraits<GLshort>: public Math::MathTypeTraits<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; }
inline constexpr static size_t size() { return sizeof(GLshort); } inline constexpr static std::size_t size() { return sizeof(GLshort); }
inline constexpr static size_t count() { return 1; } inline constexpr static std::size_t count() { return 1; }
}; };
template<> struct TypeTraits<GLuint>: public Math::MathTypeTraits<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; }
inline constexpr static size_t size() { return sizeof(GLuint); } inline constexpr static std::size_t size() { return sizeof(GLuint); }
inline constexpr static size_t count() { return 1; } inline constexpr static std::size_t count() { return 1; }
}; };
template<> struct TypeTraits<GLint>: public Math::MathTypeTraits<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; }
inline constexpr static size_t size() { return sizeof(GLint); } inline constexpr static std::size_t size() { return sizeof(GLint); }
inline constexpr static size_t count() { return 1; } inline constexpr static std::size_t count() { return 1; }
}; };
template<> struct TypeTraits<GLfloat>: public Math::MathTypeTraits<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; }
inline constexpr static size_t size() { return sizeof(GLfloat); } inline constexpr static std::size_t size() { return sizeof(GLfloat); }
inline constexpr static size_t count() { return 1; } inline constexpr static std::size_t count() { return 1; }
}; };
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
@ -226,17 +226,17 @@ 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 */
inline constexpr static size_t size() { return sizeof(GLdouble); } inline constexpr static std::size_t size() { return sizeof(GLdouble); }
inline constexpr static size_t count() { return 1; } inline constexpr static std::size_t count() { return 1; }
}; };
#endif #endif
template<class T, size_t vectorSize> struct TypeTraits<Math::Vector<vectorSize, T>> { template<class T, std::size_t vectorSize> struct TypeTraits<Math::Vector<vectorSize, T>> {
inline constexpr static Type type() { return TypeTraits<T>::type(); } inline constexpr static Type type() { return TypeTraits<T>::type(); }
/* Can not be used for indices */ /* Can not be used for indices */
/* Can not be used for images */ /* Can not be used for images */
inline constexpr static size_t size() { return sizeof(T); } inline constexpr static std::size_t size() { return sizeof(T); }
inline constexpr static size_t count() { return vectorSize; } inline constexpr static std::size_t count() { return vectorSize; }
}; };
template<class T> struct TypeTraits<Math::Vector2<T>>: public TypeTraits<Math::Vector<2, T>> {}; template<class T> struct TypeTraits<Math::Vector2<T>>: public TypeTraits<Math::Vector<2, T>> {};
@ -247,12 +247,12 @@ template<class T> struct TypeTraits<Math::Point3D<T>>: public TypeTraits<Math::V
template<class T> struct TypeTraits<Color3<T>>: public TypeTraits<Math::Vector<3, T>> {}; template<class T> struct TypeTraits<Color3<T>>: public TypeTraits<Math::Vector<3, T>> {};
template<class T> struct TypeTraits<Color4<T>>: public TypeTraits<Math::Vector<4, T>> {}; template<class T> struct TypeTraits<Color4<T>>: public TypeTraits<Math::Vector<4, T>> {};
template<class T, size_t matrixSize> struct TypeTraits<Math::Matrix<matrixSize, T>> { template<class T, std::size_t matrixSize> struct TypeTraits<Math::Matrix<matrixSize, T>> {
inline constexpr static Type type() { return TypeTraits<T>::type(); } inline constexpr static Type type() { return TypeTraits<T>::type(); }
/* Can not be used for indices */ /* Can not be used for indices */
/* Can not be used for images */ /* Can not be used for images */
inline constexpr static size_t size() { return sizeof(T); } inline constexpr static std::size_t size() { return sizeof(T); }
inline constexpr static size_t count() { return matrixSize*matrixSize; } inline constexpr static std::size_t count() { return matrixSize*matrixSize; }
}; };
template<class T> struct TypeTraits<Math::Matrix3<T>>: public TypeTraits<Math::Matrix<3, T>> {}; template<class T> struct TypeTraits<Math::Matrix3<T>>: public TypeTraits<Math::Matrix<3, T>> {};

Loading…
Cancel
Save