Generalized WireObserver to LogicObserver
[Mograsim.git] / net.mograsim.logic.core / src / net / mograsim / logic / core / components / Splitter.java
index 9eb5b2c..a6165d9 100644 (file)
@@ -1,59 +1,60 @@
-package net.mograsim.logic.core.components;
-
-import java.util.List;
-
-import net.mograsim.logic.core.timeline.Timeline;
-import net.mograsim.logic.core.types.BitVector;
-import net.mograsim.logic.core.wires.WireObserver;
-import net.mograsim.logic.core.wires.Wire.ReadEnd;
-import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
-
-public class Splitter extends Component implements WireObserver
-{
-       private ReadEnd input;
-       private ReadWriteEnd[] outputs;
-
-       public Splitter(Timeline timeline, ReadEnd input, ReadWriteEnd... outputs)
-       {
-               super(timeline);
-               this.input = input;
-               this.outputs = outputs;
-               input.addObserver(this);
-               int length = 0;
-               for (ReadEnd out : outputs)
-                       length += out.length();
-
-               if (input.length() != length)
-                       throw new IllegalArgumentException(
-                                       "The input of splitting one into n WireArrays must have length = a1.length() + a2.length() + ... + an.length().");
-       }
-
-       protected void compute()
-       {
-               BitVector inputBits = input.getValues();
-               int startIndex = 0;
-               for (int i = 0; i < outputs.length; i++)
-               {
-                       outputs[i].feedSignals(inputBits.subVector(startIndex, startIndex + outputs[i].length()));
-                       startIndex += outputs[i].length();
-               }
-       }
-
-       @Override
-       public void update(ReadEnd initiator, BitVector oldValues)
-       {
-               compute();
-       }
-
-       @Override
-       public List<ReadEnd> getAllInputs()
-       {
-               return List.of(input);
-       }
-
-       @Override
-       public List<ReadWriteEnd> getAllOutputs()
-       {
-               return List.of(outputs);
-       }
-}
+package net.mograsim.logic.core.components;\r
+\r
+import java.util.List;\r
+\r
+import net.mograsim.logic.core.LogicObservable;\r
+import net.mograsim.logic.core.LogicObserver;\r
+import net.mograsim.logic.core.timeline.Timeline;\r
+import net.mograsim.logic.core.types.BitVector;\r
+import net.mograsim.logic.core.wires.Wire.ReadEnd;\r
+import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;\r
+\r
+public class Splitter extends Component implements LogicObserver\r
+{\r
+       private ReadEnd input;\r
+       private ReadWriteEnd[] outputs;\r
+\r
+       public Splitter(Timeline timeline, ReadEnd input, ReadWriteEnd... outputs)\r
+       {\r
+               super(timeline);\r
+               this.input = input;\r
+               this.outputs = outputs;\r
+               input.registerObserver(this);\r
+               int length = 0;\r
+               for (ReadEnd out : outputs)\r
+                       length += out.length();\r
+\r
+               if (input.length() != length)\r
+                       throw new IllegalArgumentException(\r
+                                       "The input of splitting one into n WireArrays must have length = a1.length() + a2.length() + ... + an.length().");\r
+       }\r
+\r
+       protected void compute()\r
+       {\r
+               BitVector inputBits = input.getValues();\r
+               int startIndex = 0;\r
+               for (int i = 0; i < outputs.length; i++)\r
+               {\r
+                       outputs[i].feedSignals(inputBits.subVector(startIndex, startIndex + outputs[i].length()));\r
+                       startIndex += outputs[i].length();\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void update(LogicObservable initiator)\r
+       {\r
+               compute();\r
+       }\r
+\r
+       @Override\r
+       public List<ReadEnd> getAllInputs()\r
+       {\r
+               return List.of(input);\r
+       }\r
+\r
+       @Override\r
+       public List<ReadWriteEnd> getAllOutputs()\r
+       {\r
+               return List.of(outputs);\r
+       }\r
+}\r