-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCursor.cpp
More file actions
41 lines (36 loc) · 1.01 KB
/
Copy pathCursor.cpp
File metadata and controls
41 lines (36 loc) · 1.01 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
#include "HeaderFiles/Table.h"
Cursor::Cursor(Table* table){
this->table = table;
this->page = nullptr;
this->row = 0;
this->endOfTable = false;
}
Cursor Cursor::operator++(){
if(this->row < this->table->numRows - 1){
++this->row;
}
else{
this->endOfTable = true;
}
return (*this);
}
char* Cursor::value(){
// TODO: Correct this after adding table header
uint32_t pageNum = (row / table->rowsPerPage) + 1;
this->page = table->pager->read(pageNum);
if(page == nullptr){return nullptr;}
// Read Successful
uint32_t rowOffset = row % table->rowsPerPage;
uint32_t byteOffset = rowOffset * table->rowSize;
return page->buffer.get() + byteOffset;
}
void Cursor::addedChangesToCommit(){
if(page != nullptr) page->hasUncommitedChanges = true;
}
void Cursor::commitChanges(){
if(page != nullptr){
uint32_t pageNum = row / table->rowsPerPage;
page->hasUncommitedChanges = true;
this->table->pager->flush(pageNum);
}
}