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