CppLogicGateSimulator / gateOR.cpp
gateOR.cpp
Raw
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include "node.h"
#include "gateOR.h"

gateOR::gateOR()
{
    configureEmpty();
}

gateOR::gateOR(string inName)
{
    configureName(inName);
}

gateOR::gateOR (node* input1, node* input2, node* out)
{
    configureForTwoInputs(input1, input2, out);
}

int gateOR::compute()
{
    //Check status of inputs
    for(node* inNode : inputs)
    {
        if (!inNode->alreadyComputed)    //input undefined
        {
            cout<<name<<" cannot be computed"<<endl;
            return -1;
        }
    }
    output->setValue(false); //output value is 0
    for(node* inNode : inputs) //check if output value will be 1, then overwrite
    {
        if(inNode->value)   //if only one in is high, out is high
        {
            output->setValue(true);
        }
    }
    return -1;
}