InvoDB/invodb/file/page_manager.h

40 lines
925 B
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-28 23:44:50 +08:00
#include <map>
2021-10-05 14:41:15 +08:00
2021-10-23 16:28:57 +08:00
#include "storage_page.h"
2021-10-31 14:51:09 +08:00
#include "json/json.hpp"
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-31 14:51:09 +08:00
void release(const int &index);
int saveJSONToFile(const nlohmann::json& json);
nlohmann::json readJSONFromFile(const int &index);
2021-10-05 14:41:15 +08:00
private:
2021-10-28 23:44:50 +08:00
std::map<int, StoragePage> map;
2021-10-05 14:41:15 +08:00
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