From 0e5013fb03abbfbef43a9605136af4850afa776f Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 14 May 2013 14:55:08 +0100 Subject: [PATCH] + add feature_parser implementation --- include/mapnik/json/feature_parser.hpp | 57 +++++++++++++++++++++++ src/json/feature_parser.cpp | 63 ++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 include/mapnik/json/feature_parser.hpp create mode 100644 src/json/feature_parser.cpp diff --git a/include/mapnik/json/feature_parser.hpp b/include/mapnik/json/feature_parser.hpp new file mode 100644 index 000000000..3e1a6d3aa --- /dev/null +++ b/include/mapnik/json/feature_parser.hpp @@ -0,0 +1,57 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2012 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 MAPNIK_FEATURE_PARSER_HPP +#define MAPNIK_FEATURE_PARSER_HPP + +// mapnik +#include +#include +#include +#include + +// boost +#include + +// stl +#include + +namespace mapnik { namespace json { + +template struct feature_grammar; + +template +class feature_parser : private mapnik::noncopyable +{ + typedef Iterator iterator_type; + typedef mapnik::feature_impl feature_type; +public: + feature_parser(mapnik::transcoder const& tr); + ~feature_parser(); + bool parse(iterator_type first, iterator_type last, mapnik::feature_impl & f); +private: + boost::scoped_ptr > grammar_; +}; + +}} + +#endif //MAPNIK_FEATURE_PARSER_HPP diff --git a/src/json/feature_parser.cpp b/src/json/feature_parser.cpp new file mode 100644 index 000000000..688f0fe52 --- /dev/null +++ b/src/json/feature_parser.cpp @@ -0,0 +1,63 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2013 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 + * + *****************************************************************************/ + +#include + +#define BOOST_SPIRIT_USE_PHOENIX_V3 1 + +// mapnik +#include +#include + +// boost +#include +#include + +namespace mapnik { namespace json { + +#if BOOST_VERSION >= 104700 + + template + feature_parser::feature_parser(mapnik::transcoder const& tr) + : grammar_(new feature_grammar(tr)) {} + + template + feature_parser::~feature_parser() {} +#endif + + template + bool feature_parser::parse(iterator_type first, iterator_type last, mapnik::feature_impl & f) + { +#if BOOST_VERSION >= 104700 + using namespace boost::spirit; + return qi::phrase_parse(first, last, (*grammar_)(boost::phoenix::ref(f)), standard_wide::space); +#else + std::ostringstream s; + s << BOOST_VERSION/100000 << "." << BOOST_VERSION/100 % 1000 << "." << BOOST_VERSION % 100; + throw std::runtime_error("mapnik::feature_parser::parse() requires at least boost 1.47 while your build was compiled against boost " + s.str()); + return false; +#endif + } + +template class feature_parser; + +}}