make parse_map_sizes standalone method + upgrade parser to use boost::spirit::x3

This commit is contained in:
artemp 2016-12-09 11:52:25 +01:00
parent c5174d2862
commit fc54faac54
5 changed files with 64 additions and 44 deletions

View file

@ -54,6 +54,7 @@ else:
visual/report.cpp
visual/runner.cpp
visual/run.cpp
visual/parse_map_sizes.cpp
"""
)
test_program3 = test_env_local.Program('visual/run', source=source)

View file

@ -2,7 +2,7 @@
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2015 Artem Pavlenko
* Copyright (C) 2016 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -20,40 +20,36 @@
*
*****************************************************************************/
#ifndef MAP_SIZES_GRAMMAR_HPP
#define MAP_SIZES_GRAMMAR_HPP
#include "parse_map_sizes.hpp"
#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/home/x3.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#pragma GCC diagnostic pop
namespace visual_tests
{
BOOST_FUSION_ADAPT_STRUCT (
visual_tests::map_size,
(std::size_t, width)
(std::size_t, height)
)
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
namespace visual_tests {
template <typename Iterator>
struct map_sizes_grammar : qi::grammar<Iterator, std::vector<map_size>(), ascii::space_type>
namespace x3 = boost::spirit::x3;
using x3::ulong_;
auto const map_sizes_grammar = x3::rule<class map_sizes_grammar_type, std::vector<map_size> >{} =
(ulong_ >> ',' >> ulong_) % ';' ;
void parse_map_sizes(std::string const & str, std::vector<map_size> & sizes)
{
map_sizes_grammar() : map_sizes_grammar::base_type(start)
boost::spirit::x3::ascii::space_type space;
std::string::const_iterator iter = str.begin();
std::string::const_iterator end = str.end();
if (!boost::spirit::x3::phrase_parse(iter, end, map_sizes_grammar, space, sizes))
{
using namespace boost::spirit::qi;
using namespace boost::phoenix;
int_type int_;
_1_type _1;
_2_type _2;
_val_type _val;
start = (int_ >> ',' >> int_)[push_back(_val, construct<map_size>(_1, _2))] % ';';
throw std::runtime_error("Failed to parse list of sizes: '" + str + "'");
}
qi::rule<Iterator, std::vector<map_size>(), ascii::space_type> start;
};
}
#endif
}

View file

@ -0,0 +1,36 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2016 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef VISUAL_TESTS_PARSE_MAP_SIZES_HPP
#define VISUAL_TESTS_PARSE_MAP_SIZES_HPP
#include "config.hpp"
#include <vector>
#include <string>
namespace visual_tests {
void parse_map_sizes(std::string const & str, std::vector<map_size> & sizes);
}
#endif //VISUAL_TESTS_PARSE_MAP_SIZES_HPP

View file

@ -2,7 +2,7 @@
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2015 Artem Pavlenko
* Copyright (C) 2016 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -25,9 +25,11 @@
#include <future>
#include <atomic>
#include <mapnik/load_map.hpp>
#include "runner.hpp"
#include "parse_map_sizes.hpp"
namespace visual_tests
{
@ -348,19 +350,7 @@ result_list runner::test_one(runner::path_type const& style_path,
}
}
}
return results;
}
void runner::parse_map_sizes(std::string const & str, std::vector<map_size> & sizes) const
{
boost::spirit::ascii::space_type space;
std::string::const_iterator iter = str.begin();
std::string::const_iterator end = str.end();
if (!boost::spirit::qi::phrase_parse(iter, end, map_sizes_parser_, space, sizes))
{
throw std::runtime_error("Failed to parse list of sizes: '" + str + "'");
}
}
}

View file

@ -2,7 +2,7 @@
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2015 Artem Pavlenko
* Copyright (C) 2016 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -26,7 +26,6 @@
#include "config.hpp"
#include "report.hpp"
#include "renderer.hpp"
#include "map_sizes_grammar.hpp"
namespace visual_tests
{
@ -58,9 +57,7 @@ private:
result_list test_one(path_type const & style_path,
report_type & report,
std::atomic<std::size_t> & fail_limit) const;
void parse_map_sizes(std::string const & str, std::vector<map_size> & sizes) const;
const map_sizes_grammar<std::string::const_iterator> map_sizes_parser_;
const path_type styles_dir_;
const config defaults_;
const std::size_t jobs_;
@ -71,4 +68,4 @@ private:
}
#endif
#endif //VISUAL_TEST_RUNNER_HPP