Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void save_current_id_in_map_to_file(int id) {
- ofstream file;
- string file_name = "/home/twite/CLionProjects/Database/map.dat";
- file.open(file_name, ios::out | ios::app);
- file << "id" << "\n" << id << "\n" << "--" << "\n";
- file << "file_names" << "\n";
- for (const auto& current_filename: indexes[id].file_names) {
- file << current_filename << "\n";
- }
- file << "--" << "\n";
- file << "start_reading_positions" << "\n";
- for (const auto& current_start_read_pos: indexes[id].start_reading_positions) {
- file << current_start_read_pos << "\n";
- }
- file << "--" "\n";
- file << "end_reading_positions" << "\n";
- for (const auto& current_end_read_pos: indexes[id].end_reading_positions) {
- file << current_end_read_pos << "\n";
- }
- file << "--" "\n";
- file << "data_size" << "\n";
- file << indexes[id].data_size << "\n";
- file << "--" << "\n";
- }
- void load_map_from_file() {
- int id;
- index_data current_id;
- ifstream file;
- string file_name = "/home/twite/CLionProjects/Database/map.dat";
- file.open(file_name);
- string s;
- int a;
- streamoff b;
- while (getline (file, s)) {
- if (s == "id") {
- getline (file, s);
- istringstream iss(s);
- iss >> a;
- id = a;
- }
- if (s == "file_names") {
- while (getline(file, s)) {
- if (s == "--") {
- break;
- }
- current_id.file_names.push_back(s);
- }
- }
- if (s == "start_reading_positions") {
- while (getline(file, s)) {
- if (s == "--") {
- break;
- }
- istringstream iss(s);
- iss >> b;
- current_id.start_reading_positions.push_back(b);
- }
- }
- if (s == "end_reading_positions") {
- while (getline(file, s)) {
- if (s == "--") {
- break;
- }
- istringstream iss(s);
- iss >> b;
- current_id.end_reading_positions.push_back(b);
- }
- }
- if (s == "data_size") {
- getline(file, s);
- istringstream iss(s);
- iss >> a;
- current_id.data_size = a;
- indexes[id] = current_id;
- current_id.file_names.clear();
- current_id.start_reading_positions.clear();
- current_id.end_reading_positions.clear();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement