Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Checks if the specified task is correctly defined.
- If it depends on the other task and the task with specified title exsists, its level has to be the same or higher by 1.
- If not, its level has to be equal to 1.*/
- bool correct (vector<item> & task, item & current) {
- if (current.depends != "none") {
- if (number(task, current.depends) == 0)
- return false;
- else if (current.level - task[number(task, current.depends) - 1].level > 1)
- return false;
- else
- return true;
- }
- else
- if (current.level > 1)
- return false;
- else
- return true;
- }
- // Loads variables
- void get (vector<item> & task, string file) {
- fin.open (file);
- string tmp;
- item current;
- bool section = false;
- unsigned int j = 0;
- while (fin >> tmp) {
- if (tmp == "{") {
- section = true;
- current.title = "";
- current.level = 1;
- current.depends = "none";
- current.description;
- current.urgency = 10;
- current.importance = 10;
- }
- else if (tmp == "title" && section) {
- fin.get();
- getline(fin,current.title);
- }
- else if (tmp == "level" && section) {
- fin >> current.level;
- if (current.level < 1)
- current.level = 1;
- }
- else if (tmp == "depends" && section) {
- fin.get();
- getline(fin,current.depends);
- }
- else if (tmp == "description" && section) {
- fin.get();
- getline(fin,current.description);
- }
- else if (tmp == "urgency" && section) {
- fin >> current.urgency;
- if (current.urgency > 20)
- current.urgency = 20;
- else if (current.urgency < 1)
- current.urgency = 1;
- }
- else if (tmp == "importance" && section) {
- fin >> current.importance;
- if (current.importance > 20)
- current.importance = 20;
- else if (current.importance < 1)
- current.importance = 1;
- }
- else if (tmp == "}" && section) {
- section = false;
- current.number = j;
- if (correct(task, current))
- task.push_back(current);
- j++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment