Made get/setHLS final to force components to set a HLSHandler
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Tue, 1 Oct 2019 14:25:58 +0000 (16:25 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Tue, 1 Oct 2019 14:25:58 +0000 (16:25 +0200)
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/ModelComponent.java
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelClock.java
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelManualSwitch.java
plugins/net.mograsim.machine/src/net/mograsim/machine/mi/components/ModelMicroInstructionMemory.java
plugins/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelWordAddressableMemory.java

index d543c54..ded6685 100644 (file)
@@ -14,6 +14,7 @@ import net.mograsim.logic.model.model.wires.Pin;
 import net.mograsim.logic.model.serializing.IdentifyParams;
 import net.mograsim.logic.model.serializing.JSONSerializable;
 import net.mograsim.logic.model.snippets.HighLevelStateHandler;
+import net.mograsim.logic.model.snippets.highlevelstatehandlers.DefaultHighLevelStateHandler;
 
 /**
  * The base class for all model components.<br>
@@ -77,6 +78,8 @@ public abstract class ModelComponent implements JSONSerializable
                this.pinAddedListeners = new ArrayList<>();
                this.pinRemovedListeners = new ArrayList<>();
 
+               this.highLevelStateHandler = new DefaultHighLevelStateHandler();
+
                if (callInit)
                        init();
        }
@@ -216,7 +219,7 @@ public abstract class ModelComponent implements JSONSerializable
         * 
         * @author Daniel Kirschten
         */
-       public Object getHighLevelState(String stateID)
+       public final Object getHighLevelState(String stateID)
        {
                return highLevelStateHandler.getHighLevelState(stateID);
        }
@@ -230,7 +233,7 @@ public abstract class ModelComponent implements JSONSerializable
         * 
         * @author Daniel Kirschten
         */
-       public void setHighLevelState(String stateID, Object newState)
+       public final void setHighLevelState(String stateID, Object newState)
        {
                highLevelStateHandler.setHighLevelState(stateID, newState);
        }
index 3896353..d84e202 100644 (file)
@@ -20,6 +20,7 @@ import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
 import net.mograsim.logic.model.modeladapter.componentadapters.ClockAdapter;
 import net.mograsim.logic.model.serializing.IdentifyParams;
 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
+import net.mograsim.logic.model.snippets.HighLevelStateHandler;
 import net.mograsim.logic.model.util.JsonHandler;
 import net.mograsim.preferences.Preferences;
 
@@ -53,6 +54,47 @@ public class ModelClock extends ModelComponent
                this.outputPin = new Pin(model, this, "", 1, PinUsage.OUTPUT, oc.newX(width, height / 2), oc.newY(width, height / 2));
                addPin(outputPin);
 
+               setHighLevelStateHandler(new HighLevelStateHandler()
+               {
+                       @Override
+                       public Object getHighLevelState(String stateID)
+                       {
+                               switch (stateID)
+                               {
+                               case "out":
+                                       if (clock != null)
+                                               return clock.getOut().getInputValues();
+                                       return null;
+                               default:
+                                       throw new IllegalArgumentException("No high level state with ID " + stateID);
+                               }
+                       }
+
+                       @Override
+                       public void setHighLevelState(String stateID, Object newState)
+                       {
+                               switch (stateID)
+                               {
+                               case "out":
+                                       throw new UnsupportedOperationException("cannot set state of clock");
+                               default:
+                                       throw new IllegalArgumentException("No high level state with ID " + stateID);
+                               }
+                       }
+
+                       @Override
+                       public String getIDForSerializing(IdentifyParams idParams)
+                       {
+                               return null;
+                       }
+
+                       @Override
+                       public Object getParamsForSerializing(IdentifyParams idParams)
+                       {
+                               return null;
+                       }
+               });
+
                init();
        }
 
@@ -89,32 +131,6 @@ public class ModelClock extends ModelComponent
                return clock != null;
        }
 
-       @Override
-       public Object getHighLevelState(String stateID)
-       {
-               switch (stateID)
-               {
-               case "out":
-                       if (clock != null)
-                               return clock.getOut().getInputValues();
-                       return null;
-               default:
-                       return super.getHighLevelState(stateID);
-               }
-       }
-
-       @Override
-       public void setHighLevelState(String stateID, Object newState)
-       {
-               switch (stateID)
-               {
-               case "out":
-                       throw new UnsupportedOperationException("cannot set state of clock");
-               default:
-                       super.setHighLevelState(stateID, newState);
-               }
-       }
-
        public CoreClock getClock()
        {
                return clock;
index 7a99504..cf9735a 100644 (file)
@@ -19,6 +19,7 @@ import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
 import net.mograsim.logic.model.modeladapter.componentadapters.ManualSwitchAdapter;
 import net.mograsim.logic.model.serializing.IdentifyParams;
 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
+import net.mograsim.logic.model.snippets.HighLevelStateHandler;
 import net.mograsim.preferences.Preferences;
 
 public class ModelManualSwitch extends ModelComponent
@@ -48,6 +49,49 @@ public class ModelManualSwitch extends ModelComponent
                setSize(width, height);
                addPin(this.outputPin = new Pin(model, this, "", logicWidth, PinUsage.OUTPUT, width, height / 2));
 
+               setHighLevelStateHandler(new HighLevelStateHandler()
+               {
+                       @Override
+                       public Object getHighLevelState(String stateID)
+                       {
+                               switch (stateID)
+                               {
+                               case "out":
+                                       if (manualSwitch != null)
+                                               return manualSwitch.getValues();
+                                       return null;
+                               default:
+                                       throw new IllegalArgumentException("No high level state with ID " + stateID);
+                               }
+                       }
+
+                       @Override
+                       public void setHighLevelState(String stateID, Object newState)
+                       {
+                               switch (stateID)
+                               {
+                               case "out":
+                                       if (manualSwitch != null)
+                                               manualSwitch.setState((BitVector) newState);
+                                       break;
+                               default:
+                                       throw new IllegalArgumentException("No high level state with ID " + stateID);
+                               }
+                       }
+
+                       @Override
+                       public String getIDForSerializing(IdentifyParams idParams)
+                       {
+                               return null;
+                       }
+
+                       @Override
+                       public Object getParamsForSerializing(IdentifyParams idParams)
+                       {
+                               return null;
+                       }
+               });
+
                init();
        }
 
@@ -108,35 +152,6 @@ public class ModelManualSwitch extends ModelComponent
                return manualSwitch != null;
        }
 
-       @Override
-       public Object getHighLevelState(String stateID)
-       {
-               switch (stateID)
-               {
-               case "out":
-                       if (manualSwitch != null)
-                               return manualSwitch.getValues();
-                       return null;
-               default:
-                       return super.getHighLevelState(stateID);
-               }
-       }
-
-       @Override
-       public void setHighLevelState(String stateID, Object newState)
-       {
-               switch (stateID)
-               {
-               case "out":
-                       if (manualSwitch != null)
-                               manualSwitch.setState((BitVector) newState);
-                       break;
-               default:
-                       super.setHighLevelState(stateID, newState);
-                       break;
-               }
-       }
-
        @Override
        public boolean clicked(double x, double y)
        {
index aeffbd2..706734f 100644 (file)
@@ -4,6 +4,8 @@ import net.mograsim.logic.model.model.LogicModelModifiable;
 import net.mograsim.logic.model.model.wires.Pin;
 import net.mograsim.logic.model.model.wires.PinUsage;
 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
+import net.mograsim.logic.model.serializing.IdentifyParams;
+import net.mograsim.logic.model.snippets.HighLevelStateHandler;
 import net.mograsim.machine.ModelMemory;
 import net.mograsim.machine.mi.MicroInstructionMemory;
 import net.mograsim.machine.mi.MicroInstructionMemoryDefinition;
@@ -22,6 +24,38 @@ public abstract class ModelMicroInstructionMemory extends ModelMemory
                addPin(dataPin = new Pin(model, this, "D", definition.getMicroInstructionDefinition().sizeInBits(), PinUsage.OUTPUT, getWidth(),
                                50));
 
+               setHighLevelStateHandler(new HighLevelStateHandler()
+               {
+                       @Override
+                       public Object getHighLevelState(String stateID)
+                       {
+                               if (stateID.equals("memory_binding"))
+                                       return memory.getMemory();
+                               throw new IllegalArgumentException("No high level state with ID " + stateID);
+                       }
+
+                       @Override
+                       public void setHighLevelState(String stateID, Object newState)
+                       {
+                               if (stateID.equals("memory_binding"))
+                                       memory.setMemory((MicroInstructionMemory) newState);
+                               else
+                                       throw new IllegalArgumentException("No high level state with ID " + stateID);
+                       }
+
+                       @Override
+                       public String getIDForSerializing(IdentifyParams idParams)
+                       {
+                               return null;
+                       }
+
+                       @Override
+                       public Object getParamsForSerializing(IdentifyParams idParams)
+                       {
+                               return null;
+                       }
+               });
+
                init();
        }
 
@@ -50,23 +84,6 @@ public abstract class ModelMicroInstructionMemory extends ModelMemory
                this.memory = memory;
        }
 
-       @Override
-       public void setHighLevelState(String stateID, Object newState)
-       {
-               if (stateID.equals("memory_binding"))
-                       memory.setMemory((MicroInstructionMemory) newState);
-               else
-                       super.setHighLevelState(stateID, newState);
-       }
-
-       @Override
-       public Object getHighLevelState(String stateID)
-       {
-               if (stateID.equals("memory_binding"))
-                       return memory.getMemory();
-               return super.getHighLevelState(stateID);
-       }
-
        static
        {
                LogicCoreAdapter.addComponentAdapter(new MicroInstructionMemoryAdapter());
index 7490b36..b249849 100644 (file)
@@ -4,6 +4,8 @@ import net.mograsim.logic.model.model.LogicModelModifiable;
 import net.mograsim.logic.model.model.wires.Pin;
 import net.mograsim.logic.model.model.wires.PinUsage;
 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
+import net.mograsim.logic.model.serializing.IdentifyParams;
+import net.mograsim.logic.model.snippets.HighLevelStateHandler;
 import net.mograsim.machine.MainMemory;
 import net.mograsim.machine.MainMemoryDefinition;
 import net.mograsim.machine.ModelMemory;
@@ -23,6 +25,38 @@ public abstract class ModelWordAddressableMemory extends ModelMemory
                addPin(dataPin = new Pin(model, this, "D", definition.getCellWidth(), PinUsage.TRISTATE, getWidth(), 50));
                addPin(rWPin = new Pin(model, this, "RW", 1, PinUsage.INPUT, getWidth(), 70));
 
+               setHighLevelStateHandler(new HighLevelStateHandler()
+               {
+                       @Override
+                       public Object getHighLevelState(String stateID)
+                       {
+                               if (stateID.equals("memory_binding"))
+                                       return memory.getMemory();
+                               throw new IllegalArgumentException("No high level state with ID " + stateID);
+                       }
+
+                       @Override
+                       public void setHighLevelState(String stateID, Object newState)
+                       {
+                               if (stateID.equals("memory_binding"))
+                                       memory.setMemory((MainMemory) newState);
+                               else
+                                       throw new IllegalArgumentException("No high level state with ID " + stateID);
+                       }
+
+                       @Override
+                       public String getIDForSerializing(IdentifyParams idParams)
+                       {
+                               return null;
+                       }
+
+                       @Override
+                       public Object getParamsForSerializing(IdentifyParams idParams)
+                       {
+                               return null;
+                       }
+               });
+
                init();
        }
 
@@ -56,23 +90,6 @@ public abstract class ModelWordAddressableMemory extends ModelMemory
                return memory;
        }
 
-       @Override
-       public void setHighLevelState(String stateID, Object newState)
-       {
-               if (stateID.equals("memory_binding"))
-                       memory.setMemory((MainMemory) newState);
-               else
-                       super.setHighLevelState(stateID, newState);
-       }
-
-       @Override
-       public Object getHighLevelState(String stateID)
-       {
-               if (stateID.equals("memory_binding"))
-                       return memory.getMemory();
-               return super.getHighLevelState(stateID);
-       }
-
        static
        {
                LogicCoreAdapter.addComponentAdapter(new WordAddressableMemoryAdapter());