2021-10-05 14:41:15 +08:00
|
|
|
//
|
|
|
|
// Created by YuhangQ on 2021/9/24.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef INVODB_PAGE_MANAGER_H
|
|
|
|
#define INVODB_PAGE_MANAGER_H
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
2021-10-05 16:02:01 +08:00
|
|
|
#include <cstring>
|
2021-10-05 14:41:15 +08:00
|
|
|
|
|
|
|
class StoragePage {
|
|
|
|
public:
|
2021-10-05 16:02:01 +08:00
|
|
|
void print();
|
|
|
|
StoragePage() { memset(page, 0, sizeof(page)); }
|
2021-10-05 14:41:15 +08:00
|
|
|
char& operator[] (int index) { return this->page[index]; }
|
2021-10-05 16:02:01 +08:00
|
|
|
operator const char *() const { return this->page; }
|
2021-10-05 14:41:15 +08:00
|
|
|
operator char *() { return this->page; }
|
|
|
|
private:
|
|
|
|
char page[4096];
|
|
|
|
};
|
|
|
|
|
|
|
|
class PageManager {
|
|
|
|
public:
|
|
|
|
static PageManager& Instance() {
|
|
|
|
static PageManager instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
int loadDatabase(const char *filename);
|
|
|
|
StoragePage& getPage(const int &index);
|
|
|
|
void setPage(const int &index, const StoragePage &page);
|
2021-10-05 16:02:01 +08:00
|
|
|
|
2021-10-05 14:41:15 +08:00
|
|
|
private:
|
|
|
|
std::fstream stream;
|
|
|
|
|
|
|
|
// 私有化实现单例
|
2021-10-05 16:02:01 +08:00
|
|
|
PageManager() {}
|
|
|
|
~PageManager() {}
|
2021-10-05 14:41:15 +08:00
|
|
|
PageManager(const PageManager&);
|
|
|
|
PageManager& operator=(const PageManager&);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //INVODB_PAGE_MANAGER_H
|