//----------------------------------------------------------------------------------------- int precompfixt(XmlElement& xft, XmlElement& xf, ostream& outf, bool nounique) { int depth(1); XmlElement::XmlSet fldlist; xft.find("fix/fields/field", fldlist); xf.find("fix/fields/field", fldlist); if (!nounique) filter_unique(fldlist); XmlElement::XmlSet comlist, comlistfixt; Components components, componentsfixt; xft.find("fix/components/component", comlistfixt); xf.find("fix/components/component", comlist); load_components(comlistfixt, componentsfixt); load_components(comlist, components); outf << doctype << endl; outf << '<' << xft.GetTag(); output_attributes(xft, outf); outf << '>' << endl; const XmlElement *header(xft.find("fix/header")); if (header) process_messages(*header, componentsfixt, "header", 0, outf); const XmlElement *trailer(xft.find("fix/trailer")); if (trailer) process_messages(*trailer, componentsfixt, "trailer", 0, outf); outf << string(depth * 2, ' ') << "<messages>" << endl; XmlElement::XmlSet msglist; xft.find("fix/messages/message", msglist); for(auto const *pp : msglist) process_messages(*pp, componentsfixt, "message", depth, outf); msglist.clear(); xf.find("fix/messages/message", msglist); for(auto const *pp : msglist) process_messages(*pp, components, "message", depth, outf); outf << string(depth * 2, ' ') << "</messages>" << endl; process_fields(fldlist, depth, outf); dump_components(components, outf); outf << "</" << xft.GetTag() << '>' << endl; return 0; }
//----------------------------------------------------------------------------------------- void filter_unique(XmlElement::XmlSet& fldlist) { using UniqueFieldMap = map<string, const XmlElement *>; UniqueFieldMap ufm; unsigned dupls(0); for(const auto *pp : fldlist) { string name; pp->GetAttr("name", name); if (!ufm.insert({name, pp}).second) ++dupls; // cerr << "Duplicate field: " << name << endl; } fldlist.clear(); for(const auto& pp : ufm) fldlist.insert(pp.second); }
//----------------------------------------------------------------------------------------- void filter_unique(XmlElement::XmlSet& fldlist) { typedef map<string, const XmlElement *> UniqueFieldMap; UniqueFieldMap ufm; unsigned dupls(0); for(XmlElement::XmlSet::const_iterator itr(fldlist.begin()); itr != fldlist.end(); ++itr) { string name; (*itr)->GetAttr("name", name); if (!ufm.insert(UniqueFieldMap::value_type(name, *itr)).second) ++dupls; // cerr << "Duplicate field: " << name << endl; } fldlist.clear(); for(UniqueFieldMap::const_iterator itr(ufm.begin()); itr != ufm.end(); ++itr) fldlist.insert(itr->second); }