File indexing completed on 2024-04-28 03:40:45
0001 /************************************************************************************* 0002 * Copyright (C) 2007-2008 by Aleix Pol <aleixpol@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or * 0005 * modify it under the terms of the GNU General Public License * 0006 * as published by the Free Software Foundation; either version 2 * 0007 * of the License, or (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the Free Software * 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0017 *************************************************************************************/ 0018 0019 #ifndef OPERATIONS_H 0020 #define OPERATIONS_H 0021 0022 #include "operator.h" 0023 #include <expressiontype.h> 0024 0025 namespace Analitza 0026 { 0027 0028 class None; 0029 0030 class List; 0031 class Cn; 0032 class Vector; 0033 class Matrix; 0034 class CustomObject; 0035 class ExpressionType; 0036 0037 //WARNING this class can lead to some memory leaks ... we need to review all the methods and see if everything goes ok 0038 class Operations 0039 { 0040 public: 0041 typedef Object* (*UnaryOp)(Operator::OperatorType, Object*, QString**); 0042 typedef Object * (*BinaryOp)(Operator::OperatorType op, Object *, Object *, QString** correct); 0043 0044 static Object* reduce(Operator::OperatorType op, Object* oper, Object* oper1, QString** correct); 0045 static Object* reduceUnary(Operator::OperatorType op, Object* oper, QString** correct); 0046 0047 static QList<ExpressionType> infer(Analitza::Operator::OperatorType op); 0048 static QList<ExpressionType> inferUnary(Operator::OperatorType op); 0049 0050 private: 0051 static UnaryOp opsUnary[Object::custom+1]; 0052 static BinaryOp opsBinary[Object::custom+1][Object::custom+1]; 0053 0054 static Object* reduceValueNone(Operator::OperatorType op, Cn* oper, None *cntr, QString** correct); 0055 static Object* reduceNoneValue(Operator::OperatorType op, None *cntr, Cn* oper, QString** correct); 0056 static Object* reduceValueValue(Operator::OperatorType op, Cn *oper, const Cn* oper1, QString** correct); 0057 static Object* reduceUnaryValue(Operator::OperatorType op, Cn *oper, QString** correct); 0058 0059 static Object* reduceValueVector(Operator::OperatorType op, Cn *oper, Vector* vector, QString** correct); 0060 static Object* reduceVectorValue(Operator::OperatorType op, Vector* vector, Cn *oper, QString** correct); 0061 static Object* reduceVectorVector(Operator::OperatorType op, Vector* v1, Vector* v2, QString** correct); 0062 static Object* reduceMatrixVector(Operator::OperatorType op, Matrix* matrix, Vector* vector, QString** correct); 0063 static Object* reduceUnaryVector(Operator::OperatorType op, Vector* c, QString** correct); 0064 0065 static Object* reduceValueList(Operator::OperatorType op, Cn *oper, List* vector, QString** correct); 0066 static Object* reduceListList(Operator::OperatorType op, List* l1, List* l2, QString** correct); 0067 static Object* reduceUnaryList(Operator::OperatorType op, List* l, QString** correct); 0068 0069 static Object* reduceValueMatrix(Analitza::Operator::OperatorType op, Analitza::Cn* v, Analitza::Matrix* m1, QString** correct); 0070 static Object* reduceMatrixValue(Analitza::Operator::OperatorType op, Analitza::Matrix* m1, Analitza::Cn* v, QString** correct); 0071 static Object* reduceVectorMatrix(Operator::OperatorType op, Vector* vector, Matrix* matrix, QString** correct); 0072 static Object* reduceMatrixMatrix(Operator::OperatorType op, Matrix* m1, Matrix* m2, QString** correct); 0073 static Object* reduceUnaryMatrix(Analitza::Operator::OperatorType op, Analitza::Matrix* m, QString** correct); 0074 static Object* reduceMatrixNone(Operator::OperatorType op, Matrix* m, None *cntr, QString** correct); 0075 static Object* reduceNoneMatrix(Operator::OperatorType op, None *cntr, Matrix* m, QString** correct); 0076 0077 static Object* reduceCustomCustom(Operator::OperatorType op, CustomObject* v1, CustomObject* v2, QString** correct); 0078 0079 static Object* errorCase(const QString& error, QString** correct); // errorcntr is none None 0080 }; 0081 0082 } 0083 #endif