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
00026 #ifndef REGEX_FILTER_HPP
00027 #define REGEX_FILTER_HPP
00028
00029 #include <mapnik/filter.hpp>
00030 #include <mapnik/expression.hpp>
00031
00032 #include <boost/regex.hpp>
00033 #include <boost/algorithm/string.hpp>
00034
00035 namespace mapnik
00036 {
00037 template <typename FeatureT>
00038 struct regex_filter : public filter<FeatureT>
00039 {
00040
00041 regex_filter(expression<FeatureT> const& exp,
00042 std::string const& pattern)
00043 : filter<FeatureT>(),
00044 exp_(exp.clone()),
00045 pattern_(pattern) {}
00046
00047 regex_filter(regex_filter const& other)
00048 : filter<FeatureT>(),
00049 exp_(other.exp_->clone()),
00050 pattern_(other.pattern_) {}
00051
00052 bool pass(FeatureT const& feature) const
00053 {
00054 std::string text=exp_->get_value(feature).to_string();
00055 boost::trim_if(text, boost::is_any_of("'"));
00056 return boost::regex_match(text,pattern_);
00057 }
00058
00059 void accept(filter_visitor<FeatureT>& v)
00060 {
00061 exp_->accept(v);
00062 v.visit(*this);
00063 }
00064
00065 filter<FeatureT>* clone() const
00066 {
00067 return new regex_filter(*this);
00068 }
00069 std::string to_string() const
00070 {
00071 return exp_->to_string()+".match("+pattern_.str()+")";
00072 }
00073 ~regex_filter()
00074 {
00075 delete exp_;
00076 }
00077
00078 private:
00079 expression<FeatureT>* exp_;
00080 boost::regex pattern_;
00081
00082 };
00083 }
00084
00085
00086 #endif //REGEX_FILTER_HPP