Logo Search packages:      
Sourcecode: kalgebra version File versions  Download package

variables.cpp

#include "variables.h"

Variables::Variables(){
//    afegeix("x", 33.0f);
      modifica("true", 1.0f);
      modifica("false", 0.0f);
      modifica("pi", 3.141592653f);
      modifica("e", 2.718281828f);
      modifica("euler", 0.5772156649f);
//    modifica("ยบ", 3.141592653f/180.);
}

inline void Variables::afegeix(QString id, QDomElement val){
      modifica(id,val);
}

void Variables::treu(QString id, bool *ex){
      QValueList<struct VARIABLE>::iterator it;
      struct VARIABLE aux;
      it = vars.begin() ;
      for(; it != vars.end(); ++it){ 
            aux = *it;
            if(aux.nom == id){
                  vars.remove(it);
                  if(ex!=NULL) *ex=true;
                  break;
            }
      }
}

void Variables::modifica(QString id, double new_val){
      QDomDocument a;
      QDomElement e=a.createElement("cn");
      e.appendChild(a.createTextNode(QString("%1").arg(new_val, 0, 'g', 16)));
      
      modifica(id,e);
}

void Variables::modifica(QString id, QDomElement new_val){
      struct VARIABLE aux;
      
      QValueList<struct VARIABLE>::iterator it;
      for(it = vars.begin(); it != vars.end(); ++it){ 
            aux = *it;
            if(aux.nom == id){
                  vars.remove(it);
                  break;
            }
      }
      aux.nom=id;
      aux.valor=new_val;
      vars.append(aux);
}
QDomElement Variables::value(QString id, bool *ex){
// QDomElement Variables::value(QString id){
      struct VARIABLE aux;
      QValueList<struct VARIABLE>::iterator it;
      
      for(it = vars.begin(); it != vars.end(); ++it){ 
            aux = *it;
            if(aux.nom.stripWhiteSpace() == id.stripWhiteSpace()){
                  if(ex!=NULL) *ex=false;
                  return aux.valor;
            }
      }
      //error
      QDomDocument a; QString err("<cn \"constant\"> &NaN; </cn>");
      a.setContent(err);
      if(ex!=NULL) *ex=true;
      return a.documentElement();
}

QStringList Variables::getNoms(){
      struct VARIABLE aux;
      QStringList out;
      QValueList<struct VARIABLE>::iterator it;
      for(it = vars.begin(); it != vars.end(); ++it){ 
            aux = *it;
            out << aux.nom;
      }
      return out;
}

bool Variables::isvar(QDomElement e){
      if(e.tagName()=="ci"){
//          struct VARIABLE aux;
            QStringList out;
            QValueList<struct VARIABLE>::iterator it;
            for(it = vars.begin(); it != vars.end(); ++it){ 
                  if((*it).nom=="")
                        return true;
            }
      }
      return false;
}

Generated by  Doxygen 1.6.0   Back to index