/home/andreas/src/svn/mapnik/include/mapnik/math_expr.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 MATH_EXPR_HPP
00025 #define MATH_EXPR_HPP
00026 
00027 #include <mapnik/expression.hpp>
00028 
00029 namespace mapnik
00030 {
00031     template <typename T>
00032     struct add
00033     {
00034         T operator () (T const& left, T const& right)
00035         {
00036             return left + right;
00037         }
00038         static std::string to_string()
00039         {
00040             return "+";
00041         } 
00042     };
00043 
00044     template <typename T>
00045     struct sub
00046     {
00047         T operator () (T const& left, T const& right)
00048         {
00049             return left - right;
00050         }
00051         static std::string to_string()
00052         {
00053             return "-";
00054         } 
00055     };
00056     
00057     template <typename T>
00058     struct mult
00059     {
00060         T operator () (T const& left, T const& right)
00061         {
00062             return left * right;
00063         }
00064         static std::string to_string()
00065         {
00066             return "*";
00067         } 
00068     };
00069     
00070     template <typename T>
00071     struct div
00072     {
00073         T operator () (T const& left, T const& right)
00074         {
00075             return left / right;
00076         }
00077         static std::string to_string()
00078         {
00079             return "/";
00080         } 
00081     };
00082     
00083     template <typename FeatureT,typename Op>
00084     struct math_expr_b : public expression<FeatureT>
00085     {
00086         math_expr_b(expression<FeatureT> const& left,
00087                     expression<FeatureT> const& right)
00088             : expression<FeatureT>(),
00089               left_(left.clone()), 
00090               right_(right.clone()) {}
00091         math_expr_b(math_expr_b const& other)
00092             : expression<FeatureT>(),
00093               left_(other.left_->clone()),
00094               right_(other.right_->clone()) {}
00095 
00096         value get_value(FeatureT const& feature) const
00097         {
00098             return Op ()(left_->get_value(feature),right_->get_value(feature));
00099         }
00100 
00101         void accept(filter_visitor<FeatureT>& v)
00102         {
00103             left_->accept(v);
00104             right_->accept(v);
00105             v.visit(*this);
00106         }
00107 
00108         expression<FeatureT>* clone() const
00109         {
00110             return new math_expr_b<FeatureT,Op>(*this);
00111         }
00112         std::string to_string() const
00113         {
00114             return "("+left_->to_string() + Op::to_string() + right_->to_string()+")";
00115         }
00116 
00117         ~math_expr_b() 
00118         {
00119             delete left_;
00120             delete right_;
00121         }
00122     private:
00123         expression<FeatureT>* left_;
00124         expression<FeatureT>* right_;   
00125     }; 
00126 }
00127 
00128 #endif //

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