-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.h
108 lines (89 loc) · 1.97 KB
/
logic.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
103
104
105
106
107
108
//
// Created by liam on 11/04/16.
//
#ifndef COMPUTER_LOGIC_H
#define COMPUTER_LOGIC_H
// DEFINES logic gate components
#include <vector>
#include <string>
#include <map>
class Gate {
private:
bool gray = false;
static std::map<std::string, Gate*> gates;
std::string name;
protected:
bool state = false;
virtual bool calculate() = 0;
std::vector<Gate*> inputs;
public:
static Gate* factory(std::string name, std::string gateType);
static Gate* getGate(std::string name);
Gate(std::string name);
void setOutput(Gate* g);
virtual void setInput(Gate* g);
bool areParentsUpdated();
void update();
bool isGray();
void setGray();
bool getState();
//bool isGate = true;
std::vector<Gate*> outputs;
std::string getName();
void deleteInput(Gate* inputName);
void deleteOutput(Gate* outputName);
static bool isGate(std::string gateType);
// bool getIsGate();
};
class AND : public Gate {
protected:
virtual bool calculate();
public:
AND(std::string name) : Gate(name) {};
};
class OR : public Gate {
protected:
virtual bool calculate();
public:
OR (std::string name) : Gate(name) {};
};
class XOR : public Gate {
protected:
virtual bool calculate();
public:
XOR (std::string name) : Gate(name) {};
};
class NAND : public AND {
private:
bool calculate();
public:
NAND (std::string name) : AND(name) {};
};
class NOR : public OR {
private:
bool calculate();
public:
NOR (std::string name) : OR(name) {};
};
class XNOR : public XOR {
private:
bool calculate();
public:
XNOR (std::string name) : XOR(name) {};
};
class Input : public Gate {
private:
bool calculate();
public:
Input(std::string name) : Gate(name){};
void set(bool newState);
std::vector<Gate*> getOutputs();
};
class Output : public Gate {
private:
bool calculate();
public:
Output(std::string name) : Gate(name) {};
std::vector<Gate*> getInputs();
};
#endif //COMPUTER_LOGIC_H