-
Notifications
You must be signed in to change notification settings - Fork 0
/
CVarDB.cpp
73 lines (63 loc) · 1.56 KB
/
CVarDB.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
#include "CVarDB.h"
#include <cstring>
CVarDB::CVarDB() : m_nSize{1}
{
//ctor
//Create default ans variable
if (m_pDB[0].SetName("ans"))
m_pDB[0] = 0;
else
throw "Bad Allocation of ans";
}
CVariable* CVarDB::search(const char* name)
{
//search the database for the variable name
for (int i = 0; i < m_nSize; ++i)
{
if (strcmp(m_pDB[i].Name(), name) == 0)
return &m_pDB[i];
}
return NULL; //Return null if we can't find the name.
}
CMatrix CVarDB::getVal(const char*name)
{
return search(name)->Value();
}
CVariable* CVarDB::createVar(const char* name)
{
//Actually just create a new variable of the same name with value 0.
return createVar(name, 0);
}
CVariable* CVarDB::createVar(const char* name, const double& d)
{
if (m_nSize < SIZE_DB) //if we have room
{
m_pDB[m_nSize].SetName(name);
m_pDB[m_nSize].SetValue(d);
return &m_pDB[m_nSize++];
}
else
return NULL;
}
CVariable* CVarDB::createVar(const char* name, const CMatrix& m)
{
if (m_nSize < SIZE_DB) //if we have room
{
m_pDB[m_nSize].SetName(name);
m_pDB[m_nSize].SetValue(m);
return &m_pDB[m_nSize++];
}
else
return NULL;
}
void CVarDB::dump() //Essentially clears the contents of the DB
{
//Set the ans variable to zero.
m_pDB[0] = 0;
for (int i = 1; i < SIZE_DB; ++i)
{
m_pDB[0].Clear();
}
//Move the counter for the number of elements back to the beginning, so we write over the old variables.
m_nSize = 1;
}