// © Copyright 1995, Joseph Bergin. All rights reserved.

#ifndef __Circuit__
#define __Circuit__

#include "Gate.h"
#include "Array.h"
#include "Boolean.h"

// Circuit is abstract. It has a protected constructor.
class Circuit
{ 	public:
		virtual Array<Boolean> output();
//		void connect(unsigned int which, Gate * g);
			// connect input which to g's output
//		void connect(unsigned int which, Circuit c, unsigned int n);
			// Connect input which to c's n'th output.
		Gate * output(unsigned int n);
			// return a pointer to the gate connected
			// to the n'th output
	protected:
		Circuit(unsigned int inputs = 1, unsigned int outputs = 1);
//		Array<Gate *> _inputs;     // I think these are redundant
//		unsigned int _inputCount;
      Array<Gate *> _outputGates;
		unsigned int _outputCount;

};


class Adder: public Circuit
{	public:
		Adder(Gate* in1, Gate* in2);  // Inputs defined
	protected:
		AndGate _left;		// Internal gates of the circuit
		AndGate _right;
		AndGate _carry;
		OrGate _combine;
		NotGate _flipLeft;
		NotGate _flipRight;

};

class FullAdder: public Circuit
{	public:
		FullAdder(Gate* in1, Gate* in2, Gate* carryIn);

	protected:
		Adder _AB;// Order of declaration is important
		Adder _RC;// to guarantee order of construction.
		OrGate _carryOut;
};

#endif

