Skip to content

Commit

Permalink
Make all array constructors explicit (#99)
Browse files Browse the repository at this point in the history
* Make all array constructors explicit

to avoid accidental implicit casts like e.g.
Vector3f v = 0;
assigning nullpointer content.
  • Loading branch information
MaEtUgR authored and Julian Kent committed Oct 3, 2019
1 parent 7b34c1c commit 740324c
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion matrix/AxisAngle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AxisAngle : public Vector<Type, 3>
*
* @param data_ array
*/
AxisAngle(const Type data_[3]) :
explicit AxisAngle(const Type data_[3]) :
Vector<Type, 3>(data_)
{
}
Expand Down
11 changes: 10 additions & 1 deletion matrix/Dcm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ class Dcm : public SquareMatrix<Type, 3>
*
* @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_)
{
}

Expand Down
4 changes: 2 additions & 2 deletions matrix/Matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ class Matrix
// 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));
}
Expand Down
2 changes: 1 addition & 1 deletion matrix/Quaternion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Quaternion : public Vector<Type, 4>
*
* @param data_ array
*/
Quaternion(const Type data_[4]) :
explicit Quaternion(const Type data_[4]) :
Vector<Type, 4>(data_)
{
}
Expand Down
7 changes: 6 additions & 1 deletion matrix/SquareMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
{
}
Expand Down
2 changes: 1 addition & 1 deletion matrix/Vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Vector : public Matrix<Type, M, 1>
{
}

Vector(const Type data_[M]) :
explicit Vector(const Type data_[M]) :
MatrixM1(data_)
{
}
Expand Down
2 changes: 1 addition & 1 deletion matrix/Vector2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Vector2 : public Vector<Type, 2>
{
}

Vector2(const Type data_[2]) :
explicit Vector2(const Type data_[2]) :
Vector<Type, 2>(data_)
{
}
Expand Down
2 changes: 1 addition & 1 deletion matrix/Vector3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Vector3 : public Vector<Type, 3>
{
}

Vector3(const Type data_[3]) :
explicit Vector3(const Type data_[3]) :
Vector<Type, 3>(data_)
{
}
Expand Down
6 changes: 1 addition & 5 deletions test/attitude.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand All @@ -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);
Expand Down

0 comments on commit 740324c

Please sign in to comment.