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

gateAND::gateAND()
{
    configureEmpty();
}

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

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

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