Exemplo n.º 1
0
UUCount::UUCount(const std::string& str)
{
  if(str.empty())
  {
    m_uuid = boost::uuids::nil_uuid();
    m_count = 0;
  }
  else
  {
    std::vector<std::string> split_parts;
    boost::algorithm::split(split_parts, str, boost::algorithm::is_any_of(":"));
    if(split_parts.size() != 2)
      throw ParsingFailed(FromHere(), "Did not find exactly one ':' separating UUID and count when parsing UUID string " + str);
    
    try
    {
      m_uuid = boost::uuids::string_generator()(split_parts.front());
    }
    catch(std::runtime_error&)
    {
      throw ParsingFailed(FromHere(), "Invalid UUID string: " + split_parts.front());
    }
    
    try
    {
      m_count = boost::lexical_cast<Uint>(split_parts.back());
    }
    catch(boost::bad_lexical_cast& e)
    {
      throw ParsingFailed(FromHere(), "Error casting this string to Uint: " + split_parts.back());
    }
  }
}
Exemplo n.º 2
0
  Common_API bool from_str<bool> (const std::string& str)
  {
    bool match = false;
    boost::algorithm::is_equal test_equal;

    if ( test_equal(str,"true") ||
         test_equal(str,"True") ||
         test_equal(str,"on")   ||
         test_equal(str,"1")     )
    {
      return true;
    }

    if ( test_equal(str,"false") ||
         test_equal(str,"False") ||
         test_equal(str,"off")   ||
         test_equal(str,"0")      )
    {
      return false;
    }

    if (!match)
      throw ParsingFailed (FromHere(), "Incorrect option conversion to bool of string [" + str + "]" );
    return true;
  }
Exemplo n.º 3
0
 Common_API double from_str<double> (const std::string& str)
 {
   char * error;
   double result = std::strtod(str.c_str(), &error);
   if (*error != 0)
   {
     throw ParsingFailed(FromHere(), "String " + str + " could not be parsed as a number");
   }
   return result;
 }
Exemplo n.º 4
0
void SignalFrame::insert( std::vector<std::string>& input )
{
  // extract:   variable_name:type=value   or   variable_name:array[type]=value1,value2
  boost::regex expression(  "([[:word:]]+)(\\:([[:word:]]+)(\\[([[:word:]]+)\\])?=(.*))?"  );
  boost::match_results<std::string::const_iterator> what;

  boost_foreach (const std::string& arg, input)
  {

    std::string name;
    std::string type;
    std::string subtype; // in case of array<type>
    std::string value;

    if (regex_search(arg,what,expression))
    {
      name=what[1];
      type=what[3];
      subtype=what[5];
      value=what[6];

      //CFinfo << name << ":" << type << (subtype.empty() ? std::string() : std::string("["+subtype+"]"))  << "=" << value << CFendl;

      if(type == "array")
      {
        set_array(name, subtype, value, " ; ");
      }
      else
      {
        set_option(name, type, value);
      }
    }
    else
      throw ParsingFailed(FromHere(), "Could not parse [" + arg + "].\n"+
                          "Format should be:\n"
                          " -  for simple types:  variable_name:type=value\n"
                          " -  for array types:   variable_name:array[type]=value1,value2\n"
                          "  with possible type: [bool,unsigned,integer,real,string,uri]");
  }
Exemplo n.º 5
0
void OptionList::fill_from_vector( const std::vector<std::string> & args )
{
  // extract:   variable_name:type=value   or   variable_name:array[type]=value1,value2
  boost::regex expression(  "([[:word:]]+)(\\:([[:word:]]+)(\\[([[:word:]]+)\\])?=(.*))?"  );
  boost::match_results<std::string::const_iterator> what;

  boost_foreach (const std::string& arg, args)
  {

    std::string name;
    std::string type;
    std::string subtype; // in case of array<type>
    std::string value;

    if (regex_search(arg,what,expression))
    {
      name=what[1];
      type=what[3];
      subtype=what[5];
      value=what[6];

      //CFinfo << name << ":" << type << (subtype.empty() ? std::string() : std::string("["+subtype+"]"))  << "=" << value << CFendl;

      if      (type == "bool")
        set_option_to_list< OptionT<bool> >(name, from_str<bool>( value ), *this );
      else if (type == "unsigned")
        set_option_to_list< OptionT<Uint> >(name, from_str<Uint>( value ), *this );
      else if (type == "integer")
        set_option_to_list< OptionT<int> >(name, from_str<int>( value ), *this );
      else if (type == "real")
        set_option_to_list< OptionT<Real> >(name, from_str<Real>( value ), *this );
      else if (type == "string")
        set_option_to_list< OptionT<std::string> >(name, value, *this );
      else if (type == "uri")
        set_option_to_list< OptionURI >(name, from_str<URI>( value ), *this );
      else if (type == "array")
      {
        std::vector<std::string> array;

        // the strings could have comma's inside, brackets, etc...
        Uint in_brackets(0);
        std::string::iterator first = value.begin();
        std::string::iterator it = first;
        for ( ; it!=value.end(); ++it)
        {
          if (*it == '(') // opening bracket
            ++in_brackets;
          else if (*it == ')') // closing bracket
            --in_brackets;
          else if (*it == ',' && in_brackets == 0)
          {
            array.push_back(std::string(first,it));
            boost::algorithm::trim(array.back());
            first = it+1;
          }
        }
        array.push_back(std::string(first,it));
        boost::algorithm::trim(array.back());

        if (subtype == "bool")
          set_array_to_list<bool>(name, array, *this);
        else if (subtype == "unsigned")
          set_array_to_list<Uint>(name, array, *this);
        else if (subtype == "integer")
          set_array_to_list<int>(name, array, *this);
        else if (subtype == "real")
          set_array_to_list<Real>(name, array, *this);
        else if (subtype == "string")
          set_option_to_list< OptionArrayT<std::string> >(name, array, *this);
        else if (subtype == "uri")
          set_array_to_list<URI>(name, array, *this);

      }
      else
        throw ParsingFailed(FromHere(), "The type ["+type+"] of passed argument [" + arg + "] is invalid.\n"+
          "Format should be:\n"
          " -  for simple types:  variable_name:type=value\n"
          " -  for array types:   variable_name:array[type]=value1,value2\n"
          "  with possible type: [bool,unsigned,integer,real,string,uri]");
    }
    else
      throw ParsingFailed(FromHere(), "Could not parse [" + arg + "].\n"+
         "Format should be:\n"
         " -  for simple types:  variable_name:type=value\n"
         " -  for array types:   variable_name:array[type]=value1,value2\n"
         "  with possible type: [bool,unsigned,integer,real,string,uri]");
  }