Add parse_image_filters function to avoid python bindings access the internal structs.
This commit is contained in:
parent
e5d1418417
commit
df7db521bb
4 changed files with 27 additions and 20 deletions
|
@ -28,7 +28,6 @@
|
|||
#include <mapnik/value_error.hpp>
|
||||
#include "mapnik_enumeration.hpp"
|
||||
#include <mapnik/feature_type_style.hpp>
|
||||
#include <mapnik/image_filter_grammar.hpp> // image_filter_grammar
|
||||
#include <mapnik/image_filter_types.hpp> // generate_image_filters
|
||||
|
||||
using mapnik::feature_type_style;
|
||||
|
@ -45,18 +44,12 @@ std::string get_image_filters(feature_type_style & style)
|
|||
|
||||
void set_image_filters(feature_type_style & style, std::string const& filters)
|
||||
{
|
||||
std::string::const_iterator itr = filters.begin();
|
||||
std::string::const_iterator end = filters.end();
|
||||
mapnik::image_filter_grammar<std::string::const_iterator,
|
||||
std::vector<mapnik::filter::filter_type> > filter_grammar;
|
||||
std::vector<mapnik::filter::filter_type> new_filters;
|
||||
bool result = boost::spirit::qi::phrase_parse(itr,end,
|
||||
filter_grammar,
|
||||
boost::spirit::qi::ascii::space,
|
||||
new_filters);
|
||||
if (!result || itr!=end)
|
||||
|
||||
bool result = parse_image_filters(filters, new_filters);
|
||||
if (!result)
|
||||
{
|
||||
throw mapnik::value_error("failed to parse image-filters: '" + std::string(itr,end) + "'");
|
||||
throw mapnik::value_error("failed to parse image-filters: '" + filters + "'");
|
||||
}
|
||||
style.image_filters().swap(new_filters);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#ifndef MAPNIK_IMAGE_FILTER_TYPES_HPP
|
||||
#define MAPNIK_IMAGE_FILTER_TYPES_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/config.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/variant/variant_fwd.hpp>
|
||||
|
||||
|
@ -125,7 +128,9 @@ inline std::ostream& operator<< (std::ostream& os, invert)
|
|||
|
||||
inline std::ostream& operator<< (std::ostream& os, filter_type const& filter);
|
||||
|
||||
bool generate_image_filters(std::back_insert_iterator<std::string> & sink, std::vector<filter_type> const& v);
|
||||
MAPNIK_DECL bool generate_image_filters(std::back_insert_iterator<std::string> & sink, std::vector<filter_type> const& v);
|
||||
|
||||
MAPNIK_DECL bool parse_image_filters(std::string const& filters, std::vector<filter_type>& image_filters);
|
||||
|
||||
}}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*****************************************************************************/
|
||||
// mapnik
|
||||
#include <mapnik/image_filter_types.hpp>
|
||||
#include <mapnik/image_filter_grammar.hpp> // image_filter_grammar
|
||||
|
||||
// boost
|
||||
#include <boost/spirit/include/karma.hpp>
|
||||
|
@ -63,4 +64,17 @@ bool generate_image_filters(std::back_insert_iterator<std::string>& sink, std::v
|
|||
return r;
|
||||
}
|
||||
|
||||
bool parse_image_filters(std::string const& filters, std::vector<filter_type>& image_filters)
|
||||
{
|
||||
std::string::const_iterator itr = filters.begin();
|
||||
std::string::const_iterator end = filters.end();
|
||||
mapnik::image_filter_grammar<std::string::const_iterator,
|
||||
std::vector<mapnik::filter::filter_type> > filter_grammar;
|
||||
bool r = boost::spirit::qi::phrase_parse(itr,end,
|
||||
filter_grammar,
|
||||
boost::spirit::qi::ascii::space,
|
||||
image_filters);
|
||||
return r && itr==end;
|
||||
}
|
||||
|
||||
}}
|
||||
|
|
|
@ -425,15 +425,10 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
|
|||
if (filters)
|
||||
{
|
||||
std::string filter_str = *filters;
|
||||
std::string::const_iterator itr = filter_str.begin();
|
||||
std::string::const_iterator end = filter_str.end();
|
||||
bool result = boost::spirit::qi::phrase_parse(itr,end,
|
||||
sty.get_tree().image_filters_grammar,
|
||||
boost::spirit::qi::ascii::space,
|
||||
style.image_filters());
|
||||
if (!result || itr!=end)
|
||||
bool result = filter::parse_image_filters(filter_str, style.image_filters());
|
||||
if (!result)
|
||||
{
|
||||
throw config_error("failed to parse image-filters: '" + std::string(itr,end) + "'");
|
||||
throw config_error("failed to parse image-filters: '" + filter_str + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue