InvoDB/invodb/file/page_manager.h

49 lines
1.0 KiB
C
Raw Normal View History

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();
2021-10-11 22:05:45 +08:00
int next();
int setNext(const int& nextPage);
int* intArray();
2021-10-05 16:02:01 +08:00
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:
2021-10-11 22:05:45 +08:00
char page[1024];
2021-10-05 14:41:15 +08:00
};
class PageManager {
public:
static PageManager& Instance() {
static PageManager instance;
return instance;
}
2021-10-11 22:05:45 +08:00
static int loadDatabase(const char *filename);
StoragePage getPage(const int &index);
2021-10-05 14:41:15 +08:00
void setPage(const int &index, const StoragePage &page);
2021-10-11 22:05:45 +08:00
int allocate();
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