diff --git a/include/mapnik/json/error_handler.hpp b/include/mapnik/json/error_handler.hpp index 7ca761ca8..dd14a21d5 100644 --- a/include/mapnik/json/error_handler.hpp +++ b/include/mapnik/json/error_handler.hpp @@ -24,20 +24,20 @@ #define MAPNIK_JSON_ERROR_HANDLER_HPP #include +#include +#include namespace mapnik { namespace json { -struct where_message +template +struct error_handler { - using result_type = std::string; - - template - std::string operator() (Iterator first, Iterator last, std::size_t size) const + using result_type = void; + void operator() ( + Iterator first, Iterator last, + Iterator err_pos, boost::spirit::info const& what) const { - std::string str(first, last); - if (str.length() > size) - return str.substr(0, size) + "..." ; - return str; + MAPNIK_LOG_ERROR(error_handler) << what << " expected but got: " << std::string(err_pos, std::min(err_pos + 16,last)); } }; diff --git a/include/mapnik/json/feature_collection_grammar_impl.hpp b/include/mapnik/json/feature_collection_grammar_impl.hpp index d7076b67f..93c49b7b9 100644 --- a/include/mapnik/json/feature_collection_grammar_impl.hpp +++ b/include/mapnik/json/feature_collection_grammar_impl.hpp @@ -22,6 +22,7 @@ // mapnik +#include #include // spirit::qi diff --git a/include/mapnik/json/feature_grammar.hpp b/include/mapnik/json/feature_grammar.hpp index d9b50d8c9..104c6b2e7 100644 --- a/include/mapnik/json/feature_grammar.hpp +++ b/include/mapnik/json/feature_grammar.hpp @@ -31,7 +31,6 @@ #include #include #include -#include // spirit::qi #include #include @@ -89,18 +88,6 @@ struct extract_geometry } }; -template -struct error_handler -{ - using result_type = void; - void operator() ( - Iterator first, Iterator last, - Iterator err_pos, boost::spirit::info const& what) const - { - MAPNIK_LOG_ERROR(error_handler) << what << " expected but got: " << std::string(err_pos, std::min(err_pos + 16,last)); - } -}; - template > struct feature_grammar : qi::grammar feature_grammar::feature_grammar(mapnik::transcoder const& tr) : feature_grammar::base_type(feature,"feature"), json_(), - put_property_(put_property(tr)), - error_handler(ErrorHandler()) + put_property_(put_property(tr)) { qi::lit_type lit; qi::long_long_type long_long; diff --git a/include/mapnik/json/geometry_grammar.hpp b/include/mapnik/json/geometry_grammar.hpp index 677ef804f..25e724e42 100644 --- a/include/mapnik/json/geometry_grammar.hpp +++ b/include/mapnik/json/geometry_grammar.hpp @@ -29,7 +29,7 @@ #include #include #include -#include + // spirit::qi #include #include @@ -40,7 +40,7 @@ namespace qi = boost::spirit::qi; namespace standard_wide = boost::spirit::standard_wide; using standard_wide::space_type; -template +template > struct geometry_grammar : qi::grammar @@ -51,8 +51,9 @@ struct geometry_grammar : qi::symbols geometry_type_dispatch; qi::rule geometry_collection; positions_grammar coordinates; - boost::phoenix::function where_message_; boost::phoenix::function create_geometry; + // error handler + boost::phoenix::function const error_handler; }; }} diff --git a/include/mapnik/json/geometry_grammar_impl.hpp b/include/mapnik/json/geometry_grammar_impl.hpp index 0f587cfc8..b75af426b 100644 --- a/include/mapnik/json/geometry_grammar_impl.hpp +++ b/include/mapnik/json/geometry_grammar_impl.hpp @@ -21,6 +21,7 @@ *****************************************************************************/ // mapnik +#include #include #include @@ -33,8 +34,8 @@ namespace mapnik { namespace json { -template -geometry_grammar::geometry_grammar() +template +geometry_grammar::geometry_grammar() : geometry_grammar::base_type(start,"geometry") { @@ -83,20 +84,10 @@ geometry_grammar::geometry_grammar() // give some rules names geometry.name("Geometry"); geometry_collection.name("GeometryCollection"); - geometry_type_dispatch.name("Geometry dispatch"); + geometry_type_dispatch.name("Geometry type"); coordinates.name("Coordinates"); // error handler - on_error - ( - start - , std::clog - << boost::phoenix::val("Error! Expecting ") - << _4 // what failed? - << boost::phoenix::val(" here: \"") - << where_message_(_3, _2, 16) // max 16 chars - << boost::phoenix::val("\"") - << std::endl - ); + on_error(start, error_handler(_1, _2, _3, _4)); } }} diff --git a/include/mapnik/json/positions_grammar.hpp b/include/mapnik/json/positions_grammar.hpp index d85c91c08..3e4ca4c33 100644 --- a/include/mapnik/json/positions_grammar.hpp +++ b/include/mapnik/json/positions_grammar.hpp @@ -62,7 +62,7 @@ struct push_position_impl } }; -template +template > struct positions_grammar : qi::grammar { @@ -74,7 +74,8 @@ struct positions_grammar : qi::rule >(), space_type> rings_array; boost::phoenix::function set_position; boost::phoenix::function push_position; - boost::phoenix::function message; + // error handler + boost::phoenix::function const error_handler; }; }} diff --git a/include/mapnik/json/positions_grammar_impl.hpp b/include/mapnik/json/positions_grammar_impl.hpp index 3f42d1deb..0c1a5b789 100644 --- a/include/mapnik/json/positions_grammar_impl.hpp +++ b/include/mapnik/json/positions_grammar_impl.hpp @@ -34,8 +34,8 @@ namespace mapnik { namespace json { -template -positions_grammar::positions_grammar() +template +positions_grammar::positions_grammar() : positions_grammar::base_type(coords,"coordinates") { qi::lit_type lit; @@ -60,18 +60,13 @@ positions_grammar::positions_grammar() rings_array = lit('[') >> rings % lit(',') >> lit(']') ; coords.name("Coordinates"); + pos.name("Position"); + ring.name("Ring"); + rings.name("Rings"); + rings_array.name("Rings array"); + // error handler - on_error - ( - coords, - std::clog - << boost::phoenix::val("Error! Expecting ") - << _4 // what failed? - << boost::phoenix::val(" here: \"") - << message(_3, _2, 16) // max 16 chars - << boost::phoenix::val("\"") - << std::endl - ); + on_error(coords, error_handler(_1, _2, _3, _4)); } }} diff --git a/include/mapnik/json/symbolizer_grammar.hpp b/include/mapnik/json/symbolizer_grammar.hpp index 84751bd17..5f5ebe7c6 100644 --- a/include/mapnik/json/symbolizer_grammar.hpp +++ b/include/mapnik/json/symbolizer_grammar.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include namespace mapnik { namespace json { @@ -113,7 +114,7 @@ struct put_property } }; -template +template > struct symbolizer_grammar : qi::grammar { using json_value_type = util::variant; @@ -210,7 +211,7 @@ struct symbolizer_grammar : qi::grammar phoenix::function put_property_; // error - //boost::phoenix::function where_message_; + on_error(sym, error_handler(_1, _2, _3, _4)); }; diff --git a/include/mapnik/json/topojson_grammar.hpp b/include/mapnik/json/topojson_grammar.hpp index 4cb8db83d..c09b7e5fe 100644 --- a/include/mapnik/json/topojson_grammar.hpp +++ b/include/mapnik/json/topojson_grammar.hpp @@ -25,6 +25,7 @@ // mapnik #include +#include #include #include #include @@ -44,21 +45,7 @@ namespace fusion = boost::fusion; namespace standard_wide = boost::spirit::standard_wide; using standard_wide::space_type; -struct where_message -{ - using result_type = std::string; - - template - std::string operator() (Iterator first, Iterator last, std::size_t size) const - { - std::string str(first, last); - if (str.length() > size) - return str.substr(0, size) + "..." ; - return str; - } -}; - -template +template > struct topojson_grammar : qi::grammar { @@ -91,8 +78,8 @@ private: qi::rule attribute_value; // id qi::rule id; - // error - boost::phoenix::function where_message_; + // error handler + boost::phoenix::function const error_handler; }; }} diff --git a/include/mapnik/json/topojson_grammar_impl.hpp b/include/mapnik/json/topojson_grammar_impl.hpp index 10aab4ccd..3231c9f67 100644 --- a/include/mapnik/json/topojson_grammar_impl.hpp +++ b/include/mapnik/json/topojson_grammar_impl.hpp @@ -30,8 +30,8 @@ namespace fusion = boost::fusion; namespace standard_wide = boost::spirit::standard_wide; using standard_wide::space_type; -template -topojson_grammar::topojson_grammar() +template +topojson_grammar::topojson_grammar() : topojson_grammar::base_type(topology, "topojson") { qi::lit_type lit; @@ -220,19 +220,8 @@ topojson_grammar::topojson_grammar() polygon.name("polygon"); multi_polygon.name("multi_polygon"); geometry_collection.name("geometry_collection"); - - on_error - ( - topology - , std::clog - << phoenix::val("Error! Expecting ") - << _4 // what failed? - << phoenix::val(" here: \"") - << where_message_(_3, _2, 16) // where? 16 is max chars to output - << phoenix::val("\"") - << std::endl - ); - + // error handler + on_error(topology, error_handler(_1, _2, _3, _4)); } }}