Fix the build but the code is still untested.

This commit is contained in:
King_DuckZ 2018-01-18 00:16:17 +00:00
parent 6dffe9b848
commit b39621ea51

View file

@ -173,11 +173,36 @@ namespace duck { namespace sl {
MustacheEntry* m_current_mustache;
};
mstch::map to_mustache_dict_recursive (const EntryNode& parNode, std::string_view parSrc, XPAthRunner& parRunner) {
mstch::map to_mustache_dict_recursive (const EntryNode& parNode, std::string_view parSrc, XPathRunner& parRunner) {
mstch::map retval;
for (const XPathElement* xpath : parNode.xpaths) {
assert(xpath);
std::cout << "Running query for \"" << xpath->name << "\"\n";
auto results = parRunner.query(parSrc, xpath->xpath);
if (results.size() == 1) {
retval[xpath->name] = results.front();
}
else if (results.size() > 1) {
mstch::array values;
values.reserve(results.size());
std::copy(results.begin(), results.end(), std::back_inserter(values));
retval[xpath->name] = std::move(values);
}
else if (xpath->def_val) {
retval[xpath->name] = *xpath->def_val;
}
else {
retval[xpath->name] = std::string();
}
}
for (auto& curr_struct : parNode.structs) {
assert(not curr_struct.name.empty());
retval[std::string(curr_struct.name)] =
to_mustache_dict_recursive(curr_struct, parSrc, parRunner);
}
return retval;
}
mstch::map to_mustache_map (const EntryNodeList& parNodes, XPathRunner& parRunner) {
@ -195,32 +220,9 @@ namespace duck { namespace sl {
assert(false); //not implemented
}
//mstch::map curr_entry_map = to_mustache_dict_recursive(
for (const XPathElement* xpath : entry.second.xpaths) {
assert(xpath);
std::cout << "Running query for \"" << xpath->name << "\"\n";
auto results = parRunner.query(src_url, xpath->xpath);
if (results.size() == 1) {
retval[xpath->name] = results.front();
}
else if (results.size() > 1) {
mstch::array values;
values.reserve(results.size());
std::copy(results.begin(), results.end(), std::back_inserter(values));
retval[xpath->name] = std::move(values);
}
else if (xpath->def_val) {
retval[xpath->name] = *xpath->def_val;
}
else {
retval[xpath->name] = std::string();
}
}
for (auto& curr_struct : entry.second.structs) {
assert(not curr_struct.name.empty());
retval[curr_struct.name] = struct_to_mustache(curr_struct, src_url, parRunner);
}
mstch::map curr_entry_map = to_mustache_dict_recursive(entry.second, src_url, parRunner);
curr_entry_map.merge(std::move(retval));
retval.swap(curr_entry_map);
}
return retval;