Created
October 14, 2015 11:13
-
-
Save alepez/93838c7654c10215043c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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