00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef FILTER_FACTORY_HPP
00026 #define FILTER_FACTORY_HPP
00027
00028 #include <mapnik/config_error.hpp>
00029 #include <mapnik/filter_parser.hpp>
00030 #include <mapnik/unicode.hpp>
00031
00032 namespace mapnik
00033 {
00034 using std::string;
00035
00036 template<typename FeatureT>
00037 class MAPNIK_DECL filter_factory
00038 {
00039 public:
00040 static filter_ptr compile(string const& str,transcoder const& tr)
00041 {
00042 stack<shared_ptr<filter<FeatureT> > > filters;
00043 stack<shared_ptr<expression<FeatureT> > > exps;
00044 filter_grammar<FeatureT> grammar(filters,exps,tr);
00045 parse_info<std::string::const_iterator> info = parse(str.begin(), str.end(), grammar, space_p);
00046 if ( !info.full)
00047 {
00048 std::ostringstream os;
00049 os << "Failed to parse filter expression:\n"
00050 << str << "\nParsing aborted at '" << *info.stop << "'";
00051
00052 throw config_error( os.str() );
00053 }
00054
00055 if ( ! filters.empty())
00056 {
00057 return filters.top();
00058 }
00059 else
00060 {
00061
00062 return filter_ptr(new none_filter<FeatureT>());
00063 }
00064 }
00065 };
00066
00067 MAPNIK_DECL filter_ptr create_filter (std::string const& wkt, std::string const& encoding);
00068 MAPNIK_DECL filter_ptr create_filter (std::string const& wkt);
00069
00070 }
00071
00072 #endif //FILTER_FACTORY_HPP