Skip to content

Commit

Permalink
Use STL container and range-based loops on XML nodes (#730)
Browse files Browse the repository at this point in the history
* Use STL container and range-based loops on XML nodes

* Break iteration
  • Loading branch information
tobiolo authored Oct 30, 2024
1 parent 8b75dcf commit 149da3a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,14 @@ struct System {
return _(L"File load error.");
}

int GetXMLNodes(wxXmlNode *n, Vector<wxXmlNode *> &ns, Vector<wxXmlAttribute *> *ps = nullptr,
bool attributestoo = false) {
int GetXMLNodes(wxXmlNode *n, std::vector<wxXmlNode *> &ns,
std::vector<wxXmlAttribute *> *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);
}
Expand All @@ -543,8 +543,8 @@ struct System {
c->celltype = wxAtoi(n->GetAttribute(L"type", L"0"));
}

Vector<wxXmlNode *> ns;
Vector<wxXmlAttribute *> ps;
std::vector<wxXmlNode *> ns;
std::vector<wxXmlAttribute *> ps;
int numrows = GetXMLNodes(n, ns, &ps, attributestoo);
if (!numrows) return;

Expand All @@ -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<wxXmlNode *> ins;
std::vector<wxXmlNode *> ins;
int xs = GetXMLNodes(ns[i], ins);
if (!i) {
desiredxs = xs ? xs : 1;
Expand All @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit 149da3a

Please sign in to comment.