![]() |
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 //$Id$ 00024 00025 #ifndef ATTRIBUTE_COLLECTOR_HPP 00026 #define ATTRIBUTE_COLLECTOR_HPP 00027 00028 // mapnik 00029 #include <mapnik/filter.hpp> 00030 #include <mapnik/expression.hpp> 00031 #include <mapnik/feature_layer_desc.hpp> 00032 #include <mapnik/rule.hpp> 00033 // stl 00034 #include <set> 00035 #include <iostream> 00036 00037 namespace mapnik { 00038 00039 struct symbolizer_attributes : public boost::static_visitor<> 00040 { 00041 symbolizer_attributes(std::set<std::string>& names) 00042 : names_(names) {} 00043 00044 template <typename T> 00045 void operator () (T const&) const {} 00046 void operator () (text_symbolizer const& sym) 00047 { 00048 names_.insert(sym.get_name()); 00049 } 00050 void operator () (shield_symbolizer const& sym) 00051 { 00052 names_.insert(sym.get_name()); 00053 } 00054 private: 00055 std::set<std::string>& names_; 00056 }; 00057 00058 template <typename FeatureT> 00059 class attribute_collector : public filter_visitor<FeatureT> 00060 { 00061 private: 00062 std::set<std::string>& names_; 00063 public: 00064 00065 attribute_collector(std::set<std::string>& names) 00066 : names_(names) {} 00067 00068 void visit(filter<FeatureT>& /*filter*/) 00069 { 00070 //not interested 00071 } 00072 00073 void visit(expression<FeatureT>& exp) 00074 { 00075 property<FeatureT>* pf; 00076 if ((pf = dynamic_cast<property<FeatureT>*>(&exp))) 00077 { 00078 names_.insert(pf->name()); 00079 } 00080 } 00081 void visit(rule_type const& r) 00082 { 00083 const symbolizers& symbols = r.get_symbolizers(); 00084 symbolizers::const_iterator symIter=symbols.begin(); 00085 symbolizer_attributes attr(names_); 00086 while (symIter != symbols.end()) 00087 { 00088 boost::apply_visitor(attr,*symIter++); 00089 } 00090 filter_ptr const& filter = r.get_filter(); 00091 filter->accept(*this); 00092 } 00093 00094 virtual ~attribute_collector() {} 00095 private: 00096 // no copying 00097 attribute_collector(attribute_collector const&); 00098 attribute_collector& operator=(attribute_collector const&); 00099 }; 00100 } 00101 00102 #endif //ATTRIBUTE_COLLECTOR_HPP