aboutsummaryrefslogtreecommitdiff
path: root/GateAnd.cpp
blob: 93edacb39b6fe2a500774be1347215832d7fba09 (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::sim() {
	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);
}