Guest User

get.cpp

a guest
Aug 31st, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. /* Checks if the specified task is correctly defined.
  2. 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.
  3. If not, its level has to be equal to 1.*/
  4. bool correct (vector<item> & task, item & current) {
  5.     if (current.depends != "none") {
  6.         if (number(task, current.depends) == 0)
  7.             return false;
  8.         else if (current.level - task[number(task, current.depends) - 1].level > 1)
  9.             return false;
  10.         else
  11.             return true;
  12.     }
  13.     else
  14.         if (current.level > 1)
  15.             return false;
  16.         else
  17.             return true;
  18. }
  19.  
  20. // Loads variables
  21. void get (vector<item> & task, string file) {
  22.     fin.open (file);
  23.     string tmp;
  24.     item current;
  25.     bool section = false;
  26.     unsigned int j = 0;
  27.     while (fin >> tmp) {
  28.         if (tmp == "{") {
  29.             section = true;
  30.             current.title = "";
  31.             current.level = 1;
  32.             current.depends = "none";
  33.             current.description;
  34.             current.urgency = 10;
  35.             current.importance = 10;
  36.         }
  37.         else if (tmp == "title" && section) {
  38.             fin.get();
  39.             getline(fin,current.title);
  40.         }    
  41.         else if (tmp == "level" && section) {
  42.             fin >> current.level;
  43.             if (current.level < 1)
  44.                 current.level = 1;
  45.         }    
  46.         else if (tmp == "depends" && section) {
  47.             fin.get();
  48.             getline(fin,current.depends);
  49.         }    
  50.         else if (tmp == "description" && section) {
  51.             fin.get();
  52.             getline(fin,current.description);
  53.         }    
  54.         else if (tmp == "urgency" && section) {
  55.             fin >> current.urgency;
  56.             if (current.urgency > 20)
  57.                 current.urgency = 20;
  58.             else if (current.urgency < 1)
  59.                 current.urgency = 1;
  60.         }    
  61.         else if (tmp == "importance" && section) {
  62.             fin >> current.importance;
  63.             if (current.importance > 20)
  64.                 current.importance = 20;
  65.             else if (current.importance < 1)
  66.                 current.importance = 1;
  67.         }    
  68.         else if (tmp == "}" && section) {
  69.             section = false;
  70.             current.number = j;
  71.             if (correct(task, current))
  72.                 task.push_back(current);
  73.             j++;
  74.         }  
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment