Ice::Long ConnectionQuery::doInsert(const string& strPrefix, const string& table, const StringMap& properties) { if (!properties.size()) { return -1; } ostringstream sql; sql << strPrefix << table << " ("; for (StringMap::const_iterator it = properties.begin();;) { sql << it->first; if (++it == properties.end()) { break; } else { sql << ", "; } } sql << ") VALUES ("; for (StringMap::const_iterator it = properties.begin();;) { //#ifndef NEWARCH // // sql << mysqlpp::quote << it->second; // sql << "'" << mysqlpp::quote << it->second << "'"; //#else sql << "'" << mysqlpp::quote << it->second << "'"; //#endif if (++it == properties.end()) { break; } else { sql << ", "; } } sql << ")"; return doExecute(sql.str()); }
void Application::normalize(StringMap<float> &counts) { float sum=0; StringMapIterator<float> cur=counts.begin(), end=counts.end(); for(; cur!=end ; ++cur) sum+=(*cur).second; if(sum>0) for(cur=counts.begin() ; cur!=end ; ++cur) (*cur).second/=sum; }
bool compareStringMap(StringMap &a, StringMap& b) { if (a.size() != b.size()) return false; for (auto ita = a.begin(), itb = b.begin(); ita != a.end(); ++ita, ++itb) { if (ita->first.compare(itb->first) != 0 || ita->second != itb->second) return false; } return true; }
void BoshTransport::connect(const sf::Url & url, const StringMap & additionalArgs, int timeOutMs, const ResultCallback & callback){ if (mState != Unconnected) { Log (LogError) << LOGID << "Wrong State " << toString (mState) << std::endl; return xcall (abind (callback, error::WrongState)); } mUrl = url; mRid = randomRid(); mRidRecv = mRid; // Setting Parameters StringMap args = additionalArgs; args["rid"] = toString (mRid); setIfNotSet (&args, "ver", "1.10"); setIfNotSet (&args, "wait", "60"); setIfNotSet (&args, "hold", "1"); setIfNotSet (&args, "xmlns", "http://jabber.org/protocol/httpbind"); BoshNodeBuilder builder; for (StringMap::const_iterator i = args.begin(); i != args.end(); i++){ builder.addAttribute(i->first,i->second); } // Send it out... mState = Connecting; executeRequest (sf::createByteArrayPtr(builder.toString()), timeOutMs, abind (dMemFun (this, &BoshTransport::onConnectReply), callback)); }
void BoshTransport::startNextRequest (const StringMap & additionalArgs, const ResultCallback & callback) { if (mState != Connected && mState != Closing){ Log (LogWarning) << LOGID << "Strange state" << std::endl; notifyAsync (callback, error::WrongState); return; } // Building Message mRid++; BoshNodeBuilder builder; builder.addAttribute("rid", toString(mRid)); builder.addAttribute("sid", mSid); builder.addAttribute("xmlns", "http://jabber.org/protocol/httpbind"); for (StringMap::const_iterator i = additionalArgs.begin(); i != additionalArgs.end(); i++) { builder.addAttribute(i->first.c_str(), i->second); } // Adding data.. for (std::deque<ByteArrayPtr>::const_iterator i = mOutputBuffer.begin(); i != mOutputBuffer.end(); i++) { builder.addContent(*i); } mOutputBuffer.clear(); // Sending sf::ByteArrayPtr data = sf::createByteArrayPtr (builder.toString()); mOpenRids[mRid] = data; mOpenRidCount++; executeRequest (data, mLongPollTimeoutMs, abind (dMemFun (this, &BoshTransport::onRequestReply), mRid, callback)); }
/* * Save bootstrap nodes to disk */ void KBucket::saveNodes(SimpleXML& xml) { xml.addTag("Nodes"); xml.stepIn(); // get 50 random nodes to bootstrap from them next time Node::Map closestToMe; getClosestNodes(CID::generate(), closestToMe, 50, 3); for(Node::Map::const_iterator j = closestToMe.begin(); j != closestToMe.end(); j++) { const Node::Ptr& node = j->second; xml.addTag("Node"); xml.addChildAttrib("CID", node->getUser()->getCID().toBase32()); xml.addChildAttrib("type", node->getType()); xml.addChildAttrib("verified", node->isIpVerified()); if(!node->getUDPKey().key.isZero() && !node->getUDPKey().ip.empty()) { xml.addChildAttrib("key", node->getUDPKey().key.toBase32()); xml.addChildAttrib("keyIP", node->getUDPKey().ip); } StringMap params; node->getIdentity().getParams(params, Util::emptyString, false, true); for(StringMap::const_iterator i = params.begin(); i != params.end(); i++) xml.addChildAttrib(i->first, i->second); } xml.stepOut(); }
ServiceModel::ClusterHealthPolicy ManagementConfig::GetClusterHealthPolicy() const { auto clusterHealthPolicy = ServiceModel::ClusterHealthPolicy( this->ConsiderWarningAsError, static_cast<BYTE>(this->MaxPercentUnhealthyNodes), static_cast<BYTE>(this->MaxPercentUnhealthyApplications)); // Check if there are any per app type entries defined StringMap clusterHealthPolicyEntries; this->GetKeyValues(L"HealthManager/ClusterHealthPolicy", clusterHealthPolicyEntries); for (auto it = clusterHealthPolicyEntries.begin(); it != clusterHealthPolicyEntries.end(); ++it) { if (StringUtility::StartsWithCaseInsensitive<wstring>(it->first, *ApplicationTypeMaxPercentUnhealthyApplicationsPrefix)) { // Get the application type name and the value wstring appTypeName = it->first; StringUtility::Replace<wstring>(appTypeName, *ApplicationTypeMaxPercentUnhealthyApplicationsPrefix, L""); int value; if (!StringUtility::TryFromWString<int>(it->second, value)) { Assert::CodingError("Cluster manifest validation error: {0}: Error parsing app type MaxPercentUnhealthyApplication {1} as int", it->first, it->second); } auto error = clusterHealthPolicy.AddApplicationTypeHealthPolicy(move(appTypeName), static_cast<BYTE>(value)); ASSERT_IFNOT(error.IsSuccess(), "Cluster manifest validation error: {0}: Error parsing app type MaxPercentUnhealthyApplication {1}", it->first, it->second); } } return clusterHealthPolicy; }
// Copy Options into a vector so we can sort them as we like. static void sortOpts(StringMap<Option*> &OptMap, SmallVectorImpl< std::pair<const char *, Option*> > &Opts, bool ShowHidden) { SmallPtrSet<Option*, 128> OptionSet; // Duplicate option detection. for (StringMap<Option*>::iterator I = OptMap.begin(), E = OptMap.end(); I != E; ++I) { // Ignore really-hidden options. if (I->second->getOptionHiddenFlag() == ReallyHidden) continue; // Unless showhidden is set, ignore hidden flags. if (I->second->getOptionHiddenFlag() == Hidden && !ShowHidden) continue; // If we've already seen this option, don't add it to the list again. if (!OptionSet.insert(I->second)) continue; Opts.push_back(std::pair<const char *, Option*>(I->getKey().data(), I->second)); } // Sort the options list alphabetically. qsort(Opts.data(), Opts.size(), sizeof(Opts[0]), OptNameCompare); }
// this takes ownership of a module after code emission is complete // and will add it to the execution engine when required (by jl_finalize_function) void jl_finalize_module(Module *m, bool shadow) { #if !defined(USE_ORCJIT) jl_globalPM->run(*m); #endif // record the function names that are part of this Module // so it can be added to the JIT when needed for (Module::iterator I = m->begin(), E = m->end(); I != E; ++I) { Function *F = &*I; if (!F->isDeclaration()) { bool known = incomplete_fname.erase(F->getName()); (void)known; // TODO: assert(known); // llvmcall gets this wrong module_for_fname[F->getName()] = m; } } #if defined(USE_ORCJIT) || defined(USE_MCJIT) // in the newer JITs, the shadow module is separate from the execution module if (shadow) jl_add_to_shadow(m); #else bool changes = jl_try_finalize(m); while (changes) { // this definitely isn't the most efficient, but it's only for the old LLVM 3.3 JIT changes = false; for (StringMap<Module*>::iterator MI = module_for_fname.begin(), ME = module_for_fname.end(); MI != ME; ++MI) { changes |= jl_try_finalize(MI->second); } } #endif }
void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player, const std::string &formname, const StringMap &fields) { SCRIPTAPI_PRECHECKHEADER // Get core.registered_on_chat_messages lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_player_receive_fields"); // Call callbacks // param 1 objectrefGetOrCreate(L, player); // param 2 lua_pushstring(L, formname.c_str()); // param 3 lua_newtable(L); StringMap::const_iterator it; for (it = fields.begin(); it != fields.end(); ++it) { const std::string &name = it->first; const std::string &value = it->second; lua_pushstring(L, name.c_str()); lua_pushlstring(L, value.c_str(), value.size()); lua_settable(L, -3); } script_run_callbacks(L, 3, RUN_CALLBACKS_MODE_OR_SC); }
//! The Job options are synchronised using the widgetChanged slot, but we still //! need to determine if the options should be printed as part of the job. This //! is based on whether or not the associated control is enabled or not. void InputDialog::finalizeJob(Job* job) { if (!job) return; QWidget* w; QString name; StringMap::const_iterator iter; StringMap s = job->getOptions(); for (iter = s.begin(); iter != s.end(); ++iter) { name = iter.key(); w = findChild<QWidget*>(name.toLower()); // If there is no widget of this name, then we are probably dealing // with something the user wrote into the preview box, so we just // leave things alone. if (w) job->printOption(name, w->isEnabled()); } // Special case code to avoid writing the method keyword when custom is // chosen (for backward compatibility) QComboBox* method(findChild<QComboBox*>("method")); QString m(method->currentText()); if (method && (m == "Custom" || m == "TD-DFT")) { job->printOption("METHOD", false); job->printOption("EXCHANGE", true); } }
void ScriptApiMainMenu::handleMainMenuButtons(const StringMap &fields) { SCRIPTAPI_PRECHECKHEADER int error_handler = PUSH_ERROR_HANDLER(L); // Get handler function lua_getglobal(L, "core"); lua_getfield(L, -1, "button_handler"); lua_remove(L, -2); // Remove core if (lua_isnil(L, -1)) { lua_pop(L, 1); // Pop button handler return; } luaL_checktype(L, -1, LUA_TFUNCTION); // Convert fields to a Lua table lua_newtable(L); StringMap::const_iterator it; for (it = fields.begin(); it != fields.end(); ++it) { const std::string &name = it->first; const std::string &value = it->second; lua_pushstring(L, name.c_str()); lua_pushlstring(L, value.c_str(), value.size()); lua_settable(L, -3); } // Call it PCALL_RES(lua_pcall(L, 1, 0, error_handler)); lua_pop(L, 1); // Pop error handler }
QString KraftDB::replaceTagsInWord( const QString& w, StringMap replaceMap ) const { QString re( w ); QMap<int, QStringList> reMap; StringMap::Iterator it; for ( it = replaceMap.begin(); it != replaceMap.end(); ++it ) { reMap[it.key().length()] << it.key(); } QMap<int, QStringList>::Iterator reIt; for ( reIt = reMap.end(); reIt != reMap.begin(); ) { --reIt; QStringList keys = reIt.value(); kDebug() << "PP: " << keys; for ( QStringList::Iterator dtIt = keys.begin(); dtIt != keys.end(); ++dtIt ) { QString repKey = *dtIt; re.replace( repKey, replaceMap[repKey] ); } } kDebug() << "Adding to wordlist <" << re << ">"; return re; }
void SkillEditFrame::onCurrentItemChanged(DataContainerItem *current) { if (current == 0) return; QTableWidget *skillTable = this->findChild<QTableWidget *>("skillTable"); DataContainerItem *item = current; if (item->getStringData().size() > 0) { StatsContainer *skill = GenStatsReader::getContainer(*skillStats, item->getStringData()); if (skill != 0) { typedef std::map<std::string, std::string> StringMap; StringMap dataMap = skill->getBaseDataMap(); for (int i=0; i<skillTable->rowCount(); ++i) { for (int j=0; j<skillTable->columnCount(); ++j) { delete skillTable->item(i, j); } } skillTable->setRowCount(0); int row = 0; for (StringMap::iterator it = dataMap.begin(); it != dataMap.end(); ++it) { QTableWidgetItem *nameItem = new QTableWidgetItem(); nameItem->setText(it->first.c_str()); QTableWidgetItem *valueItem = new QTableWidgetItem(); valueItem->setText(it->second.c_str()); skillTable->insertRow(row); skillTable->setItem(row, 0, nameItem); skillTable->setItem(row, 1, valueItem); ++row; } skillTable->resizeRowsToContents(); skillTable->resizeColumnsToContents(); } } }
Int2StrMap XceCacheAdapter::Gets(const IntSequence& ids) { // 1 % // 2 call one by one typedef std::map< ::Ice::Int, StringList> GetsMap; GetsMap gets_map; for(IntSequence::const_iterator i = ids.begin(); i != ids.end(); ++i) { int index = *i % cluster(); gets_map[index].push_back(std::string( (const char*)&(*i), sizeof(Ice::Int) )); } // 2 串行调用 Gets Int2StrMap result; int i=0; for (GetsMap::const_iterator gmi = gets_map.begin(); gmi != gets_map.end(); ++gmi, ++i) { try { CachePrx proxy = locate<CachePrx>(_cache_proxies, "cache", gmi->first, MyUtil::TWO_WAY); StringMap subr = proxy->Gets(gmi->second); for (StringMap::const_iterator i=subr.begin(); i!=subr.end(); ++i) { int uid = *(int*)(i->first.data()); // result.insert(std::make_pair(uid, i->second)); } } catch (Ice::Exception& e) { MCE_ERROR("Gets error: cluster="<< i << e); continue; } } return result; }
MONGO_INITIALIZER(StopWords)(InitializerContext* context) { StringMap<std::set<std::string>> raw; loadStopWordMap(&raw); for (StringMap<std::set<std::string>>::const_iterator i = raw.begin(); i != raw.end(); ++i) { STOP_WORDS[i->first].reset(new StopWords(i->second)); } return Status::OK(); }
void Application::dumpCounts(StringMap<float> &counts) { StringMapIterator<float> cur=counts.begin(), end=counts.end(); for(; cur!=end ; ++cur) { StringMapElem<float> elem=*cur; String word(elem.first,elem.len); float count=elem.second; cout<<word<<"\t"<<count<<endl; } }
int main(int argc, const char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(); // Hide unrelated options. StringMap<cl::Option*> Options; cl::getRegisteredOptions(Options); for (StringMap<cl::Option *>::iterator I = Options.begin(), E = Options.end(); I != E; ++I) { if (I->second->Category != &ClangFormatCategory && I->first() != "help" && I->first() != "version") I->second->setHiddenFlag(cl::ReallyHidden); } cl::SetVersionPrinter(PrintVersion); cl::ParseCommandLineOptions( argc, argv, "A tool to format C/C++/Obj-C code.\n\n" "If no arguments are specified, it formats the code from standard input\n" "and writes the result to the standard output.\n" "If <file>s are given, it reformats the files. If -i is specified\n" "together with <file>s, the files are edited in-place. Otherwise, the\n" "result is written to the standard output.\n"); if (Help) cl::PrintHelpMessage(); if (DumpConfig) { std::string Config = clang::format::configurationAsText(clang::format::getStyle( Style, FileNames.empty() ? AssumeFilename : FileNames[0], FallbackStyle)); llvm::outs() << Config << "\n"; return 0; } bool Error = false; switch (FileNames.size()) { case 0: Error = clang::format::format("-"); break; case 1: Error = clang::format::format(FileNames[0]); break; default: if (!Offsets.empty() || !Lengths.empty() || !LineRanges.empty()) { llvm::errs() << "error: -offset, -length and -lines can only be used for " "single file.\n"; return 1; } for (unsigned i = 0; i < FileNames.size(); ++i) Error |= clang::format::format(FileNames[i]); break; } return Error ? 1 : 0; }
void Application::add(StringMap<float> &from,StringMap<float> &to) { StringMapIterator<float> cur=from.begin(), end=from.end(); for(; cur!=end ; ++cur) { StringMapElem<float> &elem=*cur; if(!to.isDefined(elem.first,elem.len)) to.lookup(elem.first,elem.len)=elem.second; else to.lookup(elem.first,elem.len)+=elem.second; } }
BlackList::BlackList(const StringRef Path) { // Validate and open blacklist file. if (Path.empty()) return; OwningPtr<MemoryBuffer> File; if (error_code EC = MemoryBuffer::getFile(Path, File)) { report_fatal_error("Can't open blacklist file: " + Path + ": " + EC.message()); } // Iterate through each line in the blacklist file. SmallVector<StringRef, 16> Lines; SplitString(File.take()->getBuffer(), Lines, "\n\r"); StringMap<std::string> Regexps; for (SmallVector<StringRef, 16>::iterator I = Lines.begin(), E = Lines.end(); I != E; ++I) { // Ignore empty lines and lines starting with "#" if (I->empty() || I->startswith("#")) continue; // Get our prefix and unparsed regexp. std::pair<StringRef, StringRef> SplitLine = I->split(":"); StringRef Prefix = SplitLine.first; std::string Regexp = SplitLine.second; if (Regexp.empty()) { // Missing ':' in the line. report_fatal_error("malformed blacklist line: " + SplitLine.first); } // Replace * with .* for (size_t pos = 0; (pos = Regexp.find("*", pos)) != std::string::npos; pos += strlen(".*")) { Regexp.replace(pos, strlen("*"), ".*"); } // Check that the regexp is valid. Regex CheckRE(Regexp); std::string Error; if (!CheckRE.isValid(Error)) { report_fatal_error("malformed blacklist regex: " + SplitLine.second + ": " + Error); } // Add this regexp into the proper group by its prefix. if (!Regexps[Prefix].empty()) Regexps[Prefix] += "|"; Regexps[Prefix] += Regexp; } // Iterate through each of the prefixes, and create Regexs for them. for (StringMap<std::string>::iterator I = Regexps.begin(), E = Regexps.end(); I != E; ++I) { Entries[I->getKey()] = new Regex(I->getValue()); } }
void checkStringMapSyntax() { StringMapSyntaxChecker checker; StringMap< StringMapSyntaxChecker *> intlookup; intlookup.begin(); intlookup.end(); intlookup.insert( "ABC", &checker ); intlookup.insertUpdate( "CDE", &checker ); intlookup.find( "ABC" ); intlookup.remove( "ABC" ); intlookup.release_objects(); }
void Html::select(const String &name, const StringMap &options, const String &def) { *mStream<<"<select name=\""<<name<<"\">\n"; for(StringMap::const_iterator it=options.begin(); it!=options.end(); ++it) { *mStream<<"<option "; if(def == it->first) *mStream<<"selected "; *mStream<<"value=\""<<it->first<<"\">"; text(it->second); *mStream<<"</option>\n"; } *mStream<<"</select>\n"; }
void ConnectionQuery::doUpdate(const string& table, const StringMap& filter, const StringMap& properties) { if (!properties.size()) { return; } ostringstream sql; sql << "UPDATE " << table << " SET "; for (StringMap::const_iterator it = properties.begin();;) { //#ifndef NEWARCH // // sql << it->first << "=" << mysqlpp::quote << it->second; // sql << it->first << "=" << "'" << mysqlpp::quote << it->second << "'"; //#else sql << it->first << "=" << "'" << mysqlpp::quote << it->second << "'"; //#endif if (++it == properties.end()) { break; } else { sql << ", "; } } if (filter.size()) { sql << " WHERE "; for (StringMap::const_iterator it = filter.begin();;) { //#ifndef NEWARCH // // sql << it->first << "=" << mysqlpp::quote << it->second; // sql << it->first << "=" << "'" << mysqlpp::quote << it->second << "'"; //#else sql << it->first << "=" << "'" << mysqlpp::quote << it->second << "'"; //#endif if (++it == filter.end()) { break; } else { sql << " AND "; } } } doExecute(sql.str()); }
PLBConfig::KeyBoolValueMap PLBConfig::KeyBoolValueMap::Parse(StringMap const & entries) { KeyBoolValueMap result; for (auto it = entries.begin(); it != entries.end(); ++it) { wstring key = Config::Parse<wstring>(it->first); bool value = Config::Parse<bool>(it->second); result[key] = value; } return result; }
PostJob::PostJob(PlatformDependent *internals, const QNetworkRequest &request, const StringMap ¶meters) : BaseJob(internals), m_ioDevice(0), m_request(request) { // Create post data int j = 0; for (StringMap::const_iterator i = parameters.begin(); i != parameters.end(); ++i) { if (j++ > 0) { m_byteArray.append('&'); } m_byteArray.append(QUrl::toPercentEncoding(i.key())); m_byteArray.append('='); m_byteArray.append(QUrl::toPercentEncoding(i.value())); } }
void Application::outputModel() { StringMapIterator<float> cur=counts.begin(), end=counts.end(); for(; cur!=end ; ++cur) { StringMapElem<float> elem=*cur; String word(elem.first,elem.len); float count=elem.second; float biasedCount=0; if(biasedCounts.isDefined(elem.first,elem.len)) biasedCount=biasedCounts.lookup(elem.first,elem.len); float ratio=biasedCount/count; cout<<word<<"\t"<<ratio<<endl; } }
void MainWindow::slotLoadProfile( const QString& id ) { const QString path = Kontact::ProfileManager::self()->profileById( id ).saveLocation(); if ( path.isNull() ) return; KConfig* const cfg = Prefs::self()->config(); Prefs::self()->writeConfig(); saveMainWindowSettings( cfg ); saveSettings(); const KConfig profile( path+"/kontactrc", /*read-only=*/false, /*useglobals=*/false ); const QStringList groups = profile.groupList(); for ( QStringList::ConstIterator it = groups.begin(), end = groups.end(); it != end; ++it ) { cfg->setGroup( *it ); typedef QMap<QString, QString> StringMap; const StringMap entries = profile.entryMap( *it ); for ( StringMap::ConstIterator it2 = entries.begin(), end = entries.end(); it2 != end; ++it2 ) { if ( it2.data() == "KONTACT_PROFILE_DELETE_KEY" ) cfg->deleteEntry( it2.key() ); else cfg->writeEntry( it2.key(), it2.data() ); } } cfg->sync(); Prefs::self()->readConfig(); applyMainWindowSettings( cfg ); KIconTheme::reconfigure(); const WId wid = winId(); KIPC::sendMessage( KIPC::PaletteChanged, wid ); KIPC::sendMessage( KIPC::FontChanged, wid ); KIPC::sendMessage( KIPC::StyleChanged, wid ); KIPC::sendMessage( KIPC::SettingsChanged, wid ); for ( int i = 0; i < KIcon::LastGroup; ++i ) KIPC::sendMessage( KIPC::IconChanged, wid, i ); loadSettings(); for ( PluginList::Iterator it = mPlugins.begin(); it != mPlugins.end(); ++it ) { if ( !(*it)->isRunningStandalone() ) { kdDebug() << "Ensure loaded: " << (*it)->identifier() << endl; (*it)->part(); } (*it)->loadProfile( path ); } }
int main(int argc, char **argv) { StringMap ejstr; StringMap::iterator si; LoadEJ("monster_E_J.txt", &ejstr); si = ejstr.begin(); while (si != ejstr.end()) { printf("msgid \"%s\"\nmsgstr \"%s\"\n\n", si->second.c_str(), si->first.c_str()); si++; } return 0; }
PLBConfig::KeyDoubleValueMap PLBConfig::KeyDoubleValueMap::Parse(StringMap const & entries) { KeyDoubleValueMap result; for (auto it = entries.begin(); it != entries.end(); ++it) { wstring key = Config::Parse<wstring>(it->first); double value = Config::Parse<double>(it->second); // remove the entry if the value is invalid if (value >= 0) { result[key] = value; } } return result; }
void Client::sendInventoryFields(const std::string &formname, const StringMap &fields) { size_t fields_size = fields.size(); FATAL_ERROR_IF(fields_size > 0xFFFF, "Unsupported number of inventory fields"); NetworkPacket pkt(TOSERVER_INVENTORY_FIELDS, 0); pkt << formname << (u16) (fields_size & 0xFFFF); StringMap::const_iterator it; for (it = fields.begin(); it != fields.end(); ++it) { const std::string &name = it->first; const std::string &value = it->second; pkt << name; pkt.putLongString(value); } Send(&pkt); }