1 package era.mi.logic.components.gates;
\r
3 import java.util.List;
\r
5 import era.mi.logic.components.BasicComponent;
\r
6 import era.mi.logic.timeline.Timeline;
\r
7 import era.mi.logic.types.BitVector.BitVectorMutator;
\r
8 import era.mi.logic.types.MutationOperation;
\r
9 import era.mi.logic.wires.Wire.ReadEnd;
\r
10 import era.mi.logic.wires.Wire.ReadWriteEnd;
\r
12 public abstract class MultiInputGate extends BasicComponent
\r
14 protected ReadEnd[] in;
\r
15 protected ReadWriteEnd out;
\r
16 protected final int length;
\r
17 protected MutationOperation op;
\r
19 protected MultiInputGate(Timeline timeline, int processTime, MutationOperation op, ReadWriteEnd out, ReadEnd... in)
\r
21 super(timeline, processTime);
\r
23 length = out.length();
\r
24 this.in = in.clone();
\r
26 throw new IllegalArgumentException(String.format("Cannot create gate with %d wires.", in.length));
\r
27 for (ReadEnd w : in)
\r
29 if (w.length() != length)
\r
30 throw new IllegalArgumentException("All wires connected to the gate must be of uniform length.");
\r
31 w.addObserver(this);
\r
37 public List<ReadEnd> getAllInputs()
\r
43 public List<ReadWriteEnd> getAllOutputs()
\r
45 return List.of(out);
\r
49 protected void compute()
\r
51 BitVectorMutator mutator = BitVectorMutator.empty();
\r
52 for (ReadEnd w : in)
\r
53 op.apply(mutator, w.getValues());
\r
54 out.feedSignals(mutator.get());
\r