int Network::getDistancesFrom(Node* start, std::map<Node*, int>& distances, std::map<Node*, int>& weights, std::set<Node*>& leaf_nodes, int max_depth) const { //make sure the output is intialized distances.clear(); weights.clear(); leaf_nodes.clear(); //This is a queue to keep track of the nodes doing a breadth first search queue<Node*> to_visit; distances[start] = 0; weights[start] = 1; int max_dist = 0, distance = 0, neighbor_max_dist = 0, weight = 1; to_visit.push(start); Node* tmp_node = 0; //Only go a certain depth: bool is_max_depth = (max_depth != -1); map<Node*, int>::iterator dit; while( to_visit.size() > 0 ) { tmp_node = to_visit.front(); int tmp_node_distance = distances[tmp_node]; distance = tmp_node_distance + 1; weight = weights[tmp_node]; //Just stop if the distance is more than we should go if( is_max_depth && (distance > max_depth) ) { break; } neighbor_max_dist = 0; NeighborIterator neighit(tmp_node, _node_to_edges.find(tmp_node)->second ); while( neighit.moveNext() ) { Node* n = neighit.current(); dit = distances.find( n ); if( dit == distances.end() ) { //We have not yet visited this node pair< map<Node*, int>::iterator, bool> result; result = distances.insert( pair<Node*, int>(n, distance) ); //Update dit: dit = result.first; weights.insert( pair<Node*, int>(n, weight) ); to_visit.push( n ); //update the maximum max_dist = (max_dist < distance ) ? distance : max_dist; } else if( dit->second == distance ) { //There is more than one way to reach this node: weights[n] += weight; } //We know dit: if( neighbor_max_dist < dit->second ) { neighbor_max_dist = dit->second; } } /** * We check all the nodes at distance d before d+1 (breadth first) * so, once a distance is assigned it is never decreased * Hence, we know now the distance of all tmp_node neighbors. * If they are all less than or equal to distance from tmp_node, * then tmp_node must be a leaf node */ if( neighbor_max_dist <= tmp_node_distance ) { leaf_nodes.insert(tmp_node); } //Remove the first element in the list to_visit.pop(); } return max_dist; }
long add(shared_ptr<CoolProp::AbstractState> AS){ ASlibrary.insert(std::pair<std::size_t, shared_ptr<CoolProp::AbstractState> >(this->next_handle, AS)); this->next_handle++; return next_handle-1; }
std::string H5Dataset::dump(std::map<haddr_t, std::string> & alreadyVisited, const unsigned int indentLevel) const { std::ostringstream os; haddr_t addr = this->getAddr(); std::map<haddr_t, std::string>::iterator it = alreadyVisited.find(addr); if (it != alreadyVisited.end()) { os << H5Object::getIndentString(indentLevel) << "DATASET \"" << getName() << "\" {" << std::endl << H5Object::getIndentString(indentLevel + 1) << "HARDLINK \"" << it->second << "\"" << std::endl << H5Object::getIndentString(indentLevel) << "}" << std::endl; return os.str(); } else { alreadyVisited.insert(std::pair<haddr_t, std::string>(addr, getCompletePath())); } const H5Type & type = const_cast<H5Dataset *>(this)->getDataType(); const H5Dataspace & space = const_cast<H5Dataset *>(this)->getSpace(); const H5AttributesList & attrs = const_cast<H5Dataset *>(this)->getAttributes(); const H5Dataset::H5Layout & layout = const_cast<H5Dataset *>(this)->getLayout(); H5Data * data = 0; try { data = &const_cast<H5Dataset *>(this)->getData(); } catch (const H5Exception & /*e*/) { } os << H5Object::getIndentString(indentLevel) << "DATASET \"" << getName() << "\" {" << std::endl << type.dump(alreadyVisited, indentLevel + 1) << space.dump(alreadyVisited, indentLevel + 1) << layout.dump(alreadyVisited, indentLevel + 1); if (data) { os << data->dump(alreadyVisited, indentLevel + 1); } else { os << H5Object::getIndentString(indentLevel + 1) << _("Error in retrieving data.") << std::endl; } os << attrs.dump(alreadyVisited, indentLevel + 1) << H5Object::getIndentString(indentLevel) << "}" << std::endl; delete &type; delete &space; if (data) { delete data; } delete &attrs; delete &layout; return os.str(); }
void InitFilenameFilterList() { if (gFilenameFiltersInited) return; gFilenameFiltersInited = true; gFilenameFilters.insert(std::pair<int, std::string>(0, "Base")); gFilenameFilters.insert(std::pair<int, std::string>(1, "Brick")); gFilenameFilters.insert(std::pair<int, std::string>(2, "Brush")); gFilenameFilters.insert(std::pair<int, std::string>(3, "Cobblestone")); gFilenameFilters.insert(std::pair<int, std::string>(4, "Cracked")); gFilenameFilters.insert(std::pair<int, std::string>(5, "Creep")); gFilenameFilters.insert(std::pair<int, std::string>(6, "Crop")); gFilenameFilters.insert(std::pair<int, std::string>(7, "Dirt")); gFilenameFilters.insert(std::pair<int, std::string>(8, "Fern")); gFilenameFilters.insert(std::pair<int, std::string>(9, "Flower")); gFilenameFilters.insert(std::pair<int, std::string>(10, "Footprints")); gFilenameFilters.insert(std::pair<int, std::string>(11, "Grass")); gFilenameFilters.insert(std::pair<int, std::string>(12, "Ice")); gFilenameFilters.insert(std::pair<int, std::string>(13, "Leaf")); gFilenameFilters.insert(std::pair<int, std::string>(14, "Mud")); gFilenameFilters.insert(std::pair<int, std::string>(15, "Moss")); gFilenameFilters.insert(std::pair<int, std::string>(16, "Road")); gFilenameFilters.insert(std::pair<int, std::string>(17, "Rock")); gFilenameFilters.insert(std::pair<int, std::string>(18, "Root")); gFilenameFilters.insert(std::pair<int, std::string>(19, "Rubble")); gFilenameFilters.insert(std::pair<int, std::string>(20, "Sand")); gFilenameFilters.insert(std::pair<int, std::string>(21, "Shore")); gFilenameFilters.insert(std::pair<int, std::string>(22, "Straw")); gFilenameFilters.insert(std::pair<int, std::string>(23, "Weed")); }
void WeightMatrix_iter::solve(std::map<unsigned int, std::vector<double> >& ret_result) { ret_result.clear(); // _prev_result.resize(_nrows); // _result.resize(_nrows); _result_parallel.resize(_nrows); for(size_t i=0; i< _nrows; i++){ // _prev_result[i].resize(_nClass, 0.0 ); // _result[i].resize(_nClass, 0.0 ); _result_parallel[i].resize(_nClass, 0.0 ); } printf("LabelProp labeled example %u\n", _mapped_trn_idx.size()); reassign_label(); size_t ncores=8; _maxIter=200; double max_diff; for (size_t iter=0; iter< _maxIter; iter++){ max_diff = 0; // for(size_t row = 0 ; row < _nrows ; row++){ // // // if ((! _nzd_indicator[row]) || (_trn_indicator[row])) // if (! _nzd_indicator[row]) // continue; // // for(size_t jj=0; jj < _Wnorm[row].size(); jj++){ // unsigned int col = _Wnorm[row][jj].j; // double val = _Wnorm[row][jj].v; // // // if ((! _nzd_indicator[col]) || (_trn_indicator[col])) // if (! _nzd_indicator[col]) // continue; // // for(int cc=0; cc<_nClass; cc++){ // (_result[row][cc]) += (val * _prev_result[col][cc]); // } // } // } size_t start_row=0; std::vector< boost::thread* > threads; size_t chunksz = _nrows/ncores; if (_nrows> (ncores*chunksz)) ncores++; for(size_t ichunk=0; ichunk < ncores; ichunk++){ size_t end_row = start_row + chunksz; if (end_row >=_nrows) end_row = _nrows; threads.push_back(new boost::thread(&WeightMatrix_iter::solve_partial, this, start_row, end_row)); start_row = end_row; } // printf("Sync all threads \n"); for (size_t ti=0; ti<threads.size(); ti++) (threads[ti])->join(); // printf("all threads done\n"); // double debug_diff=0; // for(size_t row = 0 ; row < _nrows ; row++){ // for(int cc=0; cc<_nClass; cc++){ // debug_diff += fabs(_result[row][cc] - _result_parallel[row][cc]); // } // } // if (debug_diff>0) // printf("Difference between serial and parallel = %f\n",debug_diff); for(size_t row = 0 ; row < _nrows ; row++){ // normalize_row(_result[row]); normalize_row(_result_parallel[row]); } for(size_t row = 0 ; row < _nrows ; row++){ if (_trn_indicator[row]){ continue; } double diff=0; for(int cc=0; cc<_nClass; cc++){ diff = fabs(_prev_result[row][cc] - _result_parallel[row][cc]); max_diff = (max_diff>diff) ? max_diff: diff; _prev_result[row][cc] = _result_parallel[row][cc]; } } reassign_label(); if (!(iter%10)) printf("max diff %.5f\n",max_diff); if (max_diff<EPS) break; } printf("max diff %.5f\n",max_diff); for(size_t row = 0 ; row < _nrows ; row++){ if ((! _nzd_indicator[row]) || (_trn_indicator[row])) continue; if (!(vector_sum(_result_parallel[row])>0)) _result_parallel[row].assign(_nClass, (double)(1.0/_nClass)); ret_result.insert(std::make_pair(row, _result_parallel[row])); } }
void VS_CC frameDoneCallback(void *userData, const VSFrameRef *f, int n, VSNodeRef *, const char *errorMsg) { completedFrames++; if (printFrameNumber) { std::chrono::time_point<std::chrono::high_resolution_clock> currentTime(std::chrono::high_resolution_clock::now()); std::chrono::duration<double> elapsedSeconds = currentTime - lastFpsReportTime; if (elapsedSeconds.count() > 10) { hasMeaningfulFps = true; fps = (completedFrames - lastFpsReportFrame) / elapsedSeconds.count(); lastFpsReportTime = currentTime; lastFpsReportFrame = completedFrames; } } if (f) { reorderMap.insert(std::make_pair(n, f)); while (reorderMap.count(outputFrames)) { const VSFrameRef *frame = reorderMap[outputFrames]; reorderMap.erase(outputFrames); if (!outputError) { if (y4m) { if (fwrite("FRAME\n", 1, 6, outFile) != 6) { if (errorMessage.empty()) errorMessage = "Error: fwrite() call failed when writing header, errno: " + std::to_string(errno); totalFrames = requestedFrames; outputError = true; } } if (!outputError) { const VSFormat *fi = vsapi->getFrameFormat(frame); for (int p = 0; p < fi->numPlanes; p++) { int stride = vsapi->getStride(frame, p); const uint8_t *readPtr = vsapi->getReadPtr(frame, p); int rowSize = vsapi->getFrameWidth(frame, p) * fi->bytesPerSample; int height = vsapi->getFrameHeight(frame, p); for (int y = 0; y < height; y++) { if (fwrite(readPtr, 1, rowSize, outFile) != (size_t)rowSize) { if (errorMessage.empty()) errorMessage = "Error: fwrite() call failed when writing frame: " + std::to_string(outputFrames) + ", plane: " + std::to_string(p) + ", line: " + std::to_string(y) + ", errno: " + std::to_string(errno); totalFrames = requestedFrames; outputError = true; p = 100; // break out of the outer loop break; } readPtr += stride; } } } } vsapi->freeFrame(frame); outputFrames++; } } else { outputError = true; totalFrames = requestedFrames; if (errorMessage.empty()) { if (errorMsg) errorMessage = "Error: Failed to retrieve frame " + std::to_string(n) + " with error: " + errorMsg; else errorMessage = "Error: Failed to retrieve frame " + std::to_string(n); } } if (requestedFrames < totalFrames) { vsapi->getFrameAsync(requestedFrames, node, frameDoneCallback, NULL); requestedFrames++; } if (printFrameNumber && !outputError) { if (hasMeaningfulFps) fprintf(stderr, "Frame: %d/%d (%.2f fps)\r", completedFrames, totalFrames, fps); else fprintf(stderr, "Frame: %d/%d\r", completedFrames, totalFrames); } if (totalFrames == completedFrames) { std::lock_guard<std::mutex> lock(mutex); condition.notify_one(); } }
void UpdateAI(const uint32 diff) { if (!UpdateVictim()) return; events.Update(diff); if (Phase == 1) { while (uint32 eventId = events.GetEvent()) { switch (eventId) { case EVENT_WASTE: DoSummon(NPC_WASTE, Pos[RAND(0, 3, 6, 9)]); events.RepeatEvent(urand(2000, 5000)); break; case EVENT_ABOMIN: if (nAbomination < 8) { DoSummon(NPC_ABOMINATION, Pos[RAND(1, 4, 7, 10)]); nAbomination++; events.RepeatEvent(20000); } else events.PopEvent(); break; case EVENT_WEAVER: if (nWeaver < 8) { DoSummon(NPC_WEAVER, Pos[RAND(0, 3, 6, 9)]); nWeaver++; events.RepeatEvent(25000); } else events.PopEvent(); break; case EVENT_TRIGGER: if (GameObject* pKTTrigger = me->GetMap()->GetGameObject(KTTriggerGUID)) pKTTrigger->SetPhaseMask(2, true); events.PopEvent(); break; case EVENT_PHASE: events.Reset(); DoScriptText(RAND(SAY_AGGRO_1, SAY_AGGRO_2, SAY_AGGRO_3), me); spawns.DespawnAll(); me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_DISABLE_MOVE | UNIT_FLAG_NOT_SELECTABLE); me->CastStop(); DoStartMovement(me->getVictim()); events.ScheduleEvent(EVENT_BOLT, urand(5000, 10000)); events.ScheduleEvent(EVENT_NOVA, 15000); events.ScheduleEvent(EVENT_DETONATE, urand(30000, 40000)); events.ScheduleEvent(EVENT_FISSURE, urand(10000, 30000)); events.ScheduleEvent(EVENT_BLAST, urand(60000, 120000)); if (GetDifficulty() == RAID_DIFFICULTY_25MAN_NORMAL) events.ScheduleEvent(EVENT_CHAIN, urand(30000, 60000)); Phase = 2; break; default: events.PopEvent(); break; } } } else { //start phase 3 when we are 45% health if (Phase != 3) { if (HealthBelowPct(45)) { Phase = 3 ; DoScriptText(SAY_REQUEST_AID, me); if (Creature* LichKing = Unit::GetCreature(*me, instance ? instance->GetData64(DATA_LICHKING) : 0)) DoScriptText(SAY_ANSWER_REQUEST, LichKing); for (uint8 i = 0; i <= 3; ++i) { if (GameObject* pPortal = me->GetMap()->GetGameObject(PortalsGUID[i])) { if (pPortal->getLootState() == GO_READY) pPortal->UseDoorOrButton(); } } } } else if (nGuardiansOfIcecrownCount < RAID_MODE(2, 4)) { if (uiGuardiansOfIcecrownTimer <= diff) { // TODO : Add missing text if (Creature* pGuardian = DoSummon(NPC_ICECROWN, Pos[RAND(2, 5, 8, 11)])) pGuardian->SetFloatValue(UNIT_FIELD_COMBATREACH, 2); ++nGuardiansOfIcecrownCount; uiGuardiansOfIcecrownTimer = 5000; } else uiGuardiansOfIcecrownTimer -= diff; } if (me->HasUnitState(UNIT_STAT_CASTING)) return; if (uint32 eventId = events.GetEvent()) { switch (eventId) { case EVENT_BOLT: DoCastVictim(RAID_MODE(SPELL_FROST_BOLT, H_SPELL_FROST_BOLT)); events.RepeatEvent(urand(5000, 10000)); break; case EVENT_NOVA: DoCastAOE(RAID_MODE(SPELL_FROST_BOLT_AOE, H_SPELL_FROST_BOLT_AOE)); events.RepeatEvent(urand(15000, 30000)); break; case EVENT_CHAIN: { uint32 count = urand(1, 3); for (uint8 i = 1; i <= count; i++) { Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 1, 200, true); if (target && !target->isCharmed() && (chained.find(target->GetGUID()) == chained.end())) { DoCast(target, SPELL_CHAINS_OF_KELTHUZAD); float scale = target->GetFloatValue(OBJECT_FIELD_SCALE_X); chained.insert(std::make_pair(target->GetGUID(), scale)); target->SetFloatValue(OBJECT_FIELD_SCALE_X, scale * 2); events.ScheduleEvent(EVENT_CHAINED_SPELL, 2000); //core has 2000ms to set unit flag charm } } if (!chained.empty()) DoScriptText(RAND(SAY_CHAIN_1, SAY_CHAIN_2), me); events.RepeatEvent(urand(100000, 180000)); break; } case EVENT_CHAINED_SPELL: { std::map<uint64, float>::iterator itr; for (itr = chained.begin(); itr != chained.end();) { if (Unit* player = Unit::GetPlayer(*me, (*itr).first)) { if (!player->isCharmed()) { player->SetFloatValue(OBJECT_FIELD_SCALE_X, (*itr).second); std::map<uint64, float>::iterator next = itr; ++next; chained.erase(itr); itr = next; continue; } if (Unit* target = SelectTarget(SELECT_TARGET_TOPAGGRO, 0, NotCharmedTargetSelector())) { switch (player->getClass()) { case CLASS_DRUID: if (urand(0, 1)) player->CastSpell(target, SPELL_MOONFIRE, false); else player->CastSpell(me, SPELL_LIFEBLOOM, false); break; case CLASS_HUNTER: player->CastSpell(target, RAND(SPELL_MULTI_SHOT, SPELL_VOLLEY), false); break; case CLASS_MAGE: player->CastSpell(target, RAND(SPELL_FROST_FIREBOLT, SPELL_ARCANE_MISSILES), false); break; case CLASS_WARLOCK: player->CastSpell(target, RAND(SPELL_CURSE_OF_AGONY, SPELL_SHADOW_BOLT), true); break; case CLASS_WARRIOR: player->CastSpell(target, RAND(SPELL_BLADESTORM, SPELL_CLEAVE), false); break; case CLASS_PALADIN: if (urand(0, 1)) player->CastSpell(target, SPELL_HAMMER_OF_JUSTICE, false); else player->CastSpell(me, SPELL_HOLY_SHOCK, false); break; case CLASS_PRIEST: if (urand(0, 1)) player->CastSpell(target, SPELL_VAMPIRIC_TOUCH, false); else player->CastSpell(me, SPELL_RENEW, false); break; case CLASS_SHAMAN: if (urand(0, 1)) player->CastSpell(target, SPELL_EARTH_SHOCK, false); else player->CastSpell(me, SPELL_HEALING_WAVE, false); break; case CLASS_ROGUE: player->CastSpell(target, RAND(SPELL_HEMORRHAGE, SPELL_MUTILATE), false); break; case CLASS_DEATH_KNIGHT: if (urand(0, 1)) player->CastSpell(target, SPELL_PLAGUE_STRIKE, true); else player->CastSpell(target, SPELL_HOWLING_BLAST, true); break; } } } ++itr; } if (chained.empty()) events.PopEvent(); else events.RepeatEvent(5000); break; } case EVENT_DETONATE: { std::vector<Unit*> unitList; std::list<HostileReference*> *threatList = &me->getThreatManager().getThreatList(); for (std::list<HostileReference*>::const_iterator itr = threatList->begin(); itr != threatList->end(); ++itr) { if ((*itr)->getTarget()->GetTypeId() == TYPEID_PLAYER && (*itr)->getTarget()->getPowerType() == POWER_MANA && (*itr)->getTarget()->GetPower(POWER_MANA)) unitList.push_back((*itr)->getTarget()); } if (!unitList.empty()) { std::vector<Unit*>::const_iterator itr = unitList.begin(); advance(itr, rand()%unitList.size()); DoCast(*itr, SPELL_MANA_DETONATION); DoScriptText(RAND(SAY_SPECIAL_1, SAY_SPECIAL_2, SAY_SPECIAL_3), me); } events.RepeatEvent(urand(20000, 50000)); break; } case EVENT_FISSURE: if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0)) DoCast(target, SPELL_SHADOW_FISURE); events.RepeatEvent(urand(10000, 45000)); break; case EVENT_BLAST: if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, RAID_MODE(1, 0), 0, true)) DoCast(target, SPELL_FROST_BLAST); if (rand()%2) DoScriptText(SAY_FROST_BLAST, me); events.RepeatEvent(urand(30000, 90000)); break; default: events.PopEvent(); break; } } DoMeleeAttackIfReady(); } }
void PluginUtils::setPluginJavaData(PluginProtocol* pKeyObj, PluginJavaData* pData) { erasePluginJavaData(pKeyObj); s_PluginObjMap.insert(std::pair<PluginProtocol*, PluginJavaData*>(pKeyObj, pData)); }
// TypesEqual - Two types are considered structurally equal if they have the // same "shape": Every level and element of the types have identical primitive // ID's, and the graphs have the same edges/nodes in them. Nodes do not have to // be pointer equals to be equivalent though. This uses an optimistic algorithm // that assumes that two graphs are the same until proven otherwise. // static bool TypesEqual(const Type *Ty, const Type *Ty2, std::map<const Type *, const Type *> &EqTypes) { if (Ty == Ty2) return true; if (Ty->getTypeID() != Ty2->getTypeID()) return false; if (Ty->isOpaqueTy()) return false; // Two unequal opaque types are never equal std::map<const Type*, const Type*>::iterator It = EqTypes.find(Ty); if (It != EqTypes.end()) return It->second == Ty2; // Looping back on a type, check for equality // Otherwise, add the mapping to the table to make sure we don't get // recursion on the types... EqTypes.insert(It, std::make_pair(Ty, Ty2)); // Two really annoying special cases that breaks an otherwise nice simple // algorithm is the fact that arraytypes have sizes that differentiates types, // and that function types can be varargs or not. Consider this now. // if (const IntegerType *ITy = dyn_cast<IntegerType>(Ty)) { const IntegerType *ITy2 = cast<IntegerType>(Ty2); return ITy->getBitWidth() == ITy2->getBitWidth(); } if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) { const PointerType *PTy2 = cast<PointerType>(Ty2); return PTy->getAddressSpace() == PTy2->getAddressSpace() && TypesEqual(PTy->getElementType(), PTy2->getElementType(), EqTypes); } if (const StructType *STy = dyn_cast<StructType>(Ty)) { const StructType *STy2 = cast<StructType>(Ty2); if (STy->getNumElements() != STy2->getNumElements()) return false; if (STy->isPacked() != STy2->isPacked()) return false; for (unsigned i = 0, e = STy2->getNumElements(); i != e; ++i) if (!TypesEqual(STy->getElementType(i), STy2->getElementType(i), EqTypes)) return false; return true; } if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) { const ArrayType *ATy2 = cast<ArrayType>(Ty2); return ATy->getNumElements() == ATy2->getNumElements() && TypesEqual(ATy->getElementType(), ATy2->getElementType(), EqTypes); } if (const VectorType *PTy = dyn_cast<VectorType>(Ty)) { const VectorType *PTy2 = cast<VectorType>(Ty2); return PTy->getNumElements() == PTy2->getNumElements() && TypesEqual(PTy->getElementType(), PTy2->getElementType(), EqTypes); } if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) { const FunctionType *FTy2 = cast<FunctionType>(Ty2); if (FTy->isVarArg() != FTy2->isVarArg() || FTy->getNumParams() != FTy2->getNumParams() || !TypesEqual(FTy->getReturnType(), FTy2->getReturnType(), EqTypes)) return false; for (unsigned i = 0, e = FTy2->getNumParams(); i != e; ++i) { if (!TypesEqual(FTy->getParamType(i), FTy2->getParamType(i), EqTypes)) return false; } return true; } llvm_unreachable("Unknown derived type!"); return false; }
/** * Invoked from Total Commander's command line - or by pressing enter. */ int __stdcall FsExecuteFile(HWND MainWin, bchar * fullRemoteName, bchar * verb) { gMainWin = MainWin; WLock wlock; if (!verb || !*verb) return FS_EXEC_ERROR; // disable automatic reloads lastServer = 0; bstring cmd = verb; bstring fullRemotePath; if (fullRemoteName && *fullRemoteName) fullRemotePath = fullRemoteName + 1; // set the global mode!? -- ignore, since SFTP does not support it. if (cmd.length() > 5 && cmd.substr(0, 4) == TEXT("MODE")) { if (cmd[5] == 'A') transferAscii = true; else { modeExtensions.clear(); transferAscii = false; if (cmd[5] == 'X') { size_t start = (size_t)-1; for (size_t i = 6; i < cmd.size(); ++i) { if (cmd[i] == '.') start = i; else if (cmd[i] <= 32) { size_t len = i - start; bstring x = cmd.substr(start, len); modeExtensions.insert(std::make_pair(x, x)); start = (size_t)-1; } } if (start != (size_t)-1) { bstring x = cmd.substr(start); modeExtensions.insert(std::make_pair(x, x)); } } } return FS_EXEC_OK; } bstring remotePath; if (cmd == TEXT("open")) { size_t slash = fullRemotePath.find_first_of('\\'); if (slash != (size_t)-1) return FS_EXEC_YOURSELF; // it's a server name if (fullRemotePath != EDIT_CONNECTIONS) { // get or create the server Server * server = Server::findServer(remotePath, fullRemotePath.c_str()); if (!server) return FS_EXEC_ERROR; if (!server->connect()) { Server::removeServer(server->getName().c_str()); return FS_EXEC_ERROR; } // simply get the home folder and append. Otherwise the progress bar hides // connect and get the home folder bstring response; if (!server->getHomeDir(response)) return FS_EXEC_ERROR; // return the full remote path and force reload of dir fullRemoteName[0] = '/'; bstrcpy(fullRemoteName + 1, server->getName().c_str()); bstrcat(fullRemoteName, response.c_str()); toDos(fullRemoteName); return FS_EXEC_SYMLINK; } // It's edit connections. Create a temp server - maybe we keep it. Server server(TEXT("~")); // popup config dialog config_tag const * const cfg = server.doConfig(); if (!cfg) { fullRemoteName[1] = 0; return FS_EXEC_SYMLINK; } Sftp4tc const * const session = &cfg->sftp4tc; // is there a session? bstring sessionName; #ifdef UNICODE BCONVERT(wchar_t, 256, sessionName, session->selectedSession) #else sessionName = session->selectedSession; #endif bchar buf[16]; if (sessionName.length() == 0) { // no create a name from host sessionName = TEXT("quick connection ("); bsprintf(buf, TEXT("%d) "), ++quickConnectionCount); bchar const * host; #ifdef UNICODE BCONVERT(wchar_t, 256, host, cfg->host) #else host = cfg->host; #endif sessionName = sessionName + buf + host; } else
char_t Tokenizer::GetDelimiter(TokenRange range) const { // Symbols are sorted by their precedence, in decreasing order. While the most // common delimiters are underscore, space and dot, we give comma the priority // to handle the case where words are separated by ", ". Besides, we'll be // trimming whitespace later on. static const string_t kDelimiterTable = L",_ .-+;&|~"; // Trim whitespace so that it doesn't interfere with our frequency analysis. // This proves useful for handling some edge cases, and it doesn't seem to // have any side effects. if (!TrimWhitespace(filename_, range)) return L' '; static std::map<char_t, size_t> frequency; if (frequency.empty()) { // Initialize frequency map for (const auto& character : kDelimiterTable) { frequency.insert(std::make_pair(character, 0)); } } else { // Reset frequency map for (auto& pair : frequency) { pair.second = 0; } } // Count all possible delimiters for (size_t i = range.offset; i < range.offset + range.size; i++) { const char_t character = filename_.at(i); if (IsAlphanumericChar(character)) continue; if (frequency.find(character) == frequency.end()) continue; frequency.at(character) += 1; } char_t delimiter = L'\0'; for (const auto& pair : frequency) { if (pair.second == 0) continue; // Initialize delimiter at first iteration if (delimiter == L'\0') { delimiter = pair.first; continue; } int character_distance = static_cast<int>(kDelimiterTable.find(pair.first)) - static_cast<int>(kDelimiterTable.find(delimiter)); // If the distance is negative, then the new delimiter has higher priority if (character_distance < 0) { delimiter = pair.first; continue; } // Even if the new delimiter has lower priority, it may be much more common float frequency_ratio = static_cast<float>(pair.second) / static_cast<float>(frequency[delimiter]); // The constant value was chosen by trial and error. There should be room // for improvement. if (frequency_ratio / abs(character_distance) > 0.8f) delimiter = pair.first; } return delimiter; }
std::string LoadMtl ( std::map<std::string, material_t>& material_map, const char* filename, const char* mtl_basepath) { material_map.clear(); std::stringstream err; std::string filepath; if (mtl_basepath) { filepath = std::string(mtl_basepath) + std::string(filename); } else { filepath = std::string(filename); } std::ifstream ifs(filepath.c_str()); if (!ifs) { err << "Cannot open file [" << filepath << "]" << std::endl; return err.str(); } material_t material; int maxchars = 8192; // Alloc enough size. std::vector<char> buf(maxchars); // Alloc enough size. while (ifs.peek() != -1) { ifs.getline(&buf[0], maxchars); std::string linebuf(&buf[0]); // Trim newline '\r\n' or '\r' if (linebuf.size() > 0) { if (linebuf[linebuf.size()-1] == '\n') linebuf.erase(linebuf.size()-1); } if (linebuf.size() > 0) { if (linebuf[linebuf.size()-1] == '\n') linebuf.erase(linebuf.size()-1); } // Skip if empty line. if (linebuf.empty()) { continue; } // Skip leading space. const char* token = linebuf.c_str(); token += strspn(token, " \t"); assert(token); if (token[0] == '\0') continue; // empty line if (token[0] == '#') continue; // comment line // new mtl if ((0 == strncmp(token, "newmtl", 6)) && isSpace((token[6]))) { // flush previous material. material_map.insert(std::pair<std::string, material_t>(material.name, material)); // initial temporary material InitMaterial(material); // set new mtl name char namebuf[4096]; token += 7; sscanf(token, "%s", namebuf); material.name = namebuf; continue; } // ambient if (token[0] == 'K' && token[1] == 'a' && isSpace((token[2]))) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.ambient[0] = r; material.ambient[1] = g; material.ambient[2] = b; continue; } // diffuse if (token[0] == 'K' && token[1] == 'd' && isSpace((token[2]))) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.diffuse[0] = r; material.diffuse[1] = g; material.diffuse[2] = b; continue; } // specular if (token[0] == 'K' && token[1] == 's' && isSpace((token[2]))) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.specular[0] = r; material.specular[1] = g; material.specular[2] = b; continue; } // transmittance if (token[0] == 'K' && token[1] == 't' && isSpace((token[2]))) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.transmittance[0] = r; material.transmittance[1] = g; material.transmittance[2] = b; continue; } // ior(index of refraction) if (token[0] == 'N' && token[1] == 'i' && isSpace((token[2]))) { token += 2; material.ior = parseFloat(token); continue; } // emission if(token[0] == 'K' && token[1] == 'e' && isSpace(token[2])) { token += 2; float r, g, b; parseFloat3(r, g, b, token); material.emission[0] = r; material.emission[1] = g; material.emission[2] = b; continue; } // shininess if(token[0] == 'N' && token[1] == 's' && isSpace(token[2])) { token += 2; material.shininess = parseFloat(token); continue; } // illum model if (0 == strncmp(token, "illum", 5) && isSpace(token[5])) { token += 6; material.illum = parseInt(token); continue; } // dissolve if ((token[0] == 'd' && isSpace(token[1]))) { token += 1; material.dissolve = parseFloat(token); continue; } if (token[0] == 'T' && token[1] == 'r' && isSpace(token[2])) { token += 2; material.dissolve = parseFloat(token); continue; } // ambient texture if ((0 == strncmp(token, "map_Ka", 6)) && isSpace(token[6])) { token += 7; material.ambient_texname = token; continue; } // diffuse texture if ((0 == strncmp(token, "map_Kd", 6)) && isSpace(token[6])) { token += 7; material.diffuse_texname = token; continue; } // specular texture if ((0 == strncmp(token, "map_Ks", 6)) && isSpace(token[6])) { token += 7; material.specular_texname = token; continue; } // normal texture if ((0 == strncmp(token, "map_Ns", 6)) && isSpace(token[6])) { token += 7; material.normal_texname = token; continue; } // unknown parameter const char* _space = strchr(token, ' '); if(!_space) { _space = strchr(token, '\t'); } if(_space) { int len = _space - token; std::string key(token, len); std::string value = _space + 1; material.unknown_parameter.insert(std::pair<std::string, std::string>(key, value)); } } // flush last material. material_map.insert(std::pair<std::string, material_t>(material.name, material)); return err.str(); }
EDA_COLOR_T COLOR4D::GetNearestLegacyColor( const COLOR4D &aColor ) { // Cache layer implemented here, because all callers are using wxColour static std::map< unsigned int, unsigned int > nearestCache; static double hues[NBCOLORS]; static double values[NBCOLORS]; unsigned int colorInt = aColor.ToU32(); auto search = nearestCache.find( colorInt ); if( search != nearestCache.end() ) return static_cast<EDA_COLOR_T>( search->second ); // First use ColorFindNearest to check for exact matches EDA_COLOR_T nearest = ColorFindNearest( aColor.r * 255.0, aColor.g * 255.0, aColor.b * 255.0 ); if( COLOR4D( nearest ) == aColor ) { nearestCache.insert( std::pair< unsigned int, unsigned int >( colorInt, static_cast<unsigned int>( nearest ) ) ); return nearest; } // If not, use hue and value to match. // Hue will be NAN for grayscale colors. // The legacy color palette is a grid across hue and value. // We can exploit that to find a good match -- hue is most apparent to the user. // So, first we determine the closest hue match, and then the closest value from that // "grid row" in the legacy palette. double h, s, v; aColor.ToHSV( h, s, v ); double minDist = 360.0; double legacyHue = 0.0; if( std::isnan( h ) ) { legacyHue = NAN; } else { for( EDA_COLOR_T candidate = ::BLACK; candidate < NBCOLORS; candidate = NextColor( candidate ) ) { double ch; if( hues[candidate] == 0.0 && values[candidate] == 0.0 ) { COLOR4D candidate4d( candidate ); double cs, cv; candidate4d.ToHSV( ch, cs, cv ); values[candidate] = cv; // Set the hue to non-zero for black so that we won't do this more than once hues[candidate] = ( cv == 0.0 ) ? 1.0 : ch; } else { ch = hues[candidate]; } if( fabs( ch - h ) < minDist ) { minDist = fabs( ch - h ); legacyHue = ch; } } } // Now we have the desired hue; let's find the nearest value minDist = 1.0; for( EDA_COLOR_T candidate = ::BLACK; candidate < NBCOLORS; candidate = NextColor( candidate ) ) { // If the target hue is NAN, we didn't extract the value for any colors above if( std::isnan( legacyHue ) ) { double ch, cs, cv; COLOR4D candidate4d( candidate ); candidate4d.ToHSV( ch, cs, cv ); values[candidate] = cv; hues[candidate] = ( cv == 0.0 ) ? 1.0 : ch; } if( ( std::isnan( legacyHue ) != std::isnan( hues[candidate] ) ) || hues[candidate] != legacyHue ) continue; if( fabs( values[candidate] - v ) < minDist ) { minDist = fabs( values[candidate] - v ); nearest = candidate; } } nearestCache.insert( std::pair< unsigned int, unsigned int >( colorInt, static_cast<unsigned int>( nearest ) ) ); return nearest; }
int main(int argc,char** argv) { char *channelProcessControl = NULL; char *configurationFile = NULL; if (argc!=5) { usage(); exit(0); } channelProcessControl = argv[1]; channelStereoControl = argv[2]; channelProcessReport = argv[3]; configurationFile = argv[4]; // read the configuration file to get the processes we'll need GKeyFile *keyfile; GKeyFileFlags flags = G_KEY_FILE_NONE; GError *error = NULL; gsize length, length2; /* Create a new GKeyFile object and a bitwise list of flags. */ keyfile = g_key_file_new (); /* Load the GKeyFile from keyfile.conf or return. */ if (!g_key_file_load_from_file (keyfile, configurationFile, flags, &error)) { fprintf(stderr, "Configuration file \"%s\" not found.\n", configurationFile); return -1; } // build the process table based on the configuration file // first get the names of all of the processes char **processGroups = g_key_file_get_groups(keyfile, &length); for (int i=0; i<(int)length; i++) { // for each process... // get the arguments char **thisArgs = g_key_file_get_string_list(keyfile, processGroups[i], "arguments", &length2, &error); if (thisArgs == NULL) { cout << "Error: no arguments list for process " << processGroups[i] << endl; } else { processMap.insert(std::pair<string, ProcessControlProc>(processGroups[i], ProcessControlProc(thisArgs, (int)length))); } } // now throw an error if the configuration file doesn't have all the right parts CheckForProc("paramServer"); CheckForProc("mavlinkLcmBridge"); CheckForProc("mavlinkSerial"); CheckForProc("stateEstimator"); CheckForProc("windEstimator"); CheckForProc("controller"); CheckForProc("logger"); CheckForProc("stereo"); lcm = lcm_create ("udpm://239.255.76.67:7667?ttl=1"); if (!lcm) { fprintf(stderr, "lcm_create for recieve failed. Quitting.\n"); return 1; } process_control_sub = lcmt_process_control_subscribe(lcm, channelProcessControl, &procces_control_handler, NULL); signal(SIGINT,sighandler); pthread_t processStatusThread; pthread_create( &processStatusThread, NULL, ProcessStatusThreadFunc, NULL); printf("Receiving:\n\tProcess Control LCM: %s\nPublishing LCM:\n\tStereo: %s\n\tStatus: %s\n", channelProcessControl, channelStereoControl, channelProcessReport); while (true) { // read the LCM channel lcm_handle (lcm); } return 0; }
int main (int argc, char ** argv) { std::string filename; std::ifstream trace_file; uint64_t memory_size = 8*1024*1024; // default is 8GB // Check if all arguments are given in command line if (argc != 3) { std::cout << "Please supply two arguements: <trace file> <physical memory size (B)>." << std::endl; return -1; } // Get the filename filename.assign(argv[1]); // Assign the memory size memory_size = std::stol(argv[2], nullptr, 10); // allocate array uint64_t array_size = memory_size / page_size; array_size--; // assume 1st level page table ALWAYS in memory MEME * in_memory = new MEME[array_size]; // in_memory [array_size]; uint64_t array_index = 0; //std::cout << argv[2] << " " << memory_size << " " << array_size << std::endl; // Open the file trace_file.open(filename); char operation; std::string virtual_address; std::string this_key; int byte_size; std::string file_line; std::vector<std::string> line_input; std::string token; while (std::getline(trace_file, file_line)) { // tokenize string std::istringstream ss(file_line); while(std::getline(ss, token, ' ')) { line_input.push_back(token); //std::cout << token << std::endl; } if (line_input.size() != 3) { line_input.clear(); continue; } operation = line_input[0].at(0); if (operation != 'R' && operation != 'W') { line_input.clear(); continue; } line_input[1] = line_input[1].substr(0, line_input[1].size() - 3); if (!valid_address(line_input[1])) { line_input.clear(); continue; } virtual_address = line_input[1]; this_key = line_input[1];//virtual_address;//get_VPN(virtual_address); if (!valid_size(line_input[2])) { line_input.clear(); continue; } byte_size = std::stoi(line_input[2]); if (operation == 'R') total_bytes_read += byte_size; else total_bytes_write += byte_size; auto search = vpn_tracker.find(this_key); if (search != vpn_tracker.end()) { // check if 2nd level not in memory if (!vpn_tracker[this_key].lvl_2_mem) { // find page to eject array_index = get_next_index(in_memory, array_size, array_index); eject_from_memory (in_memory[array_index].vpn, in_memory[array_index].level); // insert new page insert_into_memory (in_memory, array_index, this_key, 2); } else if (vpn_tracker[this_key].lvl_2_mem) { total_accessed++; vpn_tracker[this_key].lvl_2_clock = 1; } // check if 3rd level not in memory if (!vpn_tracker[this_key].lvl_3_mem) { // find page to eject array_index = get_next_index(in_memory, array_size, array_index); eject_from_memory (in_memory[array_index].vpn, in_memory[array_index].level); // insert new page insert_into_memory (in_memory, array_index, this_key, 3); } else if (vpn_tracker[this_key].lvl_3_mem) { total_accessed++; vpn_tracker[this_key].lvl_3_clock = 1; } // check if 4th level not in memory if (!vpn_tracker[this_key].lvl_4_mem) { // find page to eject array_index = get_next_index(in_memory, array_size, array_index); eject_from_memory (in_memory[array_index].vpn, in_memory[array_index].level); // insert new page insert_into_memory (in_memory, array_index, this_key, 4); } else if (vpn_tracker[this_key].lvl_4_mem) { total_accessed++; vpn_tracker[this_key].lvl_4_clock = 1; } vpn_tracker[this_key].num_accessed += 1; } else { PTE new_elem = {this_key, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}; vpn_tracker.insert(std::pair<std::string, PTE>(this_key, new_elem)); for (int i = 2; i < 5; ++i) { array_index = get_next_index(in_memory, array_size, array_index); eject_from_memory (in_memory[array_index].vpn, in_memory[array_index].level); insert_into_memory (in_memory, array_index, this_key, i); } } // std::cout << "num tokens: " << line_input.size() << std::endl; // { // virtual_address // } //std::cout << operation << " " << std::hex << virtual_address << " " << std::hex << get_VPN(virtual_address) << std::endl; line_input.clear(); } std::string most_accessed_vpn = ""; uint64_t num_access_vpn = 0; for (auto& x: vpn_tracker) { if (x.second.num_accessed > num_access_vpn) { num_access_vpn = x.second.num_accessed; most_accessed_vpn = x.first; } } long double page_fault_rate = (long double) total_faults / (long double) total_accessed; std::cout << "Number of pages accessed: " << vpn_tracker.size() << std::endl; //std::cout << "faults " << total_faults << " accessed " << total_accessed << std::endl; std::cout << "Page fault rate: " << page_fault_rate << std::endl; std::cout << "Most accessed VPN: " << most_accessed_vpn << std::endl; std::cout << "Number of bytes read: " << total_bytes_read << std::endl; std::cout << "Number of bytes written: " << total_bytes_write << std::endl; std::cout << "Memory footprint: " << (page_size * (1 + vpn_tracker.size())) << std::endl; delete [] in_memory; // uint64_t hex_value = 0; // std::cin >> std::hex >> hex_value; // std::cout << std::hex << get_VPN(hex_value) << std::endl; return 0; }
void FindMaxMinInColumns(oid_t leading_column_id, const std::vector<common::Value> &values, const std::vector<oid_t> &key_column_ids, const std::vector<ExpressionType> &expr_types, std::map<oid_t, std::pair<common::Value, common::Value>> &non_leading_columns) { // find extreme nums on each column. LOG_TRACE("FindMinMax leading column %d\n", leading_column_id); for (size_t i = 0; i < key_column_ids.size(); i++) { oid_t column_id = key_column_ids[i]; if (column_id == leading_column_id) { continue; } if (non_leading_columns.find(column_id) == non_leading_columns.end()) { auto type = values[i].GetTypeId(); // std::pair<Value, Value> *range = new std::pair<Value, // Value>(Value::GetMaxValue(type), // Value::GetMinValue(type)); // std::pair<oid_t, std::pair<Value, Value>> key_value(column_id, range); non_leading_columns.insert(std::pair<oid_t, std::pair<common::Value, common::Value>>( column_id, std::pair<common::Value, common::Value>( common::ValueFactory::GetNullValueByType(type), common::ValueFactory::GetNullValueByType(type)))); // non_leading_columns[column_id] = *range; // delete range; LOG_TRACE("Insert a init bounds\tleft size %lu\t right description %s\n", non_leading_columns[column_id].first.GetInfo().size(), non_leading_columns[column_id].second.GetInfo().c_str()); } if (DefinesLowerBound(expr_types[i]) || expr_types[i] == EXPRESSION_TYPE_COMPARE_EQUAL) { LOG_TRACE("min cur %lu compare with %s\n", non_leading_columns[column_id].first.GetInfo().size(), values[i].GetInfo().c_str()); if (non_leading_columns[column_id].first.IsNull() || non_leading_columns[column_id].first .CompareGreaterThan(values[i]).IsTrue()) { LOG_TRACE("Update min\n"); non_leading_columns[column_id].first = values[i].Copy(); } } if (DefinesUpperBound(expr_types[i]) || expr_types[i] == EXPRESSION_TYPE_COMPARE_EQUAL) { LOG_TRACE("max cur %s compare with %s\n", non_leading_columns[column_id].second.GetInfo().c_str(), values[i].GetInfo().c_str()); if (non_leading_columns[column_id].first.IsNull() || non_leading_columns[column_id].second. CompareLessThan(values[i]).IsTrue()) { LOG_TRACE("Update max\n"); non_leading_columns[column_id].second = values[i].Copy(); } } } // check if min value is right bound or max value is left bound, if so, update for (const auto &k_v : non_leading_columns) { if (k_v.second.first.IsNull()) { non_leading_columns[k_v.first].first = common::Type::GetMinValue(k_v.second.first.GetTypeId()); } if (k_v.second.second.IsNull()) { non_leading_columns[k_v.first].second = common::Type::GetMinValue(k_v.second.second.GetTypeId()); } } };
/** Associates whole range of K with val by inserting (K_min, val) into the map */ IntervalMap(V const& val) { map_.insert(map_.begin(), std::make_pair(std::numeric_limits<K>::lowest(), val)); };
void PluginUtils::setPluginJavaData(PluginProtocol* pKeyObj, PluginJavaData* pData) { erasePluginJavaData(pKeyObj); s_PluginObjMap.insert(std::pair<PluginProtocol*, PluginJavaData*>(pKeyObj, pData)); s_JObjPluginMap.insert(std::pair<std::string, PluginProtocol*>(pData->jclassName, pKeyObj)); }
void Apriori::confidence_iterator( float spt_AB, const std::bitset<NUM> &r_bsdata, std::map<int,Confidence_t> &r_unit) { /* * typedef std::vector<std::bitset<NUM> >::size_type IndexBitSet_t * */ std::vector<IndexBitSet_t> unitbitset; this->confidence_get_unitbitset(r_bsdata,unitbitset); /* * typedef std::list<std::pair<std::pair<IndexBitSet_t,IndexBitSet_t>,float> > Confidence_t; * */ Confidence_t cfd_unit; std::pair<std::bitset<NUM>,std::bitset<NUM> > bitpair(0x00,0x00); #if 0 { cout << "-0b" << r_bsdata.to_string() << " - "; cout << "unitbitset.size() : " << unitbitset.size() << endl; for(auto iter = unitbitset.begin(); iter!= unitbitset.end(); iter++){ cout << "u0b" << this->m_bitset_vec[*iter].to_string() << endl; } cout << "---" << endl; } #endif for(unsigned long i = 0; i<unitbitset.size(); i++){ cfd_unit.clear(); if(i == 0){ /*init r_unit*/ for(auto iter = unitbitset.begin(); iter!= unitbitset.end(); iter++){ bitpair.first.reset(); bitpair.second.reset(); /*get antecedent *(const std::bitset<NUM> &r_seccedent,const std::bitset<NUM> &r_bitset) * */ bitpair.first |= this->confidence_get_antecedent( this->m_bitset_vec[*iter], r_bsdata ); /* * confidence (A => B) * cofidence = support(AUB)/support(A) * */ float spt_ant = this->calc_support(bitpair.first); float confidence = spt_AB / spt_ant; if(this->isequal(spt_ant,0.0) == true) continue; bitpair.second |= this->m_bitset_vec[*iter]; if(confidence > this->m_confidence){ /* *typedef * std::list<std::pair<std::pair<IndexBitSet_t,IndexBitSet_t>,float> > * Confidence_t; * */ cfd_unit.push_back(std::make_pair( std::make_pair( this->get_index(bitpair.first), this->get_index(bitpair.second)) ,confidence)); } } r_unit.insert(std::make_pair(i+1,cfd_unit)); }else{ bitpair.first.reset(); bitpair.second.reset(); auto k_begin = r_unit[i].begin(); k_begin++; auto j_iter = r_unit[i].begin(); /* * std::map<int,Confidence_t> &r_unit * */ for(unsigned long j = 0; j < r_unit[i].size()-1; j_iter++,j++,k_begin++){ for(auto k_iter = k_begin; k_iter!= r_unit[i].end(); k_iter++){ bitpair.first.reset(); bitpair.second.reset(); /* *typedef * std::list<std::pair<std::pair<IndexBitSet_t,IndexBitSet_t>,float> > * Confidence_t; * */ bitpair.second |= this->m_bitset_vec[j_iter->first.second]; bitpair.second |= this->m_bitset_vec[k_iter->first.second]; #if 0 cout << "s0b" << bitpair.second.to_string() << endl; cout << "|0b" << this->m_bitset_vec[j_iter->first.second].to_string() << endl; cout << "|0b" << this->m_bitset_vec[k_iter->first.second].to_string() << endl; #endif /*get antecedent *(const std::bitset<NUM> &r_seccedent,const std::bitset<NUM> &r_bitset) * */ bitpair.first |= this->confidence_get_antecedent( bitpair.second, r_bsdata ); //cout << "a0b" << bitpair.first.to_string() << endl; /* * std::vector<std::bitset<NUM> > m_bitset_vec; * 位向量列表,用于临时存储位向量 * */ if((bitpair.second.count() == i+1) && !(this->isexist(bitpair.second,cfd_unit))){ //this->m_bitset_vec.push_back(bittmp); /* * confidence (A => B) * cofidence = support(AUB)/support(A) * */ float spt_ant = this->calc_support(bitpair.first); float confidence = spt_AB / spt_ant; if(this->isequal(spt_ant,0.0) == true) continue; if(confidence > this->m_confidence){ /* *typedef * std::list<std::pair<std::pair<IndexBitSet_t,IndexBitSet_t>,float> > * Confidence_t; * */ cfd_unit.push_back(std::make_pair( std::make_pair( this->get_index(bitpair.first), this->get_index(bitpair.second)), confidence)); #if 0 { cout << "A0b" << bitpair.first.to_string() << endl; cout << "B0b" << bitpair.second.to_string() << " - cfd : " << confidence << " - spt_AB : " << spt_AB << " - spt_ant " << spt_ant << endl; } #endif } } } } if(cfd_unit.size() == 0) break; r_unit.insert(std::make_pair(i+1,cfd_unit)); } } }
void push_back(std::map<T, Y>& in, const std::map<T, Y>& value) { in.insert(value.begin(), value.end()); }
int main(int argc, char** argv) { vector<utvonal> utvonalak; if(argc<2) { cout << "tul keves argumentum" << endl; return 0; } { osmium::io::Reader reader(argv[1]); osmium::memory::Buffer buff; while(buff=reader.read()) { for (auto& item:buff) { if(item.type() == osmium::item_type::node) { osmium::Node& n = static_cast<osmium::Node&>(item); if(n.tags().get_value_by_key("name")){ megallo megallo2; megallo2.nev=n.tags().get_value_by_key("name"); megallo2.hol_van=n.location(); terkep.insert({n.id(), megallo2}); } } if (item.type()==osmium::item_type::relation) { osmium::Relation& rel=static_cast<osmium::Relation&>(item); if (string(rel.tags().get_value_by_key("route",""))=="bus") { utvonal ut; if (rel.tags()["ref"]) ut.nev=rel.tags()["ref"]; else if (rel.tags()["name"]) ut.nev=rel.tags()["name"]; else ut.nev="???"; ut.honnan=rel.tags()["from"]; ut.hova=rel.tags()["to"]; for (auto& item:rel.members()) { if (item.type()==osmium::item_type::node && string(item.role())=="stop") ut.megallok.push_back(item.ref()); } utvonalak.push_back(ut); } } } } reader.close(); } for (auto& item:utvonalak) { static string asd=string(64,'*'); cout<<asd<<endl; cout<<"Busz szama:"<<item.nev<<", "<<item.honnan<<"-->"<<item.hova<<endl; cout<<asd<<endl; for(auto& megallo:item.megallok) { cout<<terkep[megallo].nev<<", "<<terkep[megallo].hol_van<<endl; } } cout<<"ennyit talaltam: "<<utvonalak.size()<<endl; return 0; }
void reg_local_obj(SmartObject *obj) { //std::cout << "SmartObject registered!\n"; objects.insert(std::make_pair(obj, Parametres(false, true))); }
extern std::string calStep(double frequency) { static double frequency2pitch_keys[] = {27.50, 29.14, 30.87, // A0, A0#, B0 32.70, 34.65, 36.71, 38.89, 41.20, 43.65, 46.25, 49.00, 51.91, 55.00, 58.27, 61.74, // C1 - B1 // C, C#, D, D#, E, F, F#, G, G#, A, A#, B 65.51, 69.30, 73.42, 77.78, 82.41, 87.31, 92.50, 98.00, 103.83, 110.00, 116.54, 123.47, // C2 - B2 130.81, 138.59, 146.83, 155.56, 164.81, 174.61, 185.00, 196.00, 207.65, 220.00, 233.08, 246.94, // C3 - B3 261.63, 277.18, 293.67, 311.13, 329.63, 349.23, 369.99, 392.00, 415.30, 440.00, 466.16, 493.88, // C4 - B4 523.25, 554.37, 587.33, 622.25, 659.26, 698.46, 739.99, 783.99, 830.61, 880.00, 932.33, 987.77, // C5 - B5 1046.5, 1108.7, 1174.7, 1244.5, 1318.5, 1396.9, 1480.0, 1568.0, 1661.2, 1760.0, 1864.7, 1975.5, // C6 - B6 2093.0, 2217.5, 2349.3, 2489.0, 2637.0, 2793.0, 2960.0, 3136.0, 3322.4, 3520.0, 3729.3, 3951.1, // C7 - B7 4186.0}; // C8 // 国际谱 参考 https://bideyuanli.com/%E5%A3%B0%E4%B9%90%E5%9F%BA%E7%A1%80%E7%90%86%E8%AE%BA/%E9%9F%B3%E9%AB%98 static std::map<double, std::string>pitch_names; pitch_names.insert(std::map<double, std::string>::value_type(27.50, "A0")); pitch_names.insert(std::map<double, std::string>::value_type(29.14, "A0#")); pitch_names.insert(std::map<double, std::string>::value_type(30.87, "B0")); pitch_names.insert(std::map<double, std::string>::value_type(32.70, "C1")); pitch_names.insert(std::map<double, std::string>::value_type(34.65, "C#1")); pitch_names.insert(std::map<double, std::string>::value_type(36.71, "D1")); pitch_names.insert(std::map<double, std::string>::value_type(38.89, "D#1")); pitch_names.insert(std::map<double, std::string>::value_type(41.20, "E1")); pitch_names.insert(std::map<double, std::string>::value_type(43.65, "F1")); pitch_names.insert(std::map<double, std::string>::value_type(46.25, "F#1")); pitch_names.insert(std::map<double, std::string>::value_type(49.00, "G1")); pitch_names.insert(std::map<double, std::string>::value_type(51.91, "G#1")); pitch_names.insert(std::map<double, std::string>::value_type(55.00, "A1")); pitch_names.insert(std::map<double, std::string>::value_type(58.27, "A#1")); pitch_names.insert(std::map<double, std::string>::value_type(61.74, "B1")); pitch_names.insert(std::map<double, std::string>::value_type(65.51, "C2")); pitch_names.insert(std::map<double, std::string>::value_type(69.30, "C#2")); pitch_names.insert(std::map<double, std::string>::value_type(73.42, "D2")); pitch_names.insert(std::map<double, std::string>::value_type(77.78, "D#2")); pitch_names.insert(std::map<double, std::string>::value_type(82.41, "E2")); pitch_names.insert(std::map<double, std::string>::value_type(87.31, "F2")); pitch_names.insert(std::map<double, std::string>::value_type(92.50, "F#2")); pitch_names.insert(std::map<double, std::string>::value_type(98.00, "G2")); pitch_names.insert(std::map<double, std::string>::value_type(103.83, "G#2")); pitch_names.insert(std::map<double, std::string>::value_type(110.00, "A2")); pitch_names.insert(std::map<double, std::string>::value_type(116.54, "A#2")); pitch_names.insert(std::map<double, std::string>::value_type(123.47, "B2")); pitch_names.insert(std::map<double, std::string>::value_type(130.81, "C3")); pitch_names.insert(std::map<double, std::string>::value_type(138.59, "C#3")); pitch_names.insert(std::map<double, std::string>::value_type(146.83, "D3")); pitch_names.insert(std::map<double, std::string>::value_type(155.56, "D#3")); pitch_names.insert(std::map<double, std::string>::value_type(164.81, "E3")); pitch_names.insert(std::map<double, std::string>::value_type(174.61, "F3")); pitch_names.insert(std::map<double, std::string>::value_type(185.00, "F#3")); pitch_names.insert(std::map<double, std::string>::value_type(196.00, "G3")); pitch_names.insert(std::map<double, std::string>::value_type(207.65, "G#3")); pitch_names.insert(std::map<double, std::string>::value_type(220.00, "A3")); pitch_names.insert(std::map<double, std::string>::value_type(233.08, "A#3")); pitch_names.insert(std::map<double, std::string>::value_type(246.94, "B3")); pitch_names.insert(std::map<double, std::string>::value_type(261.63, "C4")); pitch_names.insert(std::map<double, std::string>::value_type(277.18, "C#4")); pitch_names.insert(std::map<double, std::string>::value_type(293.67, "D4")); pitch_names.insert(std::map<double, std::string>::value_type(311.13, "D#4")); pitch_names.insert(std::map<double, std::string>::value_type(329.63, "E4")); pitch_names.insert(std::map<double, std::string>::value_type(349.23, "F4")); pitch_names.insert(std::map<double, std::string>::value_type(369.99, "F#4")); pitch_names.insert(std::map<double, std::string>::value_type(392.00, "G4")); pitch_names.insert(std::map<double, std::string>::value_type(415.30, "G#4")); pitch_names.insert(std::map<double, std::string>::value_type(440.00, "A4")); pitch_names.insert(std::map<double, std::string>::value_type(466.16, "A#4")); pitch_names.insert(std::map<double, std::string>::value_type(493.88, "B4")); pitch_names.insert(std::map<double, std::string>::value_type(523.25, "C5")); pitch_names.insert(std::map<double, std::string>::value_type(554.37, "C#5")); pitch_names.insert(std::map<double, std::string>::value_type(587.33, "D5")); pitch_names.insert(std::map<double, std::string>::value_type(622.25, "D#5")); pitch_names.insert(std::map<double, std::string>::value_type(659.26, "E5")); pitch_names.insert(std::map<double, std::string>::value_type(698.46, "F5")); pitch_names.insert(std::map<double, std::string>::value_type(739.99, "F#5")); pitch_names.insert(std::map<double, std::string>::value_type(783.99, "G5")); pitch_names.insert(std::map<double, std::string>::value_type(830.61, "G#5")); pitch_names.insert(std::map<double, std::string>::value_type(880.00, "A5")); pitch_names.insert(std::map<double, std::string>::value_type(932.33, "A#5")); pitch_names.insert(std::map<double, std::string>::value_type(987.77, "B5")); pitch_names.insert(std::map<double, std::string>::value_type(1046.5, "C6")); pitch_names.insert(std::map<double, std::string>::value_type(1108.7, "C#6")); pitch_names.insert(std::map<double, std::string>::value_type(1174.7, "D6")); pitch_names.insert(std::map<double, std::string>::value_type(1244.5, "D#6")); pitch_names.insert(std::map<double, std::string>::value_type(1318.5, "E6")); pitch_names.insert(std::map<double, std::string>::value_type(1396.9, "F6")); pitch_names.insert(std::map<double, std::string>::value_type(1480.0, "F#6")); pitch_names.insert(std::map<double, std::string>::value_type(1568.0, "G6")); pitch_names.insert(std::map<double, std::string>::value_type(1661.2, "G#6")); pitch_names.insert(std::map<double, std::string>::value_type(1760.0, "A6")); pitch_names.insert(std::map<double, std::string>::value_type(1864.7, "A#6")); pitch_names.insert(std::map<double, std::string>::value_type(1975.5, "B6")); pitch_names.insert(std::map<double, std::string>::value_type(2093.0, "C7")); pitch_names.insert(std::map<double, std::string>::value_type(2217.5, "C#7")); pitch_names.insert(std::map<double, std::string>::value_type(2349.3, "D7")); pitch_names.insert(std::map<double, std::string>::value_type(2489.0, "D#7")); pitch_names.insert(std::map<double, std::string>::value_type(2637.0, "E7")); pitch_names.insert(std::map<double, std::string>::value_type(2793.0, "F7")); pitch_names.insert(std::map<double, std::string>::value_type(2960.0, "F#7")); pitch_names.insert(std::map<double, std::string>::value_type(3136.0, "G7")); pitch_names.insert(std::map<double, std::string>::value_type(3322.4, "G#7")); pitch_names.insert(std::map<double, std::string>::value_type(3520.0, "A7")); pitch_names.insert(std::map<double, std::string>::value_type(3729.3, "A#7")); pitch_names.insert(std::map<double, std::string>::value_type(3951.1, "B7")); pitch_names.insert(std::map<double, std::string>::value_type(4186.0, "C8")); double pre_fre = 0.0; int arr_count = sizeof(frequency2pitch_keys) / sizeof(frequency2pitch_keys[0]); for (int i = 0 ; i < arr_count; i++) { double cur_fre = frequency2pitch_keys[i]; double next_fre = frequency2pitch_keys[i+1]; double range_min = (0==i ? 0 : cur_fre - (cur_fre - pre_fre) / 2.0); double range_max = ((arr_count-1)==i ? MAXFLOAT : cur_fre + (next_fre - cur_fre) / 2.0); if (frequency >= range_min && frequency < range_max) { std::map<double, std::string>::const_iterator citor; citor = pitch_names.find(cur_fre); return citor->second; } else { continue; } } return "UnkownPitch"; }
void RegisterPrefix( int type, const std::string& prefix ) { myPrefixes.insert( std::pair< int, std::string >( type, prefix ) ); }
/** * Insert an element into the map. Returns false if the element already was in the map. */ bool insert(Key key,Object* object) { std::pair<typename std::map<Key,Object*>::iterator,bool> ret; ret = nodes.insert(std::pair<Key,Object*>(key,object)); return ret.second; }
static void ParseConfig(std::string file, std::map<std::string, LoggerInfo> & outInfo) { //! read file content { CLog4zFile f; f.Open(file.c_str(), "r"); if (f.IsOpen()) { std::string curLoggerName; int curLineNum = 0; char buf[500]; std::string line; std::string key; std::string value; do { memset(buf, 0, 500); if (!f.ReadLine(buf, 500-1)) { break; } line = buf; curLineNum++; TrimLogConfig(line); if (line.empty()) { continue; } if (*(line.begin()) == '#') { continue; } if (*(line.begin()) == '[') { TrimLogConfig(line, '['); TrimLogConfig(line, ']'); curLoggerName = line; { std::string tmpstr = line; std::transform(tmpstr.begin(), tmpstr.end(), tmpstr.begin(), ::tolower); if (tmpstr == "main") { curLoggerName = "Main"; } } std::map<std::string, LoggerInfo>::iterator iter = outInfo.find(curLoggerName); if (iter == outInfo.end()) { LoggerInfo li; li.SetDefaultInfo(); li._name = curLoggerName; outInfo.insert(std::make_pair(li._name, li)); } else { std::cout << "log4z configure warning: dumplicate logger name:["<< curLoggerName << "] at line:" << curLineNum << std::endl; } continue; } size_t pos = line.find_first_of('='); if (pos == std::string::npos) { std::cout << "log4z configure warning: unresolved line:["<< line << "] at line:" << curLineNum << std::endl; continue; } key = line.substr(0, pos); value = line.substr(pos+1); TrimLogConfig(key); TrimLogConfig(value); std::map<std::string, LoggerInfo>::iterator iter = outInfo.find(curLoggerName); if (iter == outInfo.end()) { std::cout << "log4z configure warning: not found current logger name:["<< curLoggerName << "] at line:" << curLineNum << ", key=" <<key << ", value=" << value << std::endl; continue; } std::transform(key.begin(), key.end(), key.begin(), ::tolower); //! path if (key == "path") { iter->second._path = value; continue; } std::transform(value.begin(), value.end(), value.begin(), ::tolower); //! level if (key == "level") { if (value == "debug" || value == "all") { iter->second._level = LOG_LEVEL_DEBUG; } else if (value == "info") { iter->second._level = LOG_LEVEL_INFO; } else if (value == "warn" || value == "warning") { iter->second._level = LOG_LEVEL_WARN; } else if (value == "error") { iter->second._level = LOG_LEVEL_ERROR; } else if (value == "alarm") { iter->second._level = LOG_LEVEL_WARN; } else if (value == "fatal") { iter->second._level = LOG_LEVEL_FATAL; } } //! display else if (key == "display") { if (value == "false" || value == "0") { iter->second._display = false; } else { iter->second._display = true; } } //! monthdir else if (key == "monthdir") { if (value == "false" || value == "0") { iter->second._monthdir = false; } else { iter->second._monthdir = true; } } //! limit file size else if (key == "limitsize") { iter->second._limitsize = atoi(value.c_str()); } } while (1); } } }
// Note: UNIX-only (for now.) // bool OTString::TokenizeIntoKeyValuePairs(std::map<std::string, std::string> & mapOutput) const { #if !(defined(_WIN32) || defined(TARGET_OS_IPHONE) || defined(ANDROID)) // fabcy-pansy parser that allows for multiple level of quotes nesting and escaped quotes if (!Exists()) return true; // -------------- wordexp_t exp_result; exp_result.we_wordc = 0; exp_result.we_wordv = NULL; exp_result.we_offs = 0; if (wordexp(Get(), &exp_result, 0)) // non-zero == failure. { OTLog::vError("OTString::TokenizeIntoKeyValuePairs: Error calling wordexp() " "(to expand user-defined script args.)\nData: %s\n", Get()); // wordfree(&exp_result); return false; } // ---------------------------- if ((exp_result.we_wordc > 0) && (NULL != exp_result.we_wordv)) { // wordexp tokenizes by space (as well as expands, which is why I'm using it.) // Therefore we need to iterate through the tokens, and create a single string // with spaces between the tokens. // for (uint32_t i = 0; (i < (exp_result.we_wordc - 1)) && (exp_result.we_wordv[i] != NULL) && (exp_result.we_wordv[i+1] != NULL); // odd man out. Only PAIRS of strings are processed! i += 2) { const std::string str_key = exp_result.we_wordv[i]; const std::string str_val = exp_result.we_wordv[i+1]; OTLog::vOutput(2, "%s:Parsed: %s = %s\n", __FUNCTION__, str_key.c_str(), str_val.c_str()); mapOutput.insert(std::pair<std::string, std::string>(str_key, str_val)); } wordfree(&exp_result); } // -------------- return true; #else // simple parser that allows for one level of quotes nesting but no escaped quotes if (!Exists()) return true; const char * txt = Get(); std::string buf = txt; for (int32_t i = 0; txt[i] != 0;) { while (txt[i] == ' ') i++; int32_t k = i; int32_t k2 = i; if (txt[i] == '\'' || txt[i] == '"') { // quoted string char quote = txt[i++]; k = i; while (txt[i] != quote && txt[i] != 0) i++; if (txt[i] != quote) { OTLog::vError("%s: Unmatched quotes in: %s\n", __FUNCTION__, txt); return false; } k2 = i; i++; } else { while (txt[i] != ' ' && txt[i] != 0) i++; k2 = i; } const std::string key = buf.substr(k, k2 - k); while (txt[i] == ' ') i++; int32_t v = i; int32_t v2 = i; if (txt[i] == '\'' || txt[i] == '"') { // quoted string char quote = txt[i++]; v = i; while (txt[i] != quote && txt[i] != 0) i++; if (txt[i] != quote) { OTLog::vError("%s: Unmatched quotes in: %s\n", __FUNCTION__, txt); return false; } v2 = i; i++; } else { while (txt[i] != ' ' && txt[i] != 0) i++; v2 = i; } const std::string value = buf.substr(v, v2 - v); if (key.length() != 0 && value.length() != 0) { OTLog::vOutput(2, "%s:Parsed: %s = %s\n", __FUNCTION__, key.c_str(), value.c_str()); mapOutput.insert(std::pair<std::string, std::string>(key, value)); } } return true; #endif }
void CNodeDefManager::addNameIdMapping(content_t i, std::string name) { m_name_id_mapping.set(i, name); m_name_id_mapping_with_aliases.insert(std::make_pair(name, i)); }
//--------------------------------------------------- void initCharacterAdapterToVersion7(std::map<uint,std::string> & assocMale, std::map<uint,std::string> & assocFemale ) { assocMale.insert( make_pair( 1 , string("fy_hom_hair_style03.sitem") ) ); assocMale.insert( make_pair( 2 , string("fy_hom_hair_style02.sitem") ) ); assocMale.insert( make_pair( 3 , string("fy_hom_hair_basic01.sitem") ) ); assocMale.insert( make_pair( 4 , string("fy_hom_hair_basic02.sitem") ) ); assocMale.insert( make_pair( 30 , string("fy_hom_hair_style01.sitem") ) ); assocMale.insert( make_pair( 31 , string("fy_hom_hair_artistic01.sitem") ) ); assocMale.insert( make_pair( 32 , string("fy_hom_hair_basic03.sitem") ) ); assocMale.insert( make_pair( 16 , string("tr_hom_hair_artistic01.sitem") ) ); assocMale.insert( make_pair( 17 , string("tr_hom_hair_basic03.sitem") ) ); assocMale.insert( make_pair( 18 , string("tr_hom_hair_basic01.sitem") ) ); assocMale.insert( make_pair( 19 , string("tr_hom_hair_style01.sitem") ) ); assocMale.insert( make_pair( 36 , string("tr_hom_hair_style02.sitem") ) ); assocMale.insert( make_pair( 37 , string("tr_hom_hair_basic02.sitem") ) ); assocMale.insert( make_pair( 38 , string("tr_hom_hair_artistic02.sitem") ) ); assocMale.insert( make_pair( 10 , string("ma_hom_hair_style04.sitem") ) ); assocMale.insert( make_pair( 11 , string("ma_hom_hair_basic02.sitem") ) ); assocMale.insert( make_pair( 12 , string("ma_hom_hair_basic01.sitem") ) ); assocMale.insert( make_pair( 13 , string("ma_hom_hair_basic01.sitem") ) ); assocMale.insert( make_pair( 14 , string("ma_hom_hair_style01.sitem") ) ); assocMale.insert( make_pair( 33 , string("ma_hom_hair_artistic01.sitem") ) ); assocMale.insert( make_pair( 34 , string("ma_hom_hair_style02.sitem") ) ); assocMale.insert( make_pair( 35 , string("ma_hom_hair_style03.sitem") ) ); assocMale.insert( make_pair( 21 , string("zo_hom_hair_basic02.sitem") ) ); assocMale.insert( make_pair( 22 , string("zo_hom_hair_style01.sitem") ) ); assocMale.insert( make_pair( 23 , string("zo_hom_hair_basic01.sitem") ) ); assocMale.insert( make_pair( 24 , string("zo_hom_hair_basic03.sitem") ) ); assocMale.insert( make_pair( 39 , string("zo_hom_hair_basic04.sitem") ) ); assocMale.insert( make_pair( 40 , string("zo_hom_hair_style02.sitem") ) ); assocMale.insert( make_pair( 41 , string("zo_hom_hair_style03.sitem") ) ); assocFemale.insert( make_pair( 1 , string("fy_hof_hair_style03.sitem") ) ); assocFemale.insert( make_pair( 2 , string("fy_hof_hair_basic02.sitem") ) ); assocFemale.insert( make_pair( 3 , string("fy_hof_hair_basic01.sitem") ) ); assocFemale.insert( make_pair( 4 , string("fy_hof_hair_style01.sitem") ) ); assocFemale.insert( make_pair( 30 , string("fy_hof_hair_style02.sitem") ) ); assocFemale.insert( make_pair( 31 , string("fy_hof_hair_artistic01.sitem") ) ); assocFemale.insert( make_pair( 32 , string("fy_hof_hair_basic03.sitem") ) ); assocFemale.insert( make_pair( 16 , string("tr_hof_hair_style01.sitem") ) ); assocFemale.insert( make_pair( 17 , string("tr_hof_hair_style02.sitem") ) ); assocFemale.insert( make_pair( 18 , string("tr_hof_hair_basic01.sitem") ) ); assocFemale.insert( make_pair( 19 , string("tr_hof_hair_artistic03.sitem") ) ); assocFemale.insert( make_pair( 36 , string("tr_hof_hair_artistic04.sitem") ) ); assocFemale.insert( make_pair( 37 , string("tr_hof_hair_artistic01.sitem") ) ); assocFemale.insert( make_pair( 38 , string("tr_hof_hair_artistic02.sitem") ) ); assocFemale.insert( make_pair( 10 , string("ma_hof_hair_style01.sitem") ) ); assocFemale.insert( make_pair( 11 , string("ma_hof_hair_artistic01.sitem") ) ); assocFemale.insert( make_pair( 12 , string("ma_hof_hair_basic01.sitem") ) ); assocFemale.insert( make_pair( 13 , string("ma_hof_hair_basic01.sitem") ) ); assocFemale.insert( make_pair( 14 , string("ma_hof_hair_basic02.sitem") ) ); assocFemale.insert( make_pair( 33 , string("ma_hof_hair_style02.sitem") ) ); assocFemale.insert( make_pair( 34 , string("ma_hof_hair_artistic02.sitem") ) ); assocFemale.insert( make_pair( 35 , string("ma_hof_hair_style03.sitem") ) ); assocFemale.insert( make_pair( 21 , string("zo_hof_hair_style04.sitem") ) ); assocFemale.insert( make_pair( 22 , string("zo_hof_hair_style02.sitem") ) ); assocFemale.insert( make_pair( 23 , string("zo_hof_hair_basic01.sitem") ) ); assocFemale.insert( make_pair( 24 , string("zo_hof_hair_basic02.sitem") ) ); assocFemale.insert( make_pair( 39 , string("zo_hof_hair_basic03.sitem") ) ); assocFemale.insert( make_pair( 40 , string("zo_hof_hair_style01.sitem") ) ); assocFemale.insert( make_pair( 41 , string("zo_hof_hair_style03.sitem") ) ); }
void levelClass::readLevel(std::string nameLevel, std::list<eventClass*>& listEvent, std::list<characterClass*>& listEnemy, std::map<std::pair<int, int>, itemClass*>& mapLevel, int& endOfLevel, int& heightLevel, std::string& typeLevel, int poseXPlayer, lightManagerClass& lightManager) { std::ifstream file(nameLevel.c_str()); if(file.is_open()) { std::string line; std::string typeLine = "END"; spawnEnemyEventClass* tmpEventSpawn; changeMapEventClass* tmpChangeMap; while(std::getline(file, line)) { if(line == "END") { if(typeLine == "SPAWN_ENEMY" || typeLine == "CHANGE_MAP") typeLine = "EVENT"; else typeLine = "END"; } if(typeLine == "MAP") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line; mapLevel.insert(std::pair<std::pair<int, int>, itemClass*>(std::pair<int, int>(std::atoi(poseX.c_str()), std::atoi(poseY.c_str())), new basicBlocClass(name, std::atoi(poseX.c_str()), std::atoi(poseY.c_str())))); } else if(typeLine == "ENEMY") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line; if(name == "BOSS") listEnemy.push_back(new bossEnemyClass(std::atoi(poseX.c_str()), std::atoi(poseY.c_str()), name)); else listEnemy.push_back(new basicEnemyClass(std::atoi(poseX.c_str()), std::atoi(poseY.c_str()), name)); } else if(typeLine == "EVENT") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); if(name == "MESSAGE") { std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string width = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string height = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string message = line; while(message.find("\\n") != std::string::npos) { message.replace(message.find("\\n"), 2, "\n"); } if(std::atoi(poseX.c_str()) > poseXPlayer) { sf::RectangleShape surface; surface.setPosition(std::atoi(poseX.c_str()), std::atoi(poseY.c_str())); surface.setSize(sf::Vector2f(std::atoi(width.c_str()), std::atoi(height.c_str()))); listEvent.push_back(new messageEventClass(message, surface)); } } else if(name == "SPAWN_ENEMY") { std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string width = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string height = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string newPoseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string newPoseY = line; sf::RectangleShape surface; surface.setPosition(std::atoi(poseX.c_str()), std::atoi(poseY.c_str())); surface.setSize(sf::Vector2f(std::atoi(width.c_str()), std::atoi(height.c_str()))); tmpEventSpawn = new spawnEnemyEventClass(surface, std::atoi(newPoseX.c_str()), std::atoi(newPoseY.c_str())); typeLine = "SPAWN_ENEMY"; listEvent.push_back(tmpEventSpawn); } else if(name == "CHANGE_MAP") { std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string width = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string height = line; sf::RectangleShape surface; surface.setPosition(std::atoi(poseX.c_str()), std::atoi(poseY.c_str())); surface.setSize(sf::Vector2f(std::atoi(width.c_str()), std::atoi(height.c_str()))); tmpChangeMap = new changeMapEventClass(surface); typeLine = "CHANGE_MAP"; listEvent.push_back(tmpChangeMap); } } else if(typeLine == "SPAWN_ENEMY") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line; tmpEventSpawn->addToList(name, std::atoi(poseX.c_str()), std::atoi(poseY.c_str())); } else if(typeLine == "CHANGE_MAP") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line; tmpChangeMap->addToList(name, std::atoi(poseX.c_str()), std::atoi(poseY.c_str())); } else if(typeLine == "LIGHT_WALL") { std::string poseXFirst = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseYFirst = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseXSecond = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseYSecond = line; lightManager.addWall(sf::Vector2f(atoi(poseXFirst.c_str()), atoi(poseYFirst.c_str())), sf::Vector2f(atoi(poseXSecond.c_str()), atoi(poseYSecond.c_str()))); } else if(typeLine == "HEIGHT") { heightLevel = std::atoi(line.c_str()); } else if(typeLine == "ENDOFLEVEL") { endOfLevel = std::atoi(line.c_str()); } else if(typeLine == "TYPELEVEL") { typeLevel = line.c_str(); } if(line == "MAP") typeLine = "MAP"; else if(line == "ENEMY") typeLine = "ENEMY"; else if(line == "EVENT") typeLine = "EVENT"; else if(line == "LIGHT_WALL") typeLine = "LIGHT_WALL"; else if(line == "HEIGHT") typeLine = "HEIGHT"; else if(line == "ENDOFLEVEL") typeLine = "ENDOFLEVEL"; else if(line == "TYPELEVEL") typeLine = "TYPELEVEL"; } file.close(); } }