| 6 | #include "DataManager.h" |
| 7 | |
| 8 | DataManager::DataManager() { |
| 9 | fstream data_file; |
| 10 | data_file.open(DATA_FILE, ios::in); |
| 11 | |
| 12 | if (data_file.is_open()) { |
| 13 | string line; |
| 14 | size_t line_count = 1; |
| 15 | |
| 16 | bool reading_board = false; |
| 17 | bool reading_column = false; |
| 18 | bool reading_card = false; |
| 19 | |
| 20 | while (getline(data_file, line)) { |
| 21 | if (line.find(" ") == 0) { |
| 22 | if (!reading_card) { |
| 23 | fprintf(stderr, "ERROR: incorrect syntax in data file \"%s\"\n", |
| 24 | DATA_FILE.c_str()); |
| 25 | fprintf(stderr, "[line %zu] reading a description without a card\n", |
| 26 | line_count); |
| 27 | exit(1); |
| 28 | } else { |
| 29 | // since we are parsing the data progressively, the card |
| 30 | // to which this description belongs is the last card we have |
| 31 | line.erase(line.begin(), line.begin() + 4); |
| 32 | this->boards.back().columns.back().cards.back().description += |
| 33 | line + "\n"; |
| 34 | } |
| 35 | } else if (line.find(" ") == 0) { |
| 36 | if (!reading_card) { |
| 37 | fprintf(stderr, "ERROR: incorrect syntax in data file \"%s\"\n", |
| 38 | DATA_FILE.c_str()); |
| 39 | fprintf(stderr, |
| 40 | "[line %zu] reading a checklist item without a card\n", |
| 41 | line_count); |
| 42 | exit(1); |
| 43 | } else { |
| 44 | // since we are parsing the data progressively, the card |
| 45 | // to which this checklist item belongs is the last card we have |
| 46 | line = trim_spaces(line); |
| 47 | |
| 48 | ChecklistItem checklist_item; |
| 49 | checklist_item.done = line[0] == '+'; |
| 50 | line.erase(line.begin(), line.begin() + 1); |
| 51 | checklist_item.content = line; |
| 52 | |
| 53 | this->boards.back().columns.back().cards.back().add_checklist_item( |
| 54 | checklist_item); |
| 55 | } |
| 56 | } else if (line.find(" ") == 0) { |
| 57 | if (!reading_column) { |
| 58 | fprintf(stderr, "ERROR: incorrect syntax in data file \"%s\"\n", |
| 59 | DATA_FILE.c_str()); |
| 60 | fprintf(stderr, "[line %zu] reading a card without a column\n", |
| 61 | line_count); |
| 62 | exit(1); |
| 63 | } else |
| 64 | // since we are parsing the data progressively, the column |
| 65 | // to which this card belongs is the last column we have |
nothing calls this directly
no test coverage detected