Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Tree.h"
- int
- main (void)
- {
- Tree_node *Top;
- int returning;
- string Simbol;//символ
- ifstream file("Base.txt");
- ifstream Command_file ("Commands.txt");
- map<string, User> Users;
- getline (file, Simbol);
- getline (file, Simbol);
- Top = Construction_tree(Simbol, file);
- file.close();
- string Command;
- unsigned int Num_str = 0;
- while (!Command_file.eof())
- {
- getline (Command_file, Command);
- Num_str++;
- try
- {
- string Name_of_user = Split_str (Command, "::");
- if (Users.find(Name_of_user) == Users.end())
- {
- Users[Name_of_user];
- Users[Name_of_user].Change_point(Top);
- }
- if (Users[Name_of_user].Parse(Command) == 2)
- {
- break;
- }
- }
- catch (string i)
- {
- cout << "Неверно составлен запрос ::" << Num_str <<"-ая строка\n";
- return 0;
- }
- }
- // New_user.Parse("PRINT MATLOG 2rav ");
- // New_user.Parse("DELETE MM~MATH~VM~Afonin~");
- // returning = New_user.Parse("ADD MM|MATH|VM|[Afonin|~Proga~(123)tut opisanie~|2rav~(12)tut tozhe~|]");
- // New_user.Parse("SELECT MM");
- // New_user.Parse("PRINT Proga 2rav ");
- // New_user.Parse("CLEAR ");
- // New_user.Parse("SELECT VM");
- // New_user.Parse("END ");
- /* for (map<string, User>::iterator i = Users.begin(); i != Users.end(); i++)
- {
- delete i -> second;
- }*/
- Command_file.close();
- ofstream Out_file("Base.txt");
- Off_base(Top, Out_file);
- Out_file.close();
- Cleaner(Top);
- }
- void
- Cleaner (Tree_node * Top_node)
- {
- for (unsigned int n = 0; n < (Top_node -> Down.size()); ++n)
- {
- Cleaner (Top_node -> Down[n]);
- }
- delete Top_node;
- }
- Tree_node *
- Construction_tree(string Node, ifstream &file)
- {
- string Simbol_;
- Tree_node *Top_node = new Tree_node;
- Top_node -> Name_of_node = Node;
- getline (file, Simbol_);
- if (Simbol_ == "{")
- {
- Top_node -> IsAHum_ = false ;
- getline (file, Simbol_);
- while (Simbol_ != "}" && file)
- {
- Top_node -> Down.insert (Top_node -> Down.end(), Construction_tree(Simbol_, file));
- getline (file, Simbol_);
- }
- }
- else if (Simbol_ == "[")
- {
- getline (file, Simbol_);
- while (Simbol_ != "]"&& file)
- {
- string Name_of_work;
- string Buf;
- int End_of_name = Simbol_.find("~");
- int End_of_hours = Simbol_.find("|");
- Name_of_work = Simbol_.substr(0,End_of_name);
- Top_node -> Work[Name_of_work].Description = Simbol_.substr( End_of_hours + 1);
- Top_node -> Work[Name_of_work].Duration = Find_int_str(Simbol_.substr (End_of_name + 1, End_of_hours - End_of_name - 1));
- getline (file, Simbol_);
- }
- Top_node->IsAHum_ = true;
- }
- return Top_node;
- }
- void
- Off_base(Tree_node * Top_node, ofstream &file)
- {
- if (Top_node -> IsAHum_ == false)
- {
- file<<"\n" << Top_node -> Name_of_node << "\n{";
- cout <<"\n"<< Top_node -> Name_of_node << "\n{";
- for(unsigned int n = 0; n < Top_node -> Down.size(); ++n)
- {
- Off_base (Top_node -> Down [n], file);
- }
- file << "\n}";
- cout << "\n}";
- }
- else if(Top_node -> IsAHum_ == true)
- {
- file << "\n"<<Top_node -> Name_of_node << "\n[\n";
- cout <<"\n"<< Top_node -> Name_of_node << "\n[\n";
- for(map <string , Description_of_work>::iterator i = Top_node -> Work.begin(); i != Top_node -> Work.end(); ++i)
- {
- file << i -> first <<"~" << i -> second.Duration << "|" << i -> second.Description << "\n";
- cout << i -> first << "~"<< i -> second.Duration << "|" << i -> second.Description << "\n";
- }
- file << "]";
- cout << "]";
- }
- }
- string
- Split_str (string & Splitng_str, string separator)
- {
- string buf;
- string Word;
- int End_word;
- End_word = Splitng_str.find(separator);
- if (End_word == int(string::npos))
- {
- throw; //ВЕРНУТЬ ОШИБКУ
- }
- Word = Splitng_str.substr(0, End_word);
- Splitng_str = Splitng_str.substr(End_word+separator.length());
- return Word;
- }
- int
- Find_int_str (string New_int)
- {
- int Returning_value = 0;
- while ( New_int.length() != 0)
- {
- string Symbol = New_int.substr(0, 1);
- New_int = New_int.substr (1);
- if ( Symbol == "0")
- {
- Returning_value = Returning_value*10 + 0;
- }
- else if (Symbol == "1")
- {
- Returning_value = Returning_value*10 + 1;
- }
- else if (Symbol == "2")
- {
- Returning_value = Returning_value*10 + 2;
- }
- else if (Symbol == "3")
- {
- Returning_value = Returning_value*10 + 3;
- }
- else if (Symbol == "4")
- {
- Returning_value = Returning_value*10 + 4;
- }
- else if (Symbol == "5")
- {
- Returning_value = Returning_value*10 + 5;
- }
- else if (Symbol == "6")
- {
- Returning_value = Returning_value*10 + 6;
- }
- else if (Symbol == "7")
- {
- Returning_value = Returning_value*10 + 7;
- }
- else if (Symbol == "8")
- {
- Returning_value = Returning_value*10 + 8;
- }
- else if (Symbol == "9")
- {
- Returning_value = Returning_value*10 + 9;
- }
- else
- {
- throw "No numer";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement