static void verify(const unit_map& units, const config& cfg) { std::stringstream errbuf; LOG_REPLAY << "verifying unit structure...\n"; const size_t nunits = cfg["num_units"].to_size_t(); if(nunits != units.size()) { errbuf << "SYNC VERIFICATION FAILED: number of units from data source differ: " << nunits << " according to data source. " << units.size() << " locally\n"; std::set<map_location> locs; BOOST_FOREACH(const config &u, cfg.child_range("unit")) { const map_location loc(u); locs.insert(loc); if(units.count(loc) == 0) { errbuf << "data source says there is a unit at " << loc << " but none found locally\n"; } } for(unit_map::const_iterator j = units.begin(); j != units.end(); ++j) { if (locs.count(j->get_location()) == 0) { errbuf << "local unit at " << j->get_location() << " but none in data source\n"; } } replay::process_error(errbuf.str()); errbuf.clear(); }
//-----------------------------------------------------------------// unit_map_its create_list(const std::string& root) { unit_map_its list; if(unit_map_.empty()) { list.clear(); return list; } if(root.empty()) { list.resize(unit_map_.size()); list.clear(); for(unit_map_it it = unit_map_.begin(); it != unit_map_.end(); ++it) { list.push_back(it); } } else { auto fpath = create_full_path(root); if(fpath.empty()) { list.clear(); return list; } unit_map_it it = unit_map_.find(fpath); if(it != unit_map_.end()) { const typename unit_t::childs& ch = it->second.get_childs(); list.resize(ch.size()); list.clear(); for(const auto& s : ch) { auto path = create_full_path(s); if(!path.empty()) { it = unit_map_.find(path); if(it != unit_map_.end()) { list.push_back(it); } } } } else { list.clear(); } } std::sort(list.begin(), list.end(), [] (unit_map_it l, unit_map_it r) { return l->first < r->first; } ); return list; }
static void verify(const unit_map& units, const config& cfg) { std::stringstream errbuf; LOG_REPLAY << "verifying unit structure...\n"; const size_t nunits = cfg["num_units"].to_size_t(); if(nunits != units.size()) { errbuf << "SYNC VERIFICATION FAILED: number of units from data source differ: " << nunits << " according to data source. " << units.size() << " locally\n"; std::set<map_location> locs; for (const config &u : cfg.child_range("unit")) { const map_location loc(u); locs.insert(loc); if(units.count(loc) == 0) { errbuf << "data source says there is a unit at " << loc << " but none found locally\n"; } } for(unit_map::const_iterator j = units.begin(); j != units.end(); ++j) { if (locs.count(j->get_location()) == 0) { errbuf << "local unit at " << j->get_location() << " but none in data source\n"; } } replay::process_error(errbuf.str()); errbuf.clear(); } for (const config &un : cfg.child_range("unit")) { const map_location loc(un); const unit_map::const_iterator u = units.find(loc); if(u == units.end()) { errbuf << "SYNC VERIFICATION FAILED: data source says there is a '" << un["type"] << "' (side " << un["side"] << ") at " << loc << " but there is no local record of it\n"; replay::process_error(errbuf.str()); errbuf.clear(); } config u_cfg; u->write(u_cfg); bool is_ok = true; static const std::string fields[] = {"type","hitpoints","experience","side",""}; for(const std::string* str = fields; str->empty() == false; ++str) { if (u_cfg[*str] != un[*str]) { errbuf << "ERROR IN FIELD '" << *str << "' for unit at " << loc << " data source: '" << un[*str] << "' local: '" << u_cfg[*str] << "'\n"; is_ok = false; } } if(!is_ok) { errbuf << "(SYNC VERIFICATION FAILED)\n"; replay::process_error(errbuf.str()); errbuf.clear(); } } LOG_REPLAY << "verification passed\n"; }