Advertisement
TwITe

Untitled

Sep 30th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. //It's database library
  2. //Use the function "set_filesize" to set a default size of the data file
  3. //Use the function "set_path" to set path for saving data files
  4. #pragma once
  5. #include <iostream>
  6. #include <fstream>
  7. #include <string>
  8. #include <cassert>
  9. #include <map>
  10. #include <unordered_map>
  11. #include <vector>
  12. #include <set>
  13. using namespace std;
  14.  
  15. string filename;
  16. string user_path;
  17. const char* full_path;
  18. int num = -1;
  19. int default_filesize = 1;
  20. unordered_map <int, vector <string> > users;
  21.  
  22. void set_path(const string &saving_path) {
  23.     user_path = saving_path;
  24. }
  25.  
  26. char get_full_path() {
  27.     num++;
  28.     filename = "data" + to_string(num);
  29.     user_path = user_path + filename + ".txt";
  30.     full_path = user_path.c_str();
  31. }
  32.  
  33. void set_filesize(int user_size) {
  34.     default_filesize = user_size;
  35. }
  36.  
  37. void check_path() {
  38.     if (user_path.empty()) {
  39.         throw runtime_error("path is invalid");
  40.     }
  41. }
  42.  
  43. void write_id(int id) {
  44.  
  45. }
  46.  
  47. int file_free_space() {
  48.     ifstream current_file("test.txt", std::ifstream::binary);
  49.     current_file.seekg(0, current_file.end);
  50.     int length = current_file.tellg();
  51.     current_file.seekg(0, current_file.beg);
  52.     return default_filesize - length;
  53. }
  54.  
  55. void write_data(void* data, int array_length) {
  56.     int free_space = file_free_space();
  57.     get_full_path();
  58.     FILE * pFile;
  59.     if ()
  60.     pFile = fopen(full_path, "rw");
  61.     fwrite(&data, sizeof(data), free_space / sizeof(data), pFile);
  62.     fclose(pFile);
  63.     int current_data_size = array_length * sizeof(data);
  64.     if (current_data_size <= free_space) {
  65.        
  66.     }
  67. }
  68.  
  69. void store(int id, void* data, int array_length) {
  70.     write_id(id);
  71.     write_data(data, array_length);
  72. }
  73.  
  74. void load(int id) {
  75.    
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement