-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory.cpp
113 lines (96 loc) · 2.17 KB
/
memory.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "memory.h"
Memory::Memory() //Class Memory: Saves string-data into RAM
{
sKeyStore = new QList<QString>;
sValueStore = new QList<QString>;
}
Memory::~Memory()
{
delete sKeyStore;
delete sValueStore;
}
bool Memory::checkKeyExist(QString sKeyString)
{
bool bElementExist = sKeyStore->contains(sKeyString);
return bElementExist;
}
bool Memory::checkValueExist(QString sValueString)
{
bool bElementExist = sValueStore->contains(sValueString);
return bElementExist;
}
void Memory::clearRow(int iRow) //Deletes one row from the list
{
sKeyStore->removeAt(iRow);
sValueStore->removeAt(iRow);
}
void Memory::clearAll() //Deletes both lists
{
sValueStore->clear();
sKeyStore->clear();
}
int Memory::findKey(QString sKey)
{
int iKeyPos = sKeyStore->indexOf(sKey);
return iKeyPos;
}
int Memory::getEntryCount()
{
int iCount = sKeyStore->count();
return iCount;
}
QString Memory::getValue(QString sKeyString)
{
int iFoundRow = sKeyStore->indexOf(sKeyString);
if(iFoundRow == -1)
{
return "";
}
else
{
QString sFoundString = sValueStore->at(iFoundRow);
return sFoundString;
}
}
QString Memory::getKeyAt(int iRow)
{
QString sFileString = sKeyStore->at(iRow);
return sFileString;
}
QString Memory::getValueAt(int iRow)
{
QString sCompareString = sValueStore->at(iRow);
return sCompareString;
}
void Memory::setKeyValueEntry(QString sKeyString, QString sValueString)
{
if(sKeyString == "") //Skip, if the key is empty
{
return;
}
int iOldKeyPosition = findKey(sKeyString);
if(iOldKeyPosition == -1)
{
sKeyStore->append(sKeyString);
sValueStore->append(sValueString);
}
else
{
sValueStore->replace(iOldKeyPosition, sValueString);
}
}
void Memory::setKeyValueTable(QString *sKeyStrings, QString *sValueStrings, int iCount) //Saves Arrays in memory
{
sValueStore->clear();
sKeyStore->clear();
int i1;
for(i1=0; i1<iCount; i1++)
{
sKeyStore->insert(i1, sKeyStrings[i1]);
}
int i2;
for(i2=0; i2<iCount; i2++)
{
sValueStore->insert(i2, sValueStrings[i2]);
}
}