From e58f72933aee5c0b05cd06390f341d925264eede Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 16 Nov 2018 01:14:33 +0100 Subject: [PATCH] fix DocumentObject::isInInListRecursive and DocumentObject::isInOutListRecursive --- src/App/DocumentObject.cpp | 161 +++++++++++++++++++------------------ src/App/DocumentObject.h | 4 - 2 files changed, 81 insertions(+), 84 deletions(-) diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index 79dadaaf0d..7c79ed223b 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -297,7 +297,9 @@ std::vector DocumentObject::getInList(void) const #endif // if USE_OLD_DAG -void _getInListRecursive(std::set& objSet, const DocumentObject* obj, const DocumentObject* checkObj, int depth) +void _getInListRecursive(std::set& objSet, + const DocumentObject* obj, + const DocumentObject* checkObj, int depth) { for (const auto objIt : obj->getInList()) { // if the check object is in the recursive inList we have a cycle! @@ -326,7 +328,9 @@ std::vector DocumentObject::getInListRecursive(void) const return array; } -void _getOutListRecursive(std::set& objSet, const DocumentObject* obj, const DocumentObject* checkObj, int depth) +void _getOutListRecursive(std::set& objSet, + const DocumentObject* obj, + const DocumentObject* checkObj, int depth) { for (const auto objIt : obj->getOutList()) { // if the check object is in the recursive inList we have a cycle! @@ -355,6 +359,81 @@ std::vector DocumentObject::getOutListRecursive(void) cons return array; } +// helper for isInInListRecursive() +bool _isInInListRecursive(const DocumentObject* act, + const DocumentObject* checkObj, int depth) +{ +#ifndef USE_OLD_DAG + for (auto obj : act->getInList()) { + if (obj == checkObj) + return true; + // if we reach the depth limit we have a cycle! + if (depth <= 0) { + throw Base::RuntimeError("DocumentObject::isInInListRecursive(): cyclic dependency detected!"); + } + + if (_isInInListRecursive(obj, checkObj, depth - 1)) + return true; + } +#else + (void)act; + (void)checkObj; + (void)depth; +#endif + + return false; +} + +bool DocumentObject::isInInListRecursive(DocumentObject *linkTo) const +{ + int maxDepth = getDocument()->countObjects() + 2; + return _isInInListRecursive(this, linkTo, maxDepth); +} + +bool DocumentObject::isInInList(DocumentObject *linkTo) const +{ +#ifndef USE_OLD_DAG + if (std::find(_inList.begin(), _inList.end(), linkTo) != _inList.end()) + return true; + else + return false; +#else + (void)linkTo; + return false; +#endif +} + +// helper for isInOutListRecursive() +bool _isInOutListRecursive(const DocumentObject* act, + const DocumentObject* checkObj, int depth) +{ +#ifndef USE_OLD_DAG + for (auto obj : act->getOutList()) { + if (obj == checkObj) + return true; + // if we reach the depth limit we have a cycle! + if (depth <= 0) { + throw Base::RuntimeError("DocumentObject::isInOutListRecursive(): cyclic dependency detected!"); + } + + if (_isInOutListRecursive(obj, checkObj, depth - 1)) + return true; + } +#else + (void)act; + (void)checkObj; + (void)depth; +#endif + + return false; +} + +bool DocumentObject::isInOutListRecursive(DocumentObject *linkTo) const +{ + int maxDepth = getDocument()->countObjects() + 2; + return _isInOutListRecursive(this, linkTo, maxDepth); +} + std::vector > DocumentObject::getPathsByOutList(App::DocumentObject* to) const { @@ -400,84 +479,6 @@ bool DocumentObject::testIfLinkDAGCompatible(PropertyLinkSub &linkTo) const return this->testIfLinkDAGCompatible(linkTo_in_vector); } -bool DocumentObject::_isInInListRecursive(const DocumentObject* /*act*/, - const DocumentObject* test, - const DocumentObject* checkObj, int depth) const -{ -#ifndef USE_OLD_DAG - if (std::find(_inList.begin(), _inList.end(), test) != _inList.end()) - return true; - - for (auto obj : _inList) { - // if the check object is in the recursive inList we have a cycle! - if (obj == checkObj || depth <= 0) { - throw Base::RuntimeError("DocumentObject::isInInListRecursive(): cyclic dependency detected!"); - } - - if (_isInInListRecursive(obj, test, checkObj, depth - 1)) - return true; - } -#else - (void)test; - (void)checkObj; - (void)depth; -#endif - - return false; -} - -bool DocumentObject::isInInListRecursive(DocumentObject *linkTo) const -{ - return _isInInListRecursive(this, linkTo, this, getDocument()->countObjects()); -} - -bool DocumentObject::isInInList(DocumentObject *linkTo) const -{ -#ifndef USE_OLD_DAG - if (std::find(_inList.begin(), _inList.end(), linkTo) != _inList.end()) - return true; - else - return false; -#else - (void)linkTo; - return false; -#endif -} - -bool DocumentObject::_isInOutListRecursive(const DocumentObject* act, - const DocumentObject* test, - const DocumentObject* checkObj, int depth) const -{ -#ifndef USE_OLD_DAG - std::vector outList = act->getOutList(); - - if (std::find(outList.begin(), outList.end(), test) != outList.end()) - return true; - - for (auto obj : outList) { - // if the check object is in the recursive inList we have a cycle! - if (obj == checkObj || depth <= 0) { - throw Base::RuntimeError("DocumentObject::isInOutListRecursive(): cyclic dependency detected!"); - } - - if (_isInOutListRecursive(obj, test, checkObj, depth - 1)) - return true; - } -#else - (void)act; - (void)test; - (void)checkObj; - (void)depth; -#endif - - return false; -} - -bool DocumentObject::isInOutListRecursive(DocumentObject *linkTo) const -{ - return _isInOutListRecursive(this, linkTo, this, getDocument()->countObjects()); -} - void DocumentObject::onLostLinkToObject(DocumentObject*) { diff --git a/src/App/DocumentObject.h b/src/App/DocumentObject.h index 30dc94ea83..4a445eee06 100644 --- a/src/App/DocumentObject.h +++ b/src/App/DocumentObject.h @@ -305,10 +305,6 @@ private: // Back pointer to all the fathers in a DAG of the document // this is used by the document (via friend) to have a effective DAG handling std::vector _inList; - // helper for isInInListRecursive() - bool _isInInListRecursive(const DocumentObject *act, const DocumentObject* test, const DocumentObject* checkObj, int depth) const; - // helper for isInOutListRecursive() - bool _isInOutListRecursive(const DocumentObject *act, const DocumentObject* test, const DocumentObject* checkObj, int depth) const; }; } //namespace App