From af5c40d8e81f595cd5d7b3d374539de5d7475d4c Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 15 Mar 2025 18:39:59 +0100 Subject: [PATCH] App: Fix some linter warnings --- src/App/DocumentObserver.cpp | 129 ++++++++++++++++++++++------------- src/App/DocumentObserver.h | 33 +++++---- 2 files changed, 101 insertions(+), 61 deletions(-) diff --git a/src/App/DocumentObserver.cpp b/src/App/DocumentObserver.cpp index b123983c37..a9906c2d63 100644 --- a/src/App/DocumentObserver.cpp +++ b/src/App/DocumentObserver.cpp @@ -38,38 +38,49 @@ namespace sp = std::placeholders; DocumentT::DocumentT() = default; DocumentT::DocumentT(Document* doc) -{ - document = doc->getName(); -} + : document {doc->getName()} +{} -DocumentT::DocumentT(const std::string& name) -{ - document = name; -} +DocumentT::DocumentT(std::string name) + : document {std::move(name)} +{} DocumentT::DocumentT(const DocumentT& doc) -{ - document = doc.document; -} + : document {doc.document} +{} + +DocumentT::DocumentT(DocumentT&& doc) noexcept + : document {std::move(doc.document)} +{} DocumentT::~DocumentT() = default; -void DocumentT::operator=(const DocumentT& doc) +DocumentT& DocumentT::operator=(const DocumentT& doc) { - if (this == &doc) { - return; + if (this != &doc) { + document = doc.document; } - document = doc.document; + return *this; } -void DocumentT::operator=(const Document* doc) +DocumentT& DocumentT::operator=(DocumentT&& doc) noexcept +{ + if (this != &doc) { + document = std::move(doc.document); + } + return *this; +} + +DocumentT& DocumentT::operator=(const Document* doc) { document = doc->getName(); + return *this; } -void DocumentT::operator=(const std::string& name) +DocumentT& DocumentT::operator=(const std::string& name) { document = name; + return *this; } Document* DocumentT::getDocument() const @@ -98,7 +109,7 @@ DocumentObjectT::DocumentObjectT(const DocumentObjectT& other) *this = other; } -DocumentObjectT::DocumentObjectT(DocumentObjectT&& other) +DocumentObjectT::DocumentObjectT(DocumentObjectT&& other) noexcept { *this = std::move(other); } @@ -145,7 +156,7 @@ DocumentObjectT& DocumentObjectT::operator=(const DocumentObjectT& obj) return *this; } -DocumentObjectT& DocumentObjectT::operator=(DocumentObjectT&& obj) +DocumentObjectT& DocumentObjectT::operator=(DocumentObjectT&& obj) noexcept { if (this == &obj) { return *this; @@ -157,7 +168,7 @@ DocumentObjectT& DocumentObjectT::operator=(DocumentObjectT&& obj) return *this; } -void DocumentObjectT::operator=(const DocumentObject* obj) +DocumentObjectT& DocumentObjectT::operator=(const DocumentObject* obj) { if (!obj || !obj->isAttachedToDocument()) { object.clear(); @@ -171,9 +182,11 @@ void DocumentObjectT::operator=(const DocumentObject* obj) document = obj->getDocument()->getName(); property.clear(); } + + return *this; } -void DocumentObjectT::operator=(const Property* prop) +DocumentObjectT& DocumentObjectT::operator=(const Property* prop) { if (!prop || !prop->hasName() || !prop->getContainer() || !prop->getContainer()->isDerivedFrom()) { @@ -182,13 +195,14 @@ void DocumentObjectT::operator=(const Property* prop) document.clear(); property.clear(); } - else { - auto obj = static_cast(prop->getContainer()); + else if (auto obj = freecad_cast(prop->getContainer())) { object = obj->getNameInDocument(); label = obj->Label.getValue(); document = obj->getDocument()->getName(); property = prop->getName(); } + + return *this; } bool DocumentObjectT::operator==(const DocumentObjectT& other) const @@ -288,7 +302,7 @@ SubObjectT::SubObjectT() = default; SubObjectT::SubObjectT(const SubObjectT&) = default; -SubObjectT::SubObjectT(SubObjectT&& other) +SubObjectT::SubObjectT(SubObjectT&& other) noexcept : DocumentObjectT(std::move(other)) , subname(std::move(other.subname)) {} @@ -312,6 +326,8 @@ SubObjectT::SubObjectT(const char* docName, const char* objName, const char* s) , subname(s ? s : "") {} +SubObjectT::~SubObjectT() = default; + bool SubObjectT::operator<(const SubObjectT& other) const { if (getDocumentName() < other.getDocumentName()) { @@ -340,18 +356,18 @@ SubObjectT& SubObjectT::operator=(const SubObjectT& other) if (this == &other) { return *this; } - static_cast(*this) = other; + static_cast(*this) = other; // NOLINT subname = other.subname; return *this; } -SubObjectT& SubObjectT::operator=(SubObjectT&& other) +SubObjectT& SubObjectT::operator=(SubObjectT&& other) noexcept { if (this == &other) { return *this; } - static_cast(*this) = std::move(other); subname = std::move(other.subname); + static_cast(*this) = std::move(other); return *this; } @@ -659,8 +675,10 @@ PropertyLinkT::PropertyLinkT(const std::vector& objs) } } -PropertyLinkT::PropertyLinkT(const std::vector& objs, - const std::vector& subNames) +PropertyLinkT::PropertyLinkT( + const std::vector& objs, + const std::vector& subNames +) : PropertyLinkT() { if (!objs.empty() && objs.size() == subNames.size()) { @@ -708,7 +726,8 @@ public: if (doc) { // NOLINTBEGIN connectApplicationDeletedDocument = App::GetApplication().signalDeleteDocument.connect( - std::bind(&Private::deletedDocument, this, sp::_1)); + std::bind(&Private::deletedDocument, this, sp::_1) + ); // NOLINTEND } } @@ -801,12 +820,15 @@ public: // NOLINTBEGIN indocument = true; connectApplicationDeletedDocument = App::GetApplication().signalDeleteDocument.connect( - std::bind(&Private::deletedDocument, this, sp::_1)); + std::bind(&Private::deletedDocument, this, sp::_1) + ); App::Document* doc = obj->getDocument(); - connectDocumentCreatedObject = - doc->signalNewObject.connect(std::bind(&Private::createdObject, this, sp::_1)); - connectDocumentDeletedObject = - doc->signalDeletedObject.connect(std::bind(&Private::deletedObject, this, sp::_1)); + connectDocumentCreatedObject = doc->signalNewObject.connect( + std::bind(&Private::createdObject, this, sp::_1) + ); + connectDocumentDeletedObject = doc->signalDeletedObject.connect( + std::bind(&Private::deletedObject, this, sp::_1) + ); // NOLINTEND } } @@ -881,11 +903,14 @@ DocumentObserver::DocumentObserver() { // NOLINTBEGIN this->connectApplicationCreatedDocument = App::GetApplication().signalNewDocument.connect( - std::bind(&DocumentObserver::slotCreatedDocument, this, sp::_1)); + std::bind(&DocumentObserver::slotCreatedDocument, this, sp::_1) + ); this->connectApplicationDeletedDocument = App::GetApplication().signalDeleteDocument.connect( - std::bind(&DocumentObserver::slotDeletedDocument, this, sp::_1)); + std::bind(&DocumentObserver::slotDeletedDocument, this, sp::_1) + ); this->connectApplicationActivateDocument = App::GetApplication().signalActiveDocument.connect( - std::bind(&DocumentObserver::slotActivateDocument, this, sp::_1)); + std::bind(&DocumentObserver::slotActivateDocument, this, sp::_1) + ); // NOLINTEND } @@ -918,15 +943,20 @@ void DocumentObserver::attachDocument(Document* doc) // NOLINTBEGIN this->connectDocumentCreatedObject = _document->signalNewObject.connect( - std::bind(&DocumentObserver::slotCreatedObject, this, sp::_1)); + std::bind(&DocumentObserver::slotCreatedObject, this, sp::_1) + ); this->connectDocumentDeletedObject = _document->signalDeletedObject.connect( - std::bind(&DocumentObserver::slotDeletedObject, this, sp::_1)); + std::bind(&DocumentObserver::slotDeletedObject, this, sp::_1) + ); this->connectDocumentChangedObject = _document->signalChangedObject.connect( - std::bind(&DocumentObserver::slotChangedObject, this, sp::_1, sp::_2)); + std::bind(&DocumentObserver::slotChangedObject, this, sp::_1, sp::_2) + ); this->connectDocumentRecomputedObject = _document->signalRecomputedObject.connect( - std::bind(&DocumentObserver::slotRecomputedObject, this, sp::_1)); + std::bind(&DocumentObserver::slotRecomputedObject, this, sp::_1) + ); this->connectDocumentRecomputed = _document->signalRecomputed.connect( - std::bind(&DocumentObserver::slotRecomputedDocument, this, sp::_1)); + std::bind(&DocumentObserver::slotRecomputedDocument, this, sp::_1) + ); // NOLINTEND } } @@ -958,8 +988,7 @@ void DocumentObserver::slotCreatedObject(const App::DocumentObject& /*Obj*/) void DocumentObserver::slotDeletedObject(const App::DocumentObject& /*Obj*/) {} -void DocumentObserver::slotChangedObject(const App::DocumentObject& /*Obj*/, - const App::Property& /*Prop*/) +void DocumentObserver::slotChangedObject(const App::DocumentObject& /*Obj*/, const App::Property& /*Prop*/) {} void DocumentObserver::slotRecomputedObject(const DocumentObject& /*Obj*/) @@ -995,7 +1024,7 @@ void DocumentObjectObserver::removeFromObservation(App::DocumentObject* obj) _objects.erase(obj); } -void DocumentObjectObserver::slotCreatedDocument(const App::Document&) +void DocumentObjectObserver::slotCreatedDocument([[maybe_unused]] const App::Document& doc) {} void DocumentObjectObserver::slotDeletedDocument(const App::Document& Doc) @@ -1007,13 +1036,12 @@ void DocumentObjectObserver::slotDeletedDocument(const App::Document& Doc) } } -void DocumentObjectObserver::slotCreatedObject(const App::DocumentObject&) +void DocumentObjectObserver::slotCreatedObject([[maybe_unused]] const App::DocumentObject& obj) {} void DocumentObjectObserver::slotDeletedObject(const App::DocumentObject& Obj) { - std::set::iterator it = - _objects.find(const_cast(&Obj)); + auto it = _objects.find(const_cast(&Obj)); if (it != _objects.end()) { _objects.erase(it); } @@ -1022,7 +1050,10 @@ void DocumentObjectObserver::slotDeletedObject(const App::DocumentObject& Obj) } } -void DocumentObjectObserver::slotChangedObject(const App::DocumentObject&, const App::Property&) +void DocumentObjectObserver::slotChangedObject( + [[maybe_unused]] const App::DocumentObject& obj, + [[maybe_unused]] const App::Property& prop +) {} void DocumentObjectObserver::cancelObservation() diff --git a/src/App/DocumentObserver.h b/src/App/DocumentObserver.h index 51219ff6c9..abed70c24d 100644 --- a/src/App/DocumentObserver.h +++ b/src/App/DocumentObserver.h @@ -55,17 +55,21 @@ public: /*! Constructor */ DocumentT(Document*); // explicit bombs /*! Constructor */ - explicit DocumentT(const std::string&); + explicit DocumentT(std::string); /*! Constructor */ DocumentT(const DocumentT&); + /*! Move constructor */ + DocumentT(DocumentT&&) noexcept; /*! Destructor */ ~DocumentT(); /*! Assignment operator */ - void operator=(const DocumentT&); + DocumentT& operator=(const DocumentT&); + /*! Move assignment operator */ + DocumentT& operator=(DocumentT&&) noexcept; /*! Assignment operator */ - void operator=(const Document*); + DocumentT& operator=(const Document*); /*! Assignment operator */ - void operator=(const std::string&); + DocumentT& operator=(const std::string&); bool operator==(const DocumentT& other) const { @@ -108,7 +112,7 @@ public: /*! Constructor */ DocumentObjectT(const DocumentObjectT&); /*! Constructor */ - DocumentObjectT(DocumentObjectT&&); + DocumentObjectT(DocumentObjectT&&) noexcept; /*! Constructor */ explicit DocumentObjectT(const DocumentObject*); /*! Constructor */ @@ -122,11 +126,11 @@ public: /*! Assignment operator */ DocumentObjectT& operator=(const DocumentObjectT&); /*! Assignment operator */ - DocumentObjectT& operator=(DocumentObjectT&&); + DocumentObjectT& operator=(DocumentObjectT&&) noexcept; /*! Assignment operator */ - void operator=(const DocumentObject*); + DocumentObjectT& operator=(const DocumentObject*); /*! Assignment operator */ - void operator=(const Property*); + DocumentObjectT& operator=(const Property*); /*! Equality operator */ bool operator==(const DocumentObjectT&) const; @@ -191,11 +195,14 @@ public: /*! Constructor */ SubObjectT(); + /*! Destructor */ + ~SubObjectT(); + /*! Constructor */ SubObjectT(const SubObjectT&); /*! Constructor */ - SubObjectT(SubObjectT&&); + SubObjectT(SubObjectT&&) noexcept; /*! Constructor */ SubObjectT(const DocumentObjectT& obj, const char* subname); @@ -213,7 +220,7 @@ public: SubObjectT& operator=(const SubObjectT&); /*! Assignment operator */ - SubObjectT& operator=(SubObjectT&&); + SubObjectT& operator=(SubObjectT&&) noexcept; /*! Assignment operator */ SubObjectT& operator=(const DocumentObjectT&); @@ -376,7 +383,9 @@ public: // disable DocumentWeakPtrT(const DocumentWeakPtrT&) = delete; + DocumentWeakPtrT(DocumentWeakPtrT&&) = delete; DocumentWeakPtrT& operator=(const DocumentWeakPtrT&) = delete; + DocumentWeakPtrT& operator=(DocumentWeakPtrT&&) = delete; private: class Private; @@ -444,8 +453,6 @@ public: private: App::DocumentObject* _get() const noexcept; - -private: class Private; std::unique_ptr d; }; @@ -527,7 +534,9 @@ public: // disable WeakPtrT(const WeakPtrT&) = delete; + WeakPtrT(WeakPtrT&&) = delete; WeakPtrT& operator=(const WeakPtrT&) = delete; + WeakPtrT& operator=(WeakPtrT&&) = delete; private: DocumentObjectWeakPtrT ptr;