From a6624ef264ccd67a71cd9575462c3a23deb86016 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 5 Mar 2022 19:03:21 +0100 Subject: [PATCH] Base: fix warnings from code analysers: * replace some C-style casts with static_cast * remove unneeded destructors * define default copy-constructor and assignment operator --- src/Base/Reader.cpp | 12 ++++-------- src/Base/Reader.h | 1 - src/Base/Uuid.cpp | 4 ++-- src/Base/Uuid.h | 2 ++ src/Base/ViewProj.cpp | 25 ++++++++++++------------- src/Base/ViewProj.h | 9 +++++---- src/Base/Writer.cpp | 10 +++++----- src/Base/Writer.h | 4 ++++ 8 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/Base/Reader.cpp b/src/Base/Reader.cpp index b8b7721f01..033563722d 100644 --- a/src/Base/Reader.cpp +++ b/src/Base/Reader.cpp @@ -113,7 +113,7 @@ const char* Base::XMLReader::localName() const unsigned int Base::XMLReader::getAttributeCount() const { - return (unsigned int)AttrMap.size(); + return static_cast(AttrMap.size()); } long Base::XMLReader::getAttributeAsInteger(const char* AttrName) const @@ -136,7 +136,7 @@ unsigned long Base::XMLReader::getAttributeAsUnsigned(const char* AttrName) cons AttrMapType::const_iterator pos = AttrMap.find(AttrName); if (pos != AttrMap.end()) { - return strtoul(pos->second.c_str(),0,10); + return strtoul(pos->second.c_str(),nullptr,10); } else { // wrong name, use hasAttribute if not sure! @@ -518,12 +518,12 @@ void Base::XMLReader::resetErrors() bool Base::XMLReader::testStatus(ReaderStatus pos) const { - return StatusBits.test((size_t)pos); + return StatusBits.test(static_cast(pos)); } void Base::XMLReader::setStatus(ReaderStatus pos, bool on) { - StatusBits.set((size_t)pos, on); + StatusBits.set(static_cast(pos), on); } void Base::XMLReader::setPartialRestore(bool on) @@ -559,10 +559,6 @@ Base::Reader::Reader(std::istream& str, const std::string& name, int version) { } -Base::Reader::~Reader() -{ -} - std::string Base::Reader::getFileName() const { return this->_name; diff --git a/src/Base/Reader.h b/src/Base/Reader.h index 1b3eb1f42a..0627e45628 100644 --- a/src/Base/Reader.h +++ b/src/Base/Reader.h @@ -296,7 +296,6 @@ class BaseExport Reader : public std::istream { public: Reader(std::istream&, const std::string&, int version); - ~Reader(); std::istream& getStream(); std::string getFileName() const; int getFileVersion() const; diff --git a/src/Base/Uuid.cpp b/src/Base/Uuid.cpp index f2ede80e1c..4968b6a328 100644 --- a/src/Base/Uuid.cpp +++ b/src/Base/Uuid.cpp @@ -65,7 +65,7 @@ std::string Uuid::createUuid() QString uuid = QUuid::createUuid().toString(); uuid = uuid.mid(1); uuid.chop(1); - Uuid = (const char*)uuid.toLatin1(); + Uuid = uuid.toLatin1().constData(); return Uuid; } @@ -79,7 +79,7 @@ void Uuid::setValue(const char* sString) QString id = uuid.toString(); id = id.mid(1); id.chop(1); - _uuid = (const char*)id.toLatin1(); + _uuid = id.toLatin1().constData(); } } diff --git a/src/Base/Uuid.h b/src/Base/Uuid.h index 856b41421b..dadfba5736 100644 --- a/src/Base/Uuid.h +++ b/src/Base/Uuid.h @@ -42,6 +42,8 @@ class BaseExport Uuid public: /// Construction Uuid(); + Uuid(const Uuid&) = default; + Uuid& operator=(const Uuid&) = default; /// Destruction virtual ~Uuid(); diff --git a/src/Base/ViewProj.cpp b/src/Base/ViewProj.cpp index a40039177f..b11278ea66 100644 --- a/src/Base/ViewProj.cpp +++ b/src/Base/ViewProj.cpp @@ -31,6 +31,11 @@ ViewProjMethod::ViewProjMethod() { } +bool ViewProjMethod::isValid() const +{ + return true; +} + /*! Calculate the composed projection matrix which is a product of * projection matrix multiplied with input transformation matrix. */ @@ -82,7 +87,7 @@ ViewProjMatrix::ViewProjMatrix (const Matrix4D &rclMtx) double m31 = _clMtx[3][1]; double m32 = _clMtx[3][2]; double m33 = _clMtx[3][3]; - isOrthographic = (m30 == 0 && m31 == 0 && m32 == 0 && m33 == 1); + isOrthographic = (m30 == 0.0 && m31 == 0.0 && m32 == 0.0 && m33 == 1.0); // Only for orthographic projection mode we can compute a single // matrix performing all steps. @@ -99,10 +104,6 @@ ViewProjMatrix::ViewProjMatrix (const Matrix4D &rclMtx) _clMtxInv.inverseGauss(); } -ViewProjMatrix::~ViewProjMatrix() -{ -} - Matrix4D ViewProjMatrix::getProjectionMatrix () const { // Return the same matrix as passed to the constructor @@ -122,10 +123,12 @@ void perspectiveTransform(const Base::Matrix4D& mat, Vec& pnt) double m31 = mat[3][1]; double m32 = mat[3][2]; double m33 = mat[3][3]; - double w = (pnt.x * m30 + pnt.y * m31 + pnt.z * m32 + m33); + double w = (static_cast(pnt.x) * m30 + + static_cast(pnt.y) * m31 + + static_cast(pnt.z) * m32 + m33); mat.multVec(pnt, pnt); - pnt /= w; + pnt /= static_cast(w); } Vector3f ViewProjMatrix::operator()(const Vector3f& inp) const @@ -137,7 +140,7 @@ Vector3f ViewProjMatrix::operator()(const Vector3f& inp) const if (!isOrthographic) { dst = src; perspectiveTransform(_clMtx, dst); - dst.Set(0.5*dst.x+0.5, 0.5*dst.y+0.5, 0.5*dst.z+0.5); + dst.Set(0.5f*dst.x+0.5f, 0.5f*dst.y+0.5f, 0.5f*dst.z+0.5f); } else { _clMtx.multVec(src, dst); @@ -168,7 +171,7 @@ Vector3f ViewProjMatrix::inverse (const Vector3f& src) const { Vector3f dst; if (!isOrthographic) { - dst.Set(2.0*src.x-1.0, 2.0*src.y-1.0, 2.0*src.z-1.0); + dst.Set(2.0f*src.x-1.0f, 2.0f*src.y-1.0f, 2.0f*src.z-1.0f); perspectiveTransform(_clMtxInv, dst); } else { @@ -201,10 +204,6 @@ ViewOrthoProjMatrix::ViewOrthoProjMatrix (const Matrix4D &rclMtx) _clMtxInv.inverse(); } -ViewOrthoProjMatrix::~ViewOrthoProjMatrix() -{ -} - Matrix4D ViewOrthoProjMatrix::getProjectionMatrix () const { return _clMtx; diff --git a/src/Base/ViewProj.h b/src/Base/ViewProj.h index 1344009b0f..36891f435c 100644 --- a/src/Base/ViewProj.h +++ b/src/Base/ViewProj.h @@ -36,8 +36,11 @@ namespace Base { class BaseExport ViewProjMethod { public: - virtual ~ViewProjMethod(){} - virtual bool isValid() const { return true; } + ViewProjMethod(const ViewProjMethod&) = default; + ViewProjMethod& operator= (const ViewProjMethod&) = default; + virtual ~ViewProjMethod() = default; + + virtual bool isValid() const; /** Convert 3D point to 2D projection plane */ virtual Vector3f operator()(const Vector3f &rclPt) const = 0; /** Convert 3D point to 2D projection plane */ @@ -74,7 +77,6 @@ class BaseExport ViewProjMatrix : public ViewProjMethod { public: ViewProjMatrix (const Matrix4D &rclMtx); - virtual ~ViewProjMatrix(); Vector3f operator()(const Vector3f &rclPt) const; Vector3d operator()(const Vector3d &rclPt) const; @@ -98,7 +100,6 @@ class BaseExport ViewOrthoProjMatrix : public ViewProjMethod { public: ViewOrthoProjMatrix (const Matrix4D &rclMtx); - virtual ~ViewOrthoProjMatrix(); Vector3f operator()(const Vector3f &rclPt) const; Vector3d operator()(const Vector3d &rclPt) const; diff --git a/src/Base/Writer.cpp b/src/Base/Writer.cpp index 1a8bf2cb00..52cb6eb4bb 100644 --- a/src/Base/Writer.cpp +++ b/src/Base/Writer.cpp @@ -78,9 +78,9 @@ void Writer::insertBinFile(const char* FileName) Stream() << " bytes(fileSize); - from.read((char*)&bytes[0], fileSize); - Stream() << Base::base64_encode(&bytes[0], fileSize); + std::vector bytes(static_cast(fileSize)); + from.read(reinterpret_cast(&bytes[0]), fileSize); + Stream() << Base::base64_encode(&bytes[0], static_cast(fileSize)); Stream() << "]]>" << endl; } @@ -265,7 +265,7 @@ void ZipWriter::writeFiles() // processing the files new ones can be added size_t index = 0; while (index < FileList.size()) { - FileEntry entry = FileList.begin()[index]; + FileEntry entry = FileList[index]; ZipStream.putNextEntry(entry.FileName); entry.Object->SaveDocFile(*this); index++; @@ -305,7 +305,7 @@ void FileWriter::writeFiles() size_t index = 0; this->FileStream.close(); while (index < FileList.size()) { - FileEntry entry = FileList.begin()[index]; + FileEntry entry = FileList[index]; if (shouldWrite(entry.FileName, entry.Object)) { std::string filePath = entry.FileName; diff --git a/src/Base/Writer.h b/src/Base/Writer.h index 26ccea2d0b..b280c7804d 100644 --- a/src/Base/Writer.h +++ b/src/Base/Writer.h @@ -134,6 +134,10 @@ protected: bool forceXML; int fileVersion; + +private: + Writer(const Writer&); + Writer& operator=(const Writer&); };