/home/andreas/src/svn/mapnik/include/mapnik/rule.hpp

Go to the documentation of this file.
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 #ifndef RULE_HPP
00024 #define RULE_HPP
00025 // stl
00026 #include <string>
00027 #include <vector>
00028 // boost
00029 #include <boost/shared_ptr.hpp>
00030 #include <boost/variant.hpp>
00031 // mapnik
00032 #include <mapnik/line_symbolizer.hpp>
00033 #include <mapnik/line_pattern_symbolizer.hpp>
00034 #include <mapnik/polygon_symbolizer.hpp>
00035 #include <mapnik/polygon_pattern_symbolizer.hpp>
00036 #include <mapnik/point_symbolizer.hpp>
00037 #include <mapnik/raster_symbolizer.hpp>
00038 #include <mapnik/shield_symbolizer.hpp>
00039 #include <mapnik/text_symbolizer.hpp>
00040 #include <mapnik/filter.hpp>
00041 #include <mapnik/filter_visitor.hpp>
00042 
00043 namespace mapnik
00044 {
00045     inline bool operator==(point_symbolizer const& lhs,
00046                            point_symbolizer const& rhs)
00047     {
00048         return (&lhs == &rhs); 
00049     }
00050     inline bool operator==(line_symbolizer const& lhs,
00051                            line_symbolizer const& rhs)
00052     {
00053         return (&lhs == &rhs); 
00054     }
00055     inline bool operator==(line_pattern_symbolizer const& lhs,
00056                            line_pattern_symbolizer const& rhs)
00057     {
00058         return (&lhs == &rhs); 
00059     }
00060 
00061     inline bool operator==(polygon_symbolizer const& lhs,
00062                            polygon_symbolizer const& rhs)
00063     {
00064         return (&lhs == &rhs); 
00065     }
00066     
00067     inline bool operator==(polygon_pattern_symbolizer const& lhs,
00068                            polygon_pattern_symbolizer const& rhs)
00069     {
00070         return (&lhs == &rhs); 
00071     }
00072     
00073     inline bool operator==(raster_symbolizer const& lhs,
00074                            raster_symbolizer const& rhs)
00075     {
00076         return (&lhs == &rhs); 
00077     }
00078     
00079     inline bool operator==(text_symbolizer const& lhs,
00080                            text_symbolizer const& rhs)
00081     {
00082         return (&lhs == &rhs); 
00083     }
00084     
00085     inline bool operator==(shield_symbolizer const& lhs,
00086                            shield_symbolizer const& rhs)
00087     {
00088         return (&lhs == &rhs); 
00089     }
00090     
00091     typedef boost::variant<point_symbolizer,
00092                            line_symbolizer,
00093                            line_pattern_symbolizer,
00094                            polygon_symbolizer,
00095                            polygon_pattern_symbolizer,
00096                            raster_symbolizer,
00097                            shield_symbolizer,
00098                            text_symbolizer> symbolizer;
00099     
00100         
00101     typedef std::vector<symbolizer> symbolizers;
00102     
00103     template <typename FeatureT> class all_filter;
00104 
00105     template <typename FeatureT,template <typename> class Filter>
00106     class rule
00107     {
00108         typedef Filter<FeatureT> filter_type;
00109         typedef boost::shared_ptr<filter_type> filter_ptr;
00110     private:
00111 
00112         std::string name_;
00113         std::string title_;
00114         std::string abstract_;
00115         double min_scale_;
00116         double max_scale_;
00117         symbolizers syms_;
00118         filter_ptr filter_;
00119         bool else_filter_;
00120     public:
00121         rule()
00122             : name_(),
00123               title_(),
00124               abstract_(),
00125               min_scale_(0),
00126               max_scale_(std::numeric_limits<double>::infinity()),
00127               syms_(),
00128               filter_(new all_filter<FeatureT>),
00129               else_filter_(false) {}
00130                 
00131         rule(const std::string& name,
00132              const std::string& title="",
00133              double min_scale_denominator=0,
00134              double max_scale_denominator=std::numeric_limits<double>::infinity())
00135             : name_(name),
00136               title_(title),
00137               min_scale_(min_scale_denominator),
00138               max_scale_(max_scale_denominator),
00139               syms_(),
00140               filter_(new all_filter<FeatureT>),
00141               else_filter_(false) {}
00142             
00143         rule(const rule& rhs)    
00144             : name_(rhs.name_),
00145               title_(rhs.title_),
00146               abstract_(rhs.abstract_),
00147               min_scale_(rhs.min_scale_),
00148               max_scale_(rhs.max_scale_),
00149               syms_(rhs.syms_),
00150               filter_(rhs.filter_),
00151               else_filter_(rhs.else_filter_) {}
00152         
00153         rule& operator=(rule const& rhs) 
00154         {
00155             rule tmp(rhs);
00156             swap(tmp);
00157             return *this;
00158         }
00159         bool operator==(rule const& other)
00160         {
00161             return  (this == &other); 
00162         }
00163         
00164         void set_max_scale(double scale)
00165         {
00166             max_scale_=scale;
00167         }
00168         
00169         double get_max_scale() const
00170         {
00171             return max_scale_;
00172         }
00173         
00174         void set_min_scale(double scale)
00175         {
00176             min_scale_=scale;
00177         }
00178 
00179         double get_min_scale() const
00180         {
00181             return min_scale_;
00182         }
00183 
00184        
00185         void set_name(std::string const& name)
00186         {
00187             name_=name;
00188         }
00189         
00190         std::string const& get_name() const
00191         {
00192             return name_;
00193         }
00194         
00195         std::string const& get_title() const
00196         {
00197             return  title_;
00198         }
00199 
00200         void set_title(std::string const& title)
00201         {
00202             title_=title;
00203         }
00204   
00205         void set_abstract(std::string const& abstract)
00206         {
00207             abstract_=abstract;
00208         }
00209         
00210         std::string const& get_abstract() const
00211         {
00212             return abstract_;
00213         }
00214                 
00215         void append(const symbolizer& sym)
00216         {
00217             syms_.push_back(sym);
00218         }
00219         
00220         void remove_at(size_t index)
00221         {
00222             if (index < syms_.size())
00223             {
00224                 syms_.erase(syms_.begin()+index);
00225             }
00226         }
00227         
00228         const symbolizers& get_symbolizers() const
00229         {
00230             return syms_;
00231         }
00232         
00233         symbolizers::const_iterator begin()
00234         {
00235             return syms_.begin();
00236         }
00237         
00238         symbolizers::const_iterator end()
00239         {
00240             return syms_.end();
00241         }
00242         
00243         void set_filter(const filter_ptr& filter)
00244         {
00245             filter_=filter;
00246         }
00247 
00248         filter_ptr const& get_filter() const
00249         {
00250             return filter_;
00251         }
00252         
00253         void set_else(bool else_filter)
00254         {
00255             else_filter_=else_filter;
00256         }
00257      
00258         bool has_else_filter() const
00259         {
00260             return else_filter_;
00261         }
00262         
00263         bool active(double scale) const
00264         {
00265             return ( scale >= min_scale_ - 1e-6 && scale < max_scale_ + 1e-6);
00266         }
00267 
00268         void accept(filter_visitor<FeatureT>& v) const
00269         {
00270             v.visit(*this);
00271         }
00272         
00273     private:
00274         
00275         void swap(rule& rhs) throw()
00276         {
00277             name_=rhs.name_;
00278             title_=rhs.title_;
00279             abstract_=rhs.abstract_;
00280             min_scale_=rhs.min_scale_;
00281             max_scale_=rhs.max_scale_;
00282             syms_=rhs.syms_;
00283             filter_=rhs.filter_;
00284             else_filter_=rhs.else_filter_;
00285         }
00286     };
00287 
00288     typedef rule<Feature,filter> rule_type;
00289 }
00290 
00291 #endif //RULE_HPP

Generated on Thu Jul 19 17:59:27 2007 for Mapnik by  doxygen 1.4.7