From 149da3a41fbe2df60c110890ad1f09da8c14bf01 Mon Sep 17 00:00:00 2001 From: Tobias Predel Date: Wed, 30 Oct 2024 18:39:52 +0100 Subject: [PATCH] Use STL container and range-based loops on XML nodes (#730) * Use STL container and range-based loops on XML nodes * Break iteration --- src/system.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/system.h b/src/system.h index c506f0b5..43eb0b8d 100644 --- a/src/system.h +++ b/src/system.h @@ -513,14 +513,14 @@ struct System { return _(L"File load error."); } - int GetXMLNodes(wxXmlNode *n, Vector &ns, Vector *ps = nullptr, - bool attributestoo = false) { + int GetXMLNodes(wxXmlNode *n, std::vector &ns, + std::vector *ps = nullptr, bool attributestoo = false) { for (wxXmlNode *child = n->GetChildren(); child; child = child->GetNext()) { - if (child->GetType() == wxXML_ELEMENT_NODE) ns.push() = child; + if (child->GetType() == wxXML_ELEMENT_NODE) ns.push_back(child); } if (attributestoo && ps) for (wxXmlAttribute *child = n->GetAttributes(); child; child = child->GetNext()) { - ps->push() = child; + ps->push_back(child); } return ns.size() + (ps ? ps->size() : 0); } @@ -543,8 +543,8 @@ struct System { c->celltype = wxAtoi(n->GetAttribute(L"type", L"0")); } - Vector ns; - Vector ps; + std::vector ns; + std::vector ps; int numrows = GetXMLNodes(n, ns, &ps, attributestoo); if (!numrows) return; @@ -553,11 +553,15 @@ struct System { FillXML(c, ns[0], attributestoo); } else { bool allrow = n->GetName() == L"grid"; - loopv(i, ns) if (ns[i]->GetName() != L"row") allrow = false; + for (auto *n : ns) + if (n->GetName() != L"row") { + allrow = false; + break; + } if (allrow) { int desiredxs; loopv(i, ns) { - Vector ins; + std::vector ins; int xs = GetXMLNodes(ns[i], ins); if (!i) { desiredxs = xs ? xs : 1; @@ -566,7 +570,6 @@ struct System { } loop(j, desiredxs) if (ins.size() > j) FillXML(c->grid->C(j, i), ins[j], attributestoo); - ins.setsize_nd(0); } } else { c->AddGrid(1, numrows); @@ -575,9 +578,6 @@ struct System { loopv(i, ns) FillXML(c->grid->C(0, i + ps.size()), ns[i], attributestoo); } } - - ns.setsize_nd(0); - ps.setsize_nd(0); } void SetGridSettingsFromXML(Cell *c, wxXmlNode *n) {