Skip to content

Instantly share code, notes, and snippets.

@alepez
Created October 14, 2015 11:13
Show Gist options
  • Save alepez/93838c7654c10215043c to your computer and use it in GitHub Desktop.
Save alepez/93838c7654c10215043c to your computer and use it in GitHub Desktop.
void Template::recurseApply(PropertyTree& tree) const {
for (auto& child : tree) {
if (!child.second.empty()) {
recurseApply(child.second);
continue;
}
/* legge il valore */
auto&& value = child.second.get_value<std::string>();
if (value.size() > 4) {
/* che deve essere almeno piu' lungo di 4, visto che e' al minimo {{N}} */
auto&& begin = value.find("{{");
if (begin != std::string::npos) {
/* e cerca {{ */
auto&& end = value.find("}}");
if (end != std::string::npos) {
/* e cerca }} */
try {
/* ed estrai la stringa che indica l'indice */
auto&& indexStr = value.substr(begin + 2, end - begin - 2);
/* e converti la stringa trovata in un numero, sottraendo 1 visto che parte da 1 e non da zero */
decltype(args_)::size_type index = std::stoi(indexStr) -1;
std::cerr << child.first << ": leaf -> " << index << "\n";
if (args_.size() > index) {
/* e controlla che sia definito in args_ */
std::cerr << child.first << ": leaf -> " << args_[index] << "\n";
child.second.put_value(args_[index]);
}
} catch (...) {
/* ignore errors */
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment