Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by qnbhd on 29.01.2020.
- //
- #ifndef ANASTASIA_COMMANDSET_HPP
- #define ANASTASIA_COMMANDSET_HPP
- #include "Set.hpp"
- typedef int (*function)(int* op1, int * op2);
- class CommandFunctor {
- private:
- function worker;
- std::string nameWorker;
- int * leftOperand;
- int * rightOperand;
- public:
- CommandFunctor (function func, const std::string& nameOf, int * leftA, int * rightA) :
- worker(func),
- nameWorker (nameOf),
- leftOperand(leftA),
- rightOperand(rightA)
- {}
- ~CommandFunctor() {
- delete leftOperand;
- delete rightOperand;
- };
- virtual void operator()(){
- *rightOperand = worker (leftOperand, rightOperand);
- };
- };
- class CommandSet {
- private:
- Set<CommandFunctor*> Operators;
- Set<CommandFunctor*> Commands;
- int ** Registers;
- static int AND (int *left, int *right) {
- return *left & *right;
- }
- static int SUB (int left, int right) {
- return left - right;
- }
- public:
- CommandSet (){
- Registers = new int * [16];
- for (int i = 0; i < 16; ++i)
- Registers[i] = new int;
- }
- ~CommandSet(){
- for (int i = 0; i < 16; ++i)
- delete Registers[i];
- delete [] Registers;
- }
- void put (int commandIndex, int register1, int * address)
- {
- switch (commandIndex)
- {
- case 1:
- Commands.insert (new CommandFunctor(AND, "AND", Registers[register1], address));
- default:;
- }
- }
- void print (){
- std::cout << Commands << std::endl;
- }
- };
- #endif //ANASTASIA_COMMANDSET_HPP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement