Advertisement
Guest User

Untitled

a guest
May 31st, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. #include "Tree.h"
  2. User::User(Tree_node * Top)
  3. {
  4. Start_source_tree = Top;
  5. Top_ = *Top;
  6. Buf_.IsAHum_ = false;
  7. Buf_.Name_of_node = "Буферное дерево";
  8. }
  9. void
  10. User::Select(Tree_node Top_node_source, string Rule)
  11. {
  12. cout << Rule << "Правило \n";
  13. if (Top_node_source.Name_of_node == Rule)
  14. {
  15. cout<< Rule << " Эта вершина подошла по правило " << Top_node_source.Name_of_node << "\n";
  16. Buf_.Down.insert(Buf_.Down.end(), &Top_node_source);
  17. }
  18. else
  19. {
  20. cout << Rule << " Не подошла под правило " << Top_node_source.Name_of_node << "\n";
  21. for (int n =0; n < Top_node_source.Down.size(); ++n)
  22. {
  23. Select(*Top_node_source.Down[n], Rule);
  24. }
  25. }
  26.  
  27.  
  28. }
  29. void
  30. User::Print(Tree_node Tree_node_source, vector<string> Rule_print)
  31. {
  32. cout << Tree_node_source.Name_of_node << " Отладочный вывод\n";
  33. if(Tree_node_source.IsAHum_ == true)
  34. {
  35. cout << Tree_node_source.Name_of_node <<" Это должны быть только люди\n";
  36. for (int i = 0; i < Rule_print.size(); ++i)
  37. {
  38. cout << Rule_print[i] << " ";
  39. }
  40. cout << "\n";
  41. for(int i = 0; i < Rule_print.size(); ++i)
  42. {
  43. cout << "(" << Tree_node_source.Work[Rule_print[i]].Duration << ")~~" << Tree_node_source.Work[Rule_print[i]].Description <<" ";
  44. }
  45. cout << "\n";
  46. }
  47. else
  48. {
  49. cout << Tree_node_source.Name_of_node << "А это не люди\n";
  50. for(int n = 0; n < Tree_node_source.Down.size(); n++)
  51. {
  52. cout << Tree_node_source.Name_of_node << " Сломайся здесь\n";
  53. cout << Tree_node_source.Down[n] -> Name_of_node << "Вот ссылки на них\n";
  54. Print(*(Tree_node_source.Down[n]), Rule_print);
  55. }
  56. }
  57.  
  58. }
  59. int
  60. User::Parse (string Inp_str)
  61. {
  62. string Command;
  63. Command = Split_str(Inp_str, " ");
  64. if (Command == "SELECT")
  65. {
  66. Buf_.Down.clear();
  67. Select(Top_, Inp_str);
  68. Top_.Down.clear();
  69. for (int i = 0; i < Buf_.Down.size(); i++)
  70. {
  71. Top_.Down.insert(Top_.Down.end(), Buf_.Down[i]);
  72. }
  73. cout << "+++++++++++++++++++++++\n";
  74. Superpr(Top_);
  75. cout << "++++++++++++++++++++++++\n";
  76. return 1;
  77. }
  78. else if (Command == "ADD")
  79. {
  80. Tree_node * Tm_Buf_ = Start_source_tree;
  81. while (Inp_str.substr(0, 1) != "[" && Inp_str.length()>0)
  82. {
  83. string Way = Split_str(Inp_str, "|");
  84. Tm_Buf_ = Add(Tm_Buf_, Way);
  85. }
  86. if (Inp_str.substr(0,1) != "[")
  87. {
  88. return 0;
  89. }
  90. Split_str (Inp_str, "[");
  91. string Name_of_worker = Split_str(Inp_str, "|~");
  92. map<string, Description_of_work> New_work;
  93. while (Inp_str != "]")
  94. {
  95. string Name = Split_str (Inp_str, "~");
  96. Split_str (Inp_str, "(");
  97. New_work[Name].Duration = stoi(Split_str(Inp_str, ")"));
  98. New_work[Name].Description = Split_str(Inp_str, "~|" );
  99. }
  100. Add_worker (Tm_Buf_, Name_of_worker, New_work);
  101. return 1;
  102. }
  103. else if (Command == "DELETE")
  104. {
  105. Tree_node * Now_node = Start_source_tree;
  106. Tree_node *Prev_node;
  107. string Way;
  108. int n = 0;
  109. while (Inp_str.length() > 0)
  110. {
  111. int i = 0;
  112. Way = Split_str (Inp_str, "~");
  113. for (n = 0; n < Now_node -> Down.size(); ++n)
  114. {
  115.  
  116. if (Now_node -> Down[n]->Name_of_node == Way)
  117. {
  118. Prev_node = Now_node;
  119. Now_node = Now_node -> Down[n];
  120. i++;
  121.  
  122. break;
  123. }
  124. }
  125. if (i == 0)
  126. {
  127. cout << Way <<" "<< Inp_str<< "Ф\n";
  128. return 2;
  129. //ИСКЛЮЧЕНИЕ
  130. }
  131. }
  132. if (Now_node -> IsAHum_ == false)
  133. {
  134. //ИСКЛЮЧЕНИЕ
  135. }
  136. Prev_node -> Down.erase (Prev_node -> Down.begin() + n );
  137. delete Now_node;
  138. return 1;
  139. }
  140. else if (Command == "PRINT")
  141. {
  142. vector <string> Rules;
  143. while(Inp_str.length() > 0)
  144. {
  145. string Rule = Split_str(Inp_str, " ");
  146. Rules.insert(Rules.end(),Rule);
  147. }
  148. Print (Top_, Rules);
  149. return 1;
  150. }
  151. else if (Command == "CLEAR", Inp_str.length() == 0)
  152. {
  153. Top_ = *Start_source_tree;
  154. return 1;
  155. }
  156. else if (Command == "END")
  157. {
  158. return 2;
  159. }
  160. else
  161. {
  162. return 0;
  163. }
  164. }
  165. Tree_node*
  166. User::Add (Tree_node * Top_node, string way)
  167. {
  168. if (Top_node -> IsAHum_ == true)
  169. {
  170. }//ОШИБКА ТИПА НЕЛЬЗЯ ПОДЧИНЕННЫХ ВЫДАВАТЬ ЧЕЛОВЕКУ
  171. for(int n = 0; n < Top_node -> Down.size(); ++n)
  172. {
  173. if ((Top_node -> Down[n]) -> Name_of_node == way)
  174. {
  175. return Top_node -> Down[n];
  176. }
  177. }
  178. Tree_node * Return_node = new Tree_node;
  179. Return_node -> IsAHum_ = false;
  180. Return_node -> Name_of_node = way;
  181. Top_node -> Down.insert (Top_node -> Down.end(), Return_node);
  182. return Return_node;
  183. }
  184. void
  185. User::Add_worker (Tree_node * Top_node, string Name_of_worker, map<string, Description_of_work> Work_in)
  186. {
  187. if(Top_node -> IsAHum_ == true)
  188. {
  189. }//ОШИБКА
  190. for (int i =0; i < Top_node -> Down.size(); ++i)
  191. {
  192. if (Top_node -> Down[i] -> Name_of_node == Name_of_worker)
  193. {
  194. //ОШИБКА
  195. return;
  196. }
  197. }
  198. Tree_node * New_node = new Tree_node;
  199. New_node -> Name_of_node = Name_of_worker;
  200. New_node -> IsAHum_ = true;
  201. Top_node -> Down.insert(Top_node -> Down.end(), New_node) ;
  202. New_node -> Work = Work_in;
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement