Make all array constructors explicit (#99)

* Make all array constructors explicit

to avoid accidental implicit casts like e.g.
Vector3f v = 0;
assigning nullpointer content.
This commit is contained in:
Matthias Grob
2019-10-03 13:38:51 +02:00
committed by Julian Kent
parent 7b34c1c51d
commit 740324cf1e
9 changed files with 24 additions and 14 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ public:
*
* @param data_ array
*/
AxisAngle(const Type data_[3]) :
explicit AxisAngle(const Type data_[3]) :
Vector<Type, 3>(data_)
{
}
+10 -1
View File
@@ -56,7 +56,16 @@ public:
*
* @param _data pointer to array
*/
Dcm(const Type *data_) : SquareMatrix<Type, 3>(data_)
explicit Dcm(const Type data_[3][3]) : SquareMatrix<Type, 3>(data_)
{
}
/**
* Constructor from array
*
* @param _data pointer to array
*/
explicit Dcm(const Type data_[3*3]) : SquareMatrix<Type, 3>(data_)
{
}
+2 -2
View File
@@ -41,12 +41,12 @@ public:
// Constructors
Matrix() = default;
Matrix(const Type data_[M*N])
explicit Matrix(const Type data_[M*N])
{
memcpy(_data, data_, sizeof(_data));
}
Matrix(const Type data_[M][N])
explicit Matrix(const Type data_[M][N])
{
memcpy(_data, data_, sizeof(_data));
}
+1 -1
View File
@@ -61,7 +61,7 @@ public:
*
* @param data_ array
*/
Quaternion(const Type data_[4]) :
explicit Quaternion(const Type data_[4]) :
Vector<Type, 4>(data_)
{
}
+6 -1
View File
@@ -28,7 +28,12 @@ class SquareMatrix : public Matrix<Type, M, M>
public:
SquareMatrix() = default;
SquareMatrix(const Type data_[M][M]) :
explicit SquareMatrix(const Type data_[M][M]) :
Matrix<Type, M, M>(data_)
{
}
explicit SquareMatrix(const Type data_[M*M]) :
Matrix<Type, M, M>(data_)
{
}
+1 -1
View File
@@ -29,7 +29,7 @@ public:
{
}
Vector(const Type data_[M]) :
explicit Vector(const Type data_[M]) :
MatrixM1(data_)
{
}
+1 -1
View File
@@ -31,7 +31,7 @@ public:
{
}
Vector2(const Type data_[2]) :
explicit Vector2(const Type data_[2]) :
Vector<Type, 2>(data_)
{
}
+1 -1
View File
@@ -39,7 +39,7 @@ public:
{
}
Vector3(const Type data_[3]) :
explicit Vector3(const Type data_[3]) :
Vector<Type, 3>(data_)
{
}
+1 -5
View File
@@ -4,11 +4,10 @@
using namespace matrix;
namespace matrix {
// manually instantiated all files we intend to test
// so that coverage works correctly
// doesn't matter what test this is in
namespace matrix {
template class Matrix<float, 3, 3>;
template class Vector3<float>;
template class Vector2<float>;
@@ -17,13 +16,10 @@ template class Quaternion<float>;
template class AxisAngle<float>;
template class Scalar<float>;
template class SquareMatrix<float, 4>;
}
int main()
{
// check data
Eulerf euler_check(0.1f, 0.2f, 0.3f);
Quatf q_check(0.98334744f, 0.0342708f, 0.10602051f, .14357218f);