Base: fix warnings reported by code analysers

* disable copy-constructor and assignment operator for Stream classes
* remove destructor of sub-classes of SequencerBase
* fix some old C-style cast warnings
This commit is contained in:
wmayer
2022-03-01 12:20:27 +01:00
parent 6a9310499a
commit 9805bceec4
4 changed files with 40 additions and 32 deletions

View File

@@ -126,8 +126,8 @@ void SequencerBase::startStep()
bool SequencerBase::next(bool canAbort)
{
this->nProgress++;
float fDiv = this->nTotalSteps > 0 ? (float)this->nTotalSteps : 1000.0f;
int perc = (int)((float)this->nProgress * (100.0f / fDiv));
float fDiv = this->nTotalSteps > 0 ? static_cast<float>(this->nTotalSteps) : 1000.0f;
int perc = int((float(this->nProgress) * (100.0f / fDiv)));
// do only an update if we have increased by one percent
if (perc > this->_nLastPercentage) {
@@ -220,26 +220,8 @@ void SequencerBase::setText(const char*)
// ---------------------------------------------------------
EmptySequencer::EmptySequencer()
{
}
EmptySequencer::~EmptySequencer()
{
}
// ---------------------------------------------------------
using Base::ConsoleSequencer;
ConsoleSequencer::ConsoleSequencer ()
{
}
ConsoleSequencer::~ConsoleSequencer ()
{
}
void ConsoleSequencer::setText (const char* pszTxt)
{
printf("%s...\n", pszTxt);
@@ -252,7 +234,7 @@ void ConsoleSequencer::startStep()
void ConsoleSequencer::nextStep( bool )
{
if (this->nTotalSteps != 0)
printf("\t\t\t\t\t\t(%2.1f %%)\t\r", (float)progressInPercent());
printf("\t\t\t\t\t\t(%d %%)\t\r", progressInPercent());
}
void ConsoleSequencer::resetData()
@@ -353,8 +335,8 @@ Py::Object ProgressIndicatorPy::repr()
Py::Object ProgressIndicatorPy::start(const Py::Tuple& args)
{
char* text;
int steps;
if (!PyArg_ParseTuple(args.ptr(), "si",&text,&steps))
unsigned int steps;
if (!PyArg_ParseTuple(args.ptr(), "sI",&text,&steps))
throw Py::Exception();
if (!_seq.get())
_seq.reset(new SequencerLauncher(text,steps));

View File

@@ -206,6 +206,8 @@ protected:
protected:
/** construction */
SequencerBase();
SequencerBase(const SequencerBase&) = default;
SequencerBase& operator=(const SequencerBase&) = default;
/** Destruction */
virtual ~SequencerBase();
/**
@@ -253,9 +255,7 @@ class BaseExport EmptySequencer : public Base::SequencerBase
{
public:
/** construction */
EmptySequencer();
/** Destruction */
~EmptySequencer();
EmptySequencer() = default;
};
/**
@@ -265,9 +265,7 @@ class BaseExport ConsoleSequencer : public SequencerBase
{
public:
/** construction */
ConsoleSequencer ();
/** Destruction */
~ConsoleSequencer ();
ConsoleSequencer () = default;
protected:
/** Starts the sequencer */
@@ -374,6 +372,10 @@ public:
bool next(bool canAbort = false);
void setProgress(size_t);
bool wasCanceled() const;
private:
SequencerLauncher(const SequencerLauncher&);
void operator=(const SequencerLauncher&);
};
/** Access to the only SequencerBase instance */

View File

@@ -239,7 +239,7 @@ std::streambuf::int_type
ByteArrayOStreambuf::overflow(std::streambuf::int_type c)
{
if (c != EOF) {
char z = c;
char z = static_cast<char>(c);
if (_buffer->write (&z, 1) != 1) {
return EOF;
}
@@ -375,7 +375,7 @@ std::streambuf::int_type
IODeviceOStreambuf::overflow(std::streambuf::int_type c)
{
if (c != EOF) {
char z = c;
char z = static_cast<char>(c);
if (device->write (&z, 1) != 1) {
return EOF;
}
@@ -601,7 +601,7 @@ PyStreambuf::overflow(PyStreambuf::int_type ch)
#ifdef PYSTREAM_BUFFERED
sync();
if (ch != traits_type::eof()) {
*pptr() = ch;
*pptr() = static_cast<char>(ch);
pbump(1);
return ch;
}

View File

@@ -52,6 +52,8 @@ public:
protected:
Stream();
Stream(const Stream&) = default;
Stream& operator=(const Stream&) = default;
virtual ~Stream();
bool _swap;
@@ -147,6 +149,10 @@ protected:
std::ios_base::openmode which =
std::ios::in | std::ios::out);
private:
ByteArrayOStreambuf(const ByteArrayOStreambuf&);
ByteArrayOStreambuf& operator=(const ByteArrayOStreambuf&);
private:
QBuffer* _buffer;
};
@@ -174,6 +180,9 @@ protected:
virtual pos_type seekpos(std::streambuf::pos_type pos,
std::ios_base::openmode which =
std::ios::in | std::ios::out);
private:
ByteArrayIStreambuf(const ByteArrayIStreambuf&);
ByteArrayIStreambuf& operator=(const ByteArrayIStreambuf&);
private:
const QByteArray& _buffer;
@@ -201,6 +210,10 @@ protected:
virtual pos_type seekpos(std::streambuf::pos_type sp,
std::ios_base::openmode which =
std::ios::in | std::ios::out);
private:
IODeviceOStreambuf(const IODeviceOStreambuf&);
IODeviceOStreambuf& operator=(const IODeviceOStreambuf&);
protected:
QIODevice* device;
};
@@ -225,6 +238,9 @@ protected:
virtual pos_type seekpos(std::streambuf::pos_type sp,
std::ios_base::openmode which =
std::ios::in | std::ios::out);
private:
IODeviceIStreambuf(const IODeviceIStreambuf&);
IODeviceIStreambuf& operator=(const IODeviceIStreambuf&);
protected:
QIODevice* device;
@@ -270,6 +286,10 @@ private:
bool flushBuffer();
bool writeStr(const char* s, std::streamsize num);
private:
PyStreambuf(const PyStreambuf&);
PyStreambuf& operator=(const PyStreambuf&);
private:
PyObject* inp;
Type type;
@@ -296,6 +316,10 @@ protected:
std::ios_base::openmode which =
std::ios::in | std::ios::out);
private:
Streambuf(const Streambuf&);
Streambuf& operator=(const Streambuf&);
private:
std::string::const_iterator _beg;
std::string::const_iterator _end;