예제 #1
0
  static utymap::GeoCoordinate parseCoordinate(const ptree &coordinate) {
    if (std::distance(coordinate.begin(), coordinate.end())!=2)
      throw std::invalid_argument("Invalid geometry.");

    auto iter = coordinate.begin();
    double longitude = iter->second.get_value<double>();
    double latitude = (++iter)->second.get_value<double>();
    return utymap::GeoCoordinate(latitude, longitude);
  }
예제 #2
0
boost::shared_ptr<scxml_parser::transition> scxml_parser::parse_transition(const ptree &pt)
{
	const ptree &xmlattr = pt.get_child("<xmlattr>");
	boost::shared_ptr<transition> tr = boost::make_shared<transition>();
	try {
		using namespace boost::algorithm;
		boost::optional<string> target(xmlattr.get_optional<string>("target"));
		if(target) split(tr->target, *target, is_any_of(" "), token_compress_on);
		if(tr->target.size() > 1) parallel_target_sizes.insert(tr->target.size());
		tr->event = xmlattr.get_optional<string>("event");

		for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
			if (it->first == "<xmlcomment>") ; // ignore comments
			else if (it->first == "<xmlattr>") ; // ignore, parsed above
			else if (it->first == "script") tr->actions.push_back(parse_script(it->second));
			else if (it->first == "log") tr->actions.push_back(parse_log(it->second));
			else if (it->first == "raise") tr->actions.push_back(parse_raise(it->second));
			else cerr << "warning: unknown item '" << it->first << "' in <transition>" << endl;
		}
	}
	catch (ptree_error e) {
		cerr << "error: transition: " << e.what() << endl;
		exit(1);
	}
	return tr;
}
예제 #3
0
boost::shared_ptr<scxml_parser::action> scxml_parser::parse_log(const ptree &pt)
{
	boost::shared_ptr<action> ac = boost::make_shared<action>();
	try {
		const ptree &xmlattr = pt.get_child("<xmlattr>");

		boost::optional<string> label(xmlattr.get_optional<string>("label"));
		const string expr = xmlattr.get<string>("expr");

		ac->type = "log";
		if(label) ac->attr["label"] = *label;
		ac->attr["expr"] = expr;

		for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
			if (it->first == "<xmlcomment>") ; // ignore comments
			else if (it->first == "<xmlattr>") ; // ignore, parsed above
			else cerr << "warning: unknown item '" << it->first << "' in <log>" << endl;
		}
	}
	catch (ptree_error e) {
		cerr << "error: log: " << e.what() << endl;
		exit(1);
	}

	using_log = true;
	return ac;
}
예제 #4
0
boost::shared_ptr<scxml_parser::action> scxml_parser::parse_raise(const ptree &pt)
{
	boost::shared_ptr<action> ac = boost::make_shared<action>();
	try {
		const ptree &xmlattr = pt.get_child("<xmlattr>");

		const string event = xmlattr.get<string>("event");

		ac->type = "raise";
		ac->attr["event"] = event;

		for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
			if (it->first == "<xmlcomment>") ; // ignore comments
			else if (it->first == "<xmlattr>") ; // ignore, parsed above
			else cerr << "warning: unknown item '" << it->first << "' in <raise>" << endl;
		}
	}
	catch (ptree_error e) {
		cerr << "error: raise: " << e.what() << endl;
		exit(1);
	}

	using_event_queue = true;
	return ac;
}
예제 #5
0
void scxml_parser::parse(const ptree &pt)
{
	for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
		if (it->first == "<xmlcomment>") ; // ignore comments
		else if (it->first == "scxml") parse_scxml(it->second);
		else cerr << "warning: unknown item '" << it->first << "'" << endl;
	}
}
예제 #6
0
void PipelineReaderXML::parse_attributes(map_t& attrs, const ptree& tree)
{
    for (auto iter = tree.begin(); iter != tree.end(); ++iter)
    {
        std::string name = iter->first;
        std::string value = tree.get<std::string>(name);
        Utils::trim(value);

        attrs[name] = value;
    }
}
예제 #7
0
std::vector<Filter> MakeFilters(const ptree& pt)
{
	std::vector<Filter> filters;
	for (auto it = pt.begin(); it != pt.end(); ++it)
	{
		if (it->first == "MessageFilter" ||
			it->first == "ProcessFilter" ||
			it->first == "Filter")
			filters.push_back(MakeFilter(it->second));
	}
	return filters;
}
예제 #8
0
bool PipelineReader::parseElement_Pipeline(const ptree& tree)
{
    Stage* stage = NULL;
    Writer* writer = NULL;

    map_t attrs;
    collect_attributes(attrs, tree);

    std::string version = "";
    if (attrs.count("version"))
    {
        version = attrs["version"];
    }
    if (version != "1.0")
    {
        throw pipeline_xml_error("unsupported pipeline xml version");
    }


    bool isWriter = false;

    for (auto iter = tree.begin(); iter != tree.end(); ++iter)
    {
        const std::string& name = iter->first;
        const ptree subtree = iter->second;

        if (name == "Reader" || name == "Filter" || name == "MultiFilter")
        {
            stage = parseElement_anystage(name, subtree);
        }
        else if (name == "Writer")
        {
            writer = parseElement_Writer(subtree);
            isWriter = true;
        }
        else if (name == "<xmlattr>")
        {
            // ignore it, already parsed
        }
        else
        {
            throw pipeline_xml_error("xml reader invalid child of "
                "ReaderPipeline element");
        }
    }

    if (writer && stage)
    {
        throw pipeline_xml_error("extra nodes at front of writer pipeline");
    }

    return isWriter;
}
예제 #9
0
boost::shared_ptr<scxml_parser::action> scxml_parser::parse_script(const ptree &pt)
{
	boost::shared_ptr<action> ac = boost::make_shared<action>();
	try {
		ac->type = "script";
		ac->attr["expr"] = pt.get_value<string>();

		for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
			if (it->first == "<xmlcomment>") ; // ignore comments
			else cerr << "warning: unknown item '" << it->first << "' in <script>" << endl;
		}
	}
	catch (ptree_error e) {
		cerr << "error: action: " << e.what() << endl;
		exit(1);
	}
	return ac;
}
예제 #10
0
scxml_parser::plist<scxml_parser::action> scxml_parser::parse_entry(const ptree &pt)
{
	plist<action> l_ac;
	try {
		for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
			if (it->first == "<xmlcomment>") ; // ignore comments
			else if (it->first == "script") l_ac.push_back(parse_script(it->second));
			else if (it->first == "log") l_ac.push_back(parse_log(it->second));
			else if (it->first == "raise") l_ac.push_back(parse_raise(it->second));
			else cerr << "warning: unknown item '" << it->first << "' in <onentry> or <onexit>" << endl;
		}
	}
	catch (ptree_error e) {
		cerr << "error: onentry/onexit: " << e.what() << endl;
		exit(1);
	}
	return l_ac;
}
예제 #11
0
void scxml_parser::parse_state(const ptree &pt, const boost::shared_ptr<state> &parent)
{
	try {
		using namespace boost::algorithm;
		const ptree &xmlattr = pt.get_child("<xmlattr>");
		boost::shared_ptr<state> st = boost::make_shared<state>();
		st->id = xmlattr.get<string>("id");
		if(parent) {
			using_compound = true;
			st->parent = parent;
		}
		boost::optional<string> initial(xmlattr.get_optional<string>("initial"));
		if(initial) split(st->initial.target, *initial, is_any_of(" "), token_compress_on);
		if(st->initial.target.size() > 1) parallel_target_sizes.insert(st->initial.target.size());
		st->type = xmlattr.get_optional<string>("type");
		m_scxml.states.push_back(st);
		state_list::iterator state_i = --m_scxml.states.end();

		for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
			if (it->first == "<xmlcomment>") ; // ignore comments
			else if (it->first == "<xmlattr>") ; // ignore, parsed above
			else if (it->first == "state") parse_state(it->second, st);
			else if (it->first == "history") parse_state(it->second, st);
			else if (it->first == "parallel") parse_parallel(it->second, st);
			else if (it->first == "transition") state_i->get()->transitions.push_back(parse_transition(it->second));
			else if (it->first == "onentry") state_i->get()->entry_actions = parse_entry(it->second);
			else if (it->first == "onexit") state_i->get()->exit_actions = parse_entry(it->second);
			else if (it->first == "initial") state_i->get()->initial = parse_initial(it->second);
			else cerr << "warning: unknown item '" << it->first << "' in <state>" << endl;
		}

		// if initial state is not set, use first state in document order
		// if parent is parallel put all states in initial
		if(parent && (parent->initial.target.empty() || (parent->type && *parent->type == "parallel"))) {
			parent->initial.target.push_back(st->id);
		}
	}
	catch (ptree_error e) {
		cerr << "error: state: " << e.what() << endl;
		exit(1);
	}
}
예제 #12
0
scxml_parser::transition scxml_parser::parse_initial(const ptree &pt)
{
	scxml_parser::transition initial;
	initial.event = "initial";

	try {

		for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
			if (it->first == "<xmlcomment>") ; // ignore comments
			else if (it->first == "transition") initial = *parse_transition(it->second);
			else cerr << "warning: unknown item '" << it->first << "' in <initial>" << endl;
		}

	}
	catch (ptree_error e) {
		cerr << "error: initial: " << e.what() << endl;
		exit(1);
	}

	return initial;
}
예제 #13
0
void scxml_parser::parse_scxml(const ptree &pt)
{
	try {
		using namespace boost::algorithm;
		const ptree &xmlattr = pt.get_child("<xmlattr>");
		boost::optional<string> initial(xmlattr.get_optional<string>("initial"));
		if(initial) split(m_scxml.initial.target, *initial, is_any_of(" "), token_compress_on);
		if(m_scxml.initial.target.size() > 1) parallel_target_sizes.insert(m_scxml.initial.target.size());
		m_scxml.name = xmlattr.get<string>("name", m_scxml.name);

		for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
			if (it->first == "<xmlcomment>") ; // ignore comments
			else if (it->first == "<xmlattr>") ; // ignore, parsed above
			else if (it->first == "state") parse_state(it->second, boost::shared_ptr<state>());
			else if (it->first == "history") parse_state(it->second, boost::shared_ptr<state>());
			else if (it->first == "parallel") parse_parallel(it->second, boost::shared_ptr<state>());
			else if (it->first == "initial") m_scxml.initial = parse_initial(it->second);
			else cerr << "warning: unknown item '" << it->first << "' in <scxml>" << endl;
		}

		// if initial state is not set, use first state in document order
		if(m_scxml.initial.target.empty()) {
			if(m_scxml.states.size()) {
				m_scxml.initial.target.push_back((*m_scxml.states.begin())->id);
			}
			else {
				cerr << "error: could not set initial state" << endl;
				exit(1);
			}
		}
	}
	catch (ptree_error e) {
		cerr << "error: scxml: " << e.what() << endl;
		exit(1);
	}
}