+ add feature_parser implementation

This commit is contained in:
artemp 2013-05-14 14:55:08 +01:00
parent 26302e19af
commit 0e5013fb03
2 changed files with 120 additions and 0 deletions

View file

@ -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 <mapnik/config.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/noncopyable.hpp>
#include <mapnik/unicode.hpp>
// boost
#include <boost/scoped_ptr.hpp>
// stl
#include <vector>
namespace mapnik { namespace json {
template <typename Iterator, typename FeatureType> struct feature_grammar;
template <typename Iterator>
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<feature_grammar<iterator_type,feature_type> > grammar_;
};
}}
#endif //MAPNIK_FEATURE_PARSER_HPP

View file

@ -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 <boost/version.hpp>
#define BOOST_SPIRIT_USE_PHOENIX_V3 1
// mapnik
#include <mapnik/json/feature_parser.hpp>
#include <mapnik/json/feature_grammar.hpp>
// boost
#include <boost/version.hpp>
#include <boost/spirit/include/qi.hpp>
namespace mapnik { namespace json {
#if BOOST_VERSION >= 104700
template <typename Iterator>
feature_parser<Iterator>::feature_parser(mapnik::transcoder const& tr)
: grammar_(new feature_grammar<iterator_type,feature_type>(tr)) {}
template <typename Iterator>
feature_parser<Iterator>::~feature_parser() {}
#endif
template <typename Iterator>
bool feature_parser<Iterator>::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<std::string::const_iterator>;
}}