bool INIreaditem(const ConfigTree &cfg, const String §n, const String &item, String &value) { ConfigNode sec_it = cfg.find(sectn); if (sec_it != cfg.end()) { StrStrOIter item_it = sec_it->second.find(item); if (item_it != sec_it->second.end()) { value = item_it->second; return true; } } return false; }
void MLC_Config::copy(ConfigTree& dst, const ConfigTree& src, const std::string& path) { if (src.empty()) { // remove all existing keys ConfigTree::iterator dit = dst.begin(); while (dit != dst.end()) { boost::property_tree::path p(path); p /= dit->first; if (!dit->second.empty()) { copy(dit->second, src, p.dump()); } std::string v = dit->second.data(); dit = dst.erase(dit); notify(p.dump(), v.c_str(), NULL); } } else { // remove non-existing keys ConfigTree::iterator dit = dst.begin(); while (dit != dst.end()) { if (src.find(dit->first) == src.not_found()) { boost::property_tree::path p(path); p /= dit->first; if (!dit->second.empty()) { copy(dit->second, ConfigTree(), p.dump()); } std::string v = dit->second.data(); dit = dst.erase(dit); notify(p.dump(), v.c_str(), NULL); } else { ++dit; } } // update keys ConfigTree::const_iterator sit = src.begin(); for (; sit != src.end(); ++sit) { boost::property_tree::path p(path); p /= sit->first; optional<ConfigTree&> child = dst.get_child_optional(sit->first); if (sit->second.empty() && (!child || child.get().empty())) { if (sit->second.data().empty() && !(child)) { // both source & destination are NULL, skip it continue; } // value node std::string v; const char* oldval = NULL; const char* newval = NULL; if (child) { v = child->data(); oldval = v.c_str(); } if (sit->second.data().empty()) { dst.erase(sit->first); } else { newval = sit->second.data().c_str(); dst.put(sit->first, sit->second.data()); } notify(p.dump(), oldval, newval); } else { if (!child) { child = dst.put_child(sit->first, ConfigTree()); notify(p.dump(), NULL, ""); } copy(child.get(), sit->second, p.dump()); } } } }