Base/App: fix warnings from code analysers:

* convert old-style-casts to explicit C++ casts where possible
* make some implicit conversions explicit
This commit is contained in:
wmayer
2022-03-06 23:49:30 +01:00
parent 26ece78df4
commit 4a343ab31e
30 changed files with 211 additions and 155 deletions

View File

@@ -78,8 +78,8 @@ Branding::XmlConfig Branding::getUserDefines() const
if (!root.isNull()) {
child = root.firstChildElement();
while (!child.isNull()) {
std::string name = (const char*)child.localName().toLatin1();
std::string value = (const char*)child.text().toUtf8();
std::string name = child.localName().toLatin1().constData();
std::string value = child.text().toUtf8().constData();
if (std::find(filter.begin(), filter.end(), name) != filter.end())
cfg[name] = value;
child = child.nextSiblingElement();

View File

@@ -40,12 +40,12 @@ TYPESYSTEM_SOURCE_ABSTRACT(Data::Segment , Base::BaseClass)
TYPESYSTEM_SOURCE_ABSTRACT(Data::ComplexGeoData , Base::Persistence)
ComplexGeoData::ComplexGeoData(void)
ComplexGeoData::ComplexGeoData()
:Tag(0)
{
}
ComplexGeoData::~ComplexGeoData(void)
ComplexGeoData::~ComplexGeoData()
{
}
@@ -56,10 +56,10 @@ Data::Segment* ComplexGeoData::getSubElementByName(const char* name) const
std::string::size_type pos = element.find_first_of("0123456789");
if (pos != std::string::npos) {
index = std::atoi(element.substr(pos).c_str());
element = element.substr(0,pos);
element = element.substr(0, pos);
}
return getSubElement(element.c_str(),index);
return getSubElement(element.c_str(), static_cast<unsigned long>(index));
}
void ComplexGeoData::applyTransform(const Base::Matrix4D& rclTrf)

View File

@@ -68,7 +68,7 @@ public:
};
/// Constructor
ComplexGeoData(void);
ComplexGeoData();
/// Destructor
virtual ~ComplexGeoData();
@@ -78,7 +78,7 @@ public:
* List of different subelement types
* its NOT a list of the subelements itself
*/
virtual std::vector<const char*> getElementTypes(void) const=0;
virtual std::vector<const char*> getElementTypes() const=0;
virtual unsigned long countSubElements(const char* Type) const=0;
/// get the subelement by type and number
virtual Segment* getSubElement(const char* Type, unsigned long) const=0;
@@ -122,7 +122,7 @@ public:
* This method has to be handled by the child classes.
* the actual placement and matrix is not part of this class.
*/
virtual Base::Matrix4D getTransform(void) const = 0;
virtual Base::Matrix4D getTransform() const = 0;
//@}
/** @name Modification */
@@ -134,7 +134,7 @@ public:
/** @name Getting basic geometric entities */
//@{
/// Get the bound box
virtual Base::BoundBox3d getBoundBox(void)const=0;
virtual Base::BoundBox3d getBoundBox()const=0;
/** Get point from line object intersection */
virtual Base::Vector3d getPointFromLineIntersection(
const Base::Vector3f& base,
@@ -196,7 +196,9 @@ protected:
/// from local to outside
inline Base::Vector3d transformToOutside(const Base::Vector3f& vec) const
{
return getTransform() * Base::Vector3d(vec.x,vec.y,vec.z);
return getTransform() * Base::Vector3d(static_cast<double>(vec.x),
static_cast<double>(vec.y),
static_cast<double>(vec.z));
}
/// from local to inside
inline Base::Vector3f transformToInside(const Base::Vector3d& vec) const
@@ -204,7 +206,9 @@ protected:
Base::Matrix4D tmpM(getTransform());
tmpM.inverse();
Base::Vector3d tmp = tmpM * vec;
return Base::Vector3f((float)tmp.x,(float)tmp.y,(float)tmp.z);
return Base::Vector3f(static_cast<float>(tmp.x),
static_cast<float>(tmp.y),
static_cast<float>(tmp.z));
}
public:
mutable long Tag;

View File

@@ -171,8 +171,8 @@ public:
bool isRemoving() const {return StatusBits.test(ObjectStatus::Remove);}
/// return the status bits
unsigned long getStatus() const {return StatusBits.to_ulong();}
bool testStatus(ObjectStatus pos) const {return StatusBits.test((size_t)pos);}
void setStatus(ObjectStatus pos, bool on) {StatusBits.set((size_t)pos, on);}
bool testStatus(ObjectStatus pos) const {return StatusBits.test(size_t(pos));}
void setStatus(ObjectStatus pos, bool on) {StatusBits.set(size_t(pos), on);}
//@}
int isExporting() const;

View File

@@ -160,7 +160,7 @@ void Enumeration::setEnums(const std::vector<std::string> &values)
_EnumArray[i] = 0; // null termination
// Other state variables
_maxVal = values.size() - 1;
_maxVal = static_cast<int>(values.size() - 1);
_ownEnumArray = true;
if (_index < 0)
_index = 0;

View File

@@ -35,7 +35,7 @@ using namespace App;
//===========================================================================
// Material
//===========================================================================
Material::Material(void)
Material::Material()
{
setType(STEEL);
setType(USER_DEFINED);

View File

@@ -25,7 +25,7 @@
#define APP_MATERIAL_H
#ifdef __GNUC__
# include <stdint.h>
# include <cstdint>
#endif
#include <sstream>
@@ -100,10 +100,10 @@ public:
*/
uint32_t getPackedValue() const
{
return ((uint32_t)(r*255.0f + 0.5f) << 24 |
(uint32_t)(g*255.0f + 0.5f) << 16 |
(uint32_t)(b*255.0f + 0.5f) << 8 |
(uint32_t)(a*255.0f + 0.5f));
return (static_cast<uint32_t>(r*255.0f + 0.5f) << 24 |
static_cast<uint32_t>(g*255.0f + 0.5f) << 16 |
static_cast<uint32_t>(b*255.0f + 0.5f) << 8 |
static_cast<uint32_t>(a*255.0f + 0.5f));
}
/**
* creates FC Color from template type, e.g. Qt QColor
@@ -116,8 +116,8 @@ public:
*
*/
template <typename T>
inline T asValue(void) const {
return(T(int(r*255.0),int(g*255.0),int(b*255.0)));
inline T asValue() const {
return(T(int(r*255.0f),int(g*255.0f),int(b*255.0f)));
}
/**
* returns color as hex color "#RRGGBB"
@@ -125,9 +125,9 @@ public:
*/
std::string asHexString() const {
std::stringstream ss;
ss << "#" << std::hex << std::uppercase << std::setfill('0') << std::setw(2) << int(r*255.0)
<< std::setw(2) << int(g*255.0)
<< std::setw(2) << int(b*255.0);
ss << "#" << std::hex << std::uppercase << std::setfill('0') << std::setw(2) << int(r*255.0f)
<< std::setw(2) << int(g*255.0f)
<< std::setw(2) << int(b*255.0f);
return ss.str();
}
/**
@@ -223,7 +223,7 @@ public:
*/
//@{
/** Sets the USER_DEFINED material type. The user must set the colors afterwards. */
Material(void);
Material();
/** Defines the colors and shininess for the material \a MatName. If \a MatName isn't defined then USER_DEFINED is
* set and the user must define the colors itself.
*/

View File

@@ -64,7 +64,7 @@ PropertyFileIncluded::~PropertyFileIncluded()
}
}
void PropertyFileIncluded::aboutToSetValue(void)
void PropertyFileIncluded::aboutToSetValue()
{
// This is a trick to check in Copy() if it is called
// directly from outside or by the Undo/Redo mechanism.
@@ -78,7 +78,7 @@ void PropertyFileIncluded::aboutToSetValue(void)
this->StatusBits.reset(10);
}
std::string PropertyFileIncluded::getDocTransientPath(void) const
std::string PropertyFileIncluded::getDocTransientPath() const
{
std::string path;
PropertyContainer *co = getContainer();
@@ -100,13 +100,13 @@ std::string PropertyFileIncluded::getUniqueFileName(const std::string& path, con
return fi.filePath();
}
std::string PropertyFileIncluded::getExchangeTempFile(void) const
std::string PropertyFileIncluded::getExchangeTempFile() const
{
return Base::FileInfo::getTempFileName(Base::FileInfo
(getValue()).fileName().c_str(), getDocTransientPath().c_str());
}
std::string PropertyFileIncluded::getOriginalFileName(void) const
std::string PropertyFileIncluded::getOriginalFileName() const
{
return _OriginalName;
}
@@ -232,14 +232,14 @@ void PropertyFileIncluded::setValue(const char* sFile, const char* sName)
}
}
const char* PropertyFileIncluded::getValue(void) const
const char* PropertyFileIncluded::getValue() const
{
return _cValue.c_str();
}
PyObject *PropertyFileIncluded::getPyObject(void)
PyObject *PropertyFileIncluded::getPyObject()
{
PyObject *p = PyUnicode_DecodeUTF8(_cValue.c_str(),_cValue.size(),0);
PyObject *p = PyUnicode_DecodeUTF8(_cValue.c_str(),_cValue.size(),nullptr);
if (!p) {
throw Base::UnicodeError("PropertyFileIncluded: UTF-8 conversion failure");
}
@@ -249,7 +249,7 @@ PyObject *PropertyFileIncluded::getPyObject(void)
namespace App {
const char* getNameFromFile(PyObject* value)
{
const char* string = 0;
const char* string = nullptr;
PyObject *oname = PyObject_GetAttrString (value, "name");
if (oname) {
if (PyUnicode_Check (oname)) {
@@ -464,7 +464,7 @@ void PropertyFileIncluded::RestoreDocFile(Base::Reader &reader)
hasSetValue();
}
Property *PropertyFileIncluded::Copy(void) const
Property *PropertyFileIncluded::Copy() const
{
std::unique_ptr<PropertyFileIncluded> prop(new PropertyFileIncluded());
@@ -564,7 +564,7 @@ void PropertyFileIncluded::Paste(const Property &from)
hasSetValue();
}
unsigned int PropertyFileIncluded::getMemSize (void) const
unsigned int PropertyFileIncluded::getMemSize () const
{
unsigned int mem = Property::getMemSize();
mem += _cValue.size();

View File

@@ -44,10 +44,10 @@ class AppExport PropertyFile : public PropertyString
TYPESYSTEM_HEADER();
public:
PropertyFile(void);
PropertyFile();
virtual ~PropertyFile();
virtual const char* getEditorName(void) const
virtual const char* getEditorName() const
{ return "Gui::PropertyEditor::PropertyFileItem"; }
virtual void setFilter(const std::string filter);
@@ -76,15 +76,15 @@ class AppExport PropertyFileIncluded : public Property
TYPESYSTEM_HEADER();
public:
PropertyFileIncluded(void);
PropertyFileIncluded();
virtual ~PropertyFileIncluded();
void setValue(const char* sFile, const char* sName=0);
const char* getValue(void) const;
void setValue(const char* sFile, const char* sName=nullptr);
const char* getValue() const;
virtual const char* getEditorName(void) const
virtual const char* getEditorName() const
{ return "Gui::PropertyEditor::PropertyTransientFileItem"; }
virtual PyObject *getPyObject(void);
virtual PyObject *getPyObject();
virtual void setPyObject(PyObject *);
virtual void Save (Base::Writer &writer) const;
@@ -93,9 +93,9 @@ public:
virtual void SaveDocFile (Base::Writer &writer) const;
virtual void RestoreDocFile(Base::Reader &reader);
virtual Property *Copy(void) const;
virtual Property *Copy() const;
virtual void Paste(const Property &from);
virtual unsigned int getMemSize (void) const;
virtual unsigned int getMemSize () const;
virtual bool isSame(const Property &other) const {
if (&other == this)
@@ -111,16 +111,16 @@ public:
* this file with setValue() is the fastest way to change
* the File.
*/
std::string getExchangeTempFile(void) const;
std::string getOriginalFileName(void) const;
std::string getExchangeTempFile() const;
std::string getOriginalFileName() const;
bool isEmpty(void) const {return _cValue.empty();}
protected:
// get the transient path if the property is in a DocumentObject
std::string getDocTransientPath(void) const;
std::string getDocTransientPath() const;
std::string getUniqueFileName(const std::string&, const std::string&) const;
void aboutToSetValue(void);
void aboutToSetValue();
protected:
mutable std::string _cValue;

View File

@@ -74,7 +74,7 @@ Base::Quantity PropertyQuantity::createQuantityFromPy(PyObject *value)
else if (PyFloat_Check(value))
quant = Quantity(PyFloat_AsDouble(value),_Unit);
else if (PyLong_Check(value))
quant = Quantity((double)PyLong_AsLong(value),_Unit);
quant = Quantity(double(PyLong_AsLong(value)),_Unit);
else if (PyObject_TypeCheck(value, &(QuantityPy::Type))) {
Base::QuantityPy *pcObject = static_cast<Base::QuantityPy*>(value);
quant = *(pcObject->getQuantityPtr());

View File

@@ -42,9 +42,9 @@ Range::Range(const char * range)
std::string from;
std::string to;
assert(range != NULL);
assert(range != nullptr);
if (strchr(range, ':') == NULL) {
if (strchr(range, ':') == nullptr) {
from = range;
to = range;
}
@@ -247,13 +247,13 @@ std::string App::CellAddress::toString(Cell cell) const
if (_absCol && flags.testFlag(Cell::Absolute))
s << '$';
if (col() < 26) {
s << (char)('A' + col());
s << static_cast<char>('A' + col());
}
else {
int colnum = col() - 26;
s << (char)('A' + (colnum / 26));
s << (char)('A' + (colnum % 26));
s << static_cast<char>('A' + (colnum / 26));
s << static_cast<char>('A' + (colnum % 26));
}
}