/home/andreas/src/svn/mapnik/include/mapnik/logical.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 //$Id$
00023 
00024 #ifndef LOGICAL_HPP
00025 #define LOGICAL_HPP
00026 
00027 #include <mapnik/filter.hpp>
00028 
00029 namespace mapnik
00030 {
00031     template <typename FeatureT> 
00032     struct logical_and : public filter<FeatureT>  
00033     {
00034         logical_and(filter<FeatureT> const& filter1,
00035                     filter<FeatureT> const& filter2)
00036             : filter<FeatureT>(),
00037               filter1_(filter1.clone()),
00038               filter2_(filter2.clone()) {}
00039         
00040         logical_and(logical_and const& other)
00041             : filter<FeatureT>(),
00042               filter1_(other.filter1_->clone()),
00043               filter2_(other.filter2_->clone()) {}
00044 
00045         bool pass(const FeatureT& feature) const
00046         {
00047             return (filter1_->pass(feature) && 
00048                 filter2_->pass(feature));
00049         }
00050         std::string to_string() const
00051         {
00052             return "("+filter1_->to_string()+" and "+filter2_->to_string()+")";
00053         }
00054         
00055         filter<FeatureT>* clone() const
00056         {
00057             return new logical_and(*this);
00058         }
00059 
00060         void accept(filter_visitor<FeatureT>& v)
00061         {
00062             filter1_->accept(v);
00063             filter2_->accept(v);
00064             v.visit(*this);
00065         }
00066 
00067         virtual ~logical_and()
00068         {
00069             delete filter1_;
00070             delete filter2_;
00071         }
00072         
00073     private:
00074         filter<FeatureT>* filter1_;
00075         filter<FeatureT>* filter2_;
00076     };
00077 
00078     template <typename FeatureT> 
00079     struct logical_or : public filter<FeatureT>  
00080     {
00081         
00082         logical_or(const filter<FeatureT>& filter1,const filter<FeatureT>& filter2)
00083             : filter<FeatureT>(),
00084               filter1_(filter1.clone()),
00085               filter2_(filter2.clone()) {}
00086         
00087         logical_or(logical_or const& other)
00088             : filter<FeatureT>(),
00089               filter1_(other.filter1_->clone()),
00090               filter2_(other.filter2_->clone()) {}
00091 
00092         bool pass(const FeatureT& feature) const
00093         {
00094             if (filter1_->pass(feature))
00095             {
00096                 return true;
00097             }
00098             else
00099             {
00100                 return filter2_->pass(feature);
00101             }
00102         }
00103         filter<FeatureT>* clone() const
00104         {
00105             return new logical_or(*this);
00106         }
00107 
00108         void accept(filter_visitor<FeatureT>& v)
00109         {
00110             filter1_->accept(v);
00111             filter2_->accept(v);
00112             v.visit(*this);
00113         }
00114         std::string to_string() const
00115         {
00116             return "("+filter1_->to_string()+" or "+filter2_->to_string()+")";
00117         }       
00118         virtual ~logical_or()
00119         {  
00120             delete filter1_;
00121             delete filter2_;
00122         }
00123     private:
00124         filter<FeatureT>* filter1_;
00125         filter<FeatureT>* filter2_;
00126     };
00127 
00128     template <typename FeatureT> 
00129     struct logical_not : public filter<FeatureT>  
00130     {
00131         logical_not(filter<FeatureT> const& _filter)
00132             : filter<FeatureT>(),
00133               filter_(_filter.clone()) {}
00134         logical_not(logical_not const& other)
00135             : filter<FeatureT>(),
00136               filter_(other.filter_->clone()) {}
00137 
00138         int type() const
00139         {
00140             return filter<FeatureT>::LOGICAL_OPS;
00141         }
00142 
00143         bool pass(const FeatureT& feature) const
00144         {
00145             return !(filter_->pass(feature));
00146         }
00147 
00148         filter<FeatureT>* clone() const
00149         {
00150             return new logical_not(*this);
00151         }
00152         
00153         void accept(filter_visitor<FeatureT>& v)
00154         {
00155             filter_->accept(v);
00156             v.visit(*this);
00157         }
00158         std::string to_string() const
00159         {
00160             return "not ("+filter_->to_string()+")";
00161         }
00162          
00163         ~logical_not() 
00164         {
00165             delete filter_;
00166         }
00167     private:
00168         filter<FeatureT>* filter_;
00169     };
00170 }
00171  
00172 #endif //LOGICAL_HPP

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