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

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 VARIABLES_H
0020 #define VARIABLES_H
0021 
0022 #include <qobjectdefs.h>
0023 #include <QHash>
0024 
0025 #include "analitzaexport.h"
0026 
0027 namespace Analitza
0028 {
0029 
0030 class Cn;
0031 class Expression;
0032 class Object;
0033 
0034 
0035 /**
0036  * \class Variables
0037  * 
0038  * \ingroup AnalitzaModule
0039  *
0040  * \brief Stores the variables in a hash map and make them available.
0041  */
0042 
0043 class ANALITZA_EXPORT Variables : public QHash<QString, Object*>
0044 {
0045     Q_GADGET
0046     public:
0047         /** 
0048         *    Creates an empty variable hash table with the usual constants
0049         */
0050         Variables();
0051         
0052         /**
0053         *    Copy constructor, copies the old one, a bit heavy, be careful.
0054         */
0055         Variables(const Variables& v);
0056         
0057         /** Destroys the object */
0058         ~Variables();
0059         
0060         /**
0061         *    Modifies the value of the variable called @p name,
0062         *    and if didn't exist, a @p name variable is created with an @p o value.
0063         */
0064         void modify(const QString& name, const Object* o);
0065         
0066         /**
0067         *    Modifies the value of the variable called @p name,
0068         *    and if didn't exist, a @p name variable is created with an @p e expression.
0069         */
0070         void modify(const QString& name, const Expression& o);
0071         
0072         /**
0073         *    The same as the last one but having @p d as a value for @p name.
0074         */
0075         Cn* modify(const QString& name, const double& d);
0076         
0077         /**
0078         *    The @p orig named variable will be called @p dest , then @p orig will be removed.
0079         */
0080         void rename(const QString& orig, const QString& dest);
0081         
0082         /**
0083          * Adds again the initial constants
0084          */
0085         void initializeConstants();
0086         
0087         /** @returns the expression contained by the @p name identifier. */
0088         Expression valueExpression(const QString& name) const;
0089          
0090         QString toString() const;
0091 };
0092 
0093 }
0094 
0095 #endif