|
Hormiga 1.0
|
00001 00002 /* 00003 # Hormiga - Software de cálculo programable. 00004 # 00005 # Copyright (C) 2008, 2009 Leonardo Román, Hugo J. Curti, Norma Ercoli, 00006 # Universidad Nacional del Centro de la Provincia de Buenos Aires 00007 # (UNCPBA) 00008 # 00009 # Este programa es parte de Hormiga. 00010 # 00011 # Hormiga es software libre. Puede redistribuirlo y/o modificarlo 00012 # bajo los términos de la Licencia Pública General de GNU según es 00013 # publicada por la Free Software Foundation, versión 2. Vea el archivo 00014 # COPIA (español, no oficial) o COPYING (inglés, oficial) en directorio 00015 # raíz. 00016 # 00017 # Hormiga se distribuye con la esperanza de que sea útil, pero SIN 00018 # NINGUNA GARANTÍA, incluso sin la garantía MERCANTIL implícita o sin 00019 # garantizar la CONVENIENCIA PARA UN PROPÓSITO PARTICULAR. Véase la 00020 # Licencia Pública General de GNU para más detalles. 00021 # 00022 # Debería haber recibido una copia de la Licencia Pública General junto 00023 # con Hormiga. Si no ha sido así, escriba a la Free Software 00024 # Foundation, Inc., en 675 Mass Ave, Cambridge, MA 02139, EEUU. 00025 # Añada también información sobre cómo contactar con usted mediante 00026 # correo electrónico y postal. 00027 # 00028 # This file is part of Hormiga. 00029 # 00030 # Hormiga is free software; you can redistribute it and/or modify 00031 # it under the terms of the GNU General Public License version 2 00032 # as published by the Free Software Foundation; see the file COPYING 00033 # in the top directory for details. 00034 # 00035 # Hormiga is distributed in the hope that it will be useful, 00036 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00037 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00038 # GNU General Public License for more details. 00039 # 00040 # You should have received a copy of the GNU General Public License 00041 # along with Hormiga; if not, write to the Free Software 00042 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00043 # USA 00044 */ 00045 00046 #ifndef FUNCTION_H 00047 #define FUNCTION_H 00048 00049 #include "defines.h" 00050 00051 #include "oper/operand.h" 00052 #include "statement/statement_interface.h" 00053 00054 00076 class Function 00077 { 00078 public: 00079 virtual T_MAGNITUDE eval ( T_FUNCTION_ARGUMENTS *argv ) = 0 ; 00080 virtual T_STRING getName () = 0 ; 00081 virtual int paramsCount() = 0 ; 00082 virtual ~Function() {} 00083 }; 00084 00088 class UserFunction : public Function , public Typeable 00089 { 00090 public: 00091 UserFunction( T_STRING &symbol , T_FUNCTION_ARGUMENTS *argv , 00092 VarValue* toRet , Statement *codeBlock ) ; 00093 T_MAGNITUDE eval ( T_FUNCTION_ARGUMENTS *argv ) ; 00094 int paramsCount() { return formalParams->count() ; } 00095 T_STRING getName () { return ( this->name ) ; } 00096 protected: 00097 T_FUNCTION_ARGUMENTS *formalParams ; 00098 Statement *code ; 00099 VarValue* toRet ; 00100 T_STRING name ; 00101 }; 00102 00107 class FunctionInstanceIterator 00108 { 00109 public: 00113 const T_MAGNITUDE* first () ; 00114 00118 const T_MAGNITUDE* next () ; 00119 00127 const T_MAGNITUDE* getCurrent () ; 00128 00132 int dimesionsCount () const { return this->dimensions ; } 00133 00137 int iterationsCount () const ; 00138 00139 FunctionInstanceIterator ( Function *f , T_FUNCTION_ARGUMENTS* realArgs ) ; 00140 ~FunctionInstanceIterator () ; 00141 protected: 00153 void setup ( Function *f , 00154 T_FUNCTION_ARGUMENTS* internalArguments , 00155 T_MAGNITUDE* data , 00156 int dimensions , 00157 int currentDimension 00158 ) ; 00160 FunctionInstanceIterator ( Function *f , 00161 T_FUNCTION_ARGUMENTS* internalArguments , 00162 T_MAGNITUDE* data , 00163 int dimensions , 00164 int currentDimension 00165 ) ; 00166 00167 bool hasNext () ; 00168 00169 FunctionInstanceIterator *nextDimension ; 00170 int dimensions ; 00171 // count from 0: 00172 int localDimension ; 00173 T_MAGNITUDE* data ; 00174 00175 // Original Sequence (don't delete it): 00176 Sequence *seq ; 00177 // local sequence current value (delete it): 00178 VarValue *currVal ; 00179 // Internal argv: 00180 T_FUNCTION_ARGUMENTS* args ; 00181 // Function for evaluate (don't delete it): 00182 Function *f ; 00183 }; 00184 00185 00187 class FunctionInstance : public Operand 00188 { 00189 public: 00190 virtual T_STRING toString () const ; 00191 virtual T_MAGNITUDE getValue () const ; 00192 virtual T_STRING getSymbol () const ; 00193 virtual bool isConstantExpresion () const ; 00194 FunctionInstanceIterator* getIterator () const ; 00195 FunctionInstance ( Function *f , T_FUNCTION_ARGUMENTS *argv ) ; 00196 virtual ~FunctionInstance () ; 00197 protected: 00198 T_MAGNITUDE eval ( T_FUNCTION_ARGUMENTS *argv ) const ; 00199 T_MAGNITUDE integrate ( T_FUNCTION_ARGUMENTS *reals , 00200 T_FUNCTION_ARGUMENTS *internals , 00201 T_INT_ARRAY *seqArgs , 00202 int actualArg = 0 ) const ; 00203 Function *f ; 00204 T_FUNCTION_ARGUMENTS *argv ; 00205 }; 00206 00207 #endif // FUNCTION_H