Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. //
  2. // Created by qnbhd on 29.01.2020.
  3. //
  4.  
  5. #ifndef ANASTASIA_COMMANDSET_HPP
  6. #define ANASTASIA_COMMANDSET_HPP
  7.  
  8. #include "Set.hpp"
  9.  
  10. typedef int (*function)(int* op1, int * op2);
  11.  
  12. class CommandFunctor {
  13. private:
  14.     function worker;
  15.     std::string nameWorker;
  16.     int * leftOperand;
  17.     int * rightOperand;
  18. public:
  19.     CommandFunctor (function func, const std::string& nameOf, int * leftA, int * rightA) :
  20.             worker(func),
  21.             nameWorker (nameOf),
  22.             leftOperand(leftA),
  23.             rightOperand(rightA)
  24.     {}
  25.  
  26.     ~CommandFunctor() {
  27.         delete leftOperand;
  28.         delete rightOperand;
  29.     };
  30.  
  31.     virtual void operator()(){
  32.         *rightOperand = worker (leftOperand, rightOperand);
  33.     };
  34. };
  35.  
  36.  
  37. class CommandSet {
  38. private:
  39.     Set<CommandFunctor*> Operators;
  40.     Set<CommandFunctor*> Commands;
  41.  
  42.     int ** Registers;
  43.  
  44.     static int AND (int *left, int *right) {
  45.         return *left & *right;
  46.     }
  47.  
  48.     static int SUB (int left, int right) {
  49.         return left - right;
  50.     }
  51.  
  52. public:
  53.  
  54.     CommandSet (){
  55.         Registers = new int * [16];
  56.         for (int i = 0; i < 16; ++i)
  57.             Registers[i] = new int;
  58.     }
  59.  
  60.     ~CommandSet(){
  61.         for (int i = 0; i < 16; ++i)
  62.             delete Registers[i];
  63.         delete [] Registers;
  64.     }
  65.  
  66.     void put (int commandIndex, int register1, int * address)
  67.     {
  68.         switch (commandIndex)
  69.         {
  70.             case 1:
  71.                 Commands.insert (new CommandFunctor(AND, "AND", Registers[register1], address));
  72.             default:;
  73.         }
  74.     }
  75.  
  76.     void print (){
  77.         std::cout << Commands << std::endl;
  78.     }
  79.  
  80. };
  81.  
  82.  
  83. #endif //ANASTASIA_COMMANDSET_HPP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement