/srv/osrm/osrm-backend/src/util
Edit: /srv/osrm/osrm-backend/src/util/conditional_restrictions.cpp (2461B)
#include "util/conditional_restrictions.hpp"
#include
#include
#include
namespace osrm::util
{
#ifndef NDEBUG
// Debug output stream operators for use with BOOST_SPIRIT_DEBUG
inline std::ostream &operator<<(std::ostream &stream, const ConditionalRestriction &restriction)
{
return stream << restriction.value << "=" << restriction.condition;
}
#endif
} // namespace osrm::util
BOOST_FUSION_ADAPT_STRUCT(osrm::util::ConditionalRestriction,
(std::string, value)(std::string, condition))
namespace osrm::util
{
namespace detail
{
namespace
{
namespace qi = boost::spirit::qi;
} // namespace
template
struct conditional_restrictions_grammar
: qi::grammar()>
{
// http://wiki.openstreetmap.org/wiki/Conditional_restrictions
conditional_restrictions_grammar() : conditional_restrictions_grammar::base_type(restrictions)
{
using qi::_1;
using qi::_val;
using qi::lit;
// clang-format off
restrictions
= restriction % ';'
;
restriction
= value >> '@' >> condition
;
value
= +(qi::char_ - '@')
;
condition
= *qi::blank
>> (lit('(') >> qi::as_string[qi::no_skip[*~lit(')')]][_val = _1] >> lit(')')
| qi::as_string[qi::no_skip[*~lit(';')]][_val = _1]
)
;
// clang-format on
BOOST_SPIRIT_DEBUG_NODES((restrictions)(restriction)(value)(condition));
}
qi::rule()> restrictions;
qi::rule restriction;
qi::rule value, condition;
};
} // namespace detail
std::vector ParseConditionalRestrictions(const std::string &str)
{
auto it(str.begin()), end(str.end());
const detail::conditional_restrictions_grammar static grammar;
std::vector result;
bool ok = boost::spirit::qi::phrase_parse(it, end, grammar, boost::spirit::qi::blank, result);
if (!ok || it != end)
return std::vector();
return result;
}
} // namespace osrm::util