src/tools/values/vebMathExpr.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #include "vCore.h"
00029 #include "vebMathExpr.h"
00030 
00031 #include "mathexpr.h"
00032 
00033 namespace vValue {
00034 namespace Expr {
00035 namespace Bindings {
00036 
00038 MathExpr::MathExpr(tString const &expr) : m_operation(new ROperation(expr.c_str())), m_vararray(0), m_funcarray(0), m_varsSize(0), m_functionsSize(0) {}
00039 
00043 MathExpr::MathExpr(tString const &expr, varmap_t const &vars, funcmap_t const &functions) {
00044     // what a mess. why can't this darn library just use stl functions? :s
00045     m_vararray = new RVar*[vars.size()];
00046     unsigned int i = 0;
00047     for(varmap_t::const_iterator iter = vars.begin(); iter != vars.end(); ++iter, ++i) {
00048         m_vararray[i] = new RVar(iter->first.c_str(), iter->second);
00049     }
00050     m_funcarray = new RFunction*[functions.size()];
00051     unsigned int j = 0;
00052     m_varsSize = vars.size();
00053     m_functionsSize = functions.size();
00054     for(funcmap_t::const_iterator iter = functions.begin(); iter != functions.end(); ++iter, ++j) {
00055         m_funcarray[j] = new RFunction(iter->second);
00056         m_funcarray[j]->SetName(iter->first.c_str());
00057     }
00058     m_operation = boost::shared_ptr<ROperation>(new ROperation(expr.c_str(), vars.size(), m_vararray, functions.size(), m_funcarray));
00059 }
00060 
00061 MathExpr::~MathExpr() {
00062     if(m_vararray != 0) {
00063         for(int i = 0; i < m_varsSize; i++) {
00064             delete m_vararray[i];
00065         }
00066         delete[] m_vararray;
00067     }
00068     if(m_funcarray != 0) {
00069         for(int i = 0; i < m_functionsSize; i++) {
00070             delete m_funcarray[i];
00071         }
00072         delete[] m_funcarray;
00073     }
00074 }
00075 
00076 Base *MathExpr::copy(void) const {
00077     return new MathExpr(*this);
00078 }
00079 
00080 Variant MathExpr::GetValue() const {
00081     return m_operation->Val();
00082 }
00083 
00084 //class blah {
00085 //public:
00086 //    blah() {
00087 //        float x=4,y=3;
00088 //              vValue::Bindings::MathExpr::varmap_t vars;
00089 //              vars[tString("x")] = &x;
00090 //              vars[tString("y")] = &y;
00091 //              vValue::Bindings::MathExpr::funcmap_t functions;
00092 //              functions[tString("f")] = &sinf;
00093 //              vValue::Bindings::MathExpr expr(tString("x+f(y)"), vars, functions);
00094 //        std::cerr << expr.GetFloat() << std::endl;
00095 //    }
00096 //};
00097 //blah asdfgsf;
00098 
00099 }
00100 }
00101 }

Generated on Sat Mar 15 22:56:04 2008 for Armagetron Advanced by  doxygen 1.5.4