File indexing completed on 2024-04-28 03:40:46

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 #include "variable.h"
0020 #include "abstractexpressionvisitor.h"
0021 #include "analitzautils.h"
0022 
0023 using namespace Analitza;
0024 
0025 Ci::Ci(const QString& b)
0026     : Object(variable), m_name(b), m_function(false), m_depth(-1)
0027 {
0028     Q_ASSERT(!b.isEmpty());
0029 }
0030 
0031 Ci::~Ci()
0032 {}
0033 
0034 Ci* Ci::copy() const
0035 {
0036     Ci *c = new Ci(m_name);
0037     c->m_function = m_function;
0038     c->m_depth = m_depth;
0039     return c;
0040 }
0041 
0042 QVariant Ci::accept(AbstractExpressionVisitor* e) const
0043 {
0044     return e->visit(this);
0045 }
0046 
0047 QString Ci::toMathML() const
0048 {
0049     if(m_function)
0050         return QStringLiteral("<ci type='function'>%1</ci>").arg(m_name);
0051     else
0052         return QStringLiteral("<ci>%1</ci>").arg(m_name);
0053 }
0054 
0055 bool Ci::matches(const Object* exp, QMap<QString, const Object*>* found) const
0056 {
0057     bool ret=false;
0058     const Object* v=found->value(m_name);
0059     if(v) {
0060         ret=AnalitzaUtils::equalTree(exp, v);
0061     } else {
0062         Q_ASSERT(!found->contains(m_name));
0063         found->insert(m_name, exp);
0064         ret=true;
0065     }
0066 //     qDebug() << "maaatch" << toString() << exp->toString() << ret;
0067     return ret;
0068 }
0069 
0070 QString Ci::toHtml() const
0071 {
0072     return QStringLiteral("<span class='%1'>%2</span>").arg(m_function ? QStringLiteral("func") : QStringLiteral("var"), m_name);
0073 }