Beispiel #1
0
UIEvent
UIEvent::from_string(const std::string& str)
{
  switch(get_event_type(str))
  {
    case EV_REL: return str2rel_event(str); break;
    case EV_ABS: return str2abs_event(str); break;
    case EV_KEY: return str2key_event(str); break;
    default: throw std::runtime_error("unknown event type");
  }
}
RelAxisEventHandler*
RelAxisEventHandler::from_string(UInput& uinput, int slot, bool extra_devices,
                                 const std::string& str)
{
  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
  tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));

  UIEvent code = UIEvent::invalid();
  int     repeat = 10;
  float   value = 5.0f; 

  int j = 0;
  for(tokenizer::iterator i = tokens.begin(); i != tokens.end(); ++i, ++j)
  {
    switch(j)
    {
      case 0:
        code = str2rel_event(*i);
        break;

      case 1:
        value = boost::lexical_cast<float>(*i); 
        break;

      case 2:
        repeat = boost::lexical_cast<int>(*i); 
        break;

      default: 
        throw std::runtime_error("AxisEvent::rel_from_string(): to many arguments: " + str);
    }
  }

  if (j == 0)
  {
    throw std::runtime_error("AxisEvent::rel_from_string(): at least one argument required: " + str);
  }

  return new RelAxisEventHandler(uinput, slot, extra_devices, 
                                 code.get_device_id(), code.code,
                                 repeat, value);
}
RelRepeatAxisEventHandler*
RelRepeatAxisEventHandler::from_string(UInput& uinput, int slot, bool extra_devices, 
                                       const std::string& str)
{
  // split string at ':'
  boost::tokenizer<boost::char_separator<char> > 
    tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));
  std::vector<std::string> args;
  std::copy(tokens.begin(), tokens.end(), std::back_inserter(args));

  if (args.size() == 3)
  {
    return new RelRepeatAxisEventHandler(uinput, slot, extra_devices,
                                         str2rel_event(args[0]),
                                         boost::lexical_cast<int>(args[1]),
                                         boost::lexical_cast<float>(args[2]));
  }
  else
  {
    raise_exception(std::runtime_error, "must have three arguments");
  }
}
Beispiel #4
0
RelAxisEventHandler*
RelAxisEventHandler::from_string(const std::string& str)
{
  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
  tokenizer tokens(str, boost::char_separator<char>(":", "", boost::keep_empty_tokens));

  std::auto_ptr<RelAxisEventHandler> ev(new RelAxisEventHandler);

  int j = 0;
  for(tokenizer::iterator i = tokens.begin(); i != tokens.end(); ++i, ++j)
  {
    switch(j)
    {
      case 0:
        ev->m_code = str2rel_event(*i);
        break;

      case 1:
        ev->m_value = boost::lexical_cast<int>(*i); 
        break;

      case 2:
        ev->m_repeat = boost::lexical_cast<int>(*i); 
        break;

      default: 
        throw std::runtime_error("AxisEvent::rel_from_string(): to many arguments: " + str);
    }
  }

  if (j == 0)
  {
    throw std::runtime_error("AxisEvent::rel_from_string(): at least one argument required: " + str);
  }

  return ev.release();
}