Skip to content

Commit

Permalink
Implement rule of zero (#614)
Browse files Browse the repository at this point in the history
* Implement rule of zero
* Declare all special member functions as defaulted in SignalStatistic

---------

Signed-off-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
azeey authored Aug 6, 2024
1 parent f8c53b0 commit 00deb01
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 312 deletions.
12 changes: 0 additions & 12 deletions include/gz/math/Color.hh
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,6 @@ namespace gz::math
this->Clamp();
}

/// \brief Copy Constructor
/// \param[in] _clr Color to copy
public: Color(const Color &_clr) = default;

/// \brief Destructor
public: ~Color() = default;

/// \brief Reset the color to default values to red=0, green=0,
/// blue=0, alpha=1.
public: void Reset();
Expand Down Expand Up @@ -147,11 +140,6 @@ namespace gz::math
/// \param[in] _v value
public: void SetFromYUV(const float _y, const float _u, const float _v);

/// \brief Equal operator
/// \param[in] _pt Color to copy
/// \return Reference to this color
public: Color &operator=(const Color &_pt) = default;

/// \brief Array index operator
/// \param[in] _index Color component index(0=red, 1=green, 2=blue,
/// 3=alpha)
Expand Down
12 changes: 0 additions & 12 deletions include/gz/math/Inertial.hh
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ namespace gz::math
: massMatrix(_massMatrix), pose(_pose), addedMass(_addedMass)
{}

/// \brief Copy constructor.
/// \param[in] _inertial Inertial element to copy
public: Inertial(const Inertial<T> &_inertial) = default;

/// \brief Destructor.
public: ~Inertial() = default;

/// \brief Set the mass and inertia matrix.
///
/// \param[in] _m New MassMatrix3 object.
Expand Down Expand Up @@ -255,11 +248,6 @@ namespace gz::math
return this->massMatrix.SetMoi(R * diag * R.Transposed());
}

/// \brief Equal operator.
/// \param[in] _inertial Inertial to copy.
/// \return Reference to this object.
public: Inertial &operator=(const Inertial<T> &_inertial) = default;

/// \brief Equality comparison operator.
/// \param[in] _inertial Inertial to copy.
/// \return true if each component is equal within a default tolerance,
Expand Down
9 changes: 0 additions & 9 deletions include/gz/math/Line3.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ namespace gz::math
/// \brief Line Constructor
public: Line3() = default;

/// \brief Copy constructor
/// \param[in] _line a line object
public: Line3(const Line3<T> &_line) = default;

/// \brief Constructor.
/// \param[in] _ptA Start point of the line segment
/// \param[in] _ptB End point of the line segment
Expand Down Expand Up @@ -394,11 +390,6 @@ namespace gz::math
return _out;
}

/// \brief Assignment operator
/// \param[in] _line a new value
/// \return this
public: Line3 &operator=(const Line3<T> &_line) = default;

/// \brief Vector for storing the start and end points of the line
private: math::Vector3<T> pts[2];
};
Expand Down
13 changes: 0 additions & 13 deletions include/gz/math/MassMatrix3.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ namespace gz::math
: mass(_mass), Ixxyyzz(_ixxyyzz), Ixyxzyz(_ixyxzyz)
{}

/// \brief Copy constructor.
/// \param[in] _m MassMatrix3 element to copy
public: MassMatrix3(const MassMatrix3<T> &_m) = default;

/// \brief Destructor.
public: ~MassMatrix3() = default;

/// \brief Set the mass.
/// \param[in] _m New mass value.
/// \return True if the MassMatrix3 is valid.
Expand Down Expand Up @@ -251,12 +244,6 @@ namespace gz::math
return this->IsValid();
}

/// \brief Equal operator.
/// \param[in] _massMatrix MassMatrix3 to copy.
/// \return Reference to this object.
public: MassMatrix3 &operator=(const MassMatrix3<T> &_massMatrix)
= default;

/// \brief Equality comparison operator.
/// \param[in] _m MassMatrix3 to copy.
/// \return true if each component is equal within a default tolerance,
Expand Down
12 changes: 0 additions & 12 deletions include/gz/math/Matrix3.hh
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ namespace gz::math
std::memset(this->data, 0, sizeof(this->data[0][0])*9);
}

/// \brief Copy constructor.
/// \param _m Matrix to copy
public: Matrix3(const Matrix3<T> &_m) = default;

/// \brief Construct a matrix3 using nine values.
/// \param[in] _v00 Row 0, Col 0 value
/// \param[in] _v01 Row 0, Col 1 value
Expand Down Expand Up @@ -145,9 +141,6 @@ namespace gz::math
1 - 2 * qt.X()*qt.X() - 2 * qt.Y()*qt.Y());
}

/// \brief Desctructor
public: ~Matrix3() = default;

/// \brief Set a single value.
/// \param[in] _row row index. _row is clamped to the range [0,2]
/// \param[in] _col column index. _col is clamped to the range [0,2]
Expand Down Expand Up @@ -274,11 +267,6 @@ namespace gz::math
this->data[2][c] = _v.Z();
}

/// \brief Equal operator. this = _mat
/// \param _mat Matrix to copy.
/// \return This matrix.
public: Matrix3<T> &operator=(const Matrix3<T> &_mat) = default;

/// \brief Subtraction operator.
/// \param[in] _m Matrix to subtract.
/// \return The element wise difference of two matrices.
Expand Down
12 changes: 0 additions & 12 deletions include/gz/math/Matrix4.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ namespace gz::math
memset(this->data, 0, sizeof(this->data[0][0])*16);
}

/// \brief Copy constructor
/// \param _m Matrix to copy
public: Matrix4(const Matrix4<T> &_m) = default;

/// \brief Constructor
/// \param[in] _v00 Row 0, Col 0 value
/// \param[in] _v01 Row 0, Col 1 value
Expand Down Expand Up @@ -110,9 +106,6 @@ namespace gz::math
this->SetTranslation(_pose.Pos());
}

/// \brief Destructor
public: ~Matrix4() = default;

/// \brief Change the values
/// \param[in] _v00 Row 0, Col 0 value
/// \param[in] _v01 Row 0, Col 1 value
Expand Down Expand Up @@ -539,11 +532,6 @@ namespace gz::math
this->data[0][3], this->data[1][3], this->data[2][3], this->data[3][3]);
}

/// \brief Equal operator. this = _mat
/// \param _mat Incoming matrix
/// \return itself
public: Matrix4<T> &operator=(const Matrix4<T> &_mat) = default;

/// \brief Equal operator for 3x3 matrix
/// \param _mat Incoming matrix
/// \return itself
Expand Down
9 changes: 0 additions & 9 deletions include/gz/math/Matrix6.hh
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ namespace gz::math
memset(this->data, 0, sizeof(this->data[0][0])*MatrixSize*MatrixSize);
}

/// \brief Copy constructor
/// \param _m Matrix to copy
public: Matrix6(const Matrix6<T> &_m) = default;

/// \brief Constructor
/// \param[in] _v00 Row 0, Col 0 value
/// \param[in] _v01 Row 0, Col 1 value
Expand Down Expand Up @@ -294,11 +290,6 @@ namespace gz::math
this->data[5][5]);
}

/// \brief Assignment operator. this = _mat
/// \param _mat Incoming matrix
/// \return itself
public: Matrix6<T> &operator=(const Matrix6<T> &_mat) = default;

/// \brief Multiplication assignment operator. This matrix will
/// become equal to this * _m2.
/// \param[in] _m2 Incoming matrix.
Expand Down
12 changes: 0 additions & 12 deletions include/gz/math/OrientedBox.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ namespace gz::math
{
}

/// \brief Copy constructor.
/// \param[in] _b OrientedBox to copy.
public: OrientedBox(const OrientedBox<T> &_b) = default;

/// \brief Destructor
public: ~OrientedBox() = default;

/// \brief Get the length along the x dimension
/// \return Value of the length in the x dimension
public: T XLength() const
Expand Down Expand Up @@ -137,11 +130,6 @@ namespace gz::math
this->pose = _pose;
}

/// \brief Assignment operator. Set this box to the parameter
/// \param[in] _b OrientedBox to copy
/// \return The new box.
public: OrientedBox &operator=(const OrientedBox<T> &_b) = default;

/// \brief Equality test operator
/// \param[in] _b OrientedBox to test
/// \return True if equal
Expand Down
12 changes: 0 additions & 12 deletions include/gz/math/Plane.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ namespace gz::math
this->Set(_normal, _size, _offset);
}

/// \brief Copy constructor
/// \param[in] _plane Plane to copy
public: Plane(const Plane &_plane) = default;

/// \brief Destructor
public: ~Plane() = default;

/// \brief Set the plane
/// \param[in] _normal The plane normal
/// \param[in] _offset Offset along the normal
Expand Down Expand Up @@ -255,11 +248,6 @@ namespace gz::math
return this->d;
}

/// \brief Equal operator
/// \param _p another plane
/// \return itself
public: Plane<T> &operator=(const Plane<T> &_p) = default;

/// \brief Plane normal
private: Vector3<T> normal;

Expand Down
11 changes: 0 additions & 11 deletions include/gz/math/Pose3.hh
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,6 @@ namespace gz::math
{
}

/// \brief Copy constructor.
/// \param[in] _pose Pose3<T> to copy
public: Pose3(const Pose3<T> &_pose) = default;

/// \brief Destructor.
public: ~Pose3() = default;

/// \brief Set the pose from a Vector3<T> and a Quaternion<T>
/// \param[in] _pos The position.
/// \param[in] _rot The rotation.
Expand Down Expand Up @@ -212,10 +205,6 @@ namespace gz::math
return *this;
}

/// \brief Assignment operator
/// \param[in] _pose Pose3<T> to copy
public: Pose3<T> &operator=(const Pose3<T> &_pose) = default;

/// \brief Add one point to a vector: result = this + pos.
/// \param[in] _pos Position to add to this pose
/// \return The resulting position.
Expand Down
12 changes: 0 additions & 12 deletions include/gz/math/Quaternion.hh
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,6 @@ namespace gz::math
this->SetFromMatrix(_mat);
}

/// \brief Copy constructor. This constructor does not normalize the
/// quaternion.
/// \param[in] _qt Quaternion<T> to copy
public: Quaternion(const Quaternion<T> &_qt) = default;

/// \brief Destructor
public: ~Quaternion() = default;

/// \brief Assignment operator
/// \param[in] _qt Quaternion<T> to copy
public: Quaternion<T> &operator=(const Quaternion<T> &_qt) = default;

/// \brief Invert the quaternion. The quaternion is first normalized,
/// then inverted.
public: void Invert()
Expand Down
63 changes: 26 additions & 37 deletions include/gz/math/SignalStats.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <string>
#include <gz/math/Helpers.hh>
#include <gz/math/config.hh>
#include <gz/utils/ImplPtr.hh>

namespace gz::math
{
Expand All @@ -39,11 +40,29 @@ namespace gz::math
public: SignalStatistic();

/// \brief Destructor
public: virtual ~SignalStatistic();
public: virtual ~SignalStatistic() = default;

// Since we have to declare the destructor virtual, we have to declare the
// all the special member functions as defaulted.
// See https://en.cppreference.com/w/cpp/language/rule_of_three

/// \brief Copy constructor
/// \param[in] _ss SignalStatistic to copy
public: SignalStatistic(const SignalStatistic &_ss);
public: SignalStatistic(const SignalStatistic &_ss) = default;

/// \brief Move constructor
/// \param[in] _ss SignalStatistic to move
public: SignalStatistic(SignalStatistic &&_ss) = default;

/// \brief Assignment operator
/// \param[in] _s A SignalStatistic to copy
/// \return this
public: SignalStatistic &operator=(const SignalStatistic &_s) = default;

/// \brief Move assignment operator
/// \param[in] _s A SignalStatistic to copy
/// \return this
public: SignalStatistic &operator=(SignalStatistic &&_s) = default;

/// \brief Get the current value of the statistical measure.
/// \return Current value of the statistical measure.
Expand All @@ -64,17 +83,11 @@ namespace gz::math
/// \brief Forget all previous data.
public: virtual void Reset();

#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
/// \brief Pointer to private data.
protected: std::unique_ptr<SignalStatisticPrivate> dataPtr;
#ifdef _WIN32
#pragma warning(pop)
#endif
public: class Implementation;
GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
protected: ::gz::utils::ImplPtr<Implementation> dataPtr;
GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
};

/// \class SignalMaximum SignalStats.hh gz/math/SignalStats.hh
Expand Down Expand Up @@ -172,23 +185,13 @@ namespace gz::math
public: virtual void InsertData(const double _data) override;
};

/// \brief Forward declare private data class.
class SignalStatsPrivate;

/// \class SignalStats SignalStats.hh gz/math/SignalStats.hh
/// \brief Collection of statistics for a scalar signal.
class GZ_MATH_VISIBLE SignalStats
{
/// \brief Constructor
public: SignalStats();

/// \brief Destructor
public: ~SignalStats();

/// \brief Copy constructor
/// \param[in] _ss SignalStats to copy
public: SignalStats(const SignalStats &_ss);

/// \brief Get number of data points in first statistic.
/// Technically you can have different numbers of data points
/// in each statistic if you call InsertStatistic after InsertData,
Expand Down Expand Up @@ -229,22 +232,8 @@ namespace gz::math
/// \brief Forget all previous data.
public: void Reset();

/// \brief Assignment operator
/// \param[in] _s A SignalStats to copy
/// \return this
public: SignalStats &operator=(const SignalStats &_s);

#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
/// \brief Pointer to private data.
private: std::unique_ptr<SignalStatsPrivate> dataPtr;
#ifdef _WIN32
#pragma warning(pop)
#endif
GZ_UTILS_IMPL_PTR(dataPtr)
};
} // namespace GZ_MATH_VERSION_NAMESPACE
} // namespace gz::math
Expand Down
Loading

0 comments on commit 00deb01

Please sign in to comment.