From db0f6534c341b7be56be508c010e66e2602bf4f0 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 20 Aug 2023 14:54:51 +0200 Subject: [PATCH] Base: modernize C++: use equals default --- src/Base/Axis.cpp | 20 +--------- src/Base/Axis.h | 10 +++-- src/Base/Builder3D.cpp | 4 +- src/Base/Exception.cpp | 18 +-------- src/Base/Exception.h | 2 +- src/Base/Placement.cpp | 19 ++------- src/Base/Placement.h | 8 ++-- src/Base/Tools2D.h | 88 ++++++++++++------------------------------ src/Base/Tools3D.cpp | 29 -------------- src/Base/Tools3D.h | 10 +++-- src/Base/Type.cpp | 25 ------------ src/Base/Type.h | 22 ++++------- 12 files changed, 57 insertions(+), 198 deletions(-) diff --git a/src/Base/Axis.cpp b/src/Base/Axis.cpp index 0f4ac79bbf..6b615cece2 100644 --- a/src/Base/Axis.cpp +++ b/src/Base/Axis.cpp @@ -26,18 +26,10 @@ using namespace Base; -Axis::Axis() = default; - -Axis::Axis(const Axis& that) -{ - this->_base = that._base; - this->_dir = that._dir; -} - Axis::Axis(const Vector3d& Orig, const Vector3d& Dir) + : _base{Orig} + , _dir{Dir} { - this->_base = Orig; - this->_dir = Dir; } void Axis::reverse() @@ -80,11 +72,3 @@ Axis Axis::operator *(const Placement &p) const a *= p; return a; } - -Axis& Axis::operator = (const Axis &New) -{ - this->_base = New._base; - this->_dir = New._dir; - return *this; -} - diff --git a/src/Base/Axis.h b/src/Base/Axis.h index 4adf3d3944..3a2b963c38 100644 --- a/src/Base/Axis.h +++ b/src/Base/Axis.h @@ -36,8 +36,9 @@ class BaseExport Axis { public: /// default constructor - Axis(); - Axis(const Axis&); + Axis() = default; + Axis(const Axis&) = default; + Axis(Axis&&) = default; Axis(const Vector3d& Orig, const Vector3d& Dir); /// Destruction ~Axis () = default; @@ -57,10 +58,11 @@ public: Axis operator *(const Placement &p) const; bool operator ==(const Axis&) const; bool operator !=(const Axis&) const; - Axis& operator =(const Axis&); + Axis& operator =(const Axis&) = default; + Axis& operator =(Axis&&) = default; //@} -protected: +private: Vector3d _base; Vector3d _dir; }; diff --git a/src/Base/Builder3D.cpp b/src/Base/Builder3D.cpp index 25cfe518ba..391cc2ceb3 100644 --- a/src/Base/Builder3D.cpp +++ b/src/Base/Builder3D.cpp @@ -918,9 +918,7 @@ InventorBuilder::InventorBuilder(std::ostream& output) result << "#Inventor V2.1 ascii \n\n"; } -InventorBuilder:: ~InventorBuilder() -{ -} +InventorBuilder:: ~InventorBuilder() = default; void InventorBuilder::increaseIndent() { diff --git a/src/Base/Exception.cpp b/src/Base/Exception.cpp index 068cc3d1e4..a1a74e174e 100644 --- a/src/Base/Exception.cpp +++ b/src/Base/Exception.cpp @@ -45,16 +45,7 @@ Exception::Exception() _sErrMsg = "FreeCAD Exception"; } -Exception::Exception(const Exception &inst) - : BaseClass(inst) - , _sErrMsg(inst._sErrMsg) - , _file(inst._file) - , _line(inst._line) - , _function(inst._function) - , _isTranslatable(inst._isTranslatable) - , _isReported(inst._isReported) -{ -} +Exception::Exception(const Exception &inst) = default; Exception::Exception(const char * sMessage) : _sErrMsg(sMessage) @@ -282,13 +273,6 @@ FileException::FileException() _sErrMsgAndFileName = _sErrMsg; } -FileException::FileException(const FileException &inst) - : Exception(inst._sErrMsg.c_str()) - , file(inst.file) - , _sErrMsgAndFileName(inst._sErrMsgAndFileName.c_str()) -{ -} - void FileException::setFileName(const char * sFileName) { file.setFile(sFileName); diff --git a/src/Base/Exception.h b/src/Base/Exception.h index 818355ce7d..a36a047ff3 100644 --- a/src/Base/Exception.h +++ b/src/Base/Exception.h @@ -245,7 +245,7 @@ public: /// standard construction FileException(); /// Construction - FileException(const FileException &inst); + FileException(const FileException&) = default; /// Destruction ~FileException() noexcept override = default; /// Assignment operator diff --git a/src/Base/Placement.cpp b/src/Base/Placement.cpp index 36bb98c438..d2e3bcf729 100644 --- a/src/Base/Placement.cpp +++ b/src/Base/Placement.cpp @@ -36,24 +36,18 @@ Placement::Placement(const Base::Matrix4D& matrix) fromMatrix(matrix); } -Placement::Placement(const Placement& that) -{ - this->_pos = that._pos; - this->_rot = that._rot; -} - Placement::Placement(const Vector3d& Pos, const Rotation &Rot) + : _pos(Pos) + , _rot(Rot) { - this->_pos = Pos; - this->_rot = Rot; } Placement::Placement(const Vector3d& Pos, const Rotation &Rot, const Vector3d& Cnt) + : _rot(Rot) { Vector3d RotC = Cnt; Rot.multVec(RotC, RotC); this->_pos = Pos + Cnt - RotC; - this->_rot = Rot; } Placement Placement::fromDualQuaternion(DualQuat qq) @@ -161,13 +155,6 @@ Placement Placement::operator*(const Placement & p) const return plm; } -Placement& Placement::operator = (const Placement& New) -{ - this->_pos = New._pos; - this->_rot = New._rot; - return *this; -} - Placement Placement::pow(double t, bool shorten) const { return Placement::fromDualQuaternion(this->toDualQuaternion().pow(t, shorten)); diff --git a/src/Base/Placement.h b/src/Base/Placement.h index f4c5b9d76d..c4f835f8ef 100644 --- a/src/Base/Placement.h +++ b/src/Base/Placement.h @@ -40,7 +40,8 @@ class BaseExport Placement public: /// default constructor Placement(); - Placement(const Placement&); + Placement(const Placement&) = default; + Placement(Placement&&) = default; Placement(const Base::Matrix4D& matrix); Placement(const Vector3d& Pos, const Rotation &Rot); Placement(const Vector3d& Pos, const Rotation &Rot, const Vector3d& Cnt); @@ -76,7 +77,8 @@ public: Placement operator *(const Placement & p) const; bool operator == (const Placement&) const; bool operator != (const Placement&) const; - Placement& operator = (const Placement&); + Placement& operator = (const Placement&) = default; + Placement& operator = (Placement&&) = default; Placement pow(double t, bool shorten = true) const; Placement& multRight(const Base::Placement& p); @@ -89,7 +91,7 @@ public: static Placement slerp(const Placement & p0, const Placement & p1, double t); static Placement sclerp(const Placement & p0, const Placement & p1, double t, bool shorten = true); -protected: +private: Vector3 _pos; Base::Rotation _rot; }; diff --git a/src/Base/Tools2D.h b/src/Base/Tools2D.h index 913fb24883..d2a2b39098 100644 --- a/src/Base/Tools2D.h +++ b/src/Base/Tools2D.h @@ -54,10 +54,13 @@ public: inline Vector2d(); inline Vector2d(float x, float y); inline Vector2d(double x, double y); - inline Vector2d(const Vector2d &v); + inline Vector2d(const Vector2d&) = default; + inline Vector2d(Vector2d&&) = default; + ~Vector2d() = default; // operators - inline Vector2d& operator= (const Vector2d &v); + inline Vector2d& operator= (const Vector2d&) = default; + inline Vector2d& operator= (Vector2d&&) = default; inline bool operator== (const Vector2d &v) const; inline Vector2d operator+ () const; inline Vector2d operator+ (const Vector2d &v) const; @@ -104,13 +107,16 @@ public: double MinX, MinY, MaxX, MaxY; inline BoundBox2d (); - inline BoundBox2d (const BoundBox2d &rclBB); + inline BoundBox2d (const BoundBox2d&) = default; + inline BoundBox2d (BoundBox2d&&) = default; inline BoundBox2d (double fX1, double fY1, double fX2, double fY2); + ~BoundBox2d() = default; inline bool IsValid (); inline bool IsEqual(const BoundBox2d&, double tolerance) const; // operators - inline BoundBox2d& operator= (const BoundBox2d& rclBB); + inline BoundBox2d& operator= (const BoundBox2d&) = default; + inline BoundBox2d& operator= (BoundBox2d&&) = default; inline bool operator== (const BoundBox2d& rclBB) const; // methods @@ -139,7 +145,9 @@ public: Vector2d clV1, clV2; Line2d () = default; - inline Line2d (const Line2d &rclLine); + ~Line2d () = default; + inline Line2d (const Line2d&) = default; + inline Line2d (Line2d&&) = default; inline Line2d (const Vector2d &rclV1, const Vector2d &rclV2); // methods @@ -147,7 +155,8 @@ public: BoundBox2d CalcBoundBox () const; // operators - inline Line2d& operator= (const Line2d& rclLine); + inline Line2d& operator= (const Line2d&) = default; + inline Line2d& operator= (Line2d&&) = default; inline bool operator== (const Line2d& rclLine) const; // misc @@ -167,10 +176,12 @@ class BaseExport Polygon2d { public: Polygon2d () = default; - inline Polygon2d (const Polygon2d &rclPoly); - virtual ~Polygon2d () = default; + inline Polygon2d (const Polygon2d&) = default; + inline Polygon2d (Polygon2d&&) = default; + ~Polygon2d () = default; inline Polygon2d& operator = (const Polygon2d &rclP); + inline Polygon2d& operator = (Polygon2d &&rclP); // admin-interface inline size_t GetCtVectors () const; @@ -210,18 +221,6 @@ inline Vector2d::Vector2d(double x, double y) { } -inline Vector2d::Vector2d(const Vector2d &v) -: x(v.x), y(v.y) -{ -} - -inline Vector2d& Vector2d::operator= (const Vector2d &v) -{ - x = v.x; - y = v.y; - return *this; -} - inline bool Vector2d::operator== (const Vector2d &v) const { return (x == v.x) && (y == v.y); @@ -381,16 +380,9 @@ inline bool Vector2d::IsEqual(const Vector2d& v, double tolerance) const // ======================================== -inline Polygon2d::Polygon2d (const Polygon2d &rclPoly) -{ - *this = rclPoly; -} +inline Polygon2d& Polygon2d::operator = (const Polygon2d &rclP) = default; -inline Polygon2d& Polygon2d::operator = (const Polygon2d &rclP) -{ - _aclVct = rclP._aclVct; - return *this; -} +inline Polygon2d& Polygon2d::operator = (Polygon2d &&rclP) = default; inline void Polygon2d::DeleteAll () { @@ -442,12 +434,6 @@ inline Vector2d& Polygon2d::At (size_t ulNdx) } -inline Line2d::Line2d (const Line2d &rclLine) - : clV1 (rclLine.clV1), - clV2 (rclLine.clV2) -{ -} - inline Line2d::Line2d (const Vector2d &rclV1, const Vector2d &rclV2) : clV1 (rclV1), clV2 (rclV2) { @@ -458,13 +444,6 @@ inline double Line2d::Length () const return (clV2 - clV1).Length (); } -inline Line2d& Line2d::operator= (const Line2d& rclLine) -{ - clV1 = rclLine.clV1; - clV2 = rclLine.clV2; - return *this; -} - inline bool Line2d::operator== (const Line2d& rclLine) const { return (clV1 == rclLine.clV1) && (clV2 == rclLine.clV2); @@ -481,20 +460,12 @@ inline BoundBox2d::BoundBox2d () MaxX = MaxY = - DOUBLE_MAX; } -inline BoundBox2d::BoundBox2d (const BoundBox2d &rclBB) - : MinX (rclBB.MinX), - MinY (rclBB.MinY), - MaxX (rclBB.MaxX), - MaxY (rclBB.MaxY) -{ -} - inline BoundBox2d::BoundBox2d (double fX1, double fY1, double fX2, double fY2) + : MinX(std::min(fX1, fX2)) + , MinY(std::min(fY1, fY2)) + , MaxX(std::max(fX1, fX2)) + , MaxY(std::max(fY1, fY2)) { - MinX = std::min(fX1, fX2); - MaxX = std::max(fX1, fX2); - MinY = std::min(fY1, fY2); - MaxY = std::max(fY1, fY2); } inline bool BoundBox2d::IsValid () @@ -508,15 +479,6 @@ inline bool BoundBox2d::IsEqual(const BoundBox2d& b, double tolerance) const Vector2d(MaxX, MaxY).IsEqual(Vector2d(b.MaxX, b.MaxY), tolerance); } -inline BoundBox2d& BoundBox2d::operator= (const BoundBox2d& rclBB) -{ - MinX = rclBB.MinX; - MinY = rclBB.MinY; - MaxX = rclBB.MaxX; - MaxY = rclBB.MaxY; - return *this; -} - inline bool BoundBox2d::operator== (const BoundBox2d& rclBB) const { return (MinX == rclBB.MinX) && diff --git a/src/Base/Tools3D.cpp b/src/Base/Tools3D.cpp index af9694b251..b58aedb454 100644 --- a/src/Base/Tools3D.cpp +++ b/src/Base/Tools3D.cpp @@ -34,19 +34,6 @@ using namespace Base; -template -Line3::Line3(const Line3& line) - : p1(line.p1) - , p2(line.p2) -{ -} - -template -Line3::Line3(Line3&& line) -{ - *this = std::move(line); -} - template Line3::Line3(const Vector3& p1, const Vector3& p2) : p1(p1) @@ -54,22 +41,6 @@ Line3::Line3(const Vector3& p1, const Vector3 -Line3& Line3::operator= (const Line3& line) -{ - p1 = line.p1; - p2 = line.p2; - return *this; -} - -template -Line3& Line3::operator= (Line3&& line) -{ - p1 = std::move(line.p1); - p2 = std::move(line.p2); - return *this; -} - template bool Line3::operator== (const Line3& line) const { diff --git a/src/Base/Tools3D.h b/src/Base/Tools3D.h index 7c57d33be1..8bf7d14e95 100644 --- a/src/Base/Tools3D.h +++ b/src/Base/Tools3D.h @@ -58,13 +58,13 @@ public: Line3() = default; ~Line3() = default; - Line3(const Line3& line); - Line3(Line3&& line); + Line3(const Line3& line) = default; + Line3(Line3&& line) = default; Line3(const Vector3& p1, const Vector3& p2); // operators - Line3& operator= (const Line3& line); - Line3& operator= (Line3&& line); + Line3& operator= (const Line3& line) = default; + Line3& operator= (Line3&& line) = default; bool operator== (const Line3& line) const; // methods @@ -111,8 +111,10 @@ public: Polygon3() = default; ~Polygon3() = default; Polygon3(const Polygon3& poly) = default; + Polygon3(Polygon3&& poly) = default; Polygon3& operator = (const Polygon3& poly) = default; + Polygon3& operator = (Polygon3&& poly) = default; size_t GetSize() const; void Add (const Vector3& p); diff --git a/src/Base/Type.cpp b/src/Base/Type.cpp index 247d74b0ae..64c205cdfe 100644 --- a/src/Base/Type.cpp +++ b/src/Base/Type.cpp @@ -55,31 +55,6 @@ map Type::typemap; vector Type::typedata; set Type::loadModuleSet; -//************************************************************************** -// Construction/Destruction - -/** - * A constructor. - * A more elaborate description of the constructor. - */ -Type::Type() -: index(0) -{ -} - - -Type::Type(const Type& type) -:index(type.index) -{ -} - - -/** - * A destructor. - * A more elaborate description of the destructor. - */ -Type::~Type() = default; - void *Type::createInstance() { instantiationMethod method = typedata[index]->instMethod; diff --git a/src/Base/Type.h b/src/Base/Type.h index 60c9f990ec..23e5d1c233 100644 --- a/src/Base/Type.h +++ b/src/Base/Type.h @@ -81,10 +81,11 @@ class BaseExport Type { public: /// Construction - Type(const Type& type); - Type(); + Type(const Type& type) = default; + Type(Type&& type) = default; + Type() = default; /// Destruction - virtual ~Type(); + ~Type() = default; /// creates a instance of this type void *createInstance(); @@ -111,7 +112,8 @@ public: unsigned int getKey() const; bool isBad() const; - void operator = (const Type type); + Type& operator = (const Type& type) = default; + Type& operator = (Type&& type) = default; bool operator == (const Type type) const; bool operator != (const Type type) const; @@ -129,14 +131,10 @@ protected: private: - - - unsigned int index; - + unsigned int index{0}; static std::map typemap; static std::vector typedata; - static std::set loadModuleSet; }; @@ -154,12 +152,6 @@ Type::operator != (const Type type) const return (this->getKey() != type.getKey()); } -inline void -Type::operator = (const Type type) -{ - this->index = type.getKey(); -} - inline bool Type::operator == (const Type type) const {