00001 00002 // MathCore = a WYSIWYG equation editor + a powerful math engine // 00003 // Copyright (C) 2003 by Francesco Montorsi // 00004 // // 00005 // This library is free software; you can redistribute it and/or // 00006 // modify it under the terms of the GNU Lesser General Public // 00007 // License as published by the Free Software Foundation; either // 00008 // version 2.1 of the License, or (at your option) any later // 00009 // version. // 00010 // // 00011 // This library 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 // 00017 // License along with this program; if not, write to the Free // 00018 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, // 00019 // MA 02111-1307, USA. // 00020 // // 00021 // For any comment, suggestion or feature request, please contact // 00022 // the administrator of the project at frm@users.sourceforge.net // 00023 // // 00030 00031 00032 00033 // optimization for GCC compiler 00034 #ifdef __GNUG__ 00035 #pragma implementation "AddSubOp.h" 00036 #endif 00037 00038 // includes 00039 #include "mc/mcprec.h" 00040 #ifdef __BORLANDC__ 00041 #pragma hdrstop 00042 #endif 00043 00044 #ifndef mcPRECOMP 00045 #include "mc/AddSubOp.h" 00046 #include "mc/ElementArray.h" 00047 #endif 00048 00049 00050 00051 mcIMPLEMENT_MAIN_CLASS(mcAddSubOp, mcOperator); 00052 00053 00054 00055 00056 // ----------------- 00057 // mcADDSUBOP 00058 // ----------------- 00059 00060 mcAddSubOp::mcAddSubOp(mcElementType t) 00061 { 00062 // be sure that everything is okay 00063 mcASSERT(t == mcET_ADDOP || 00064 t == mcET_SUBOP, wxT("Invalid element type")); 00065 00066 mcCREATE_HELPER_CLASSES(mcAddSubOp); 00067 00068 // we are now ready 00069 data_AddProperty(mcEP_INITIALIZED); 00070 if (data_GetType() != t) 00071 hlp()->mdata_nType = t; 00072 } 00073 00074 00075 00076 // ----------------- 00077 // mcADDSUBOPMATH 00078 // ----------------- 00079 00080 bool mcAddSubOpHelpers::math_CanBeApplied(const mcElement &l, const mcElement &r) const 00081 { return l.math_CanBeAddedWith(r); } 00082 00083 mcBasicOpRes mcAddSubOpHelpers::math_ApplySimple(mcElement &p1, const mcElement &p2) const 00084 { 00085 if (!math_CanBeApplied(p1, p2)) 00086 return mcBOR_INVALID; 00087 00088 if (data_isAddOp()) 00089 p1.math_SimpleAdd(p2); 00090 else 00091 p1.math_SimpleSubtract(p2); 00092 00093 return mcBOR_REMOVE_OPERAND; 00094 } 00095 00096 mcBasicOpRes mcAddSubOpHelpers::math_Apply(mcElement &p1, const mcElement &p2, mcElement *pp) const 00097 { 00098 if (!math_CanBeApplied(p1, p2)) 00099 return mcBOR_INVALID; 00100 00101 return p1.math_Add(p2, pp, data_isAddOp()); 00102 } 00103 00104 mcRealValue mcAddSubOpHelpers::math_Evaluate(mcRealValue v1, mcRealValue v2) const 00105 { 00106 if (data_isAddOp()) 00107 return v1+v2; 00108 return v1-v2; 00109 } 00110
[ Top ] |