first commit

This commit is contained in:
YuhangQ 2021-10-05 14:41:15 +08:00
commit 07218a800a
10 changed files with 142 additions and 0 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@ -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

2
.idea/InvoDB.iml generated Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/InvoDB.iml" filepath="$PROJECT_DIR$/.idea/InvoDB.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -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;
}

43
invodb/io/page_manager.h Normal file
View File

@ -0,0 +1,43 @@
//
// Created by YuhangQ on 2021/9/24.
//
#ifndef INVODB_PAGE_MANAGER_H
#define INVODB_PAGE_MANAGER_H
#include <iostream>
#include <fstream>
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

View File

@ -0,0 +1,5 @@
//
// Created by YuhangQ on 2021/9/30.
//
#include "virtual_storage.h"

View File

@ -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

15
invodb/main.cpp Normal file
View File

@ -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;
}

12
invodb/main.h Normal file
View File

@ -0,0 +1,12 @@
//
// Created by YuhangQ on 2021/9/24.
//
#ifndef INVODB_MAIN_H
#define INVODB_MAIN_H
#include <iostream>
#include "io/page_manager.h"
#include "io/virtual_storage.h"
#endif //INVODB_MAIN_H