示例#1
0
int main(int argc, char *argv[])
{
  StrStrMap dict;
  dict.insert(make_pair("day", "Tag"));
  dict.insert(make_pair("strage", "frem"));
  dict.insert(make_pair("Cat",  "Auto"));
  dict.insert(make_pair("smart", "elegant"));
  dict.insert(make_pair("trait", "Merkmal"));
  dict.insert(make_pair("smart", "something"));

  StrStrMap::iterator pos;
  cout.setf(ios::left, ios::adjustfield);
  cout << ' ' << setw(10) << "english" << "german" << endl;
  cout << setfill('-') << setw(20) << ""
       << setfill('-') << endl;
  for(pos = dict.begin(); pos != dict.end(); ++pos)
    cout << ' ' << setw(10) << pos->first.c_str()
	 << pos->second << endl;
  cout << endl;

  string word("smart");
  cout << word << endl;
  for(pos = dict.lower_bound(word); pos != dict.upper_bound(word); ++pos)
    cout << " " << pos->second << endl;

  cout << "=================Testing Find ===============" << endl;
  test_find();
  return 0;
}
示例#2
0
/****************************************
* MapTypeValueFactory
****************************************/
QVariant MapTypeValueFactory::getValueFromString(const QString &str, bool *ok) const {
    setIfNotNull(ok, true);
    StrStrMap map = StrPackUtils::unpackMap(str, StrPackUtils::SingleQuotes);
    QVariantMap variantMap;
    foreach (const QString& key, map.keys()) {
        variantMap.insert(key, map.value(key));
    }
    return variantMap;
}
示例#3
0
ExternalToolValidation DefaultExternalToolValidations::rValidation(){
    QString rExecutable = "Rscript";
    QStringList rArgs;
    rArgs << "--version";
    QString rmsg = "R";
    StrStrMap rerrMsgs;
    rerrMsgs.insert(ExternalToolValidation::DEFAULT_DESCR_KEY, "R Script required for this tool. Please install R Script or set your PATH variable if you have it installed.");

    ExternalToolValidation rValidation("", rExecutable, rArgs, rmsg, rerrMsgs);
    return rValidation;
}
示例#4
0
ExternalToolValidation DefaultExternalToolValidations::pythonValidation(){
    QString pythonExecutable = "python";
    QStringList pythonArgs;
    pythonArgs << "--version";
    QString pmsg = "Python";
    StrStrMap perrMsgs;
    perrMsgs.insert(ExternalToolValidation::DEFAULT_DESCR_KEY, "Python 2 required for this tool. Please install Python or set your PATH variable if you have it installed.");

    ExternalToolValidation pythonValidation("", pythonExecutable, pythonArgs, pmsg, perrMsgs);
    return pythonValidation;
}
示例#5
0
void Server::handleRequest(shared_ptr<tcp::socket> socket, Logger log) {
  // ProfilerStart("/home/sowa/local_workspace/pje/log/server.perf");
  Server* server = this;
  vector<char> buffer(1024*1024);
  error_code error;
  socket->read_some(boost::asio::buffer(buffer), error);
  string request(buffer.size(), 0);
  copy(buffer.begin(), buffer.end(), request.begin());
  string remoteIp = socket->remote_endpoint().address().to_string();
  log.info("received request from " + remoteIp);
  string query = server->retrieveQuery(request);
  log.debug("query: \"" + query + "\"");
  string command = server->retrieveCommand(query);
  StrStrMap args = server->retrieveArgs(query, server->workDir());
  string argsString = "{";
  for (StrStrMap::const_iterator i = args.begin();
       i != args.end();
       ++i) {
    argsString += i->first + ": " + i->second + ", ";
  }
  argsString = argsString.substr(0, argsString.size() - 2);
  argsString += "}";
  log.info("executing command <" + command + "> with args " + argsString);
  int tries = 10;
  while (tries) {
    try {
      Command::execute(*server, socket, command, args, log);
      tries = 0;
    } catch(const std::bad_alloc&) {
      --tries;
      if (tries) {
        _log.error("not enough memory to complete task: retrying");
        boost::this_thread::sleep(boost::posix_time::seconds(3));
      } else {
        _log.error("not enough memory to complete task: giving up");
      }
    }
  }
  socket->close();
  // ProfilerStop();
}