bool CrossingPaths::WillPathsCross(std::map<std::pair<int, int>, int>& pathMap, std::pair<int, int>& position, int changeX, int changeY) { bool hasCrossed = false; bool isNegative = false; if (changeX != 0) { isNegative = changeX < 0; for (int i = 0; i < std::abs(changeX); i++) { position.first += isNegative ? -1 : 1; if (!hasCrossed) { hasCrossed = IsNodeInMap(pathMap, position); } pathMap.emplace(position, 1); } } else { isNegative = changeY < 0; for (int i = 0; i < std::abs(changeY); i++) { position.second += isNegative ? -1 : 1; if (!hasCrossed) { hasCrossed = IsNodeInMap(pathMap, position); } pathMap.emplace(position, 1); } } return hasCrossed; }
void init_filters() { filters.emplace("comb", std::make_unique<comb>()); filters.emplace("echo", std::make_unique<echo>()); filters.emplace("biquad", std::make_unique<biqd>()); }
static void emplaceString(std::map<std::string, Kdbx::XorredBuffer>& strings, const char* name, const QByteArray& data, bool protect, QWidget* widget){ if (protect){ std::vector<uint8_t> mask = getRandomBytes(data.size(), widget); strings.emplace(name, Kdbx::XorredBuffer::fromRaw(data.begin(), data.end(), mask.begin())); }else{ strings.emplace(name, Kdbx::XorredBuffer(data.begin(), data.end())); } }
static void addRangeToDetails(std::map<std::string, std::string> &a, const char *minKey, const char *maxKey, const std::pair<uint16_t, uint16_t> &range) { a.emplace(minKey, ring::to_string(range.first)); a.emplace(maxKey, ring::to_string(range.second)); }
void add_color_info(const config& v, bool build_defaults) { if(build_defaults) { default_colors.clear(); } for(const config& teamC : v.child_range("color_range")) { const config::attribute_value* a1 = teamC.get("id"), *a2 = teamC.get("rgb"); if(!a1 || !a2) { continue; } std::string id = *a1; std::vector<color_t> temp; for(const auto& s : utils::split(*a2)) { try { temp.push_back(color_t::from_hex_string(s)); } catch(const std::invalid_argument&) { std::stringstream ss; ss << "can't parse color string:\n" << teamC.debug() << "\n"; throw config::error(ss.str()); } } team_rgb_range.emplace(id, color_range(temp)); team_rgb_name.emplace(id, teamC["name"].t_str()); LOG_NG << "registered color range '" << id << "': " << team_rgb_range[id].debug() << '\n'; // Ggenerate palette of same name; std::vector<color_t> tp = palette(team_rgb_range[id]); if(!tp.empty()) { team_rgb_colors.emplace(id, tp); } if(build_defaults && teamC["default"].to_bool()) { default_colors.push_back(*a1); } } for(const config &cp : v.child_range("color_palette")) { for(const config::attribute& rgb : cp.attribute_range()) { std::vector<color_t> temp; for(const auto& s : utils::split(rgb.second)) { try { temp.push_back(color_t::from_hex_string(s)); } catch(const std::invalid_argument&) { ERR_NG << "Invalid color in palette: " << s << std::endl; } } team_rgb_colors.emplace(rgb.first, temp); LOG_NG << "registered color palette: " << rgb.first << '\n'; } } }
void init_orchestra() { orchestra.emplace("beep", std::make_unique<beep>()); orchestra.emplace("amp-mod", std::make_unique<amp_mod>()); orchestra.emplace("freq-mod", std::make_unique<freq_mod>()); orchestra.emplace("ks-string", std::make_unique<ks_string>()); orchestra.emplace("diphthong", std::make_unique<diphthong>()); }
/** create a map of the workspaces corresponding to each bank * @param banks :: [input] list of bank IDs; must not be empty. must not have * duplicate entries. * @param workspaces :: [input] list of corresponding workspaces or empty * vector for default MAY NEED TO BE size_t <int, size_t> * @param workspaceOfBank :: [output] map to indicate the workspace that a * bank's parameters will be put in */ void LoadFullprofResolution::createBankToWorkspaceMap( const std::vector<int> &banks, const std::vector<int> &workspaces, std::map<int, size_t> &workspaceOfBank) { if (workspaces.size() == 0) { for (size_t i = 0; i < banks.size(); i++) { workspaceOfBank.emplace(banks[i], i + 1); } } else { for (size_t i = 0; i < banks.size(); i++) { workspaceOfBank.emplace(banks[i], workspaces[i]); } } }
unsigned int getTextura(const char *path) { auto it = texturas.find(path); if(it != texturas.end()) return it->second; else { GLuint textureID; unsigned int t[2], tw, th; unsigned char *texData; ilGenImages(2,t); ilBindImage(t[0]); ilLoadImage((ILstring)path); tw = ilGetInteger(IL_IMAGE_WIDTH); th = ilGetInteger(IL_IMAGE_HEIGHT); ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); texData = ilGetData(); glGenTextures(1,&textureID); // unsigned int texID - variavel global; glBindTexture(GL_TEXTURE_2D,textureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData); texturas.emplace(path, textureID); return textureID; } }
void pre_generation(std::array<TERRAIN_FEATURES, 6> & ambient_relief) { std::random_device rd; std::mt19937 gen(rd()); std::vector<std::pair<TERRAIN_FEATURES, int>> features_and_frequencies = {std::make_pair(TERRAIN_FEATURES::WATER, 1)}; for (size_t i = 0; i < 6; i++) { auto it = find_if(features_and_frequencies.begin(), features_and_frequencies.end(), [&ambient_relief, i](std::pair<TERRAIN_FEATURES, int> & p){return p.first == ambient_relief[i];}); if(it == features_and_frequencies.end()) features_and_frequencies.push_back(std::make_pair(ambient_relief[i], 1)); else it->second++; } std::vector<int> frequencies; for (size_t i = 0; i < features_and_frequencies.size(); i++) frequencies.push_back(features_and_frequencies[i].second); std::discrete_distribution<> d(frequencies.begin(), frequencies.end()); for (int i = -SIDE_SIZE + 1; i < SIDE_SIZE; i++) { for (int j = -SIDE_SIZE + 1; j < SIDE_SIZE; j++) { for (int k = -SIDE_SIZE + 1; k < SIDE_SIZE; k++) { if (i + j + k != 0) continue; TERRAIN_FEATURES feature = features_and_frequencies[d(gen)].first; std::array<grid_tile *, 6> neighbours = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}; battleground.emplace(std::make_tuple(i, j, k), grid_tile(neighbours, i, j, k, nullptr, feature)); //battleground[14*i + j] = grid_tile(neighbours, i, j, nullptr, feature); } } } }
/** Fills the unit map and ordered vector with the same data * @param orderedVector the vector to fill * @param unitMap the map to fill * @param caption the caption of the unit * @param unit the unit of measure of the unit */ void ConvertAxesToRealSpace::fillUnitMap( std::vector<std::string> &orderedVector, std::map<std::string, std::string> &unitMap, const std::string &caption, const std::string &unit) { unitMap.emplace(caption, unit); orderedVector.push_back(caption); }
static void FinishRead(u64 id, s64 cycles_late) { // We can't simply pop s_result_queue and always get the ReadResult // we want, because the DVD thread may add ReadResults to the queue // in a different order than we want to get them. What we do instead // is to pop the queue until we find the ReadResult we want (the one // whose ID matches userdata), which means we may end up popping // ReadResults that we don't want. We can't add those unwanted results // back to the queue, because the queue can only have one writer. // Instead, we add them to a map that only is used by the CPU thread. // When this function is called again later, it will check the map for // the wanted ReadResult before it starts searching through the queue. ReadResult result; auto it = s_result_map.find(id); if (it != s_result_map.end()) { result = std::move(it->second); s_result_map.erase(it); } else { while (true) { while (!s_result_queue.Pop(result)) s_result_queue_expanded.Wait(); if (result.first.id == id) break; else s_result_map.emplace(result.first.id, std::move(result)); } } // We have now obtained the right ReadResult. const ReadRequest& request = result.first; const std::vector<u8>& buffer = result.second; DEBUG_LOG(DVDINTERFACE, "Disc has been read. Real time: %" PRIu64 " us. " "Real time including delay: %" PRIu64 " us. " "Emulated time including delay: %" PRIu64 " us.", request.realtime_done_us - request.realtime_started_us, Common::Timer::GetTimeUs() - request.realtime_started_us, (CoreTiming::GetTicks() - request.time_started_ticks) / (SystemTimers::GetTicksPerSecond() / 1000000)); if (buffer.size() != request.length) { PanicAlertT("The disc could not be read (at 0x%" PRIx64 " - 0x%" PRIx64 ").", request.dvd_offset, request.dvd_offset + request.length); } else { if (request.copy_to_ram) Memory::CopyToEmu(request.output_address, buffer.data(), request.length); } // Notify the emulated software that the command has been executed DVDInterface::FinishExecutingCommand(request.reply_type, DVDInterface::INT_TCINT, cycles_late, buffer); }
std::pair<MatVec*, bool> SimpleMatrixVectorProvider:: get_(std::size_t& id, std::map<std::size_t, MatVec*>& unused_map, std::map<MatVec*, std::size_t>& used_map, Args&&... args) { if (id >= _next_id) { OGS_FATAL("An obviously uninitialized id argument has been passed." " This might not be a serious error for the current implementation," " but it might become one in the future." " Hence, I will abort now."); } if (do_search) { auto it = unused_map.find(id); if (it != unused_map.end()) // unused matrix/vector found return { ::detail::transfer(unused_map, used_map, it), false }; } // not searched or not found, so create a new one id = _next_id++; auto res = used_map.emplace( MathLib::MatrixVectorTraits<MatVec>::newInstance(std::forward<Args>(args)...).release(), id); assert(res.second && "Emplacement failed."); return { res.first->first, true }; }
// "flood fill" a tile name to adjacent tiles of certain terrain static void flood_name(const map_location& start, const std::string& name, std::map<map_location,std::string>& tile_names, const t_translation::ter_match& tile_types, const terrain_map& terrain, unsigned width, unsigned height, size_t label_count, std::map<map_location,std::string>* labels, const std::string& full_name) { map_location adj[6]; get_adjacent_tiles(start,adj); size_t n; //if adjacent tiles are tiles and unnamed, name them for(n = 0; n < 6; n++) { //we do not care for tiles outside the middle part //cast to unsigned to skip x < 0 || y < 0 as well. if(unsigned(adj[n].x) >= width / 3 || unsigned(adj[n].y) >= height / 3) { continue; } const t_translation::terrain_code terr = terrain[adj[n].x + (width / 3)][adj[n].y + (height / 3)]; const map_location loc(adj[n].x, adj[n].y); if((t_translation::terrain_matches(terr, tile_types)) && (tile_names.find(loc) == tile_names.end())) { tile_names.emplace(loc, name); //labeling decision: this is result of trial and error on what looks best in game if(label_count % 6 == 0) { //ensure that labels do not occur more often than every 6 recursions labels->emplace(loc, full_name); label_count++; //ensure that no adjacent tiles get labeled } flood_name(adj[n], name, tile_names, tile_types, terrain, width, height, label_count++, labels, full_name); } } }
bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only) { std::lock_guard<std::mutex> ulock(cs_dir_locks); fs::path pathLockFile = directory / lockfile_name; // If a lock for this directory already exists in the map, don't try to re-lock it if (dir_locks.count(pathLockFile.string())) { return true; } // Create empty lock file if it doesn't exist. FILE* file = fsbridge::fopen(pathLockFile, "a"); if (file) fclose(file); try { auto lock = MakeUnique<boost::interprocess::file_lock>(pathLockFile.string().c_str()); if (!lock->try_lock()) { return false; } if (!probe_only) { // Lock successful and we're not just probing, put it into the map dir_locks.emplace(pathLockFile.string(), std::move(lock)); } } catch (const boost::interprocess::interprocess_exception& e) { return error("Error while attempting to lock directory %s: %s", directory.string(), e.what()); } return true; }
void cy::argp_register(const std::string& cmd, int32_t uid, argp_cmd_type cmd_type, argp_param_type param_type) { // check arguments if(cmd.empty()) throw std::runtime_error("no command given"); if(cmd_type == ARGP_CT_SINGLE && cmd.size() != 1) throw std::runtime_error("command of type 'single' cannot contain multiple characters"); // check for uid uniqueness if(g_cmd_registry.find(uid) != g_cmd_registry::end) throw std::runtime_error("given uid not unique"); if(uid_is_reserved(uid)) throw std::runtime_error("given uid is reserved!"); // check for command uniqueness for(std::map<int32_t, cy::argp_arg_extra_info>::iterator it = g_cmd_registry.begin(); it != g_cmd_registry.end(); it++) { if(cmd == it->second.cmd && cmd_type == it->second.cmd_type) throw std::runtime_error("equivalent command already registered"); } // construct the info struct cy::argp_arg_extra_info aaei = make_info_struct(cmd, cmd_type, param_type); // put in registry g_cmd_registry.emplace(uid, aaei); }
void map_insert(std::map<RK,RV>& m, PK&& k, PV&& v) { static_assert(std::is_same<RK,typename std::decay<PK>::type>::value, "implicit conversions disallowed for the key!"); m.emplace(std::piecewise_construct, std::forward_as_tuple(std::forward<PK>(k)), std::forward_as_tuple(std::forward<PV>(v))); }
void Profiler::TimerStart(const std::string timerName, const char* sourceFile, const char* func, unsigned int line) { std::pair<std::map<std::string,StopWatchItem>::iterator,bool> ret; Profiler::initLogger(); StopWatchItem item = {sourceFile, func, line}; ret = GlobalProfilerMap.emplace(timerName, item); if ( ! ret.second ) { if ( ret.first->second.sourceFile == sourceFile && ret.first->second.func == func && ret.first->second.line == line ) { _logger->Message(Logger::DEBUG, sourceFile, func, line, "restart timer '%s'", timerName.c_str() ); ret.first->second.startTime = clock(); } else { _logger->Message(Logger::DEBUG, sourceFile, func, line, "ERROR timer '%s' started in multiple locations. First occurence %s:%d:%s()", timerName.c_str(), profiler_getBaseName(ret.first->second.sourceFile).c_str(), ret.first->second.line, ret.first->second.func ); } } else { _logger->Message(Logger::DEBUG, sourceFile, func, line, "start timer '%s'", timerName.c_str() ); } }
void registerHleModule(const std::string &name, HleModule *module) { if (std::find(decaf::config::system::lle_modules.begin(), decaf::config::system::lle_modules.end(), name) != decaf::config::system::lle_modules.end()) { gLog->warn("Replacing HLE with LLE for module {}.", name); return; } // Register module decaf_check(sHleModules.find(name) == sHleModules.end()); sHleModules.emplace(name, module); // Register every function symbol auto &symbolMap = module->getSymbolMap(); for (auto &pair : symbolMap) { auto symbol = pair.second; if (symbol->type == HleSymbol::Function) { registerHleFunc(reinterpret_cast<HleFunction *>(symbol)); } } }
void setupSprites() { // Serious hate. { PickupData p(Pickup::Food, Sprites::FOOD_TURKEY); p.Health = 10; pickups.emplace( p.Type, p ); } { PickupData p(Pickup::Ammo, Sprites::GUN_AMMO); p.Ammo = 8; pickups.emplace( p.Type, p ); } { PickupData p(Pickup::Smg, Sprites::GUN_SMG); p.Weapon = Weapon::Smg; pickups.emplace( p.Type, p ); } { PickupData p(Pickup::Chest, Sprites::TREASURE_CHEST); p.Score = 1000; pickups.emplace( p.Type, p ); } { PickupData p(Pickup::Chalice, Sprites::TREASURE_CHALICE); p.Score = 100; pickups.emplace( p.Type, p ); } // gruel is 4hp // blood is 1hp if < 11hp // medkit is 25 hp }
void RPCRunLater(const std::string& name, std::function<void(void)> func, int64_t nSeconds) { if (!timerInterface) throw JSONRPCError(RPC_INTERNAL_ERROR, "No timer handler registered for RPC"); deadlineTimers.erase(name); LogPrint(BCLog::RPC, "queue run of timer %s in %i seconds (using %s)\n", name, nSeconds, timerInterface->Name()); deadlineTimers.emplace(name, std::unique_ptr<RPCTimerBase>(timerInterface->NewTimer(func, nSeconds*1000))); }
Detector & create_default(box2d<double> const & extent) { auto it = cache_.emplace( std::piecewise_construct, std::forward_as_tuple("default"), std::forward_as_tuple(extent)).first; return it->second; }
inline void setDestinationOutStream(){ TokenId ti; ti.setOutputStream(); tOutput[dOutput] = OutputToken(NULL, ti); destinationsMap.emplace((Computable*) NULL, dOutput); ++dOutput; assert(dOutput <= MAX_INSTRUCTION_INPUTS); }
static void insertEntity(const QJsonValue &value, std::map<QString, Entity::Ptr> &map, std::vector<QString> &texts) { Entity::Ptr entity {new T(value.toObject())}; if (!private_util::hasValue(map, entity->text())) { texts.push_back(entity->text()); } map.emplace(entity->text(), entity); }
void json_flag::load( JsonObject &jo ) { auto id = jo.get_string( "id" ); auto &f = json_flags_all.emplace( id, json_flag( id ) ).first->second; jo.read( "info", f.info_ ); jo.read( "conflicts", f.conflicts_ ); jo.read( "inherit", f.inherit_ ); }
inline void setSource(Computable* c = NULL){ if(c){ sourcesMap.emplace(c, dInput); }else{ throw std::runtime_error("Impossible to set NULL source."); } ++dInput; assert(dInput <= MAX_INSTRUCTION_INPUTS); }
bool validate_property(Command * object, unsigned int index) { const std::string & identifier = *object->payload.property_.identifier; if (structure_properties.find(identifier) != structure_properties.end()) return false; structure_properties.emplace(identifier, index); return true; }
bool CppParser::addRenamedKeyword(const std::string& keyword, std::string renamedKeyword) { extern int GetKeywordId(const std::string& keyword); auto id = GetKeywordId(keyword); if (id == -1) return false; gRenamedKeywords.emplace(std::make_pair(std::move(renamedKeyword), id)); return true; }
void registerHleModuleAlias(const std::string &module, const std::string &alias) { auto itr = gHleModules.find(module); // TODO: Error if the module is missing! if (itr != gHleModules.end()) { gHleModules.emplace(alias, itr->second); } }
static void load_replacement_mods( const std::string path ) { read_from_file_optional_json( path, [&]( JsonIn &jsin ) { jsin.start_array(); while (!jsin.end_array()) { auto arr = jsin.get_array(); mod_replacements.emplace( arr.get_string( 0 ), arr.size() > 1 ? arr.get_string( 1 ) : "" ); } } ); }
MemoryDB& open (std::string const& path) { std::lock_guard<std::mutex> _(mutex_); auto const result = map_.emplace (std::piecewise_construct, std::make_tuple(path), std::make_tuple()); MemoryDB& db = result.first->second; if (db.open) throw std::runtime_error("already open"); return db; }