diff --git a/src/Base/Console.cpp b/src/Base/Console.cpp index 54154bcb6d..8abe5ac791 100644 --- a/src/Base/Console.cpp +++ b/src/Base/Console.cpp @@ -117,13 +117,10 @@ ConsoleOutput* ConsoleOutput::instance = nullptr; ConsoleSingleton::ConsoleSingleton() - : _bVerbose(true) - , _bCanRefresh(true) - , connectionMode(Direct) #ifdef FC_DEBUG - ,_defaultLogLevel(FC_LOGLEVEL_LOG) + : _defaultLogLevel(FC_LOGLEVEL_LOG) #else - ,_defaultLogLevel(FC_LOGLEVEL_MSG) + : _defaultLogLevel(FC_LOGLEVEL_MSG) #endif { } diff --git a/src/Base/Console.h b/src/Base/Console.h index 3dcf6d54cc..fcda8f5a2d 100644 --- a/src/Base/Console.h +++ b/src/Base/Console.h @@ -511,8 +511,7 @@ enum class ContentType { class BaseExport ILogger { public: - ILogger() - :bErr(true), bMsg(true), bLog(true), bWrn(true), bCritical(true), bNotification(false){} + ILogger() = default; virtual ~ILogger() = 0; /** Used to send a Log message at the given level. @@ -562,7 +561,12 @@ public: } virtual const char *Name(){return nullptr;} - bool bErr, bMsg, bLog, bWrn, bCritical, bNotification; + bool bErr{true}; + bool bMsg{true}; + bool bLog{true}; + bool bWrn{true}; + bool bCritical{true}; + bool bNotification{false}; }; @@ -810,9 +814,9 @@ protected: static PyObject *sPyGetStatus (PyObject *self,PyObject *args); static PyObject *sPyGetObservers (PyObject *self,PyObject *args); - bool _bVerbose; - bool _bCanRefresh; - ConnectionMode connectionMode; + bool _bVerbose{true}; + bool _bCanRefresh{true}; + ConnectionMode connectionMode{Direct}; // Singleton! ConsoleSingleton(); diff --git a/src/Base/FileTemplate.cpp b/src/Base/FileTemplate.cpp index 9114a6b800..99065f4dda 100644 --- a/src/Base/FileTemplate.cpp +++ b/src/Base/FileTemplate.cpp @@ -36,13 +36,7 @@ using namespace Base; * A constructor. * A more elaborate description of the constructor. */ -ClassTemplate::ClassTemplate() - : enumPtr(nullptr) - , enumVar(TVal1) - , publicVar(0) - , handler(nullptr) -{ -} +ClassTemplate::ClassTemplate() = default; /** * A destructor. diff --git a/src/Base/FileTemplate.h b/src/Base/FileTemplate.h index 9e18094782..52518505f4 100644 --- a/src/Base/FileTemplate.h +++ b/src/Base/FileTemplate.h @@ -101,8 +101,8 @@ public: TVal2, /**< enum value TVal2. */ TVal3 /**< enum value TVal3. */ } - *enumPtr, /**< enum pointer. Details. */ - enumVar; /**< enum variable. Details. */ + *enumPtr{nullptr}, /**< enum pointer. Details. */ + enumVar{TVal1}; /**< enum variable. Details. */ /** * A pure virtual member. @@ -127,13 +127,13 @@ public: * a public variable. * Details. */ - int publicVar; + int publicVar{0}; /** * a function variable. * Details. */ - int (*handler)(int a,int b); + int (*handler)(int a,int b){nullptr}; std::string something; }; diff --git a/src/Base/Parameter.cpp b/src/Base/Parameter.cpp index 7b67523deb..a75e99e9f8 100644 --- a/src/Base/Parameter.cpp +++ b/src/Base/Parameter.cpp @@ -81,9 +81,7 @@ public: // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- - DOMTreeErrorReporter() : - fSawErrors(false) { - } + DOMTreeErrorReporter() = default; ~DOMTreeErrorReporter() override = default; @@ -109,7 +107,7 @@ public: // method. Its used by the main code to suppress output if there are // errors. // ----------------------------------------------------------------------- - bool fSawErrors; + bool fSawErrors{false}; }; @@ -1441,7 +1439,6 @@ static XercesDOMParser::ValSchemes gValScheme = XercesDOMParser::Val_Au /** Default construction */ ParameterManager::ParameterManager() - : ParameterGrp(), _pDocument(nullptr), paramSerializer(nullptr) { _Manager = this; diff --git a/src/Base/Parameter.h b/src/Base/Parameter.h index 457f57be28..dde736e858 100644 --- a/src/Base/Parameter.h +++ b/src/Base/Parameter.h @@ -414,8 +414,8 @@ public: private: - XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *_pDocument; - ParameterSerializer * paramSerializer; + XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *_pDocument{nullptr}; + ParameterSerializer * paramSerializer{nullptr}; bool gDoNamespaces ; bool gDoSchema ; diff --git a/src/Base/PyObjectBase.cpp b/src/Base/PyObjectBase.cpp index 1859c2a9a0..5bc3d81b56 100644 --- a/src/Base/PyObjectBase.cpp +++ b/src/Base/PyObjectBase.cpp @@ -55,10 +55,8 @@ typedef struct { } PyBaseProxy; // Constructor -PyObjectBase::PyObjectBase(void* p,PyTypeObject *T) - : _pcTwinPointer(p) - , baseProxy(nullptr) - , attrDict(nullptr) +PyObjectBase::PyObjectBase(void* voidp, PyTypeObject *T) + : _pcTwinPointer(voidp) { #if PY_VERSION_HEX < 0x030b0000 Py_TYPE(this) = T; diff --git a/src/Base/PyObjectBase.h b/src/Base/PyObjectBase.h index 5143c59baf..d72ffbf8b7 100644 --- a/src/Base/PyObjectBase.h +++ b/src/Base/PyObjectBase.h @@ -342,10 +342,10 @@ protected: void * _pcTwinPointer; public: - PyObject* baseProxy; + PyObject* baseProxy{nullptr}; private: - PyObject* attrDict; + PyObject* attrDict{nullptr}; }; diff --git a/src/Base/Reader.cpp b/src/Base/Reader.cpp index 306871eeb2..c3e6c0ed7d 100644 --- a/src/Base/Reader.cpp +++ b/src/Base/Reader.cpp @@ -56,9 +56,7 @@ using namespace std; // --------------------------------------------------------------------------- Base::XMLReader::XMLReader(const char* FileName, std::istream& str) - : DocumentSchema(0), ProgramVersion(""), FileVersion(0), Level(0), - CharacterCount(0), ReadType(None), _File(FileName), _valid(false), - _verbose(true) + : _File(FileName) { #ifdef _MSC_VER str.imbue(std::locale::empty()); diff --git a/src/Base/Reader.h b/src/Base/Reader.h index aa66f5390a..64149820a0 100644 --- a/src/Base/Reader.h +++ b/src/Base/Reader.h @@ -214,11 +214,11 @@ public: //@} /// Schema Version of the document - int DocumentSchema; + int DocumentSchema{0}; /// Version of FreeCAD that wrote this document std::string ProgramVersion; /// Version of the file format - int FileVersion; + int FileVersion{0}; /// sets simultaneously the global and local PartialRestore bits void setPartialRestore(bool on); @@ -278,10 +278,10 @@ protected: //@} - int Level; + int Level{0}; std::string LocalName; std::string Characters; - unsigned int CharacterCount; + unsigned int CharacterCount{0}; std::streamsize CharacterOffset{-1}; std::map AttrMap; @@ -297,14 +297,14 @@ protected: EndElement, StartCDATA, EndCDATA - } ReadType; + } ReadType{None}; FileInfo _File; XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader* parser; XERCES_CPP_NAMESPACE_QUALIFIER XMLPScanToken token; - bool _valid; - bool _verbose; + bool _valid{false}; + bool _verbose{true}; std::vector FileNames; diff --git a/src/Base/Sequencer.cpp b/src/Base/Sequencer.cpp index 75459c7737..b9b29020d0 100644 --- a/src/Base/Sequencer.cpp +++ b/src/Base/Sequencer.cpp @@ -78,7 +78,6 @@ SequencerBase& SequencerBase::Instance () } SequencerBase::SequencerBase() - : nProgress(0), nTotalSteps(0), _bLocked(false), _bCanceled(false), _nLastPercentage(-1) { SequencerP::appendInstance(this); } diff --git a/src/Base/Sequencer.h b/src/Base/Sequencer.h index dac92da7d9..cd7d202e10 100644 --- a/src/Base/Sequencer.h +++ b/src/Base/Sequencer.h @@ -236,13 +236,15 @@ protected: virtual void resetData(); protected: - size_t nProgress; /**< Stores the current amount of progress.*/ - size_t nTotalSteps; /**< Stores the total number of steps */ + //NOLINTBEGIN + size_t nProgress{0}; /**< Stores the current amount of progress.*/ + size_t nTotalSteps{0}; /**< Stores the total number of steps */ + //NOLINTEND private: - bool _bLocked; /**< Lock/unlock sequencer. */ - bool _bCanceled; /**< Is set to true if the last pending operation was canceled */ - int _nLastPercentage; /**< Progress in percent. */ + bool _bLocked{false}; /**< Lock/unlock sequencer. */ + bool _bCanceled{false}; /**< Is set to true if the last pending operation was canceled */ + int _nLastPercentage{-1}; /**< Progress in percent. */ }; /** This special sequencer might be useful if you want to suppress any indication diff --git a/src/Base/Stream.cpp b/src/Base/Stream.cpp index 7eea30139e..d23aa7439a 100644 --- a/src/Base/Stream.cpp +++ b/src/Base/Stream.cpp @@ -40,9 +40,7 @@ using namespace Base; -Stream::Stream() : _swap(false) -{ -} +Stream::Stream() = default; Stream::~Stream() = default; @@ -82,56 +80,56 @@ OutputStream& OutputStream::operator << (uint8_t uch) OutputStream& OutputStream::operator << (int16_t s) { - if (_swap) SwapEndian(s); + if (isSwapped()) SwapEndian(s); _out.write((const char*)&s, sizeof(int16_t)); return *this; } OutputStream& OutputStream::operator << (uint16_t us) { - if (_swap) SwapEndian(us); + if (isSwapped()) SwapEndian(us); _out.write((const char*)&us, sizeof(uint16_t)); return *this; } OutputStream& OutputStream::operator << (int32_t i) { - if (_swap) SwapEndian(i); + if (isSwapped()) SwapEndian(i); _out.write((const char*)&i, sizeof(int32_t)); return *this; } OutputStream& OutputStream::operator << (uint32_t ui) { - if (_swap) SwapEndian(ui); + if (isSwapped()) SwapEndian(ui); _out.write((const char*)&ui, sizeof(uint32_t)); return *this; } OutputStream& OutputStream::operator << (int64_t l) { - if (_swap) SwapEndian(l); + if (isSwapped()) SwapEndian(l); _out.write((const char*)&l, sizeof(int64_t)); return *this; } OutputStream& OutputStream::operator << (uint64_t ul) { - if (_swap) SwapEndian(ul); + if (isSwapped()) SwapEndian(ul); _out.write((const char*)&ul, sizeof(uint64_t)); return *this; } OutputStream& OutputStream::operator << (float f) { - if (_swap) SwapEndian(f); + if (isSwapped()) SwapEndian(f); _out.write((const char*)&f, sizeof(float)); return *this; } OutputStream& OutputStream::operator << (double d) { - if (_swap) SwapEndian(d); + if (isSwapped()) SwapEndian(d); _out.write((const char*)&d, sizeof(double)); return *this; } @@ -163,56 +161,56 @@ InputStream& InputStream::operator >> (uint8_t& uch) InputStream& InputStream::operator >> (int16_t& s) { _in.read((char*)&s, sizeof(int16_t)); - if (_swap) SwapEndian(s); + if (isSwapped()) SwapEndian(s); return *this; } InputStream& InputStream::operator >> (uint16_t& us) { _in.read((char*)&us, sizeof(uint16_t)); - if (_swap) SwapEndian(us); + if (isSwapped()) SwapEndian(us); return *this; } InputStream& InputStream::operator >> (int32_t& i) { _in.read((char*)&i, sizeof(int32_t)); - if (_swap) SwapEndian(i); + if (isSwapped()) SwapEndian(i); return *this; } InputStream& InputStream::operator >> (uint32_t& ui) { _in.read((char*)&ui, sizeof(uint32_t)); - if (_swap) SwapEndian(ui); + if (isSwapped()) SwapEndian(ui); return *this; } InputStream& InputStream::operator >> (int64_t& l) { _in.read((char*)&l, sizeof(int64_t)); - if (_swap) SwapEndian(l); + if (isSwapped()) SwapEndian(l); return *this; } InputStream& InputStream::operator >> (uint64_t& ul) { _in.read((char*)&ul, sizeof(uint64_t)); - if (_swap) SwapEndian(ul); + if (isSwapped()) SwapEndian(ul); return *this; } InputStream& InputStream::operator >> (float& f) { _in.read((char*)&f, sizeof(float)); - if (_swap) SwapEndian(f); + if (isSwapped()) SwapEndian(f); return *this; } InputStream& InputStream::operator >> (double& d) { _in.read((char*)&d, sizeof(double)); - if (_swap) SwapEndian(d); + if (isSwapped()) SwapEndian(d); return *this; } @@ -284,11 +282,12 @@ ByteArrayOStreambuf::seekpos(std::streambuf::pos_type pos, // ---------------------------------------------------------------------- -ByteArrayIStreambuf::ByteArrayIStreambuf(const QByteArray& data) : _buffer(data) +ByteArrayIStreambuf::ByteArrayIStreambuf(const QByteArray& data) + : _buffer(data) + , _beg(0) + , _end(data.size()) + , _cur(0) { - _beg = 0; - _end = data.size(); - _cur = 0; } ByteArrayIStreambuf::~ByteArrayIStreambuf() = default; @@ -416,7 +415,7 @@ IODeviceOStreambuf::seekpos(std::streambuf::pos_type pos, // ---------------------------------------------------------------------- -IODeviceIStreambuf::IODeviceIStreambuf(QIODevice* dev) : device(dev), buffer{} +IODeviceIStreambuf::IODeviceIStreambuf(QIODevice* dev) : device(dev) { setg (buffer+pbSize, // beginning of putback area buffer+pbSize, // read position @@ -441,7 +440,7 @@ using std::memcpy; * - use number of characters read * - but at most size of putback area */ - int numPutback; + int numPutback{}; numPutback = gptr() - eback(); if (numPutback > pbSize) { numPutback = pbSize; @@ -454,7 +453,7 @@ using std::memcpy; numPutback); // read at most bufSize new characters - int num; + int num{}; num = device->read(buffer+pbSize, bufSize); if (num <= 0) { // ERROR or EOF @@ -488,7 +487,7 @@ IODeviceIStreambuf::seekoff(std::streambuf::off_type off, endpos = device->size(); break; default: - return pos_type(off_type(-1)); + return {off_type(-1)}; } if (endpos != curpos) { @@ -514,7 +513,6 @@ IODeviceIStreambuf::seekpos(std::streambuf::pos_type pos, // http://www.icce.rug.nl/documents/cplusplus/cplusplus24.html PyStreambuf::PyStreambuf(PyObject* o, std::size_t buf_size, std::size_t put_back) : inp(o) - , type(Unknown) , put_back(std::max(put_back, std::size_t(1))) , buffer(std::max(buf_size, put_back) + put_back) { @@ -529,7 +527,7 @@ PyStreambuf::PyStreambuf(PyObject* o, std::size_t buf_size, std::size_t put_back PyStreambuf::~PyStreambuf() { - sync(); + PyStreambuf::sync(); Py_DECREF(inp); } @@ -547,7 +545,7 @@ PyStreambuf::int_type PyStreambuf::underflow() start += put_back; } - std::size_t n; + std::size_t n{}; Py::Tuple arg(1); long len = static_cast(buffer.size() - (start - base)); arg.setItem(0, Py::Long(len)); @@ -731,7 +729,7 @@ Streambuf::Streambuf(const std::string& data) { _beg = data.begin(); _end = data.end(); - _cur = _beg; + _cur = _beg; //NOLINT } Streambuf::~Streambuf() = default; diff --git a/src/Base/Stream.h b/src/Base/Stream.h index ad39055cb1..10097b0757 100644 --- a/src/Base/Stream.h +++ b/src/Base/Stream.h @@ -49,14 +49,19 @@ public: ByteOrder byteOrder() const; void setByteOrder(ByteOrder); + virtual ~Stream(); protected: Stream(); Stream(const Stream&) = default; + Stream(Stream&&) = default; Stream& operator=(const Stream&) = default; - virtual ~Stream(); + Stream& operator=(Stream&&) = default; - bool _swap; + bool isSwapped() const { return _swap; }; + +private: + bool _swap{false}; }; /** @@ -82,7 +87,9 @@ public: OutputStream& operator << (double d); OutputStream (const OutputStream&) = delete; + OutputStream (OutputStream&&) = delete; void operator = (const OutputStream&) = delete; + void operator = (OutputStream&&) = delete; private: std::ostream& _out; @@ -117,7 +124,9 @@ public: } InputStream (const InputStream&) = delete; + InputStream (InputStream&&) = delete; void operator = (const InputStream&) = delete; + void operator = (InputStream&&) = delete; private: std::istream& _in; @@ -149,7 +158,9 @@ protected: public: ByteArrayOStreambuf(const ByteArrayOStreambuf&) = delete; + ByteArrayOStreambuf(ByteArrayOStreambuf&&) = delete; ByteArrayOStreambuf& operator=(const ByteArrayOStreambuf&) = delete; + ByteArrayOStreambuf& operator=(ByteArrayOStreambuf&&) = delete; private: QBuffer* _buffer; @@ -180,7 +191,9 @@ protected: std::ios::in | std::ios::out) override; public: ByteArrayIStreambuf(const ByteArrayIStreambuf&) = delete; + ByteArrayIStreambuf(ByteArrayIStreambuf&&) = delete; ByteArrayIStreambuf& operator=(const ByteArrayIStreambuf&) = delete; + ByteArrayIStreambuf& operator=(ByteArrayIStreambuf&&) = delete; private: const QByteArray& _buffer; @@ -210,9 +223,11 @@ protected: std::ios::in | std::ios::out) override; public: IODeviceOStreambuf(const IODeviceOStreambuf&) = delete; + IODeviceOStreambuf(IODeviceOStreambuf&&) = delete; IODeviceOStreambuf& operator=(const IODeviceOStreambuf&) = delete; + IODeviceOStreambuf& operator=(IODeviceOStreambuf&&) = delete; -protected: +private: QIODevice* device; }; @@ -238,9 +253,11 @@ protected: std::ios::in | std::ios::out) override; public: IODeviceIStreambuf(const IODeviceIStreambuf&) = delete; + IODeviceIStreambuf(IODeviceIStreambuf&&) = delete; IODeviceIStreambuf& operator=(const IODeviceIStreambuf&) = delete; + IODeviceIStreambuf& operator=(IODeviceIStreambuf&&) = delete; -protected: +private: QIODevice* device; /* data buffer: * - at most, pbSize characters in putback area plus @@ -248,7 +265,7 @@ protected: */ static const int pbSize = 4; // size of putback area static const int bufSize = 1024; // size of the data buffer - char buffer[bufSize+pbSize]; // data buffer + char buffer[bufSize+pbSize]{}; // data buffer }; class BaseExport PyStreambuf : public std::streambuf @@ -286,11 +303,13 @@ private: public: PyStreambuf(const PyStreambuf&) = delete; + PyStreambuf(PyStreambuf&&) = delete; PyStreambuf& operator=(const PyStreambuf&) = delete; + PyStreambuf& operator=(PyStreambuf&&) = delete; private: PyObject* inp; - Type type; + Type type{Unknown}; const std::size_t put_back; std::vector buffer; }; @@ -316,7 +335,9 @@ protected: public: Streambuf(const Streambuf&) = delete; + Streambuf(Streambuf&&) = delete; Streambuf& operator=(const Streambuf&) = delete; + Streambuf& operator=(Streambuf&&) = delete; private: std::string::const_iterator _beg; @@ -338,6 +359,8 @@ class ofstream : public std::ofstream { public: ofstream() = default; + ofstream(const ofstream&) = delete; + ofstream(ofstream&&) = delete; ofstream(const FileInfo& fi, ios_base::openmode mode = std::ios::out | std::ios::trunc) #ifdef _MSC_VER @@ -354,6 +377,9 @@ public: std::ofstream::open(fi.filePath().c_str(), mode); #endif } + + ofstream& operator = (const ofstream&) = delete; + ofstream& operator = (ofstream&&) = delete; }; /** @@ -366,6 +392,8 @@ class ifstream : public std::ifstream { public: ifstream() = default; + ifstream(const ifstream&) = delete; + ifstream(ifstream&&) = delete; ifstream(const FileInfo& fi, ios_base::openmode mode = std::ios::in) #ifdef _MSC_VER @@ -382,6 +410,9 @@ public: std::ifstream::open(fi.filePath().c_str(), mode); #endif } + + ifstream& operator = (const ifstream&) = delete; + ifstream& operator = (ifstream&&) = delete; }; } // namespace Base diff --git a/src/Base/ViewProj.cpp b/src/Base/ViewProj.cpp index b11278ea66..e627e5ad67 100644 --- a/src/Base/ViewProj.cpp +++ b/src/Base/ViewProj.cpp @@ -26,10 +26,7 @@ using namespace Base; -ViewProjMethod::ViewProjMethod() - : hasTransform(false) -{ -} +ViewProjMethod::ViewProjMethod() = default; bool ViewProjMethod::isValid() const { diff --git a/src/Base/ViewProj.h b/src/Base/ViewProj.h index cc78cd2054..414229c0e9 100644 --- a/src/Base/ViewProj.h +++ b/src/Base/ViewProj.h @@ -65,7 +65,7 @@ protected: void transformInput(const Base::Vector3d&, Base::Vector3d&) const; private: - bool hasTransform; + bool hasTransform{false}; Base::Matrix4D transform; }; diff --git a/src/Base/Writer.cpp b/src/Base/Writer.cpp index b1d592f787..91455e24fa 100644 --- a/src/Base/Writer.cpp +++ b/src/Base/Writer.cpp @@ -77,10 +77,6 @@ struct cdata_filter { // --------------------------------------------------------------------------- Writer::Writer() - : indent(0) - , indBuf{} - , forceXML(false) - , fileVersion(1) { indBuf[0] = '\0'; } diff --git a/src/Base/Writer.h b/src/Base/Writer.h index 05d65558ad..51cf93cee6 100644 --- a/src/Base/Writer.h +++ b/src/Base/Writer.h @@ -24,7 +24,6 @@ #define BASE_WRITER_H -#include #include #include #include @@ -150,11 +149,11 @@ protected: std::vector Errors; std::set Modes; - short indent; - char indBuf[1024]; + short indent{0}; + char indBuf[1024]{}; - bool forceXML; - int fileVersion; + bool forceXML{false}; + int fileVersion{1}; public: Writer(const Writer&) = delete;