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:
@@ -66,9 +66,9 @@ using namespace Base;
|
||||
std::string ConvertFromWideString(const std::wstring& string)
|
||||
{
|
||||
int neededSize = WideCharToMultiByte(CP_UTF8, 0, string.c_str(), -1, 0, 0,0,0);
|
||||
char * CharString = new char[neededSize];
|
||||
char * CharString = new char[static_cast<size_t>(neededSize)];
|
||||
WideCharToMultiByte(CP_UTF8, 0, string.c_str(), -1, CharString, neededSize,0,0);
|
||||
std::string String((char*)CharString);
|
||||
std::string String(CharString);
|
||||
delete [] CharString;
|
||||
CharString = NULL;
|
||||
return String;
|
||||
@@ -77,7 +77,7 @@ std::string ConvertFromWideString(const std::wstring& string)
|
||||
std::wstring ConvertToWideString(const std::string& string)
|
||||
{
|
||||
int neededSize = MultiByteToWideChar(CP_UTF8, 0, string.c_str(), -1, 0, 0);
|
||||
wchar_t* wideCharString = new wchar_t[neededSize];
|
||||
wchar_t* wideCharString = new wchar_t[static_cast<size_t>(neededSize)];
|
||||
MultiByteToWideChar(CP_UTF8, 0, string.c_str(), -1, wideCharString, neededSize);
|
||||
std::wstring wideString(wideCharString);
|
||||
delete [] wideCharString;
|
||||
@@ -110,7 +110,7 @@ const std::string &FileInfo::getTempPath()
|
||||
wchar_t buf[MAX_PATH + 2];
|
||||
GetTempPathW(MAX_PATH + 1,buf);
|
||||
int neededSize = WideCharToMultiByte(CP_UTF8, 0, buf, -1, 0, 0, 0, 0);
|
||||
char* dest = new char[neededSize];
|
||||
char* dest = new char[static_cast<size_t>(neededSize)];
|
||||
WideCharToMultiByte(CP_UTF8, 0, buf, -1,dest, neededSize, 0, 0);
|
||||
tempPath = dest;
|
||||
delete [] dest;
|
||||
@@ -383,14 +383,15 @@ bool FileInfo::isDir () const
|
||||
return false;
|
||||
}
|
||||
return S_ISDIR(st.st_mode);
|
||||
#endif
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
// TODO: Check for valid path name
|
||||
return true;
|
||||
//return true;
|
||||
}
|
||||
|
||||
unsigned int FileInfo::size () const
|
||||
|
||||
@@ -40,7 +40,7 @@ void FutureWatcherProgress::progressValueChanged(int v)
|
||||
{
|
||||
if (steps == 0)
|
||||
return;
|
||||
unsigned int step = (100 * v) / steps;
|
||||
unsigned int step = (100 * static_cast<unsigned int>(v)) / steps;
|
||||
if (step > current) {
|
||||
current = step;
|
||||
seq.next();
|
||||
|
||||
@@ -127,7 +127,8 @@ Py::Object Vector2dPy::repr()
|
||||
Py::Float y(v.y);
|
||||
std::stringstream str;
|
||||
str << "Vector2 (";
|
||||
str << (std::string)x.repr() << ", "<< (std::string)y.repr();
|
||||
str << static_cast<std::string>(x.repr()) << ", "
|
||||
<< static_cast<std::string>(y.repr());
|
||||
str << ")";
|
||||
|
||||
return Py::String(str.str());
|
||||
|
||||
@@ -89,28 +89,28 @@ unsigned int StdInputStream::readBytes( XMLByte* const toFill, const unsigned i
|
||||
#else
|
||||
XMLFilePos StdInputStream::curPos() const
|
||||
{
|
||||
return stream.tellg();
|
||||
return static_cast<XMLFilePos>(stream.tellg());
|
||||
}
|
||||
|
||||
XMLSize_t StdInputStream::readBytes( XMLByte* const toFill, const XMLSize_t maxToRead )
|
||||
XMLSize_t StdInputStream::readBytes(XMLByte* const toFill, const XMLSize_t maxToRead)
|
||||
{
|
||||
//
|
||||
// Read up to the maximum bytes requested. We return the number
|
||||
// actually read.
|
||||
//
|
||||
|
||||
stream.read((char *)toFill,maxToRead);
|
||||
XMLSize_t len = stream.gcount();
|
||||
stream.read(reinterpret_cast<char *>(toFill), static_cast<std::streamsize>(maxToRead));
|
||||
std::streamsize len = stream.gcount();
|
||||
|
||||
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
||||
const QString text = codec->toUnicode((char *)toFill, len, &state);
|
||||
const QString text = codec->toUnicode(reinterpret_cast<char *>(toFill), static_cast<int>(len), &state);
|
||||
if (state.invalidChars > 0) {
|
||||
// In case invalid characters were found decode back to 'utf-8' and replace
|
||||
// them with '?'
|
||||
// First, Qt replaces invalid characters with '\0' (see ConvertInvalidToNull)
|
||||
// but Xerces doesn't like this because it handles this as termination. Thus,
|
||||
// we have to go through the array and replace '\0' with '?'.
|
||||
XMLSize_t pos = 0;
|
||||
std::streamsize pos = 0;
|
||||
QByteArray ba = codec->fromUnicode(text);
|
||||
for (int i=0; i<ba.length(); i++, pos++) {
|
||||
if (pos < len && ba[i] == '\0')
|
||||
@@ -118,7 +118,7 @@ XMLSize_t StdInputStream::readBytes( XMLByte* const toFill, const XMLSize_t max
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
return static_cast<XMLSize_t>(len);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -289,16 +289,16 @@ void PlacementPy::setRotation(Py::Object arg)
|
||||
{
|
||||
Py::Rotation rot;
|
||||
if (rot.accepts(arg.ptr())) {
|
||||
getPlacementPtr()->setRotation((Base::Rotation)Py::Rotation(arg));
|
||||
getPlacementPtr()->setRotation(static_cast<Base::Rotation>(Py::Rotation(arg)));
|
||||
return;
|
||||
}
|
||||
Py::Tuple tuple;
|
||||
if (tuple.accepts(arg.ptr())) {
|
||||
tuple = arg;
|
||||
getPlacementPtr()->setRotation(Base::Rotation((double)Py::Float(tuple[0]),
|
||||
(double)Py::Float(tuple[1]),
|
||||
(double)Py::Float(tuple[2]),
|
||||
(double)Py::Float(tuple[3])
|
||||
getPlacementPtr()->setRotation(Base::Rotation(static_cast<double>(Py::Float(tuple[0])),
|
||||
static_cast<double>(Py::Float(tuple[1])),
|
||||
static_cast<double>(Py::Float(tuple[2])),
|
||||
static_cast<double>(Py::Float(tuple[3]))
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -438,12 +438,21 @@ double num_change(char* yytext,char dez_delim,char grp_delim)
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wmissing-noreturn"
|
||||
#endif
|
||||
|
||||
// error func
|
||||
void Quantity_yyerror(char *errorinfo)
|
||||
{
|
||||
throw Base::ParserError(errorinfo);
|
||||
}
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
|
||||
// for VC9 (isatty and fileno not supported anymore)
|
||||
//#ifdef _MSC_VER
|
||||
|
||||
@@ -115,8 +115,15 @@ int QuantityPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
int i8=0;
|
||||
PyErr_Clear(); // set by PyArg_ParseTuple()
|
||||
if (PyArg_ParseTuple(args, "|diiiiiiii", &f,&i1,&i2,&i3,&i4,&i5,&i6,&i7,&i8)) {
|
||||
if (f != DOUBLE_MAX) {
|
||||
*self = Quantity(f,Unit(i1,i2,i3,i4,i5,i6,i7,i8));
|
||||
if (f < DOUBLE_MAX) {
|
||||
*self = Quantity(f,Unit{static_cast<int8_t>(i1),
|
||||
static_cast<int8_t>(i2),
|
||||
static_cast<int8_t>(i3),
|
||||
static_cast<int8_t>(i4),
|
||||
static_cast<int8_t>(i5),
|
||||
static_cast<int8_t>(i6),
|
||||
static_cast<int8_t>(i7),
|
||||
static_cast<int8_t>(i8)});
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -218,8 +225,15 @@ PyObject* QuantityPy::getValueAs(PyObject *args)
|
||||
int i8=0;
|
||||
PyErr_Clear();
|
||||
if (PyArg_ParseTuple(args, "d|iiiiiiii", &f,&i1,&i2,&i3,&i4,&i5,&i6,&i7,&i8)) {
|
||||
if (f!=DOUBLE_MAX) {
|
||||
quant = Quantity(f,Unit(i1,i2,i3,i4,i5,i6,i7,i8));
|
||||
if (f < DOUBLE_MAX) {
|
||||
quant = Quantity(f,Unit{static_cast<int8_t>(i1),
|
||||
static_cast<int8_t>(i2),
|
||||
static_cast<int8_t>(i3),
|
||||
static_cast<int8_t>(i4),
|
||||
static_cast<int8_t>(i5),
|
||||
static_cast<int8_t>(i6),
|
||||
static_cast<int8_t>(i7),
|
||||
static_cast<int8_t>(i8)});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -278,7 +292,7 @@ PyObject * QuantityPy::number_int_handler (PyObject *self)
|
||||
}
|
||||
|
||||
QuantityPy* q = static_cast<QuantityPy*>(self);
|
||||
return PyLong_FromLong((long)q->getValue());
|
||||
return PyLong_FromLong(long(q->getValue()));
|
||||
}
|
||||
|
||||
PyObject * QuantityPy::number_negative_handler (PyObject *self)
|
||||
|
||||
@@ -515,7 +515,7 @@ Rotation Rotation::makeRotationByAxes(Vector3d xdir, Vector3d ydir, Vector3d zdi
|
||||
|
||||
|
||||
auto dropPriority = [&order](int index){
|
||||
char tmp;
|
||||
int tmp;
|
||||
if (index == 0){
|
||||
tmp = order[0];
|
||||
order[0] = order[1];
|
||||
@@ -531,7 +531,7 @@ Rotation Rotation::makeRotationByAxes(Vector3d xdir, Vector3d ydir, Vector3d zdi
|
||||
//pick up the strict direction
|
||||
Vector3d mainDir;
|
||||
for (int i = 0; i < 3; ++i){
|
||||
mainDir = *(dirs[order[0]]);
|
||||
mainDir = *(dirs[size_t(order[0])]);
|
||||
if (mainDir.Length() > tol)
|
||||
break;
|
||||
else
|
||||
@@ -544,7 +544,7 @@ Rotation Rotation::makeRotationByAxes(Vector3d xdir, Vector3d ydir, Vector3d zdi
|
||||
//pick up the 2nd priority direction, "hint" direction.
|
||||
Vector3d hintDir;
|
||||
for (int i = 0; i < 2; ++i){
|
||||
hintDir = *(dirs[order[1]]);
|
||||
hintDir = *(dirs[size_t(order[1])]);
|
||||
if ((hintDir.Cross(mainDir)).Length() > tol)
|
||||
break;
|
||||
else
|
||||
|
||||
@@ -166,7 +166,7 @@ std::string Base::Tools::escapedUnicodeToUtf8(const std::string& s)
|
||||
Base::PyGILStateLocker lock;
|
||||
std::string string;
|
||||
|
||||
PyObject* unicode = PyUnicode_DecodeUnicodeEscape(s.c_str(), s.size(), "strict");
|
||||
PyObject* unicode = PyUnicode_DecodeUnicodeEscape(s.c_str(), static_cast<Py_ssize_t>(s.size()), "strict");
|
||||
if (!unicode)
|
||||
return string;
|
||||
if (PyUnicode_Check(unicode)) {
|
||||
|
||||
@@ -263,14 +263,19 @@ struct BaseExport Tools
|
||||
* @param s String to convert.
|
||||
* @return A std::string encoded as UTF-8.
|
||||
*/
|
||||
static inline std::string toStdString(const QString& s) { QByteArray tmp = s.toUtf8(); return std::string(tmp.constData(), tmp.size()); }
|
||||
static inline std::string toStdString(const QString& s) {
|
||||
QByteArray tmp = s.toUtf8();
|
||||
return std::string(tmp.constData(), static_cast<size_t>(tmp.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief fromStdString Convert a std::string encoded as UTF-8 into a QString.
|
||||
* @param s std::string, expected to be UTF-8 encoded.
|
||||
* @return String represented as a QString.
|
||||
*/
|
||||
static inline QString fromStdString(const std::string & s) { return QString::fromUtf8(s.c_str(), s.size()); }
|
||||
static inline QString fromStdString(const std::string & s) {
|
||||
return QString::fromUtf8(s.c_str(), static_cast<int>(s.size()));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ double Vector2d::GetAngle (const Vector2d &rclVect) const
|
||||
{
|
||||
fNum = (*this * rclVect) / fDivid;
|
||||
if (fNum < -1)
|
||||
return F_PI;
|
||||
return D_PI;
|
||||
else
|
||||
if (fNum > 1)
|
||||
return 0.0;
|
||||
@@ -186,11 +186,11 @@ bool Line2d::Intersect (const Line2d& rclLine, Vector2d &rclV) const
|
||||
if (fabs (clV2.x - clV1.x) > 1e-10)
|
||||
m1 = (clV2.y - clV1.y) / (clV2.x - clV1.x);
|
||||
else
|
||||
m1 = FLOAT_MAX;
|
||||
m1 = DOUBLE_MAX;
|
||||
if (fabs (rclLine.clV2.x - rclLine.clV1.x) > 1e-10)
|
||||
m2 = (rclLine.clV2.y - rclLine.clV1.y) / (rclLine.clV2.x - rclLine.clV1.x);
|
||||
else
|
||||
m2 = FLOAT_MAX;
|
||||
m2 = DOUBLE_MAX;
|
||||
if (m1 == m2) /****** RETURN ERR (parallel lines) *************/
|
||||
return false;
|
||||
|
||||
@@ -198,13 +198,13 @@ bool Line2d::Intersect (const Line2d& rclLine, Vector2d &rclV) const
|
||||
b2 = rclLine.clV1.y - m2 * rclLine.clV1.x;
|
||||
|
||||
// calc intersection
|
||||
if (m1 == FLOAT_MAX)
|
||||
if (m1 == DOUBLE_MAX)
|
||||
{
|
||||
rclV.x = clV1.x;
|
||||
rclV.y = m2 * rclV.x + b2;
|
||||
}
|
||||
else
|
||||
if (m2 == FLOAT_MAX)
|
||||
if (m2 == DOUBLE_MAX)
|
||||
{
|
||||
rclV.x = rclLine.clV1.x;
|
||||
rclV.y = m1 * rclV.x + b1;
|
||||
|
||||
@@ -176,8 +176,10 @@ public:
|
||||
// admin-interface
|
||||
inline size_t GetCtVectors () const;
|
||||
inline bool Add (const Vector2d &rclVct);
|
||||
inline Vector2d& operator[] (size_t ulNdx) const;
|
||||
inline Vector2d& At (size_t ulNdx) const;
|
||||
inline const Vector2d& operator[] (size_t ulNdx) const;
|
||||
inline const Vector2d& At (size_t ulNdx) const;
|
||||
inline Vector2d& operator[] (size_t ulNdx);
|
||||
inline Vector2d& At (size_t ulNdx);
|
||||
inline bool Delete (size_t ulNdx);
|
||||
inline void DeleteAll ();
|
||||
|
||||
@@ -200,7 +202,7 @@ inline Vector2d::Vector2d()
|
||||
}
|
||||
|
||||
inline Vector2d::Vector2d(float x, float y)
|
||||
: x(x), y(y)
|
||||
: x(double(x)), y(double(y))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -410,7 +412,8 @@ inline bool Polygon2d::Delete (size_t ulNdx)
|
||||
{
|
||||
if ( ulNdx < _aclVct.size() )
|
||||
{
|
||||
std::vector<Vector2d>::iterator it = _aclVct.begin() + ulNdx;
|
||||
std::vector<Vector2d>::iterator it = _aclVct.begin();
|
||||
std::advance(it, ulNdx);
|
||||
_aclVct.erase ( it );
|
||||
return true;
|
||||
}
|
||||
@@ -418,16 +421,27 @@ inline bool Polygon2d::Delete (size_t ulNdx)
|
||||
return false;
|
||||
}
|
||||
|
||||
inline Vector2d& Polygon2d::operator[] (size_t ulNdx) const
|
||||
inline const Vector2d& Polygon2d::operator[] (size_t ulNdx) const
|
||||
{
|
||||
return (Vector2d&) _aclVct[ulNdx];
|
||||
return _aclVct[ulNdx];
|
||||
}
|
||||
|
||||
inline Vector2d& Polygon2d::At (size_t ulNdx) const
|
||||
inline const Vector2d& Polygon2d::At (size_t ulNdx) const
|
||||
{
|
||||
return (Vector2d&) _aclVct[ulNdx];
|
||||
return _aclVct.at(ulNdx);
|
||||
}
|
||||
|
||||
inline Vector2d& Polygon2d::operator[] (size_t ulNdx)
|
||||
{
|
||||
return _aclVct[ulNdx];
|
||||
}
|
||||
|
||||
inline Vector2d& Polygon2d::At (size_t ulNdx)
|
||||
{
|
||||
return _aclVct.at(ulNdx);
|
||||
}
|
||||
|
||||
|
||||
inline Line2d::Line2d (const Line2d &rclLine)
|
||||
: clV1 (rclLine.clV1),
|
||||
clV2 (rclLine.clV2)
|
||||
|
||||
@@ -142,7 +142,7 @@ Type Type::badType()
|
||||
const Type Type::createType(const Type parent, const char *name, instantiationMethod method)
|
||||
{
|
||||
Type newType;
|
||||
newType.index = Type::typedata.size();
|
||||
newType.index = static_cast<unsigned int>(Type::typedata.size());
|
||||
TypeData * typeData = new TypeData(name, newType, parent,method);
|
||||
Type::typedata.push_back(typeData);
|
||||
|
||||
@@ -232,7 +232,7 @@ int Type::getAllDerivedFrom(const Type type, std::vector<Type> & List)
|
||||
|
||||
int Type::getNumTypes()
|
||||
{
|
||||
return typedata.size();
|
||||
return static_cast<int>(typedata.size());
|
||||
}
|
||||
|
||||
Type Type::getTypeIfDerivedFrom(const char* name , const Type parent, bool bLoadModule)
|
||||
|
||||
@@ -65,14 +65,14 @@ Unit::Unit(int8_t Length,
|
||||
int8_t Angle)
|
||||
{
|
||||
checkRange("unit",
|
||||
(int32_t)Length,
|
||||
(int32_t)Mass,
|
||||
(int32_t)Time,
|
||||
(int32_t)ElectricCurrent,
|
||||
(int32_t)ThermodynamicTemperature,
|
||||
(int32_t)AmountOfSubstance,
|
||||
(int32_t)LuminousIntensity,
|
||||
(int32_t)Angle);
|
||||
Length,
|
||||
Mass,
|
||||
Time,
|
||||
ElectricCurrent,
|
||||
ThermodynamicTemperature,
|
||||
AmountOfSubstance,
|
||||
LuminousIntensity,
|
||||
Angle);
|
||||
|
||||
Sig.Length = Length;
|
||||
Sig.Mass = Mass;
|
||||
@@ -122,14 +122,14 @@ Unit::Unit(const QString& expr)
|
||||
Unit Unit::pow(signed char exp) const
|
||||
{
|
||||
checkRange("pow()",
|
||||
(int32_t)Sig.Length * (int32_t)exp,
|
||||
(int32_t)Sig.Mass * (int32_t)exp,
|
||||
(int32_t)Sig.Time * (int32_t)exp,
|
||||
(int32_t)Sig.ElectricCurrent * (int32_t)exp,
|
||||
(int32_t)Sig.ThermodynamicTemperature * (int32_t)exp,
|
||||
(int32_t)Sig.AmountOfSubstance * (int32_t)exp,
|
||||
(int32_t)Sig.LuminousIntensity * (int32_t)exp,
|
||||
(int32_t)Sig.Angle * (int32_t)exp);
|
||||
Sig.Length * exp,
|
||||
Sig.Mass * exp,
|
||||
Sig.Time * exp,
|
||||
Sig.ElectricCurrent * exp,
|
||||
Sig.ThermodynamicTemperature * exp,
|
||||
Sig.AmountOfSubstance * exp,
|
||||
Sig.LuminousIntensity * exp,
|
||||
Sig.Angle * exp);
|
||||
|
||||
Unit result;
|
||||
result.Sig.Length = Sig.Length * exp;
|
||||
@@ -172,14 +172,14 @@ bool Unit::operator ==(const Unit& that) const
|
||||
Unit Unit::operator *(const Unit &right) const
|
||||
{
|
||||
checkRange("* operator",
|
||||
(int32_t)Sig.Length + (int32_t)right.Sig.Length,
|
||||
(int32_t)Sig.Mass + (int32_t)right.Sig.Mass,
|
||||
(int32_t)Sig.Time + (int32_t)right.Sig.Time,
|
||||
(int32_t)Sig.ElectricCurrent + (int32_t)right.Sig.ElectricCurrent,
|
||||
(int32_t)Sig.ThermodynamicTemperature + (int32_t)right.Sig.ThermodynamicTemperature,
|
||||
(int32_t)Sig.AmountOfSubstance + (int32_t)right.Sig.AmountOfSubstance,
|
||||
(int32_t)Sig.LuminousIntensity + (int32_t)right.Sig.LuminousIntensity,
|
||||
(int32_t)Sig.Angle + (int32_t)right.Sig.Angle);
|
||||
Sig.Length +right.Sig.Length,
|
||||
Sig.Mass + right.Sig.Mass,
|
||||
Sig.Time + right.Sig.Time,
|
||||
Sig.ElectricCurrent + right.Sig.ElectricCurrent,
|
||||
Sig.ThermodynamicTemperature + right.Sig.ThermodynamicTemperature,
|
||||
Sig.AmountOfSubstance + right.Sig.AmountOfSubstance,
|
||||
Sig.LuminousIntensity + right.Sig.LuminousIntensity,
|
||||
Sig.Angle + right.Sig.Angle);
|
||||
|
||||
Unit result;
|
||||
result.Sig.Length = Sig.Length + right.Sig.Length;
|
||||
@@ -197,14 +197,14 @@ Unit Unit::operator *(const Unit &right) const
|
||||
Unit Unit::operator /(const Unit &right) const
|
||||
{
|
||||
checkRange("/ operator",
|
||||
(int32_t)Sig.Length - (int32_t)right.Sig.Length,
|
||||
(int32_t)Sig.Mass - (int32_t)right.Sig.Mass,
|
||||
(int32_t)Sig.Time - (int32_t)right.Sig.Time,
|
||||
(int32_t)Sig.ElectricCurrent - (int32_t)right.Sig.ElectricCurrent,
|
||||
(int32_t)Sig.ThermodynamicTemperature - (int32_t)right.Sig.ThermodynamicTemperature,
|
||||
(int32_t)Sig.AmountOfSubstance - (int32_t)right.Sig.AmountOfSubstance,
|
||||
(int32_t)Sig.LuminousIntensity - (int32_t)right.Sig.LuminousIntensity,
|
||||
(int32_t)Sig.Angle - (int32_t)right.Sig.Angle);
|
||||
Sig.Length - right.Sig.Length,
|
||||
Sig.Mass - right.Sig.Mass,
|
||||
Sig.Time - right.Sig.Time,
|
||||
Sig.ElectricCurrent - right.Sig.ElectricCurrent,
|
||||
Sig.ThermodynamicTemperature - right.Sig.ThermodynamicTemperature,
|
||||
Sig.AmountOfSubstance - right.Sig.AmountOfSubstance,
|
||||
Sig.LuminousIntensity - right.Sig.LuminousIntensity,
|
||||
Sig.Angle - right.Sig.Angle);
|
||||
|
||||
Unit result;
|
||||
result.Sig.Length = Sig.Length - right.Sig.Length;
|
||||
|
||||
@@ -140,7 +140,7 @@ PyObject* UnitsApi::sSetSchema(PyObject * /*self*/, PyObject *args)
|
||||
PyErr_SetString(PyExc_ValueError, "invalid schema value");
|
||||
return nullptr;
|
||||
}
|
||||
setSchema((UnitSystem)index);
|
||||
setSchema(static_cast<UnitSystem>(index));
|
||||
}
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ QString UnitsSchema::toLocale(const Base::Quantity& quant, double factor, const
|
||||
QLocale Lc;
|
||||
const QuantityFormat& format = quant.getFormat();
|
||||
if (format.option != QuantityFormat::None) {
|
||||
uint opt = static_cast<uint>(format.option);
|
||||
int opt = format.option;
|
||||
Lc.setNumberOptions(static_cast<QLocale::NumberOptions>(opt));
|
||||
}
|
||||
|
||||
|
||||
@@ -235,18 +235,18 @@ QString UnitsSchemaImperialBuilding::schemaTranslate(const Quantity &quant, doub
|
||||
minden = quant.getFormat().getDenominator();
|
||||
|
||||
// Compute and round the total number of fractional units
|
||||
ntot = (int)std::round(totalInches * (double)minden);
|
||||
ntot = static_cast<int>(std::round(totalInches * static_cast<double>(minden)));
|
||||
|
||||
// If this is zero, nothing to do but return
|
||||
if( ntot==0 )
|
||||
return QString::fromLatin1("0");
|
||||
|
||||
// Compute the whole number of feet and remaining units
|
||||
feet = (int)std::floor(ntot / (12*minden));
|
||||
feet = static_cast<int>(std::floor(ntot / (12*minden)));
|
||||
ntot = ntot - 12*minden*feet;
|
||||
|
||||
// Compute the remaining number of whole inches
|
||||
inches = (int)std::floor(ntot/minden);
|
||||
inches = static_cast<int>(std::floor(ntot/minden));
|
||||
|
||||
// Lastly the fractional quantities
|
||||
num = ntot - inches*minden;
|
||||
@@ -387,9 +387,9 @@ QString UnitsSchemaImperialCivil::schemaTranslate(const Base::Quantity& quant, d
|
||||
// double wholeSeconds = std::floor(rawSeconds);
|
||||
// double remainSeconds = rawSeconds - wholeSeconds;
|
||||
|
||||
int outDeg = (int) wholeDegrees;
|
||||
int outMin = (int) wholeMinutes;
|
||||
int outSec = (int) std::round(rawSeconds);
|
||||
int outDeg = static_cast<int>(wholeDegrees);
|
||||
int outMin = static_cast<int>(wholeMinutes);
|
||||
int outSec = static_cast<int>(std::round(rawSeconds));
|
||||
|
||||
std::stringstream output;
|
||||
output << outDeg << degreeString.toUtf8().constData();
|
||||
|
||||
@@ -47,7 +47,9 @@ std::string VectorPy::representation() const
|
||||
Py::Float z(ptr->z);
|
||||
std::stringstream str;
|
||||
str << "Vector (";
|
||||
str << (std::string)x.repr() << ", "<< (std::string)y.repr() << ", "<< (std::string)z.repr();
|
||||
str << static_cast<std::string>(x.repr()) << ", "
|
||||
<< static_cast<std::string>(y.repr()) << ", "
|
||||
<< static_cast<std::string>(z.repr());
|
||||
str << ")";
|
||||
|
||||
return str.str();
|
||||
@@ -192,8 +194,10 @@ PyObject * VectorPy::sequence_item (PyObject *self, Py_ssize_t index)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
unsigned short pos = index % 3;
|
||||
|
||||
Base::Vector3d a = static_cast<VectorPy*>(self)->value();
|
||||
return Py_BuildValue("d", a[index]);
|
||||
return Py_BuildValue("d", a[pos]);
|
||||
}
|
||||
|
||||
int VectorPy::sequence_ass_item(PyObject *self, Py_ssize_t index, PyObject *value)
|
||||
@@ -207,9 +211,11 @@ int VectorPy::sequence_ass_item(PyObject *self, Py_ssize_t index, PyObject *valu
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned short pos = index % 3;
|
||||
|
||||
if (PyNumber_Check(value)) {
|
||||
VectorPy::PointerType ptr = static_cast<VectorPy*>(self)->getVectorPtr();
|
||||
(*ptr)[index] = PyFloat_AsDouble(value);
|
||||
(*ptr)[pos] = PyFloat_AsDouble(value);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError, "value must be float");
|
||||
@@ -255,11 +261,11 @@ PyObject * VectorPy::mapping_subscript(PyObject *self, PyObject *item)
|
||||
}
|
||||
else if (PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
Base::Vector3d v = static_cast<VectorPy*>(self) ->value();
|
||||
Py::Tuple xyz(slicelength);
|
||||
Py::Tuple xyz(static_cast<size_t>(slicelength));
|
||||
|
||||
for (cur = start, i = 0; i < slicelength;
|
||||
cur += step, i++) {
|
||||
xyz.setItem(i, Py::Float(v[cur]));
|
||||
for (cur = start, i = 0; i < slicelength; cur += step, i++) {
|
||||
unsigned short pos = cur % 3;
|
||||
xyz.setItem(static_cast<Py::sequence_index_type>(i), Py::Float(v[pos]));
|
||||
}
|
||||
|
||||
return Py::new_reference_to(xyz);
|
||||
@@ -622,7 +628,7 @@ void VectorPy::setLength(Py::Float arg)
|
||||
throw Py::RuntimeError(std::string("Cannot set length of null vector"));
|
||||
}
|
||||
|
||||
double val = (double)arg/len;
|
||||
double val = static_cast<double>(arg)/len;
|
||||
ptr->x *= val;
|
||||
ptr->y *= val;
|
||||
ptr->z *= val;
|
||||
@@ -637,7 +643,7 @@ Py::Float VectorPy::getx() const
|
||||
void VectorPy::setx(Py::Float arg)
|
||||
{
|
||||
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
|
||||
ptr->x = (double)arg;
|
||||
ptr->x = static_cast<double>(arg);
|
||||
}
|
||||
|
||||
Py::Float VectorPy::gety() const
|
||||
@@ -649,7 +655,7 @@ Py::Float VectorPy::gety() const
|
||||
void VectorPy::sety(Py::Float arg)
|
||||
{
|
||||
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
|
||||
ptr->y = (double)arg;
|
||||
ptr->y = static_cast<double>(arg);
|
||||
}
|
||||
|
||||
Py::Float VectorPy::getz() const
|
||||
@@ -661,7 +667,7 @@ Py::Float VectorPy::getz() const
|
||||
void VectorPy::setz(Py::Float arg)
|
||||
{
|
||||
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
|
||||
ptr->z = (double)arg;
|
||||
ptr->z = static_cast<double>(arg);
|
||||
}
|
||||
|
||||
PyObject *VectorPy::getCustomAttributes(const char* /*attr*/) const
|
||||
@@ -693,7 +699,7 @@ PyObject * VectorPy::number_divide_handler (PyObject* self, PyObject* other)
|
||||
|
||||
Base::Vector3d vec = static_cast<VectorPy*>(self) ->value();
|
||||
double div = PyFloat_AsDouble(other);
|
||||
if (div == 0) {
|
||||
if (div == 0.0) {
|
||||
PyErr_Format(PyExc_ZeroDivisionError, "'%s' division by zero",
|
||||
Py_TYPE(self)->tp_name);
|
||||
return nullptr;
|
||||
|
||||
Reference in New Issue
Block a user