![]() |
C++ API DOCUMENTATION |
00001 /***************************************************************************** 00002 * 00003 * This file is part of Mapnik (c++ mapping toolkit) 00004 * 00005 * Copyright (C) 2006 Artem Pavlenko 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 * 00021 *****************************************************************************/ 00022 00023 00024 //$Id$ 00025 00026 #ifndef REGEX_FILTER_HPP 00027 #define REGEX_FILTER_HPP 00028 // mapnik 00029 #include <mapnik/filter.hpp> 00030 #include <mapnik/expression.hpp> 00031 // boost 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