Base: fix warnings from code analysers:

* replace some C-style casts with static_cast
* remove unneeded destructors
* define default copy-constructor and assignment operator
This commit is contained in:
wmayer
2022-03-05 19:03:21 +01:00
parent 9de55d010c
commit a6624ef264
8 changed files with 34 additions and 33 deletions

View File

@@ -113,7 +113,7 @@ const char* Base::XMLReader::localName() const
unsigned int Base::XMLReader::getAttributeCount() const
{
return (unsigned int)AttrMap.size();
return static_cast<unsigned int>(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<size_t>(pos));
}
void Base::XMLReader::setStatus(ReaderStatus pos, bool on)
{
StatusBits.set((size_t)pos, on);
StatusBits.set(static_cast<size_t>(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;

View File

@@ -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;

View File

@@ -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();
}
}

View File

@@ -42,6 +42,8 @@ class BaseExport Uuid
public:
/// Construction
Uuid();
Uuid(const Uuid&) = default;
Uuid& operator=(const Uuid&) = default;
/// Destruction
virtual ~Uuid();

View File

@@ -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<double>(pnt.x) * m30 +
static_cast<double>(pnt.y) * m31 +
static_cast<double>(pnt.z) * m32 + m33);
mat.multVec(pnt, pnt);
pnt /= w;
pnt /= static_cast<typename Vec::num_type>(w);
}
Vector3f ViewProjMatrix::operator()(const Vector3f& inp) const
@@ -137,7 +140,7 @@ Vector3f ViewProjMatrix::operator()(const Vector3f& inp) const
if (!isOrthographic) {
dst = src;
perspectiveTransform<Vector3f>(_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<Vector3f>(_clMtxInv, dst);
}
else {
@@ -201,10 +204,6 @@ ViewOrthoProjMatrix::ViewOrthoProjMatrix (const Matrix4D &rclMtx)
_clMtxInv.inverse();
}
ViewOrthoProjMatrix::~ViewOrthoProjMatrix()
{
}
Matrix4D ViewOrthoProjMatrix::getProjectionMatrix () const
{
return _clMtx;

View File

@@ -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;

View File

@@ -78,9 +78,9 @@ void Writer::insertBinFile(const char* FileName)
Stream() << "<![CDATA[";
std::ifstream::pos_type fileSize = from.tellg();
from.seekg(0, std::ios::beg);
std::vector<unsigned char> bytes(fileSize);
from.read((char*)&bytes[0], fileSize);
Stream() << Base::base64_encode(&bytes[0], fileSize);
std::vector<unsigned char> bytes(static_cast<size_t>(fileSize));
from.read(reinterpret_cast<char*>(&bytes[0]), fileSize);
Stream() << Base::base64_encode(&bytes[0], static_cast<unsigned int>(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;

View File

@@ -134,6 +134,10 @@ protected:
bool forceXML;
int fileVersion;
private:
Writer(const Writer&);
Writer& operator=(const Writer&);
};