refactor error handler to work with mapnik/debug macros

This commit is contained in:
artemp 2014-09-22 10:09:34 +01:00
parent e7e235a8b5
commit 5df668d126
2 changed files with 21 additions and 17 deletions

View file

@ -31,10 +31,11 @@
#include <mapnik/value.hpp>
#include <mapnik/json/generic_json.hpp>
#include <mapnik/json/value_converters.hpp>
#include <mapnik/debug.hpp>
// spirit::qi
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/support_line_pos_iterator.hpp>
namespace mapnik { namespace json {
@ -88,7 +89,19 @@ struct extract_geometry
}
};
template <typename Iterator, typename FeatureType>
template <typename Iterator>
struct error_handler
{
using result_type = void;
void operator() (
Iterator first, Iterator last,
Iterator err_pos, boost::spirit::info const& what) const
{
MAPNIK_LOG_WARN(error_handler) << what << " expected in input";
}
};
template <typename Iterator, typename FeatureType, typename ErrorHandler = error_handler<Iterator> >
struct feature_grammar :
qi::grammar<Iterator, void(FeatureType&),
space_type>
@ -110,7 +123,7 @@ struct feature_grammar :
phoenix::function<put_property> put_property_;
phoenix::function<extract_geometry> extract_geometry_;
// error handler
boost::phoenix::function<where_message> where_message_;
boost::phoenix::function<ErrorHandler> const error_handler;
// geometry
geometry_grammar<Iterator> geometry_grammar_;
};

View file

@ -26,11 +26,12 @@
namespace mapnik { namespace json {
template <typename Iterator, typename FeatureType>
feature_grammar<Iterator,FeatureType>::feature_grammar(mapnik::transcoder const& tr)
template <typename Iterator, typename FeatureType, typename ErrorHandler>
feature_grammar<Iterator,FeatureType,ErrorHandler>::feature_grammar(mapnik::transcoder const& tr)
: feature_grammar::base_type(feature,"feature"),
json_(),
put_property_(put_property(tr))
put_property_(put_property(tr)),
error_handler(ErrorHandler())
{
qi::lit_type lit;
qi::long_long_type long_long;
@ -116,17 +117,7 @@ feature_grammar<Iterator,FeatureType>::feature_grammar(mapnik::transcoder const&
properties.name("Properties");
attributes.name("Attributes");
on_error<fail>
(
feature
, 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
);
on_error<fail>(feature, error_handler(_1, _2, _3, _4));
}