-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables.cpp
executable file
·91 lines (71 loc) · 1.31 KB
/
variables.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
*
* This is a simple variable list for scicalc
*
* Friedrich Feichtinger, 13.09.2012
*
*/
#include "variables.h"
#include "parseException.h"
#include <cmath>
#include <QDebug>
QList<Variable*>Variables::variables;
void Variables::init()
{
variables.clear();
// math
set("pi", M_PI);
// mechanic
set("_g", 9.81);
set("_G", 6.67384e-11);
// electromagnetism
set("_mu0", 4*M_PI*1e-7);
set("_eps0", 8.85418781762e-12);
set("_c0", 299792458);
set("_e", 1.60217653e-19);
// thermodynamic
set("_kB", 1.3806488e-23);
// quantum physic
set("_h", 6.62606957e-34);
}
void Variables::set(QString name, long double value)
{
//qDebug() << "setVariable" << name;
// search the list for this name
Variable* var=search(name);
// check if variable allready exists
if(var==0)
{
// no: let's make a new variable
var=new Variable(name, value);
variables.append(var);
}
else
{
// yes: let's change it's value
var->value=value;
}
}
long double Variables::get(QString name)
{
Variable* var=search(name);
if(var==0)
{
throw ParseException("variable '"+name+"' has no value yet");
}
else
{
return var->value;
}
}
Variable* Variables::search(QString name)
{
for(int i=0; i<variables.length(); i++)
{
if(variables.at(i)->name==name)
{
return variables.at(i);
}
}
return 0;
}