void setBarIndexes( std::multimap<ReducedFraction, MidiChord> &chords, const ReducedFraction &basicQuant, const ReducedFraction &lastTick, const TimeSigMap *sigmap) { if (chords.empty()) return; auto it = chords.begin(); for (int barIndex = 0;; ++barIndex) { // iterate over all measures by indexes const auto endBarTick = ReducedFraction::fromTicks(sigmap->bar2tick(barIndex + 1, 0)); if (endBarTick <= it->first) continue; for (; it != chords.end(); ++it) { const auto onTime = Quantize::findQuantizedChordOnTime(*it, basicQuant); #ifdef QT_DEBUG const auto barStart = ReducedFraction::fromTicks(sigmap->bar2tick(barIndex, 0)); Q_ASSERT_X(!(it->first >= barStart && onTime < barStart), "MChord::setBarIndexes", "quantized on time cannot be in previous bar"); #endif if (onTime < endBarTick) { it->second.barIndex = barIndex; continue; } break; } if (it == chords.end() || endBarTick > lastTick) break; } Q_ASSERT_X(areBarIndexesSet(chords), "MChord::setBarIndexes", "Not all bar indexes were set"); Q_ASSERT_X(areBarIndexesSuccessive(chords), "MChord::setBarIndexes", "Bar indexes are not successive"); }
virtual int OnSendSnotice(char &sno, std::string &desc, const std::string &msg) { std::multimap<char, std::string>::const_iterator it = logstreams.find(sno); char buf[MAXBUF]; if (it == logstreams.end()) return 0; snprintf(buf, MAXBUF, "\2%s\2: %s", desc.c_str(), msg.c_str()); while (it != logstreams.end()) { if (it->first != sno) { it++; continue; } Channel *c = ServerInstance->FindChan(it->second); if (c) { c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf); ServerInstance->PI->SendChannelPrivmsg(c, 0, buf); } it++; } return 0; }
void PatternLink::GenerateConnections( const std::multimap<lem::UCString,const Word_Form*> & points, SynPatternResult * cur_result ) const { typedef std::multimap<lem::UCString,const Word_Form*>::const_iterator IT; IT it_from = points.find( from_marker ); if( it_from==points.end() ) { lem::MemFormatter mem; mem.printf( "Can not find node %us.%us to create link head", from_marker.c_str(), from_node.c_str() ); throw lem::E_BaseException( mem.string() ); } const Word_Form * node0 = it_from->second; std::pair<IT,IT> pit = points.equal_range( to_marker ); if( pit.first==points.end() && !optional_to_node ) { lem::MemFormatter mem; mem.printf( "Can not find node %us to create link tail", to_marker.c_str() ); throw lem::E_BaseException( mem.string() ); } for( IT it=pit.first; it!=pit.second; ++it ) { const Solarix::Word_Form * node1 = it->second; PatternLinkEdge new_edge( node0, link_type, node1 ); cur_result->AddLinkageEdge( new_edge ); } return; }
/** \brief This function calculates the number of duplicates based from the filenames and their sizes. \param files The file structure consisting of a map of file size and file name. \return An unsigned int equal to the number of duplicates found. **/ unsigned int DuplicateFinder::DuplicateComparison( const std::multimap<unsigned int, std::wstring> & files ) { unsigned int numDupes = 0; //check to see if a file's size has other matching files' sizes auto mit = files.begin(); //mit is an iterator through the file list while( mit != files.end() ) //while searching through the list { //checking the file immediately after the currently iterated file if( ( std::next( mit ) != files.end() ) ) { if( ( std::next( mit ) )->first == mit->first ) // if filesize is same as next's: { //open the iterated entry boost::filesystem::ifstream original( mit->second, std::ios::binary ); if( original.is_open() ) //if we opened it... { //open the next file to compare boost::filesystem::ifstream checking( ( std::next( mit ) )->second, std::ios::binary ); if( checking.is_open() ) //if successfully opened, { char originalByte; //for original's same byte char nextByte; //for next's same byte //start by reading check's first byte checking.read( &nextByte, sizeof( char ) ); //start by reading original's first byte original.read( &originalByte, sizeof( char ) ); //while we're not at the end of the files while( !checking.eof() || !original.eof() ) { //check to make sure the bytes are not different if( nextByte != originalByte ) { break; //move on to the next file } //read in the next bytes checking.read( &nextByte, sizeof( char ) ); original.read( &originalByte, sizeof( char ) ); } //if we were at the end of both files, we report a duplicate into the //duplicate list and add an extra entry to "numberOfDuplicates" if( checking.eof() && original.eof() ) { duplicates.push_back( next( mit )->second + std::wstring( L" is a duplicate of ") + mit->second); ++numDupes; } } } } } ++mit; } return numDupes; }
std::multimap<ReducedFraction, MidiChord>::const_iterator findFirstChordInRange(const std::multimap<ReducedFraction, MidiChord> &chords, const ReducedFraction &startRangeTick, const ReducedFraction &endRangeTick) { auto iter = chords.lower_bound(startRangeTick); if (iter != chords.end() && iter->first >= endRangeTick) iter = chords.end(); return iter; }
void minimizeNumberOfRests( std::multimap<ReducedFraction, MidiChord> &chords, const TimeSigMap *sigmap, const std::multimap<ReducedFraction, MidiTuplet::TupletData> &tuplets) { for (auto it = chords.begin(); it != chords.end(); ++it) { for (MidiNote ¬e: it->second.notes) { const auto barStart = MidiBar::findBarStart(note.offTime, sigmap); const auto barFraction = ReducedFraction( sigmap->timesig(barStart.ticks()).timesig()); auto durationStart = (it->first > barStart) ? it->first : barStart; if (it->second.isInTuplet) { const auto &tuplet = it->second.tuplet->second; if (note.offTime >= tuplet.onTime + tuplet.len) durationStart = tuplet.onTime + tuplet.len; } auto endTime = (barStart == note.offTime) ? barStart : barStart + barFraction; if (note.isInTuplet) { const auto &tuplet = note.tuplet->second; if (note.offTime == tuplet.onTime + tuplet.len) continue; endTime = barStart + Quantize::quantizeToLarge( note.offTime - barStart, tuplet.len / tuplet.tupletNumber); } const auto beatLen = Meter::beatLength(barFraction); const auto beatTime = barStart + Quantize::quantizeToLarge( note.offTime - barStart, beatLen); if (endTime > beatTime) endTime = beatTime; auto next = std::next(it); while (next != chords.end() && (next->second.voice != it->second.voice || next->first < note.offTime)) { ++next; } if (next != chords.end()) { if (next->first < endTime) endTime = next->first; if (next->second.isInTuplet && !note.isInTuplet) { const auto &tuplet = next->second.tuplet->second; if (tuplet.onTime < endTime) endTime = tuplet.onTime; } } lengthenNote(note, it->second.voice, it->first, durationStart, endTime, barStart, barFraction, tuplets); } } }
void dispatch_callbacks() const { mappedinput input = current_mappedinput; for( auto it = callbacks.begin(); it != callbacks.end(); ++it ) ( *it->second )( input ); }
void World::GetPersistentData(std::vector<PersistentDataItem> *vec, const std::string &key, bool prefix) { vec->clear(); if (!BuildPersistentCache()) return; auto eqrange = persistent_index.equal_range(key); if (prefix) { if (key.empty()) { eqrange.first = persistent_index.begin(); eqrange.second = persistent_index.end(); } else { std::string bound = key; if (bound[bound.size()-1] != '/') bound += "/"; eqrange.first = persistent_index.lower_bound(bound); bound[bound.size()-1]++; eqrange.second = persistent_index.lower_bound(bound); } } for (auto it = eqrange.first; it != eqrange.second; ++it) { auto hfig = df::historical_figure::find(-it->second); if (hfig && hfig->name.has_name) vec->push_back(dataFromHFig(hfig)); } }
void flush_immediate_sync() { auto seq_no = processor_.max_finished_seq_no(); for (auto it = immediate_sync_promises_.begin(), end = immediate_sync_promises_.end(); it != end && it->first <= seq_no; it = immediate_sync_promises_.erase(it)) { do_immediate_sync(std::move(it->second)); } }
void GroupTransformer::putData(RddPartition* output, std::multimap<PbMessagePtr, PbMessagePtr, idgs::store::less>& localCache) { if (!localCache.empty()) { PbMessagePtr key; std::vector<PbMessagePtr> values; for (auto it = localCache.begin(); it != localCache.end(); ++it) { if (idgs::store::equals_to()(const_cast<PbMessagePtr&>(it->first), key)) { values.push_back(it->second); } else { if (!values.empty()) { output->put(key, values); values.clear(); } values.clear(); key = it->first; values.push_back(it->second); } } if (!values.empty()) { output->put(key, values); values.clear(); } localCache.clear(); } }
void deactivateAll() { for (iter_t i = ev.begin(); i != ev.end(); ++i) { i->second->activate_cmd(0); } }
void AudioOutputDeviceManager::removeDeviceEventProc( int _card , std::multimap< int, const AudioOutputDevice * > & _devices ) { auto iterators = _devices.equal_range( _card ); if( iterators.first == _devices.end() ) { return; } DevicesDeleter deleter( _devices , iterators ); std::for_each( iterators.first , iterators.second , [ this ] ( std::pair< const int, const AudioOutputDevice * > & _pair ) { const auto DEVICE = _pair.second; this->callDisconnectEventHandler( *DEVICE ); } ); }
static void PASCAL Timer(unsigned int uTimerID, unsigned int uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) { AsyncEvent *p; double tm; std::multimap<double, AsyncEvent *>::iterator e; while (1) { p = s_acSleep.get(); if (p == NULL) break; tm = s_time + s_now + p->result(); s_tms.insert(std::make_pair(tm, p)); } atom_xchg(&s_now, (int)(v8::internal::OS::TimeCurrentMillis() - s_time)); while (1) { e = s_tms.begin(); if (e == s_tms.end()) break; if (e->first > s_time + s_now) break; e->second->apost(0); s_tms.erase(e); } }
void ImageView::setFeatures(const std::multimap<int, cv::KeyPoint> & refWords, const QColor & color) { qDeleteAll(_features); _features.clear(); rtabmap::KeypointItem * item = 0; for(std::multimap<int, cv::KeyPoint>::const_iterator i = refWords.begin(); i != refWords.end(); ++i ) { const cv::KeyPoint & r = (*i).second; int id = (*i).first; QString info = QString( "WordRef = %1\n" "Laplacian = %2\n" "Dir = %3\n" "Hessian = %4\n" "X = %5\n" "Y = %6\n" "Size = %7").arg(id).arg(1).arg(r.angle).arg(r.response).arg(r.pt.x).arg(r.pt.y).arg(r.size); float radius = r.size/2.0f; item = new rtabmap::KeypointItem(r.pt.x-radius, r.pt.y-radius, radius*2, info, color); scene()->addItem(item); _features.insert(id, item); item->setVisible(_showFeatures->isChecked()); item->setZValue(1); } }
void deinitCs() { for(std::multimap<std::string, char *>::iterator it = event_dict.begin();it != event_dict.end();++it) { free(it->second); } }
void PeakMatchingResults::GetMatches(std::vector<int> &vectFeatureIndices, std::vector<int> &vectMassTagIndices, std::vector<int> &vectProteinIndices , const std::vector<MultiAlignEngine::MassTags::Protein>* &vectProteins, const std::vector<MultiAlignEngine::MassTags::MassTag>* &vectMasstags) const { // The mass tag database has stored in it all the proteins and mass tags corresponding to the matches. // So thats where we need to get all the data from. int numMatches = (int) mvectPeakMatches.size(); std::set <int> massTagID; stdext::hash_map <int, int > massTagSeen; // first get all mass tags in the matches into the set of mass tags. for (int matchNum = 0; matchNum < numMatches; matchNum++) { PeakMatch match = mvectPeakMatches[matchNum]; massTagSeen.insert(std::pair<int,int>(match.mintMasstagID, matchNum)); } // copy hash to mass tag vector std::vector<int> vectMassTagIDs; vectMassTagIDs.reserve(massTagSeen.size()); for (stdext::hash_map <int, int >::iterator massTagIter = massTagSeen.begin(); massTagIter != massTagSeen.end(); massTagIter++) { vectMassTagIDs.push_back((*massTagIter).first); } vectMasstags = mobjMasstagDB.GetMassTagVector(); vectProteins = mobjMasstagDB.GetProteinVector(); const std::multimap<int,int> mapMassTagId2ProteinIndex = mobjMasstagDB.GetMassTagId2ProteinIndexMap(); const stdext::hash_map <int, int > hashMapMassTagId2Index = mobjMasstagDB.GetMassTagId2IndexHash(); // now the relevant mass tags are copied, their ids are copied, the protein names are copied. // So lets create the table of matches using the three vectors vectFeatureIndices, vectMassTagIndices and // vectProteinIndices. Basically, vectFeatureIndices will have the index of the ms feature in a peak match. // the vectMassTagIndices will have the corresponding massTagID, and vectProteinIndices will have the corresponding // parent protein. for (std::multimap<int,int>::const_iterator featureIter = mmapFeatureIndex2PeakMatch.begin(); featureIter != mmapFeatureIndex2PeakMatch.end(); featureIter++) { int featureIndex = (*featureIter).first; int peakMatchIndex = (*featureIter).second; PeakMatch pkMatch = mvectPeakMatches[peakMatchIndex]; int massTagID = pkMatch.mintMasstagID; stdext::hash_map <int, int>::const_iterator massTagIterHash = hashMapMassTagId2Index.find(massTagID); int massTagIndex = (*massTagIterHash).second; // now go through each of the parent proteins of this massTagID and push the triplet into their // corresponding vectors for (std::multimap<int,int>::const_iterator massTagIter = mapMassTagId2ProteinIndex.find(massTagID); massTagIter != mapMassTagId2ProteinIndex.end(); massTagIter++) { if ((*massTagIter).first != massTagID) break; vectFeatureIndices.push_back(featureIndex); vectMassTagIndices.push_back(massTagIndex); vectProteinIndices.push_back((*massTagIter).second); } } }
void DebugInfoXmlWriter::WriteChildProcessEntry(const Debug::DebugeeInfo& debuggeeInfo, const std::multimap<DWORD, DWORD>& mmapChildProcesses, DWORD dwProcessId) { m_spWriter->WriteStartElement(_T("process")); if (dwProcessId == 0) m_spWriter->WriteAttributeString(_T("image-name"), _T("debugger")); else { CString cszText; cszText.Format(_T("0x%08x"), dwProcessId); m_spWriter->WriteAttributeString(_T("pid"), cszText); if (debuggeeInfo.IsProcessInfoAvail(dwProcessId)) { const Debug::ProcessInfo processInfo = debuggeeInfo.GetProcessInfo(dwProcessId); m_spWriter->WriteAttributeString(_T("image-name"), processInfo.ImageName()); } else m_spWriter->WriteAttributeString(_T("image-name"), _T("unknown")); } m_spWriter->WriteStartElementEnd(); // find all child entries std::multimap<DWORD, DWORD>::const_iterator iter = mmapChildProcesses.find(dwProcessId); while (iter != mmapChildProcesses.end() && iter->first == dwProcessId) { WriteChildProcessEntry(debuggeeInfo, mmapChildProcesses, iter->second); ++iter; } m_spWriter->WriteEndElement(); }
~mapper() { for( auto c = callbacks.begin(); c != callbacks.end(); ++c ) { delete c->second; } }
virtual void Run() { now = v8::base::OS::TimeCurrentMillis(); while (1) { AsyncEvent *p; std::multimap<double, AsyncEvent *>::iterator e; wait(); now = v8::base::OS::TimeCurrentMillis(); while (1) { p = s_acSleep.get(); if (p == NULL) break; s_tms.insert(std::make_pair(now + p->result(), p)); } while (1) { e = s_tms.begin(); if (e == s_tms.end()) break; if (e->first > now) break; e->second->apost(0); s_tms.erase(e); } } }
netCDF::NcVar NetCDFFile::getVariable(const std::string &variableName) const { if( variableName.empty() == true ) { /// returns a null object return netCDF::NcVar(); } const std::multimap< std::string, netCDF::NcVar > vars = file.getVars(); for( std::multimap< std::string, netCDF::NcVar >::const_iterator it = vars.begin(); it != vars.end(); ++it ) { const std::string varName = (*it).first; if( varName == variableName ) { const netCDF::NcVar var = (*it).second; return var; } } /// returns a null object return netCDF::NcVar(); }
void *MemoryPool::pop(size_t s, int loc) { void *addr = nullptr; if ((s > MIN_BLOCK_SIZE) && (s < MAX_BLOCK_SIZE)) { locker_.lock(); // find MemoryPool block which is not smaller than demand size auto pt = pool_.lower_bound(s); if (pt != pool_.end()) { size_t ts = 0; std::tie(ts, addr) = *pt; if (ts < s * 2) { s = ts; pool_.erase(pt); pool_depth_ -= s; } else { addr = nullptr; } } locker_.unlock(); } if (addr == nullptr) { try { #ifdef __CUDA__ SP_DEVICE_CALL(cudaMallocManaged(&addr, s)); #else addr = malloc(s); #endif } catch (std::bad_alloc const &error) { THROW_EXCEPTION_BAD_ALLOC(s); } } return addr; }
netCDF::NcGroupAtt NetCDFFile::getAttribute(const std::string &attributeName) const { if( attributeName.empty() == true ) { /// returns a null object return netCDF::NcGroupAtt(); } const std::multimap< std::string, netCDF::NcGroupAtt > attributes = file.getAtts(); for( std::multimap< std::string, netCDF::NcGroupAtt >::const_iterator it = attributes.begin(); it != attributes.end(); ++it ) { const std::string attrName = (*it).first; if( attrName == attributeName ) { const netCDF::NcGroupAtt att = (*it).second; return att; } } return netCDF::NcGroupAtt(); }
netCDF::NcDim NetCDFFile::getDimension(const std::string &dimensionName) const { if( dimensionName.empty() == true ) { /// returns a null object return netCDF::NcDim(); } const std::multimap< std::string, netCDF::NcDim > dims = file.getDims(); for( std::multimap< std::string, netCDF::NcDim >::const_iterator it = dims.begin(); it != dims.end(); ++it ) { const std::string dimName = (*it).first; if( dimName == dimensionName ) { const netCDF::NcDim dim = (*it).second; return dim; } } /// returns a null object return netCDF::NcDim(); }
bool ltr_int_broadcast_pose(linuxtrack_full_pose_t &pose) { pthread_mutex_lock(&send_mx); std::multimap<std::string, int>::iterator i; int res; bool checkSlaves = false; //Send updated pose to all clients //printf("Master: %g %g %g\n", pose.pose.raw_pitch, pose.pose.raw_yaw, pose.pose.raw_roll); for(i = slaves.begin(); i != slaves.end();) { res = ltr_int_send_data(i->second, &pose); if(res == -EPIPE) { ltr_int_log_message("Slave @socket %d left!\n", i->second); close(i->second); i->second = -1; slaves.erase(i++); checkSlaves = true; } else { ++i; } } if(checkSlaves && (slaves.size() == 0)) { no_slaves = true; } pthread_mutex_unlock(&send_mx); return true; }
void NetCDFFile::PrintAllVariables(std::ostream & output) const { /// retrieves all the variables const std::multimap< std::string, netCDF::NcVar > vars = file.getVars(); for( std::multimap< std::string, netCDF::NcVar >::const_iterator it = vars.begin(); it != vars.end(); ++it ) { const std::string varName = (*it).first; std::vector< std::size_t > dimensions; GetVariableDimensions( dimensions, varName ), output << varName << " = " << "("; for( std::size_t k = 0; k < dimensions.size(); k++ ) { output << dimensions[k]; if( k < dimensions.size() - 1 ) { output << ","; } } output << ")" << std::endl; } }
bool DumbRelayConsumer::check_authentication(const std::multimap<std::string, std::string> ¶ms) { // Construct the data for the post. std::ostringstream data; CURL *curl = new_curl_handle(); data << "openid.mode=check_authentication"; for(std::multimap<std::string, std::string>::const_iterator iter = params.begin(); iter != params.end(); ++iter) { if(iter->first.compare("openid.mode") == 0) continue; char *tmp; tmp = curl_easy_escape(curl, iter->first.c_str(), iter->first.size()); data << "&" << tmp << "="; curl_free(tmp); tmp = curl_easy_escape(curl, iter->second.c_str(), iter->second.size()); data << tmp; curl_free(tmp); } // Clean up after curl. curl_easy_cleanup(curl); // Prepare the curl handle. std::string content = contact_openid_provider(data.str()); // Check to see if we can find the is_valid:true response. return content.find("\nis_valid:true\n") != content.npos; }
void query_recommender::merge_recommended_queries(std::multimap<double,std::string,std::less<double> > &related_queries, hash_map<const char*,double,hash<const char*>,eqstr> &update) { hash_map<const char*,double,hash<const char*>,eqstr>::iterator hit; std::multimap<double,std::string,std::less<double> >::iterator mit = related_queries.begin(); while(mit!=related_queries.end()) { std::string rquery = (*mit).second; if ((hit = update.find(rquery.c_str()))!=update.end()) { (*hit).second = std::min((*mit).first,(*hit).second); std::multimap<double,std::string,std::less<double> >::iterator mit2 = mit; ++mit; related_queries.erase(mit2); } else ++mit; } hit = update.begin(); hash_map<const char*,double,hash<const char*>,eqstr>::iterator chit; while(hit!=update.end()) { related_queries.insert(std::pair<double,std::string>((*hit).second,std::string((*hit).first))); chit = hit; ++hit; free_const((*chit).first); } }
std::set<u_int> get_keys(std::multimap<u_int,record> map) { std::set<u_int> temp; std::multimap<u_int,record>::iterator it; for(it = map.begin(); it != map.end(); ++it) temp.insert(it->first); return temp; }
static void LoadLadspaEffect(wxSortedArrayString &uniq, wxString fname, DL_Array &dls) { wxLogNull logNo; LADSPA_Descriptor_Function mainFn = NULL; // Since we now have builtin VST support, ignore the VST bridge as it // causes duplicate menu entries to appear. wxFileName f(fname); if (f.GetName().CmpNoCase(wxT("vst-bridge")) == 0) { return; } // As a courtesy to some plug-ins that might be bridges to // open other plug-ins, we set the current working // directory to be the plug-in's directory. wxString saveOldCWD = ::wxGetCwd(); wxString prefix = ::wxPathOnly(fname); ::wxSetWorkingDirectory(prefix); wxDynamicLibrary* pDLL = new wxDynamicLibrary(); dls.push_back(pDLL); if (pDLL && pDLL->Load(fname, wxDL_LAZY)) { mainFn = (LADSPA_Descriptor_Function)(pDLL->GetSymbol(wxT(descriptorFnName))); } if (mainFn) { int index = 0; const LADSPA_Descriptor *data; data = mainFn(index); while(data) { wxString uniqid = wxString::Format(wxT("%08x-%s"), data->UniqueID, LAT1CTOWX(data->Label).c_str()); if (uniq.Index(uniqid) == wxNOT_FOUND) { uniq.Add(uniqid); std::set<wxString> categories; #if defined(USE_LIBLRDF) && defined(EFFECT_CATEGORIES) std::multimap<unsigned long, wxString>::const_iterator iter; iter = gPluginCategories.lower_bound(data->UniqueID); for ( ; (iter != gPluginCategories.end() && iter->first == data->UniqueID); ++iter) categories.insert(iter->second); #endif LadspaEffect *effect = new LadspaEffect(data, categories); EffectManager::Get().RegisterEffect(effect); } // Get next plugin index++; data = mainFn(index); } } ::wxSetWorkingDirectory(saveOldCWD); }
bool insert_uniq(std::multimap<K, V>& map, const std::pair<K, V>& pair) { if (find_pair(map, pair) == map.end()) { map.insert(pair); return true; } return false; }