move boost::phoenix usage into _impl.hpp

This commit is contained in:
artemp 2016-03-24 17:11:06 +00:00
parent b73a42131a
commit 450533ebc6
2 changed files with 46 additions and 43 deletions

View file

@ -32,53 +32,19 @@
#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_function.hpp>
#pragma GCC diagnostic pop
namespace mapnik { namespace json {
using position_type = mapnik::geometry::point<double>;
using box_type = box2d<double>;
using boxes_type = std::vector<std::pair<box_type, std::pair<std::size_t, std::size_t>>>;
namespace qi = boost::spirit::qi;
struct calculate_bounding_box_impl
{
using result_type = void;
template <typename T0, typename T1>
result_type operator() (T0 & bbox, T1 const& pos) const
{
if (pos)
{
double x = pos->x;
double y = pos->y;
if (!bbox.valid())
{
bbox.init(x, y, x, y); //TODO: add init(x,y) convinience method
}
else
{
bbox.expand_to_include(x, y);
}
}
}
};
struct push_box_impl
{
using result_type = void;
template <typename T0, typename T1, typename T2, typename T3>
void operator() (T0 & boxes, T1 const& begin, T2 const& box, T3 const& range) const
{
if (box.valid()) boxes.emplace_back(box, std::make_pair(std::distance(begin, range.begin()), std::distance(range.begin(), range.end())));
}
};
template <typename Iterator, typename Boxes = boxes_type, typename ErrorHandler = error_handler<Iterator> >
template <typename Iterator, typename Boxes, typename ErrorHandler = error_handler<Iterator> >
struct extract_bounding_box_grammar :
qi::grammar<Iterator, void(Boxes&), space_type>
{
using position_type = mapnik::geometry::point<double>;
using boxes_type = Boxes;
using box_type = typename Boxes::value_type::first_type;
extract_bounding_box_grammar();
// rules
qi::rule<Iterator, void(boxes_type&), space_type> start;
@ -91,11 +57,6 @@ struct extract_bounding_box_grammar :
qi::rule<Iterator, void(box_type&), space_type> rings_array;
// generic JSON support
json::generic_json<Iterator> json;
// phoenix functions
boost::phoenix::function<push_box_impl> push_box;
boost::phoenix::function<calculate_bounding_box_impl> calculate_bounding_box;
// error handler
boost::phoenix::function<ErrorHandler> const error_handler;
};
}}

View file

@ -29,12 +29,48 @@
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/repository/include/qi_iter_pos.hpp>
#include <boost/spirit/include/phoenix_function.hpp>
// stl
#include <iostream>
#include <string>
namespace mapnik { namespace json {
struct calculate_bounding_box_impl
{
using result_type = void;
template <typename T0, typename T1>
result_type operator() (T0 & bbox, T1 const& pos) const
{
if (pos)
{
typename T0::value_type x = pos->x;
typename T0::value_type y = pos->y;
if (!bbox.valid())
{
bbox.init(x, y);
}
else
{
bbox.expand_to_include(x, y);
}
}
}
};
struct push_box_impl
{
using result_type = void;
template <typename T0, typename T1, typename T2, typename T3>
void operator() (T0 & boxes, T1 const& begin, T2 const& box, T3 const& range) const
{
if (box.valid()) boxes.emplace_back(box,
std::make_pair(std::distance(begin,
range.begin()),
std::distance(range.begin(), range.end())));
}
};
namespace repo = boost::spirit::repository;
template <typename Iterator, typename Boxes, typename ErrorHandler>
@ -61,6 +97,12 @@ extract_bounding_box_grammar<Iterator, Boxes, ErrorHandler>::extract_bounding_bo
using qi::fail;
using qi::on_error;
// phoenix functions
boost::phoenix::function<push_box_impl> push_box;
boost::phoenix::function<calculate_bounding_box_impl> calculate_bounding_box;
// error handler
boost::phoenix::function<ErrorHandler> const error_handler;
start = features(_r1)
;