diff --git a/include/cantera/base/xml.h b/include/cantera/base/xml.h index f5a127155..0aaa708e6 100644 --- a/include/cantera/base/xml.h +++ b/include/cantera/base/xml.h @@ -566,9 +566,19 @@ public: * * @param children output vector of pointers to XML_Node children * with the matching name + * @deprecated To be removed after Cantera 2.2. Use the version that returns + * the vector of child nodes */ void getChildren(const std::string& name, std::vector& children) const; + //! Get a vector of pointers to XML_Node containing all of the children + //! of the current node which matche the given name + /*! + * @param name Name of the XML_Node children to search for + * @return vector of pointers to child XML_Nodes with the matching name + */ + std::vector getChildren(const std::string& name) const; + //! Return a changeable reference to a child of the current node, named by the argument /*! * Note the underlying data allows for more than one XML element with the same name. diff --git a/src/base/ctml.cpp b/src/base/ctml.cpp index 07209e1d9..ff53ed7b2 100644 --- a/src/base/ctml.cpp +++ b/src/base/ctml.cpp @@ -183,8 +183,7 @@ void getNamedStringValue(const Cantera::XML_Node& node, const std::string& nameS void getIntegers(const Cantera::XML_Node& node, std::map& v) { - std::vector f; - node.getChildren("integer",f); + std::vector f = node.getChildren("integer"); for (size_t i = 0; i < f.size(); i++) { const XML_Node& fi = *f[i]; if (fi["min"] != "" && fi["max"] != "") { @@ -329,16 +328,14 @@ size_t getFloatArray(const Cantera::XML_Node& node, std::vector & v, { const Cantera::XML_Node* readNode = &node; if (node.name() != nodeName) { - vector ll; - node.getChildren(nodeName, ll); + vector ll = node.getChildren(nodeName); if (ll.size() == 0) { throw CanteraError("getFloatArray", "wrong xml element type/name: was expecting " + nodeName + "but accessed " + node.name()); } else { readNode = ll[0]; - ll.clear(); - readNode->getChildren("floatArray", ll); + ll = readNode->getChildren("floatArray"); if (ll.size() > 0) { readNode = ll[0]; } diff --git a/src/base/xml.cpp b/src/base/xml.cpp index 1c46916c3..877a5b01d 100644 --- a/src/base/xml.cpp +++ b/src/base/xml.cpp @@ -897,6 +897,8 @@ void XML_Node::unlock() void XML_Node::getChildren(const std::string& nm, std::vector& children_) const { + warn_deprecated("XML_Node::getChildren", "To be removed after Cantera 2.2." + "Use overload that returns the vector of XML_Node pointers."); for (size_t i = 0; i < nChildren(); i++) { if (child(i).name() == nm) { children_.push_back(&child(i)); @@ -904,6 +906,17 @@ void XML_Node::getChildren(const std::string& nm, } } +std::vector XML_Node::getChildren(const std::string& nm) const +{ + std::vector children_; + for (size_t i = 0; i < nChildren(); i++) { + if (child(i).name() == nm) { + children_.push_back(&child(i)); + } + } + return children_; +} + XML_Node& XML_Node::child(const std::string& aloc) const { string::size_type iloc; diff --git a/src/equil/MultiPhase.cpp b/src/equil/MultiPhase.cpp index b80a8788e..9b6cdd0c4 100644 --- a/src/equil/MultiPhase.cpp +++ b/src/equil/MultiPhase.cpp @@ -755,8 +755,7 @@ void importFromXML(string infile, string id) if (x.name() != "multiphase") throw CanteraError("MultiPhase::importFromXML", "Current XML_Node is not a multiphase element."); - vector phases; - x.getChildren("phase",phases); + vector phases = x.getChildren("phase"); int np = phases.size(); int n; ThermoPhase* p; diff --git a/src/kinetics/importKinetics.cpp b/src/kinetics/importKinetics.cpp index 4a30e1091..3b609d019 100644 --- a/src/kinetics/importKinetics.cpp +++ b/src/kinetics/importKinetics.cpp @@ -206,8 +206,7 @@ bool getReagents(const XML_Node& rxn, Kinetics& kin, int rp, */ if (rp == 1 && rxn.hasChild("order")) { - std::vector ord; - rxn.getChildren("order", ord); + std::vector ord = rxn.getChildren("order"); doublereal forder; for (size_t nn = 0; nn < ord.size(); nn++) { const XML_Node& oo = *ord[nn]; @@ -306,8 +305,7 @@ bool getOrders(const XML_Node& rxnNode, Kinetics& kin, * Check to see if reaction orders have been specified. */ if (rxnNode.hasChild("order")) { - std::vector ord; - rxnNode.getChildren("order", ord); + std::vector ord = rxnNode.getChildren("order"); doublereal forder; for (size_t nn = 0; nn < ord.size(); nn++) { const XML_Node& oo = *ord[nn]; @@ -327,8 +325,7 @@ bool getOrders(const XML_Node& rxnNode, Kinetics& kin, } if (rxnNode.hasChild("orders")) { - std::vector orders; - rxnNode.getChildren("orders", orders); + std::vector orders = rxnNode.getChildren("orders"); // // Doesn't really make sense to have more than one of these blocks // @@ -628,8 +625,7 @@ static void getStick(const XML_Node& node, Kinetics& kin, static void getCoverageDependence(const XML_Node& node, thermo_t& surfphase, ReactionData& rdata) { - vector cov; - node.getChildren("coverage", cov); + vector cov = node.getChildren("coverage"); size_t k, nc = cov.size(); doublereal e; string spname; @@ -1131,8 +1127,6 @@ bool installReactionArrays(const XML_Node& p, Kinetics& kin, std::string default_phase, bool check_for_duplicates) { rxninfo _rxns; - - vector rarrays; int itot = 0; /* * Search the children of the phase element for the @@ -1142,7 +1136,7 @@ bool installReactionArrays(const XML_Node& p, Kinetics& kin, * Each one will be processed sequentially, with the * end result being purely additive. */ - p.getChildren("reactionArray",rarrays); + vector rarrays = p.getChildren("reactionArray"); if (rarrays.empty()) { kin.finalize(); return false; @@ -1190,11 +1184,8 @@ bool installReactionArrays(const XML_Node& p, Kinetics& kin, * a reaction if it's tagged by one of the include fields. * Or, we include all reactions if there are no include fields. */ - vector incl; - rxns.getChildren("include",incl); - - vector allrxns; - rdata->getChildren("reaction",allrxns); + vector incl = rxns.getChildren("include"); + vector allrxns = rdata->getChildren("reaction"); // if no 'include' directive, then include all reactions if (incl.empty()) { for (size_t i = 0; i < allrxns.size(); i++) { diff --git a/src/oneD/Domain1D.cpp b/src/oneD/Domain1D.cpp index 95cfb1082..660aa9c48 100644 --- a/src/oneD/Domain1D.cpp +++ b/src/oneD/Domain1D.cpp @@ -109,8 +109,7 @@ XML_Node& Domain1D::save(XML_Node& o, const doublereal* const sol) void Domain1D::restore(const XML_Node& dom, doublereal* soln, int loglevel) { vector_fp values; - vector nodes; - dom.getChildren("floatArray", nodes); + vector nodes = dom.getChildren("floatArray"); for (size_t i = 0; i < nodes.size(); i++) { string title = nodes[i]->attrib("title"); getFloatArray(*nodes[i], values, false); diff --git a/src/oneD/Sim1D.cpp b/src/oneD/Sim1D.cpp index ef52112a0..082f5d7dd 100644 --- a/src/oneD/Sim1D.cpp +++ b/src/oneD/Sim1D.cpp @@ -127,8 +127,7 @@ void Sim1D::restore(const std::string& fname, const std::string& id, throw CanteraError("Sim1D::restore","No solution with id = "+id); } - vector xd; - f->getChildren("domain", xd); + vector xd = f->getChildren("domain"); if (xd.size() != m_nd) { throw CanteraError("Sim1D::restore", "Solution does not contain the " " correct number of domains. Found " + diff --git a/src/oneD/StFlow.cpp b/src/oneD/StFlow.cpp index 73bfd8f4f..73a9e3d23 100644 --- a/src/oneD/StFlow.cpp +++ b/src/oneD/StFlow.cpp @@ -587,8 +587,7 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel) size_t nsp = m_thermo->nSpecies(); vector_int did_species(nsp, 0); - vector str; - dom.getChildren("string",str); + vector str = dom.getChildren("string"); for (size_t istr = 0; istr < str.size(); istr++) { const XML_Node& nd = *str[istr]; writelog(nd["title"]+": "+nd.value()+"\n"); @@ -598,8 +597,7 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel) pp = getFloat(dom, "pressure", "pressure"); setPressure(pp); - vector d; - dom.child("grid_data").getChildren("floatArray",d); + vector d = dom.child("grid_data").getChildren("floatArray"); size_t nd = d.size(); vector_fp x; diff --git a/src/thermo/LatticeSolidPhase.cpp b/src/thermo/LatticeSolidPhase.cpp index ea28940e1..4024c6d9c 100644 --- a/src/thermo/LatticeSolidPhase.cpp +++ b/src/thermo/LatticeSolidPhase.cpp @@ -342,8 +342,7 @@ void LatticeSolidPhase::installSlavePhases(Cantera::XML_Node* phaseNode) XML_Node& eosdata = phaseNode->child("thermo"); XML_Node& la = eosdata.child("LatticeArray"); - std::vector lattices; - la.getChildren("phase",lattices); + std::vector lattices = la.getChildren("phase"); for (size_t n = 0; n < m_nlattice; n++) { LatticePhase* lp = m_lattice[n]; size_t nsp = lp->nSpecies(); @@ -471,8 +470,7 @@ void LatticeSolidPhase::setParametersFromXML(const XML_Node& eosdata) { eosdata._require("model","LatticeSolid"); XML_Node& la = eosdata.child("LatticeArray"); - std::vector lattices; - la.getChildren("phase",lattices); + std::vector lattices = la.getChildren("phase"); size_t nl = lattices.size(); m_nlattice = nl; for (size_t n = 0; n < nl; n++) { diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index 2be07b9e0..308c2e2b7 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -243,8 +243,7 @@ static void formSpeciesXMLNodeList(std::vector &spDataNodeList, // spArray_names field, then add all species // defined in the corresponding database to the phase if (nsp == 1 && spnames[0] == "all") { - std::vector allsp; - db->getChildren("species", allsp); + std::vector allsp = db->getChildren("species"); nsp = allsp.size(); spnames.resize(nsp); for (size_t nn = 0; nn < nsp; nn++) { @@ -266,8 +265,7 @@ static void formSpeciesXMLNodeList(std::vector &spDataNodeList, } } } else if (nsp == 1 && spnames[0] == "unique") { - std::vector allsp; - db->getChildren("species", allsp); + std::vector allsp = db->getChildren("species"); nsp = allsp.size(); spnames.resize(nsp); for (size_t nn = 0; nn < nsp; nn++) { @@ -388,8 +386,7 @@ bool importPhase(XML_Node& phase, ThermoPhase* th, * sources. For each one, a speciesArray element must be * present. ***************************************************************/ - vector sparrays; - phase.getChildren("speciesArray", sparrays); + vector sparrays = phase.getChildren("speciesArray"); if (ssConvention != cSS_CONVENTION_SLAVE) { if (sparrays.empty()) { throw CanteraError("importPhase", @@ -641,8 +638,7 @@ const XML_Node* speciesXML_Node(const std::string& kname, throw CanteraError("speciesXML_Node()", "Unexpected phaseSpeciesData name: " + jname); } - vector xspecies; - phaseSpeciesData->getChildren("species", xspecies); + vector xspecies = phaseSpeciesData->getChildren("species"); for (size_t j = 0; j < xspecies.size(); j++) { const XML_Node& sp = *xspecies[j]; jname = sp["name"];