![]() |
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 EXPRESSION_HPP 00026 #define EXPRESSION_HPP 00027 00028 #include <mapnik/value.hpp> 00029 #include <mapnik/filter_visitor.hpp> 00030 00031 namespace mapnik { 00032 template <typename FeatureT> class filter_visitor; 00033 template <typename FeatureT> 00034 class expression 00035 { 00036 public: 00037 virtual value get_value(FeatureT const& feature) const=0; 00038 virtual void accept(filter_visitor<FeatureT>& v)=0; 00039 virtual expression<FeatureT>* clone() const=0; 00040 virtual std::string to_string() const=0; 00041 virtual ~expression() {} 00042 }; 00043 00044 template <typename FeatureT> 00045 class literal : public expression<FeatureT> 00046 { 00047 public: 00048 literal(bool val) 00049 : expression<FeatureT>(), 00050 value_(val) {} 00051 literal(int val) 00052 : expression<FeatureT>(), 00053 value_(val) {} 00054 literal(double val) 00055 : expression<FeatureT>(), 00056 value_(val) {} 00057 literal(UnicodeString const& val) 00058 : expression<FeatureT>(), 00059 value_(val) {} 00060 literal(literal const& other) 00061 : expression<FeatureT>(), 00062 value_(other.value_) {} 00063 00064 value get_value(FeatureT const& /*feature*/) const 00065 { 00066 return value_; 00067 } 00068 00069 void accept(filter_visitor<FeatureT>& v) 00070 { 00071 v.visit(*this); 00072 } 00073 00074 expression<FeatureT>* clone() const 00075 { 00076 return new literal(*this); 00077 } 00078 00079 std::string to_string() const 00080 { 00081 return value_.to_expression_string(); 00082 } 00083 ~literal() {} 00084 private: 00085 value value_; 00086 }; 00087 00088 00089 template <typename FeatureT> 00090 class property : public expression<FeatureT> 00091 { 00092 public: 00093 property(std::string const& name) 00094 : expression<FeatureT>(), 00095 name_(name) 00096 {} 00097 00098 property(property const& other) 00099 : expression<FeatureT>(), 00100 name_(other.name_) 00101 {} 00102 00103 value get_value(FeatureT const& feature) const 00104 { 00105 return feature[name_]; 00106 } 00107 void accept(filter_visitor<FeatureT>& v) 00108 { 00109 v.visit(*this); 00110 } 00111 expression<FeatureT>* clone() const 00112 { 00113 return new property(*this); 00114 } 00115 std::string const& name() const 00116 { 00117 return name_; 00118 } 00119 00120 std::string to_string() const 00121 { 00122 return "["+name_+"]"; 00123 } 00124 00125 ~property() {} 00126 00127 private: 00128 std::string name_; 00129 }; 00130 } 00131 00132 #endif //EXPRESSION_HPP