File indexing completed on 2024-04-28 03:40:45
0001 /************************************************************************************* 0002 * Copyright (C) 2007 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 OPERATOR_H 0020 #define OPERATOR_H 0021 0022 #include "object.h" 0023 #include "analitzaexport.h" 0024 0025 namespace Analitza 0026 { 0027 0028 /** 0029 * \class Operator 0030 * 0031 * \ingroup AnalitzaModule 0032 * 0033 * \brief Is the operator representation in the trees. 0034 */ 0035 0036 class ANALITZA_EXPORT Operator : public Object 0037 { 0038 public: 0039 /** Specifies the type of an operator */ 0040 enum OperatorType { 0041 none=0, 0042 plus, times, minus, divide, quotient, 0043 power, root, factorial, 0044 _and, _or, _xor, _not, 0045 gcd, lcm, rem, factorof, 0046 max, min, 0047 lt, gt, eq, neq, leq, geq, implies, 0048 approx, abs, floor, ceiling, 0049 sin, cos, tan, 0050 sec, csc, cot, 0051 sinh, cosh, tanh, 0052 sech, csch, coth, 0053 arcsin, arccos, arctan, 0054 arccot,// arccoth, 0055 arccosh, arccsc, arccsch, 0056 arcsec, arcsech, arcsinh, arctanh, 0057 exp, ln, log, 0058 conjugate, arg, real, imaginary, 0059 sum, product, diff, 0060 card, scalarproduct, selector, _union, 0061 forall, exists, 0062 0063 map, filter, 0064 0065 transpose, 0066 0067 function, nOfOps 0068 }; 0069 /** Constructor. Creates an operator with @p t type .*/ 0070 explicit Operator(OperatorType t) : Object(oper), m_optype(t) {} 0071 0072 /** Copy constructor */ 0073 constexpr Operator(const Operator&) = default; 0074 0075 /** Destructor */ 0076 ~Operator() override {} 0077 0078 /** Sets an operator type to the object */ 0079 void setOperator(OperatorType t) { m_optype=t; } 0080 0081 /** Returns the number of params expected for the operator type. */ 0082 int nparams() const { return nparams(m_optype); } 0083 0084 /** Returns the operator type. */ 0085 OperatorType operatorType() const { return m_optype; } 0086 0087 /** Returns the string expression representation of the operator. */ 0088 QString name() const; 0089 0090 /** Returns whether @p o is equal to this operator. */ 0091 bool operator==(const Operator& o) const { return m_optype==o.m_optype; } 0092 0093 /** Returns whether @p o is equal to this operator. */ 0094 bool operator==(OperatorType o) const { return m_optype==o; } 0095 0096 /** Returns whether @p o is different to this operator. */ 0097 bool operator!=(OperatorType o) const { return m_optype!=o; } 0098 0099 /** Returns whether @p o is different to this operator. */ 0100 bool operator!=(const Operator& o) const { return m_optype!=o.m_optype; } 0101 0102 /** Makes this operator equal to @p a. */ 0103 Operator operator=(const Operator &a) { m_optype=a.operatorType(); return *this;} 0104 0105 /** Returns the multiplicity operator. e.g. 5+5+5+5=5*4 -> times is the multiplicityOperator of plus. */ 0106 OperatorType multiplicityOperator() const { return multiplicityOperator(m_optype); } 0107 0108 /** Returns if it is a trigonometric operator. */ 0109 bool isTrigonometric() const { return isTrigonometric(m_optype); } 0110 0111 /** Returns whether this operator needs bounding. */ 0112 bool isBounded() const; 0113 0114 /** Returns whether it is a correct object. */ 0115 bool isCorrect() const { return m_type==Object::oper && m_optype!=Operator::none;} 0116 0117 Operator inverse() const; 0118 0119 /** Returns the multiplicity operator of an operator @p t. e.g. 5+5+5+5=5*4 -> times is the multiplicityOperator of plus. */ 0120 static OperatorType multiplicityOperator(const OperatorType& t); 0121 0122 /** Converts a @p s operator tag to the operator. */ 0123 static OperatorType toOperatorType(const QString &s); 0124 0125 virtual bool matches(const Object*, QMap<QString, const Object*>*) const override; 0126 virtual bool decorate(const QMap< QString, Object** >& ) { return false; } 0127 0128 virtual QVariant accept(AbstractExpressionVisitor*) const override; 0129 virtual Operator* copy() const override; 0130 0131 static const char words[nOfOps][14]; 0132 private: 0133 /** Returns if it is a trigonometric operator. */ 0134 static bool isTrigonometric(OperatorType o); 0135 0136 /** Returns the expected number of parameters of a type. If there can be multiple parameters, -1 is returned */ 0137 static int nparams(OperatorType o); 0138 0139 OperatorType m_optype; 0140 }; 0141 0142 } 0143 0144 #endif