aboutsummaryrefslogtreecommitdiff
path: root/GateAnd.cpp
blob: 6f19d61f6b0fc4af5a7826ff2b6d2fb1673a5c55 (plain)
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
#include "GateAnd.h"

GateAnd GateAnd::instance(GateAnd::type);

GateAnd::GateAnd(const char * type) : Node(type) { }

void GateAnd::compare() {
	SignalLevel new_out = HIGH;
	// TODO: fix segfault somewhere below
	for (int i = 0; i < this->inputs.size(); i++){
		switch (this->inputs[i]->getLevel()){
			case LOW:
				new_out = LOW;
				break;
			case HIGH:
				continue;
				break;
			case UNDEFINED:
			default:
				new_out = UNDEFINED;
				// TODO: exception!!
				break;
		}
	}

	if (this->output->getLevel() == new_out) return;

	this->output->setLevel(new_out);
}

GateAnd::GateAnd(const GateAnd * prototype) : Node() { }

GateAnd * GateAnd::clone() const {
	return new GateAnd(this);
}