From f6b03c822f2719d030c82b2015a34d24e777193b Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <github@naumov.de> Date: Tue, 18 May 2021 23:15:21 +0200 Subject: [PATCH] [GL] Use for-range loops. Add iterator IF. --- Applications/FileIO/Gmsh/GMSHPolygonTree.cpp | 31 ++++++++------------ GeoLib/SimplePolygonTree.cpp | 9 +++--- GeoLib/SimplePolygonTree.h | 14 +++++++++ 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Applications/FileIO/Gmsh/GMSHPolygonTree.cpp b/Applications/FileIO/Gmsh/GMSHPolygonTree.cpp index a2d41ac4f4e..db5b2124b14 100644 --- a/Applications/FileIO/Gmsh/GMSHPolygonTree.cpp +++ b/Applications/FileIO/Gmsh/GMSHPolygonTree.cpp @@ -60,7 +60,7 @@ void GMSHPolygonTree::markSharedSegments() return; } - for (auto& child : _children) + for (auto& child : *this) { std::size_t const n_pnts(child->polygon().getNumberOfPoints()); for (std::size_t k(1); k < n_pnts; k++) @@ -81,17 +81,14 @@ bool GMSHPolygonTree::insertStation(GeoLib::Point const* station) if (polygon().isPntInPolygon(*station)) { // try to insert station into the child nodes - for (std::list<SimplePolygonTree*>::const_iterator it( - _children.begin()); - it != _children.end(); - ++it) + for (auto* child : *this) { - if ((*it)->polygon().isPntInPolygon(*station)) + if (child->polygon().isPntInPolygon(*station)) { - bool rval(dynamic_cast<GMSHPolygonTree*>((*it))->insertStation( + bool rval(dynamic_cast<GMSHPolygonTree*>(child)->insertStation( station)); // stop recursion if sub SimplePolygonTree is a leaf - if (rval && (*it)->getNumberOfChildren() == 0) + if (rval && child->getNumberOfChildren() == 0) { _stations.push_back(station); } @@ -115,9 +112,9 @@ void GMSHPolygonTree::insertPolyline(GeoLib::PolylineWithSegmentMarker* ply) // check if polyline segments are inside of the polygon, intersect the // polygon or are part of the boundary of the polygon - for (auto* polygon_tree : _children) + for (auto* child : *this) { - dynamic_cast<GMSHPolygonTree*>(polygon_tree)->insertPolyline(ply); + dynamic_cast<GMSHPolygonTree*>(child)->insertPolyline(ply); } // calculate possible intersection points between the node polygon and the @@ -334,7 +331,7 @@ void GMSHPolygonTree::createGMSHPoints(std::vector<GMSHPoint*>& gmsh_pnts) const } // walk through children - for (auto child : _children) + for (auto* child : *this) { dynamic_cast<GMSHPolygonTree*>(child)->createGMSHPoints(gmsh_pnts); } @@ -405,7 +402,7 @@ void GMSHPolygonTree::writeLineConstraints(std::size_t& line_offset, void GMSHPolygonTree::writeSubPolygonsAsLineConstraints( std::size_t& line_offset, std::size_t sfc_number, std::ostream& out) const { - for (auto child : _children) + for (auto* child : *this) { dynamic_cast<GMSHPolygonTree*>(child) ->writeSubPolygonsAsLineConstraints(line_offset, sfc_number, out); @@ -500,10 +497,9 @@ void GMSHPolygonTree::writeAdditionalPointData(std::size_t& pnt_id_offset, void GMSHPolygonTree::getPointsFromSubPolygons( std::vector<GeoLib::Point const*>& pnts) const { - for (std::list<SimplePolygonTree*>::const_iterator it(_children.begin()); - it != _children.end(); ++it) + for (auto const* child : *this) { - dynamic_cast<GMSHPolygonTree*>((*it))->getPointsFromSubPolygons(pnts); + dynamic_cast<GMSHPolygonTree*>(child)->getPointsFromSubPolygons(pnts); } } @@ -516,10 +512,9 @@ void GMSHPolygonTree::getStationsInsideSubPolygons( stations.push_back(_stations[k]); } - for (std::list<SimplePolygonTree*>::const_iterator it(_children.begin()); - it != _children.end(); ++it) + for (auto const* child : *this) { - dynamic_cast<GMSHPolygonTree*>((*it))->getStationsInsideSubPolygons( + dynamic_cast<GMSHPolygonTree*>(child)->getStationsInsideSubPolygons( stations); } } diff --git a/GeoLib/SimplePolygonTree.cpp b/GeoLib/SimplePolygonTree.cpp index 9db6a5d01f5..070d87e6c22 100644 --- a/GeoLib/SimplePolygonTree.cpp +++ b/GeoLib/SimplePolygonTree.cpp @@ -51,14 +51,13 @@ void SimplePolygonTree::insertSimplePolygonTree( { Polygon const& polygon = polygon_hierarchy->polygon(); bool nfound(true); - for (std::list<SimplePolygonTree*>::const_iterator it(_children.begin()); - it != _children.end() && nfound; - ++it) + for (auto* child : _children) { - if ((*it)->polygon().isPolylineInPolygon(polygon)) + if (child->polygon().isPolylineInPolygon(polygon)) { - (*it)->insertSimplePolygonTree(polygon_hierarchy); + child->insertSimplePolygonTree(polygon_hierarchy); nfound = false; + break; } } if (nfound) diff --git a/GeoLib/SimplePolygonTree.h b/GeoLib/SimplePolygonTree.h index c742eb9e045..7ceda36eac1 100644 --- a/GeoLib/SimplePolygonTree.h +++ b/GeoLib/SimplePolygonTree.h @@ -73,6 +73,20 @@ protected: * in the _node_polygon */ std::list<SimplePolygonTree*> _children; + +public: + decltype(_children)::iterator begin() { return _children.begin(); } + decltype(_children)::iterator end() { return _children.end(); } + + decltype(_children)::const_iterator begin() const + { + return _children.begin(); + } + decltype(_children)::const_iterator end() const + { + return _children.end(); + } + }; /** -- GitLab