Example #1
0
  shared_ptr<OutputPlugin>
  OutputPlugin::getPlugin(std::string Details, const dynamo::Simulation* Sim)
  {
    typedef boost::tokenizer<boost::char_separator<char> > tokenizer;

    rapidxml::xml_document<> doc;
    rapidxml::xml_node<> *node = doc.allocate_node(rapidxml::node_element, 
						   doc.allocate_string("OP"));

    boost::char_separator<char> DetailsSep(":");
    boost::char_separator<char> OptionsSep(",");
    boost::char_separator<char> ValueSep("=", "", boost::keep_empty_tokens);

    tokenizer tokens(Details, DetailsSep);
    tokenizer::iterator details_iter = tokens.begin();

    node->append_attribute(doc.allocate_attribute
			   ("Type", doc.allocate_string(details_iter->c_str())));

    ++details_iter;
    if (details_iter != tokens.end())
      {
	tokenizer option_tokens(*details_iter, OptionsSep);

	if (++details_iter != tokens.end())
	  M_throw() << "Two colons in outputplugin options " << *details_iter;

	for (tokenizer::iterator options_iter = option_tokens.begin();
	     options_iter != option_tokens.end(); ++options_iter)
	  {
	    tokenizer value_tokens(*options_iter, ValueSep);

	    tokenizer::iterator value_iter = value_tokens.begin();
	    std::string opName(*value_iter);
	    std::string val;
	    if (++value_iter == value_tokens.end())
	      //There is no value to save, must be a flag
	      val = "";
	    else
	      val = *value_iter;

	    node->append_attribute(doc.allocate_attribute
				   (doc.allocate_string(opName.c_str()), 
				    doc.allocate_string(val.c_str())));
	  }
      }

    return getPlugin(magnet::xml::Node(node, NULL), Sim);
  }
Example #2
0
void Kernel::collectExtraOptions()
{

    for (const auto& o : m_extra_options)
    {

        typedef boost::tokenizer<boost::char_separator<char>> tokenizer;

        // if we don't have --, we're not an option we
        // even care about
        if (!boost::algorithm::find_first(o, "--")) continue;

        // Find the dimensions listed and put them on the id list.
        boost::char_separator<char> equal("=");
        boost::char_separator<char> dot(".");
        // boost::erase_all(o, " "); // Wipe off spaces
        tokenizer option_tokens(o, equal);
        std::vector<std::string> option_split;
        for (auto ti = option_tokens.begin(); ti != option_tokens.end(); ++ti)
            option_split.push_back(boost::lexical_cast<std::string>(*ti));
        if (!(option_split.size() == 2))
        {
            std::ostringstream oss;
            oss << "option '" << o << "' did not split correctly. Is it in the form --readers.las.option=foo?";
            throw app_usage_error(oss.str());
        }

        std::string option_value(option_split[1]);
        std::string stage_value(option_split[0]);
        boost::algorithm::erase_all(stage_value, "--");

        tokenizer name_tokens(stage_value, dot);
        std::vector<std::string> stage_values;
        for (auto ti = name_tokens.begin(); ti != name_tokens.end(); ++ti)
        {
            stage_values.push_back(*ti);
        }

        std::string option_name = *stage_values.rbegin();
        std::ostringstream stage_name_ostr;
        bool bFirst(true);
        for (auto s = stage_values.begin(); s != stage_values.end()-1; ++s)
        {
            auto s2 = boost::algorithm::erase_all_copy(*s, " ");

            if (bFirst)
            {
                bFirst = false;
            }
            else
                stage_name_ostr <<".";
            stage_name_ostr << s2;
        }
        std::string stage_name(stage_name_ostr.str());

        auto found = m_extra_stage_options.find(stage_name);
        if (found == m_extra_stage_options.end())
            m_extra_stage_options.insert(std::make_pair(stage_name, Option(option_name, option_value, "")));
        else
            found->second.add(Option(option_name, option_value, ""));
    }
}