File indexing completed on 2024-04-28 03:40:39
0001 /************************************************************************************* 0002 * Copyright (C) 2007-2009 by Aleix Pol <aleixpol@kde.org> * 0003 * Copyright (C) 2014 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com> * 0004 * * 0005 * This program is free software; you can redistribute it and/or * 0006 * modify it under the terms of the GNU General Public License * 0007 * as published by the Free Software Foundation; either version 2 * 0008 * of the License, or (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the Free Software * 0017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0018 *************************************************************************************/ 0019 0020 #ifndef ANALITZAUTILS_H 0021 #define ANALITZAUTILS_H 0022 0023 #include <QStringList> 0024 #include "object.h" 0025 #include "analitzaexport.h" 0026 0027 namespace Analitza 0028 { 0029 class Object; 0030 class Container; 0031 class Variables; 0032 class Expression; 0033 class Apply; 0034 class List; 0035 } 0036 0037 /** 0038 * \namespace AnalitzaUtils 0039 * 0040 * \brief Utils for manipulate the objects of the tree. 0041 * 0042 * \ingroup AnalitzaModule 0043 */ 0044 0045 namespace AnalitzaUtils 0046 { 0047 0048 /** Convenience function */ 0049 void ANALITZA_EXPORT objectWalker(const Analitza::Expression& o, const QByteArray& prefix=QByteArray()); 0050 0051 /** Creates a QVariant out of an Expression @p res */ 0052 QVariant ANALITZA_EXPORT expressionToVariant(const Analitza::Expression& res); 0053 0054 /** Creates an expression out of a QVariant @p v, it will assert if it's not the correct type. */ 0055 Analitza::Expression ANALITZA_EXPORT variantToExpression(const QVariant& v); 0056 0057 QString ANALITZA_EXPORT generateDependencyGraph(const Analitza::Variables* v); 0058 0059 bool hasTheVar(const QSet<QString>& vars, const Analitza::Object * o); 0060 bool hasTheVar(const QSet<QString>& vars, const Analitza::Apply * a); 0061 bool hasTheVar(const QSet<QString>& vars, const Analitza::Container * c); 0062 0063 bool isLambda(const Analitza::Object* o); 0064 ANALITZA_EXPORT QStringList dependencies(const Analitza::Object* o, const QStringList& scope); 0065 0066 /** Returns whether there is any variable in the @p o tree. 0067 @p bvars tells the already defined variables (which won't return true). */ 0068 bool hasVars(const Analitza::Object* o, 0069 const QStringList& bvars=QStringList()); 0070 0071 /** Returns whether @p o1 is equal to @p o2. */ 0072 bool equalTree(const Analitza::Object * o1, const Analitza::Object * o2); 0073 0074 /** Prints an expression tree from a node @p o. @p prefix will be the start of every item line */ 0075 void objectWalker(const Analitza::Object* o, const QByteArray& prefix=QByteArray()); 0076 0077 QString listToString(const Analitza::List* list); 0078 0079 Analitza::Object* replaceDepth(int depth, Analitza::Object* tree, Analitza::Object* towhat); 0080 0081 /** tells how much @p depth is being used inside @p tree */ 0082 int countDepth(int depth, const Analitza::Object* tree); 0083 } 0084 0085 #endif // ANALITZAUTILS_H