osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 00020 #ifndef OSGEARTHSYMBOLOGY_EXPRESSION_H 00021 #define OSGEARTHSYMBOLOGY_EXPRESSION_H 1 00022 00023 #include <osgEarthSymbology/Common> 00024 #include <osgEarth/Config> 00025 #include <osgEarth/GeoData> 00026 #include <osgEarth/TileKey> 00027 00028 namespace osgEarth { namespace Symbology 00029 { 00033 class OSGEARTHSYMBOLOGY_EXPORT NumericExpression 00034 { 00035 public: 00036 typedef std::pair<std::string,unsigned> Variable; 00037 typedef std::vector<Variable> Variables; 00038 00039 public: 00040 NumericExpression() { } 00041 00042 NumericExpression( const Config& conf ); 00043 00045 NumericExpression( const std::string& expr ); 00046 00048 NumericExpression( double staticValue ); 00049 00051 NumericExpression( const NumericExpression& rhs ); 00052 00054 const Variables& variables() const { return _vars; } 00055 00057 void set( const Variable& var, double value ); 00058 00060 double eval() const; 00061 00063 const std::string& expr() const { return _src; } 00064 00066 bool empty() const { return _src.empty(); } 00067 00068 public: 00069 Config getConfig() const; 00070 void mergeConfig( const Config& conf ); 00071 00072 private: 00073 enum Op { OPERAND, VARIABLE, ADD, SUB, MULT, DIV, MOD, MIN, MAX, LPAREN, RPAREN, COMMA }; // in low-high precedence order 00074 typedef std::pair<Op,double> Atom; 00075 typedef std::vector<Atom> AtomVector; 00076 typedef std::stack<Atom> AtomStack; 00077 00078 std::string _src; 00079 AtomVector _rpn; 00080 Variables _vars; 00081 double _value; 00082 bool _dirty; 00083 00084 void init(); 00085 }; 00086 00087 //-------------------------------------------------------------------- 00088 00092 class OSGEARTHSYMBOLOGY_EXPORT StringExpression 00093 { 00094 public: 00095 typedef std::pair<std::string,unsigned> Variable; 00096 typedef std::vector<Variable> Variables; 00097 00098 public: 00099 StringExpression() { } 00100 00101 StringExpression( const Config& conf ); 00102 00104 StringExpression( const std::string& expr ); 00105 00107 StringExpression( const StringExpression& rhs ); 00108 00110 const Variables& variables() const { return _vars; } 00111 00113 void set( const Variable& var, const std::string& value ); 00114 00116 const std::string& eval() const; 00117 00119 const std::string& expr() const { return _src; } 00120 00122 bool empty() const { return _src.empty(); } 00123 00124 void setURIContext( const URIContext& uriContext ) { _uriContext = uriContext; } 00125 const URIContext& uriContext() const { return _uriContext; } 00126 00127 public: 00128 Config getConfig() const; 00129 void mergeConfig( const Config& conf ); 00130 00131 private: 00132 enum Op { OPERAND, VARIABLE }; // in low-high precedence order 00133 typedef std::pair<Op,std::string> Atom; 00134 typedef std::vector<Atom> AtomVector; 00135 00136 std::string _src; 00137 AtomVector _infix; 00138 Variables _vars; 00139 std::string _value; 00140 bool _dirty; 00141 URIContext _uriContext; 00142 00143 void init(); 00144 }; 00145 00146 00147 00148 } } // namespace osgEarth::Symbology 00149 00150 #endif // OSGEARTHSYMBOLOGY_EXPRESSION_H