-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBGM_StudentFileManager.cpp
More file actions
118 lines (99 loc) · 2.55 KB
/
BGM_StudentFileManager.cpp
File metadata and controls
118 lines (99 loc) · 2.55 KB
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
114
115
116
117
118
#include "BGM_StudentFileManager.h"
namespace BGM
{
StudentFileManager::StudentFileManager(const char* fileName)
: DataFileManager<Student>::DataFileManager(fileName), mask(*((unsigned*)(buffer+STUDENTFILEMANAGER_MASK_OFFSET)))
{
if(numberOfBlock==1 && currentBlock==1 && numberOfData==0)
mask = 0x00000000;
}
unsigned StudentFileManager::getMask() const
{
return mask;
}
void StudentFileManager::setMask(unsigned m)
{
mask = m;
}
void StudentFileManager::deleteData(signed int index)
{
int* slotHead = (int*)(DataFileManager<Student>::dataList + index);
(*slotHead) = nextSlot;
dataList[index].setID(0);
////delete test
//for(int i=1; i<38; i++)
// slotHead[i] = 0x00000000;
nextSlot = index;
numberOfData--;
}
void StudentFileManager::deleteData(unsigned id)
{
int i;
for(i=0; DataFileManager<Student>::dataList[i].getID()!=id && i<STUDENTS_PER_BLOCK; i++);
if(i == STUDENTS_PER_BLOCK)
return;
else
{
int* slotHead = (int*)(DataFileManager<Student>::dataList + i);
(*slotHead) = nextSlot;
nextSlot = i;
numberOfData--;
//if(numberOfBlock == 0)
// deleteBlock(currentBlock);
}
}
//»ç¿ëºÒ°¡
Student StudentFileManager::searchData(const Student& student)
{
int i;
unsigned id = student.getID();
for(i=0; DataFileManager<Student>::dataList[i].getID()!=id && i<STUDENTS_PER_BLOCK; i++);
return DataFileManager<Student>::dataList[i];
}
//»ç¿ëºÒ°¡
void StudentFileManager::deleteData(const Student& student)
{
}
float StudentFileManager::getScore(blockId_t block, unsigned ID)
{
if(currentBlock != block)
{
storeBlock();
loadBlock(block);
}
int i;
for(i=0; i<STUDENTS_PER_BLOCK && dataList[i].getID()!= ID ; i++);
if(i == STUDENTS_PER_BLOCK || dataList[i].getID()==0)
return -1;
else
{
float result = dataList[i].getScore();
deleteData(i);
return result;
}
}
//for debug
void StudentFileManager::printBlock()
{
char filename[50];
strcpy(filename, "DataBlock");
unsigned current = currentBlock;
for(int i=0; i<current; current/=10)
{
filename[9+i] = '0'+current%10;
filename[9+i+1] = 0;
}
strcat(filename, ".csv");
std::ofstream outFile(filename);
outFile << "numberOfData," << numberOfData << ",nextSlot," << nextSlot <<",lastSlot," << lastSlot << std::endl;
for(int i=0; i<STUDENTS_PER_BLOCK; i++)
{
if((dataList[i].getName())[0]!='n' && (dataList[i].getName())[1]!='a')
outFile << '-' << (dataList[i].getName())[0] << ',';
else
outFile << dataList[i].getID() << ',';
}
outFile << std::endl;
outFile.close();
}
}