From 07218a800af241850668b33e8b80e9e164ee624f Mon Sep 17 00:00:00 2001 From: YuhangQ Date: Tue, 5 Oct 2021 14:41:15 +0800 Subject: [PATCH] first commit --- .idea/.gitignore | 8 +++++++ .idea/InvoDB.iml | 2 ++ .idea/modules.xml | 8 +++++++ .idea/vcs.xml | 6 +++++ invodb/io/page_manager.cpp | 23 +++++++++++++++++++ invodb/io/page_manager.h | 43 +++++++++++++++++++++++++++++++++++ invodb/io/virtual_storage.cpp | 5 ++++ invodb/io/virtual_storage.h | 20 ++++++++++++++++ invodb/main.cpp | 15 ++++++++++++ invodb/main.h | 12 ++++++++++ 10 files changed, 142 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/InvoDB.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 invodb/io/page_manager.cpp create mode 100644 invodb/io/page_manager.h create mode 100644 invodb/io/virtual_storage.cpp create mode 100644 invodb/io/virtual_storage.h create mode 100644 invodb/main.cpp create mode 100644 invodb/main.h diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/InvoDB.iml b/.idea/InvoDB.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/InvoDB.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f4b947f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/invodb/io/page_manager.cpp b/invodb/io/page_manager.cpp new file mode 100644 index 0000000..c61587e --- /dev/null +++ b/invodb/io/page_manager.cpp @@ -0,0 +1,23 @@ +// +// Created by YuhangQ on 2021/9/24. +// + +#include "page_manager.h" + +int PageManager::loadDatabase(const char *filename) { + stream.open(filename); + + printf("%d", stream.is_open()); + + stream << "hello" << std::endl; + stream.flush(); + return 0; +} + +StoragePage& PageManager::getPage(const int &index) { + StoragePage page; + // 调整指针位置 + stream.seekg((index - 1) << 2); + stream.read(page, 4096); + return page; +} \ No newline at end of file diff --git a/invodb/io/page_manager.h b/invodb/io/page_manager.h new file mode 100644 index 0000000..94a30ef --- /dev/null +++ b/invodb/io/page_manager.h @@ -0,0 +1,43 @@ +// +// Created by YuhangQ on 2021/9/24. +// + +#ifndef INVODB_PAGE_MANAGER_H +#define INVODB_PAGE_MANAGER_H + +#include +#include + +class StoragePage { +public: + char& operator[] (int index) { return this->page[index]; } + operator const char *() { return this->page; } + operator char *() { return this->page; } + ~StoragePage() { + printf("我被回收了"); + } +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); +private: + std::fstream stream; + + // 私有化实现单例 + PageManager(); + ~PageManager(); + PageManager(const PageManager&); + PageManager& operator=(const PageManager&); +}; + + +#endif //INVODB_PAGE_MANAGER_H diff --git a/invodb/io/virtual_storage.cpp b/invodb/io/virtual_storage.cpp new file mode 100644 index 0000000..ce9bfd8 --- /dev/null +++ b/invodb/io/virtual_storage.cpp @@ -0,0 +1,5 @@ +// +// Created by YuhangQ on 2021/9/30. +// + +#include "virtual_storage.h" diff --git a/invodb/io/virtual_storage.h b/invodb/io/virtual_storage.h new file mode 100644 index 0000000..ed6cf1b --- /dev/null +++ b/invodb/io/virtual_storage.h @@ -0,0 +1,20 @@ +// +// Created by YuhangQ on 2021/9/30. +// + +#ifndef INVODB_VIRTUAL_STORAGE_H +#define INVODB_VIRTUAL_STORAGE_H + + + + + +class VirtualStorage { +public: + +private: + +}; + + +#endif //INVODB_VIRTUAL_STORAGE_H diff --git a/invodb/main.cpp b/invodb/main.cpp new file mode 100644 index 0000000..f0896fd --- /dev/null +++ b/invodb/main.cpp @@ -0,0 +1,15 @@ +// +// Created by YuhangQ on 2021/9/24. +// + +#include "main.h" + + +int main() { + PageManager& manager = PageManager::Instance(); + manager.loadDatabase("test.invodb"); + + manager.getPage(0); + + return 0; +} \ No newline at end of file diff --git a/invodb/main.h b/invodb/main.h new file mode 100644 index 0000000..6784a4e --- /dev/null +++ b/invodb/main.h @@ -0,0 +1,12 @@ +// +// Created by YuhangQ on 2021/9/24. +// + +#ifndef INVODB_MAIN_H +#define INVODB_MAIN_H + +#include +#include "io/page_manager.h" +#include "io/virtual_storage.h" + +#endif //INVODB_MAIN_H