本文整理汇总了C++中unit_map::count方法的典型用法代码示例。如果您正苦于以下问题:C++ unit_map::count方法的具体用法?C++ unit_map::count怎么用?C++ unit_map::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unit_map
的用法示例。
在下文中一共展示了unit_map::count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: verify
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();
}
示例2: verify
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";
}