Advertisement
Joporezka1

kl33_cl-app

May 26th, 2022
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.55 KB | None | 0 0
  1. #include "cl_base.h"
  2. #include "child2.h"
  3. #include "child3.h"
  4. #include "child4.h"
  5. #include "child5.h"
  6. #include "child6.h"
  7. #include "child7.h"
  8. #include "cl_application.h"
  9. #include <iostream>
  10. #include <string>
  11. using namespace std;
  12.  
  13. #define SIGNAL_D( signal_f ) ( TYPE_SIGNAL ) ( & signal_f )
  14. #define HENDLER_D( hendler_f ) ( TYPE_HENDLER ) ( & hendler_f )
  15.    
  16. typedef void ( cl_base :: * TYPE_SIGNAL ) ( string & );
  17. typedef void ( cl_base :: * TYPE_HENDLER ) ( string );
  18.  
  19. cl_application::cl_application(cl_base* b, string n):cl_base(b,n) { n_class = 1;}
  20.  
  21.  
  22. int cl_application::bild_tree_objects() {
  23.     string parent_path;
  24.     string child;
  25.     cl_base* parent=nullptr;
  26.    
  27.     int cl_num,readiness1;
  28.     cin >> parent_path;
  29.     //создание головного объекта
  30.     this->set_name(parent_path);
  31.    
  32.     while (true)
  33.     {
  34.         parent = nullptr;
  35.         cin >> parent_path;
  36.         if(parent_path=="endtree") break;
  37.        
  38.         cl_base* parent = this->get_ptr_from_path(parent_path);
  39.        
  40.             if(parent==nullptr){
  41.                 cout<<"Object tree\n";
  42.                 this->print_tree();
  43.                 cout<<"\nThe head object "<<parent_path<<" is not found";
  44.                 return -1;
  45.             }
  46.        
  47.        
  48.         cin >> child;
  49.         cin >> cl_num;
  50.         if(cl_num==2) child2* ch = new child2(parent,child);
  51.         else if(cl_num==3) child3* ch = new child3(parent,child);
  52.         else if(cl_num==4) child4* ch = new child4(parent,child);
  53.         else if(cl_num==5) child5* ch = new child5(parent,child);
  54.         else if(cl_num==6) child6* ch = new child6(parent,child);
  55.     }
  56.    
  57.     TYPE_SIGNAL sigs[] = {SIGNAL_D(cl_application::signal),SIGNAL_D(child2::signal),SIGNAL_D(child3::signal),
  58.                             SIGNAL_D(child4::signal),SIGNAL_D(child5::signal),SIGNAL_D(child6::signal),SIGNAL_D(child7::signal)};
  59.     TYPE_HENDLER hans[] = {HENDLER_D(cl_application::handler), HENDLER_D(child2::handler),
  60.                             HENDLER_D(child3::handler), HENDLER_D(child4::handler),
  61.                             HENDLER_D(child5::handler), HENDLER_D(child6::handler), HENDLER_D(child7::handler)};
  62.    
  63.     while(true){
  64.         string sender_path, reciever_path,message;
  65.         cin>>sender_path;
  66.         if(sender_path == "end_of_connections") break;
  67.        
  68.         cin>>reciever_path;
  69.        
  70.         cl_base* ob_sender = this -> get_ptr_from_path(sender_path);
  71.         cl_base* ob_reciever = this -> get_ptr_from_path(reciever_path);
  72.        
  73.         ob_sender -> set_connect (sigs[ob_sender->n_class-1],ob_reciever, hans[ob_reciever->n_class-1]);
  74.     }
  75.     return 0;
  76. }
  77.  
  78. void cl_application::signal(string& mes){
  79.     if(readiness){
  80.         cout<<endl<<"Signal from "<<get_abs_path();
  81.     }
  82.     mes+= " (class: 1)";
  83. }
  84. void cl_application::handler(string& mes){
  85.     if(readiness){
  86.         cout<<endl<<"Signal to "<<get_abs_path()<<" Text: "<<mes;
  87.     }
  88. }
  89.  
  90. int cl_application::exec_app() {
  91.    
  92.     TYPE_SIGNAL sigs[] = {SIGNAL_D(cl_application::signal),SIGNAL_D(child2::signal),SIGNAL_D(child3::signal),
  93.                             SIGNAL_D(child4::signal),SIGNAL_D(child5::signal),SIGNAL_D(child6::signal)};
  94.     TYPE_HENDLER hans[] = {HENDLER_D(cl_application::handler), HENDLER_D(child2::handler),
  95.                             HENDLER_D(child3::handler), HENDLER_D(child4::handler),
  96.                             HENDLER_D(child5::handler), HENDLER_D(child6::handler)};
  97.    
  98.     cout<<"Object tree\n";
  99.     this->print_tree();
  100.    
  101.     string command,arg,message;
  102.    
  103.     cl_base* temp = this;
  104.     cl_base* temp2 = this;
  105.    
  106.     int ready;
  107.    
  108.     while(true){
  109.  
  110.         cin>>command;
  111.         if(command=="END") return 0;
  112.         //cout<<endl;
  113.        
  114.         cin>>arg;
  115.        
  116.        
  117.         if(command == "EMIT"){
  118.             getline(cin,message);
  119.             temp = this->get_ptr_from_path(arg);
  120.             if(temp!=nullptr){
  121.                 temp->emit_signal(sigs[temp->n_class -1],message);
  122.             }else{
  123.                 cout<<endl<<"Object "<<arg<<" not found";
  124.             }
  125.            
  126.         }else if(command == "SET_CONNECT"){
  127.             cin>>message;
  128.             temp = this->get_ptr_from_path(arg);
  129.             temp2 = this->get_ptr_from_path(message);
  130.             if(temp==nullptr)
  131.                 cout<<endl<<"Object "<<arg<<" not found";
  132.             else if(temp2==nullptr)
  133.                 cout<<endl<<"Handler object "<<message<<" not found";
  134.             else{
  135.                 temp->set_connect(sigs[temp->n_class-1], temp2,hans[temp2->n_class-1]);
  136.             }
  137.            
  138.         }else if(command == "DELETE_CONNECT"){
  139.             cin>>message;
  140.             temp = this->get_ptr_from_path(arg);
  141.             temp2 = this->get_ptr_from_path(message);
  142.             if(temp==nullptr)
  143.                 cout<<endl<<"Object "<<arg<<" not found";
  144.             else if(temp2==nullptr)
  145.                 cout<<endl<<"Handler object "<<message<<" not found";
  146.             else{
  147.                 temp->delete_connect(sigs[temp->n_class-1], temp2,hans[temp2->n_class-1]);
  148.             }
  149.            
  150.         }else if(command == "SET_CONDITION"){
  151.             cin>>ready;
  152.             temp = this->get_ptr_from_path(arg);
  153.             if(temp!=nullptr){
  154.                 temp->set_readiness(ready);
  155.             }else{
  156.                 cout<<endl<<"Object "<<arg<<" not found";
  157.             }
  158.         }
  159.        
  160.     }
  161.     return 0;
  162. }
  163.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement