本文整理汇总了C++中IdSet类的典型用法代码示例。如果您正苦于以下问题:C++ IdSet类的具体用法?C++ IdSet怎么用?C++ IdSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IdSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Execute
string DeleteCommand::Execute ( )
{
executionCounter++;
Controller * controller = Controller::GetInstance( );
IdSet allAgregates = controller->GetAllAgregatesInDocument( );
vector<IdSet>::iterator parentsIterator = parentAgregates.begin( );
// For each object to delete
for ( IdSet::iterator it = targets.begin( ); it != targets.end( ); ++it )
{
// Remove it from the document
controller->RemoveObjectFromDocument( *it );
// Find all agregates containing the deleted object
// in order to remember them
Agregate * currentAgregate;
for ( IdSet::iterator jt = allAgregates.begin( );
jt != allAgregates.end( ); ++jt )
{
currentAgregate = (Agregate *) controller->GetObjectById( *jt );
if ( currentAgregate->Contains( *it ) )
{
currentAgregate->RemoveComponent( *it );
parentsIterator->insert( *jt );
}
}
parentsIterator++;
}
return STATUS_OK;
}
示例2: IndexKeywords
size_t Private::IndexKeywords(
std::string const & keyword,
Table const & mapping,
IdSetTable & id_set,
bool is_keyword_complete)
{
IdSet set;
if (is_keyword_complete) {
auto iter = mapping.find(keyword);
if (iter != mapping.end())
set.insert(iter->second);
} else {
for (auto & pair : mapping)
if (pair.first.find(keyword) != std::string::npos)
set.insert(pair.second);
}
if (!set.empty()) {
auto iter = std::find(id_set.begin(), id_set.end(), set);
if (iter == id_set.end()) {
id_set.push_back(std::move(set));
return id_set.size() - 1U;
} else
return std::distance(id_set.begin(), iter);
}
return ~size_t(0U);
}
示例3: least_common_ancestor
SSATmp* least_common_ancestor(SSATmp* s1, SSATmp* s2) {
if (s1 == s2) return s1;
if (s1 == nullptr || s2 == nullptr) return nullptr;
IdSet<SSATmp> seen;
auto const step = [] (SSATmp* v) {
assertx(v != nullptr);
return v->inst()->isPassthrough() ?
v->inst()->getPassthroughValue() :
nullptr;
};
auto const process = [&] (SSATmp*& v) {
if (v == nullptr) return false;
if (seen[v]) return true;
seen.add(v);
v = step(v);
return false;
};
while (s1 != nullptr || s2 != nullptr) {
if (process(s1)) return s1;
if (process(s2)) return s2;
}
return nullptr;
}
示例4: Enumerate
static inline bool
Enumerate(JSContext *cx, JSObject *obj, JSObject *pobj, jsid id,
bool enumerable, uintN flags, IdSet& ht, AutoIdVector *props)
{
JS_ASSERT_IF(flags & JSITER_OWNONLY, obj == pobj);
if (!(flags & JSITER_OWNONLY) || pobj->isProxy() || pobj->getOps()->enumerate) {
/* If we've already seen this, we definitely won't add it. */
IdSet::AddPtr p = ht.lookupForAdd(id);
if (JS_UNLIKELY(!!p))
return true;
/*
* It's not necessary to add properties to the hash table at the end of
* the prototype chain, but custom enumeration behaviors might return
* duplicated properties, so always add in such cases.
*/
if ((pobj->getProto() || pobj->isProxy() || pobj->getOps()->enumerate) && !ht.add(p, id))
return false;
}
if (enumerable || (flags & JSITER_HIDDEN))
return props->append(id);
return true;
}
示例5: unpackIdSet
IdSet InputFrame::unpackIdSet(){
IdSet set;
uint32_t msize = unpackInt();
for(uint32_t i = 0; i < msize; ++i){
set.insert( unpackInt() );
}
return set;
}
示例6: BuildIdSet
IdSet MoonInstanceScript::BuildIdSet(uint32 pCount, ...)
{
IdSet NewSet;
va_list List;
va_start(List, pCount);
for(uint32 i = 0; i < pCount; ++i)
NewSet.insert(va_arg(List, uint32));
va_end(List);
return NewSet;
}
示例7: fill_by_set
void DesignStore::init(){
Persistence* persistence = Game::getGame()->getPersistence();
next_designid = persistence->getMaxDesignId() + 1;
next_componentid = persistence->getMaxComponentId() + 1;
next_propertyid = persistence->getMaxPropertyId() + 1;
next_categoryid = persistence->getMaxCategoryId() + 1;
IdSet ids = persistence->getCategoryIds();
fill_by_set( designs, persistence->getDesignIds(), Design::Ptr() );
fill_by_set( categories, persistence->getCategoryIds(), Category::Ptr() );
fill_by_set( components, persistence->getComponentIds(), Component::Ptr() );
ids = persistence->getPropertyIds();
for(IdSet::iterator itcurr = ids.begin(); itcurr != ids.end(); ++itcurr){
properties[*itcurr] = persistence->retrieveProperty(*itcurr);
propertyIndex[properties[*itcurr]->getName()] = (*itcurr);
}
}
示例8: GetMatchedRegions
void CountryInfoGetter::GetMatchedRegions(string const & enNamePrefix, IdSet & regions) const
{
for (size_t i = 0; i < m_countries.size(); ++i)
{
// Match english name with region file name (they are equal in almost all cases).
// @todo Do it smarter in future.
string s = m_countries[i].m_name;
strings::AsciiToLower(s);
if (strings::StartsWith(s, enNamePrefix.c_str()))
regions.push_back(i);
}
}
示例9: removeUnreachable
bool removeUnreachable(IRUnit& unit) {
FTRACE(2, "removing unreachable blocks\n");
auto modified = false;
IdSet<Block> visited;
smart::stack<Block*> stack;
stack.push(unit.entry());
// Find all blocks reachable from the entry block.
while (!stack.empty()) {
auto* b = stack.top();
stack.pop();
if (visited[b]) continue;
visited.add(b);
if (auto* taken = b->taken()) {
if (!visited[taken]) stack.push(taken);
}
if (auto* next = b->next()) {
if (!visited[next]) stack.push(next);
}
}
// Erase any blocks not found above.
auto* trace = unit.main();
auto& blocks = trace->blocks();
for (auto it = blocks.begin(); it != blocks.end(); ) {
auto* b = *it;
if (!visited[b]) {
FTRACE(3, "removing unreachable B{}\n", b->id());
it = trace->erase(it);
modified = true;
} else {
++it;
}
}
return modified;
}
示例10: Enumerate
static inline bool
Enumerate(JSContext *cx, JSObject *obj, JSObject *pobj, jsid id,
bool enumerable, uintN flags, IdSet& ht, AutoIdVector *props)
{
JS_ASSERT_IF(flags & JSITER_OWNONLY, obj == pobj);
/*
* We implement __proto__ using a property on |Object.prototype|, but
* because __proto__ is highly deserving of removal, we don't want it to
* show up in property enumeration, even if only for |Object.prototype|
* (think introspection by Prototype-like frameworks that add methods to
* the built-in prototypes). So exclude __proto__ if the object where the
* property was found has no [[Prototype]] and might be |Object.prototype|.
*/
if (JS_UNLIKELY(!pobj->getProto() && JSID_IS_ATOM(id, cx->runtime->atomState.protoAtom)))
return true;
if (!(flags & JSITER_OWNONLY) || pobj->isProxy() || pobj->getOps()->enumerate) {
/* If we've already seen this, we definitely won't add it. */
IdSet::AddPtr p = ht.lookupForAdd(id);
if (JS_UNLIKELY(!!p))
return true;
/*
* It's not necessary to add properties to the hash table at the end of
* the prototype chain, but custom enumeration behaviors might return
* duplicated properties, so always add in such cases.
*/
if ((pobj->getProto() || pobj->isProxy() || pobj->getOps()->enumerate) && !ht.add(p, id))
return false;
}
if (enumerable || (flags & JSITER_HIDDEN))
return props->append(id);
return true;
}
示例11: generateListOptions
ListParameter::Options BuildFleet::generateListOptions(){
ListParameter::Options options;
IdSet designs = Game::getGame()->getPlayerManager()->getPlayer(((Planet*)(Game::getGame()->getObjectManager()->getObject(Game::getGame()->getOrderManager()->getOrderQueue(orderqueueid)->getObjectId())->getObjectBehaviour()))->getOwner())->getPlayerView()->getUsableDesigns();
Game::getGame()->getObjectManager()->doneWithObject(Game::getGame()->getOrderManager()->getOrderQueue(orderqueueid)->getObjectId());
DesignStore::Ptr ds = Game::getGame()->getDesignStore();
std::set<Design::Ptr> usable;
for(IdSet::iterator itcurr = designs.begin(); itcurr != designs.end(); ++itcurr){
Design::Ptr design = ds->getDesign(*itcurr);
if(design->getCategoryId() == 1){
usable.insert(design);
}
}
for(std::set<Design::Ptr>::iterator itcurr = usable.begin();
itcurr != usable.end(); ++itcurr){
Design::Ptr design = (*itcurr);
options[design->getDesignId()] = ListParameter::Option(design->getName(), 100);
}
Logger::getLogger()->debug("Exiting BuildFleet::generateListOptions");
return options;
}
示例12: static_analysis
/** Statically analyse the given ast.
*
* \param ast_ The AST.
* \param in_object Whether or not ast_ is within the lexical scope of an object AST.
* \param vars The variables defined within lexical scope of ast_.
* \returns The free variables in ast_.
*/
static IdSet static_analysis(AST *ast_, bool in_object, const IdSet &vars)
{
IdSet r;
if (auto *ast = dynamic_cast<const Apply*>(ast_)) {
append(r, static_analysis(ast->target, in_object, vars));
for (AST *arg : ast->arguments)
append(r, static_analysis(arg, in_object, vars));
} else if (auto *ast = dynamic_cast<const Array*>(ast_)) {
for (AST *el : ast->elements)
append(r, static_analysis(el, in_object, vars));
} else if (auto *ast = dynamic_cast<const Binary*>(ast_)) {
append(r, static_analysis(ast->left, in_object, vars));
append(r, static_analysis(ast->right, in_object, vars));
} else if (dynamic_cast<const BuiltinFunction*>(ast_)) {
// Nothing to do.
} else if (auto *ast = dynamic_cast<const Conditional*>(ast_)) {
append(r, static_analysis(ast->cond, in_object, vars));
append(r, static_analysis(ast->branchTrue, in_object, vars));
append(r, static_analysis(ast->branchFalse, in_object, vars));
} else if (auto *ast = dynamic_cast<const Error*>(ast_)) {
return static_analysis(ast->expr, in_object, vars);
} else if (auto *ast = dynamic_cast<const Function*>(ast_)) {
auto new_vars = vars;
IdSet params;
for (auto *p : ast->parameters) {
if (params.find(p) != params.end()) {
throw StaticError(ast_->location, "Duplicate function parameter: " + p->name);
}
params.insert(p);
new_vars.insert(p);
}
auto fv = static_analysis(ast->body, in_object, new_vars);
for (auto *p : ast->parameters)
fv.erase(p);
append(r, fv);
} else if (dynamic_cast<const Import*>(ast_)) {
// Nothing to do.
} else if (dynamic_cast<const Importstr*>(ast_)) {
// Nothing to do.
} else if (auto *ast = dynamic_cast<const Index*>(ast_)) {
append(r, static_analysis(ast->target, in_object, vars));
append(r, static_analysis(ast->index, in_object, vars));
} else if (auto *ast = dynamic_cast<const Local*>(ast_)) {
IdSet ast_vars;
for (const auto &bind: ast->binds) {
ast_vars.insert(bind.first);
}
auto new_vars = vars;
append(new_vars, ast_vars);
IdSet fvs;
for (const auto &bind: ast->binds)
append(fvs, static_analysis(bind.second, in_object, new_vars));
append(fvs, static_analysis(ast->body, in_object, new_vars));
for (const auto &bind: ast->binds)
fvs.erase(bind.first);
append(r, fvs);
} else if (dynamic_cast<const LiteralBoolean*>(ast_)) {
// Nothing to do.
} else if (dynamic_cast<const LiteralNumber*>(ast_)) {
// Nothing to do.
} else if (dynamic_cast<const LiteralString*>(ast_)) {
// Nothing to do.
} else if (dynamic_cast<const LiteralNull*>(ast_)) {
// Nothing to do.
} else if (auto *ast = dynamic_cast<Object*>(ast_)) {
for (auto field : ast->fields) {
append(r, static_analysis(field.name, in_object, vars));
append(r, static_analysis(field.body, true, vars));
}
} else if (auto *ast = dynamic_cast<ObjectComposition*>(ast_)) {
auto new_vars = vars;
new_vars.insert(ast->id);
append(r, static_analysis(ast->field, false, new_vars));
//.........这里部分代码省略.........
示例13: append
/** Inserts all of s into r. */
static void append(IdSet &r, const IdSet &s)
{
r.insert(s.begin(), s.end());
}
示例14: doCombat
void RSPCombat::doCombat(std::map<uint32_t, IdSet> sides) {
Game* game = Game::getGame();
PlayerManager::Ptr playermanager = game->getPlayerManager();
ObjectManager* objectmanager = game->getObjectManager();
DesignStore::Ptr ds = game->getDesignStore();
const char * const rsp[] = {"rock", "scissors", "paper"};
IdSet listallobids;
IdSet listallplayerids;
std::map<uint32_t, std::vector<Combatant*> > fleetcache;
battlelogger.reset(new BattleXML::BattleLogger());
msgstrings.clear();
for(std::map<uint32_t, IdSet>::iterator itmap = sides.begin(); itmap != sides.end(); ++itmap) {
std::vector<Combatant*> pcombatant;
Player::Ptr player = playermanager->getPlayer(itmap->first);
battlelogger->startSide(player->getName());
IdSet theset = itmap->second;
for(IdSet::iterator itset = theset.begin(); itset != theset.end(); ++itset) {
listallobids.insert(*itset);
IGObject::Ptr obj = objectmanager->getObject (*itset);
objectcache[*itset] = obj;
if(obj->getType() == obT_Fleet) {
Fleet* f2 = (Fleet*)(obj->getObjectBehaviour());
IdMap shiplist = f2->getShips();
uint32_t damage = f2->getDamage();
for(IdMap::reverse_iterator itship = shiplist.rbegin(); itship != shiplist.rend(); ++itship) {
for(uint32_t i = 0; i < itship->second; i++) {
Combatant* f1 = new Combatant();
f1->setOwner(itmap->first);
f1->setObject(obj->getID());
f1->setShipType(itship->first);
uint32_t mydamage = damage / std::max(1U, (unsigned int)(shiplist.size() - i));
f1->setDamage(mydamage);
damage -= mydamage;
std::string type = ds->getDesign(itship->first)->getName();
f1->setBattleXmlType(type);
f1->setBattleXmlId(str(boost::format("%1%-%2%-%3%") % type % obj->getID() % i));
f1->setBattleXmlName(str(boost::format("%1%'s %2%, %3% %4%") % player->getName() % obj->getName() % type % i));
battlelogger->addCombatant(f1);
pcombatant.push_back(f1);
}
}
} else {
int shipcount = 2;
int homeplanetid = game->getResourceManager()->getResourceDescription("Home Planet")->getResourceType();
if(((Planet*)(obj->getObjectBehaviour()))->getResource(homeplanetid) == 1) {
//three more for home planets
shipcount += 3;
}
for(int i = 0; i < shipcount; i++) {
Combatant* f1 = new Combatant();
f1->setOwner(itmap->first);
f1->setObject(obj->getID());
f1->setShipType(0);
f1->setBattleXmlType("planet");
f1->setBattleXmlId(str(boost::format("planet-%1%-%2%") % obj->getID() % i));
f1->setBattleXmlName(str(boost::format("%1%'s colony on %2%, Defense battery %3%") % player->getName() % obj->getName() % i));
battlelogger->addCombatant(f1);
pcombatant.push_back(f1);
}
}
}
listallplayerids.insert(itmap->first);
battlelogger->endSide();
//sort combatant list by ship type, descending
sort(pcombatant.begin(), pcombatant.end(), CombatantSorter());
fleetcache[itmap->first] = pcombatant;
}
for(std::set<uint32_t>::iterator itplayer = listallplayerids.begin(); itplayer != listallplayerids.end(); ++itplayer) {
msgstrings[*itplayer] = "";
}
Random* random = Game::getGame()->getRandom();
Logger::getLogger()->debug("Combat start");
while(fleetcache.size() >= 2) {
battlelogger->startRound();
uint32_t pos1, pos2;
if(fleetcache.size() == 2) {
pos1 = 0;
pos2 = 1;
} else {
pos1 = pos2 = random->getInRange(0U, ((uint32_t)(fleetcache.size() - 1)));
while(pos2 == pos1) {
pos2 = random->getInRange(0U, ((uint32_t)(fleetcache.size() - 1)));
}
}
std::map<uint32_t, std::vector<Combatant*> >::iterator itpa = fleetcache.begin();
advance(itpa, pos1);
std::map<uint32_t, std::vector<Combatant*> >::iterator itpb = fleetcache.begin();
advance(itpb, pos2);
//.........这里部分代码省略.........
示例15: listAllSeries
bool listAllSeries(const std::string& rootCategory, const std::string& outputFile) {
bool result(false);
using namespace fredcpp;
// Initialize
Api api;
api.withLogger(external::SimpleLogger::getInstance())
.withExecutor(external::CurlHttpClient::getInstance())
.withParser(external::PugiXmlParser::getInstance())
;
external::SimpleLogger::getInstance().enableInfo();
FREDCPP_LOG_INFO(FREDCPP_FACILITY << " version " << FREDCPP_VERSION_STRING
<< " (" << FREDCPP_BRIEF << ")");
FREDCPP_LOG_INFO("Getting API key from environment variable " << ENV_API_KEY << " ...");
api.withKey(getKeyFromEnv(ENV_API_KEY));
// Build a list of available sub-categories under the root
FREDCPP_LOG_INFO("Building list of available sub-categories of category " << rootCategory << " ...");
ChildrenByIdMap categoryTree;
if ( 0 == buildCategoryTree(api, categoryTree, rootCategory)) {
FREDCPP_LOG_FATAL("Unable to retrieve categories");
exit(EXIT_FAILURE);
}
FREDCPP_LOG_INFO("Available categories count:" << categoryTree.size());
FREDCPP_LOG_INFO("Creating output data file " << outputFile << " ...");
std::ofstream output(outputFile.c_str());
if (!output) {
exitOnBadOutputFile(outputFile);
}
// Get series
IdSet uniqueSeries;
ApiResponse response;
for (ChildrenByIdMap::iterator it = categoryTree.begin();
it != categoryTree.end();
++it) {
std::string categoryId(it->first);
api.get(ApiRequestBuilder::CategorySeries(categoryId)
, response) || exitOnApiError(response);
if (!response.entities.size()) {
FREDCPP_LOG_INFO("category:" << categoryId << " contains no series");
}
// Print series
// NOTE: a given series can belong to multiple categories,
// so keep track of unique series
for (std::size_t n = 0; n < response.entities.size(); ++n) {
std::string seriesId (response.entities[n].attribute("id"));
if (uniqueSeries.find(seriesId) != uniqueSeries.end()) {
continue;
}
uniqueSeries.insert(seriesId);
output << response.entities[n].attribute("id")
<< "|" << response.entities[n].attribute("frequency_short")
<< "|" << response.entities[n].attribute("title")
<< "|" << response.entities[n].attribute("observation_start")
<< "|" << response.entities[n].attribute("observation_end")
<< "|"
<< std::endl;
}
}
// Report stats
FREDCPP_LOG_INFO("root-category:" << rootCategory
<< " sub-categories-count:" << categoryTree.size() - 1
<< " series-count:" << uniqueSeries.size());
output.close();
FREDCPP_LOG_INFO("Successfully created file " << outputFile);
result = true;
return (result);
//.........这里部分代码省略.........