Browse Source

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.
master
Matthias Grob 5 years ago committed by Julian Kent
parent
commit
740324cf1e
  1. 2
      matrix/AxisAngle.hpp
  2. 11
      matrix/Dcm.hpp
  3. 4
      matrix/Matrix.hpp
  4. 2
      matrix/Quaternion.hpp
  5. 7
      matrix/SquareMatrix.hpp
  6. 2
      matrix/Vector.hpp
  7. 2
      matrix/Vector2.hpp
  8. 2
      matrix/Vector3.hpp
  9. 6
      test/attitude.cpp

2
matrix/AxisAngle.hpp

@ -37,7 +37,7 @@ public:
* *
* @param data_ array * @param data_ array
*/ */
AxisAngle(const Type data_[3]) : explicit AxisAngle(const Type data_[3]) :
Vector<Type, 3>(data_) Vector<Type, 3>(data_)
{ {
} }

11
matrix/Dcm.hpp

@ -56,7 +56,16 @@ public:
* *
* @param _data pointer to array * @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_)
{ {
} }

4
matrix/Matrix.hpp

@ -41,12 +41,12 @@ public:
// Constructors // Constructors
Matrix() = default; Matrix() = default;
Matrix(const Type data_[M*N]) explicit Matrix(const Type data_[M*N])
{ {
memcpy(_data, data_, sizeof(_data)); memcpy(_data, data_, sizeof(_data));
} }
Matrix(const Type data_[M][N]) explicit Matrix(const Type data_[M][N])
{ {
memcpy(_data, data_, sizeof(_data)); memcpy(_data, data_, sizeof(_data));
} }

2
matrix/Quaternion.hpp

@ -61,7 +61,7 @@ public:
* *
* @param data_ array * @param data_ array
*/ */
Quaternion(const Type data_[4]) : explicit Quaternion(const Type data_[4]) :
Vector<Type, 4>(data_) Vector<Type, 4>(data_)
{ {
} }

7
matrix/SquareMatrix.hpp

@ -28,7 +28,12 @@ class SquareMatrix : public Matrix<Type, M, M>
public: public:
SquareMatrix() = default; 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_) Matrix<Type, M, M>(data_)
{ {
} }

2
matrix/Vector.hpp

@ -29,7 +29,7 @@ public:
{ {
} }
Vector(const Type data_[M]) : explicit Vector(const Type data_[M]) :
MatrixM1(data_) MatrixM1(data_)
{ {
} }

2
matrix/Vector2.hpp

@ -31,7 +31,7 @@ public:
{ {
} }
Vector2(const Type data_[2]) : explicit Vector2(const Type data_[2]) :
Vector<Type, 2>(data_) Vector<Type, 2>(data_)
{ {
} }

2
matrix/Vector3.hpp

@ -39,7 +39,7 @@ public:
{ {
} }
Vector3(const Type data_[3]) : explicit Vector3(const Type data_[3]) :
Vector<Type, 3>(data_) Vector<Type, 3>(data_)
{ {
} }

6
test/attitude.cpp

@ -4,11 +4,10 @@
using namespace matrix; using namespace matrix;
namespace matrix {
// manually instantiated all files we intend to test // manually instantiated all files we intend to test
// so that coverage works correctly // so that coverage works correctly
// doesn't matter what test this is in // doesn't matter what test this is in
namespace matrix {
template class Matrix<float, 3, 3>; template class Matrix<float, 3, 3>;
template class Vector3<float>; template class Vector3<float>;
template class Vector2<float>; template class Vector2<float>;
@ -17,13 +16,10 @@ template class Quaternion<float>;
template class AxisAngle<float>; template class AxisAngle<float>;
template class Scalar<float>; template class Scalar<float>;
template class SquareMatrix<float, 4>; template class SquareMatrix<float, 4>;
} }
int main() int main()
{ {
// check data // check data
Eulerf euler_check(0.1f, 0.2f, 0.3f); Eulerf euler_check(0.1f, 0.2f, 0.3f);
Quatf q_check(0.98334744f, 0.0342708f, 0.10602051f, .14357218f); Quatf q_check(0.98334744f, 0.0342708f, 0.10602051f, .14357218f);

Loading…
Cancel
Save