diff --git a/include/mapnik/json/extract_bounding_box_grammar.hpp b/include/mapnik/json/extract_bounding_box_grammar.hpp index 2df4def47..906e7126d 100644 --- a/include/mapnik/json/extract_bounding_box_grammar.hpp +++ b/include/mapnik/json/extract_bounding_box_grammar.hpp @@ -32,53 +32,19 @@ #pragma GCC diagnostic push #include #include -#include #pragma GCC diagnostic pop namespace mapnik { namespace json { -using position_type = mapnik::geometry::point; -using box_type = box2d; -using boxes_type = std::vector>>; - namespace qi = boost::spirit::qi; -struct calculate_bounding_box_impl -{ - using result_type = void; - template - 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 - 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 > +template > struct extract_bounding_box_grammar : qi::grammar { + using position_type = mapnik::geometry::point; + using boxes_type = Boxes; + using box_type = typename Boxes::value_type::first_type; extract_bounding_box_grammar(); // rules qi::rule start; @@ -91,11 +57,6 @@ struct extract_bounding_box_grammar : qi::rule rings_array; // generic JSON support json::generic_json json; - // phoenix functions - boost::phoenix::function push_box; - boost::phoenix::function calculate_bounding_box; - // error handler - boost::phoenix::function const error_handler; }; }} diff --git a/include/mapnik/json/extract_bounding_box_grammar_impl.hpp b/include/mapnik/json/extract_bounding_box_grammar_impl.hpp index f2a89d5c1..8a7fc331c 100644 --- a/include/mapnik/json/extract_bounding_box_grammar_impl.hpp +++ b/include/mapnik/json/extract_bounding_box_grammar_impl.hpp @@ -29,12 +29,48 @@ #include #include #include +#include // stl #include #include namespace mapnik { namespace json { +struct calculate_bounding_box_impl +{ + using result_type = void; + template + 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 + 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 @@ -61,6 +97,12 @@ extract_bounding_box_grammar::extract_bounding_bo using qi::fail; using qi::on_error; + // phoenix functions + boost::phoenix::function push_box; + boost::phoenix::function calculate_bounding_box; + // error handler + boost::phoenix::function const error_handler; + start = features(_r1) ;