Advertisement
TwITe

Untitled

Dec 2nd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.56 KB | None | 0 0
  1. void save_current_id_in_map_to_file(int id) {
  2.     ofstream file;
  3.     string file_name = "/home/twite/CLionProjects/Database/map.dat";
  4.     file.open(file_name, ios::out | ios::app);
  5.     file << "id" << "\n" << id << "\n" << "--" << "\n";
  6.     file << "file_names" << "\n";
  7.     for (const auto& current_filename: indexes[id].file_names) {
  8.         file << current_filename << "\n";
  9.     }
  10.     file << "--" << "\n";
  11.     file << "start_reading_positions" << "\n";
  12.     for (const auto& current_start_read_pos: indexes[id].start_reading_positions) {
  13.         file << current_start_read_pos << "\n";
  14.     }
  15.     file << "--" "\n";
  16.     file << "end_reading_positions" << "\n";
  17.     for (const auto& current_end_read_pos: indexes[id].end_reading_positions) {
  18.         file << current_end_read_pos << "\n";
  19.     }
  20.     file << "--" "\n";
  21.     file << "data_size" << "\n";
  22.     file << indexes[id].data_size << "\n";
  23.     file << "--" << "\n";
  24. }
  25.  
  26. void load_map_from_file() {
  27.     int id;
  28.     index_data current_id;
  29.     ifstream file;
  30.     string file_name = "/home/twite/CLionProjects/Database/map.dat";
  31.     file.open(file_name);
  32.     string s;
  33.     int a;
  34.     streamoff b;
  35.     while (getline (file, s)) {
  36.         if (s == "id") {
  37.             getline (file, s);
  38.             istringstream iss(s);
  39.             iss >> a;
  40.             id = a;
  41.         }
  42.         if (s == "file_names") {
  43.             while (getline(file, s)) {
  44.                 if (s == "--") {
  45.                     break;
  46.                 }
  47.                 current_id.file_names.push_back(s);
  48.             }
  49.         }
  50.         if (s == "start_reading_positions") {
  51.             while (getline(file, s)) {
  52.                 if (s == "--") {
  53.                     break;
  54.                 }
  55.                 istringstream iss(s);
  56.                 iss >> b;
  57.                 current_id.start_reading_positions.push_back(b);
  58.             }
  59.         }
  60.         if (s == "end_reading_positions") {
  61.             while (getline(file, s)) {
  62.                 if (s == "--") {
  63.                     break;
  64.                 }
  65.                 istringstream iss(s);
  66.                 iss >> b;
  67.                 current_id.end_reading_positions.push_back(b);
  68.             }
  69.         }
  70.         if (s == "data_size") {
  71.             getline(file, s);
  72.             istringstream iss(s);
  73.             iss >> a;
  74.             current_id.data_size = a;
  75.             indexes[id] = current_id;
  76.             current_id.file_names.clear();
  77.             current_id.start_reading_positions.clear();
  78.             current_id.end_reading_positions.clear();
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement