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