Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Tree.h"
- User::User(Tree_node * Top)
- {
- Start_source_tree = Top;
- Top_ = *Top;
- Buf_.IsAHum_ = false;
- Buf_.Name_of_node = "Буферное дерево";
- }
- void
- User::Select(Tree_node Top_node_source, string Rule)
- {
- cout << Rule << "Правило \n";
- if (Top_node_source.Name_of_node == Rule)
- {
- cout<< Rule << " Эта вершина подошла по правило " << Top_node_source.Name_of_node << "\n";
- Buf_.Down.insert(Buf_.Down.end(), &Top_node_source);
- }
- else
- {
- cout << Rule << " Не подошла под правило " << Top_node_source.Name_of_node << "\n";
- for (int n =0; n < Top_node_source.Down.size(); ++n)
- {
- Select(*Top_node_source.Down[n], Rule);
- }
- }
- }
- void
- User::Print(Tree_node Tree_node_source, vector<string> Rule_print)
- {
- cout << Tree_node_source.Name_of_node << " Отладочный вывод\n";
- if(Tree_node_source.IsAHum_ == true)
- {
- cout << Tree_node_source.Name_of_node <<" Это должны быть только люди\n";
- for (int i = 0; i < Rule_print.size(); ++i)
- {
- cout << Rule_print[i] << " ";
- }
- cout << "\n";
- for(int i = 0; i < Rule_print.size(); ++i)
- {
- cout << "(" << Tree_node_source.Work[Rule_print[i]].Duration << ")~~" << Tree_node_source.Work[Rule_print[i]].Description <<" ";
- }
- cout << "\n";
- }
- else
- {
- cout << Tree_node_source.Name_of_node << "А это не люди\n";
- for(int n = 0; n < Tree_node_source.Down.size(); n++)
- {
- cout << Tree_node_source.Name_of_node << " Сломайся здесь\n";
- cout << Tree_node_source.Down[n] -> Name_of_node << "Вот ссылки на них\n";
- Print(*(Tree_node_source.Down[n]), Rule_print);
- }
- }
- }
- int
- User::Parse (string Inp_str)
- {
- string Command;
- Command = Split_str(Inp_str, " ");
- if (Command == "SELECT")
- {
- Buf_.Down.clear();
- Select(Top_, Inp_str);
- Top_.Down.clear();
- for (int i = 0; i < Buf_.Down.size(); i++)
- {
- Top_.Down.insert(Top_.Down.end(), Buf_.Down[i]);
- }
- cout << "+++++++++++++++++++++++\n";
- Superpr(Top_);
- cout << "++++++++++++++++++++++++\n";
- return 1;
- }
- else if (Command == "ADD")
- {
- Tree_node * Tm_Buf_ = Start_source_tree;
- while (Inp_str.substr(0, 1) != "[" && Inp_str.length()>0)
- {
- string Way = Split_str(Inp_str, "|");
- Tm_Buf_ = Add(Tm_Buf_, Way);
- }
- if (Inp_str.substr(0,1) != "[")
- {
- return 0;
- }
- Split_str (Inp_str, "[");
- string Name_of_worker = Split_str(Inp_str, "|~");
- map<string, Description_of_work> New_work;
- while (Inp_str != "]")
- {
- string Name = Split_str (Inp_str, "~");
- Split_str (Inp_str, "(");
- New_work[Name].Duration = stoi(Split_str(Inp_str, ")"));
- New_work[Name].Description = Split_str(Inp_str, "~|" );
- }
- Add_worker (Tm_Buf_, Name_of_worker, New_work);
- return 1;
- }
- else if (Command == "DELETE")
- {
- Tree_node * Now_node = Start_source_tree;
- Tree_node *Prev_node;
- string Way;
- int n = 0;
- while (Inp_str.length() > 0)
- {
- int i = 0;
- Way = Split_str (Inp_str, "~");
- for (n = 0; n < Now_node -> Down.size(); ++n)
- {
- if (Now_node -> Down[n]->Name_of_node == Way)
- {
- Prev_node = Now_node;
- Now_node = Now_node -> Down[n];
- i++;
- break;
- }
- }
- if (i == 0)
- {
- cout << Way <<" "<< Inp_str<< "Ф\n";
- return 2;
- //ИСКЛЮЧЕНИЕ
- }
- }
- if (Now_node -> IsAHum_ == false)
- {
- //ИСКЛЮЧЕНИЕ
- }
- Prev_node -> Down.erase (Prev_node -> Down.begin() + n );
- delete Now_node;
- return 1;
- }
- else if (Command == "PRINT")
- {
- vector <string> Rules;
- while(Inp_str.length() > 0)
- {
- string Rule = Split_str(Inp_str, " ");
- Rules.insert(Rules.end(),Rule);
- }
- Print (Top_, Rules);
- return 1;
- }
- else if (Command == "CLEAR", Inp_str.length() == 0)
- {
- Top_ = *Start_source_tree;
- return 1;
- }
- else if (Command == "END")
- {
- return 2;
- }
- else
- {
- return 0;
- }
- }
- Tree_node*
- User::Add (Tree_node * Top_node, string way)
- {
- if (Top_node -> IsAHum_ == true)
- {
- }//ОШИБКА ТИПА НЕЛЬЗЯ ПОДЧИНЕННЫХ ВЫДАВАТЬ ЧЕЛОВЕКУ
- for(int n = 0; n < Top_node -> Down.size(); ++n)
- {
- if ((Top_node -> Down[n]) -> Name_of_node == way)
- {
- return Top_node -> Down[n];
- }
- }
- Tree_node * Return_node = new Tree_node;
- Return_node -> IsAHum_ = false;
- Return_node -> Name_of_node = way;
- Top_node -> Down.insert (Top_node -> Down.end(), Return_node);
- return Return_node;
- }
- void
- User::Add_worker (Tree_node * Top_node, string Name_of_worker, map<string, Description_of_work> Work_in)
- {
- if(Top_node -> IsAHum_ == true)
- {
- }//ОШИБКА
- for (int i =0; i < Top_node -> Down.size(); ++i)
- {
- if (Top_node -> Down[i] -> Name_of_node == Name_of_worker)
- {
- //ОШИБКА
- return;
- }
- }
- Tree_node * New_node = new Tree_node;
- New_node -> Name_of_node = Name_of_worker;
- New_node -> IsAHum_ = true;
- Top_node -> Down.insert(Top_node -> Down.end(), New_node) ;
- New_node -> Work = Work_in;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement