-
Notifications
You must be signed in to change notification settings - Fork 0
/
Command.h
102 lines (76 loc) · 2.15 KB
/
Command.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
enum Command_t {STANDART, JUMP, PUSH};
class Command
{
public:
Command_t getType() {return type_;}
int getLength() {return length_;}
unsigned char getCommand() {return command_;}
void fillTranslation(char* pointer)
{
memcpy(pointer, translation_, length_);
}
Command(Command_t type, int length, unsigned char command, char* translation)
{
if(length < 0 || !translation);
type_ = type;
length_ = length;
command_ = command;
char* translation_ = new char[length_];
memcpy(translation_, translation, length_);
copy_ = false;
}
~Command() {if(!copy_) delete[] translation_;}
Command* operator=(Command* item) {return item;}
Command(const Command& item)
{
length_ = item.length_;
type_ = item.type_;
command_ = item.command_;
translation_ = item.translation_;
copy_ = true;
}
protected:
Command_t type_;
int length_;
unsigned command_;
char* translation_;
bool copy_;
};
class Jmp : public Command
{
public:
void setJmpLength(size_t length)
{
*(size_t*)(translation_ + indent_) = length;
}
int getJmpLength() {return *(size_t*)(translation_ + indent_);}
Jmp(Command_t type, int length, unsigned char command, char* translation, unsigned int indent)
:Command(type, length, command, translation)
{
if(indent <= 0);
indent_ = indent;
}
Jmp* operator=(Jmp* item) {return item;}
~Jmp() {if(!copy_) delete[] translation_;}
void operator=(const Jmp&);
Jmp(const Jmp& item) : Command(item)
{
indent_ = 0;
}
private:
unsigned int indent_;
};
class Push : public Command
{
public:
void setNumber(double number)
{
*(double*)(translation_ + 1) = number;
}
Push(Command_t type, int length, unsigned char command, char* translation)
:Command(type, length, command, translation) {}
Push* operator=(Push* item) {return item;}
~Push() {delete[] translation_;}
void operator=(const Push&);
Push(const Push& item) : Command(item) {}
};