Serializing now serializes everything; among many other things:
[Mograsim.git] / net.mograsim.logic.model.am2900 / src / net / mograsim / logic / model / examples / ComponenetSerializer.java
1 package net.mograsim.logic.model.examples;
2
3 import java.io.IOException;
4
5 import net.mograsim.logic.model.model.ViewModelModifiable;
6 import net.mograsim.logic.model.model.components.mi.nandbased.GUI_rsLatch;
7 import net.mograsim.logic.model.model.components.mi.nandbased.GUIand;
8 import net.mograsim.logic.model.model.components.mi.nandbased.GUIand41;
9 import net.mograsim.logic.model.model.components.mi.nandbased.GUIandor414;
10 import net.mograsim.logic.model.model.components.mi.nandbased.GUIdemux2;
11 import net.mograsim.logic.model.model.components.mi.nandbased.GUIdff;
12 import net.mograsim.logic.model.model.components.mi.nandbased.GUIdlatch;
13 import net.mograsim.logic.model.model.components.mi.nandbased.GUIdlatch4;
14 import net.mograsim.logic.model.model.components.mi.nandbased.GUIfulladder;
15 import net.mograsim.logic.model.model.components.mi.nandbased.GUIhalfadder;
16 import net.mograsim.logic.model.model.components.mi.nandbased.GUImux1;
17 import net.mograsim.logic.model.model.components.mi.nandbased.GUImux1_4;
18 import net.mograsim.logic.model.model.components.mi.nandbased.GUInand3;
19 import net.mograsim.logic.model.model.components.mi.nandbased.GUInot4;
20 import net.mograsim.logic.model.model.components.mi.nandbased.GUIor4;
21 import net.mograsim.logic.model.model.components.mi.nandbased.GUIor_4;
22 import net.mograsim.logic.model.model.components.mi.nandbased.GUIram2;
23 import net.mograsim.logic.model.model.components.mi.nandbased.GUIram4;
24 import net.mograsim.logic.model.model.components.mi.nandbased.GUIsel2_4;
25 import net.mograsim.logic.model.model.components.mi.nandbased.GUIsel3_4;
26 import net.mograsim.logic.model.model.components.mi.nandbased.GUIxor;
27 import net.mograsim.logic.model.model.components.mi.nandbased.am2901.GUIAm2901;
28 import net.mograsim.logic.model.model.components.mi.nandbased.am2901.GUIAm2901ALUFuncDecode;
29 import net.mograsim.logic.model.model.components.mi.nandbased.am2901.GUIAm2901ALUInclDecode;
30 import net.mograsim.logic.model.model.components.mi.nandbased.am2901.GUIAm2901ALUInclSourceDecodeInclFunctionDecode;
31 import net.mograsim.logic.model.model.components.mi.nandbased.am2901.GUIAm2901ALUOneBit;
32 import net.mograsim.logic.model.model.components.mi.nandbased.am2901.GUIAm2901DestDecode;
33 import net.mograsim.logic.model.model.components.mi.nandbased.am2901.GUIAm2901QReg;
34 import net.mograsim.logic.model.model.components.mi.nandbased.am2901.GUIAm2901SourceDecode;
35 import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
36 import net.mograsim.logic.model.serializing.IdentifierGetter;
37 import net.mograsim.logic.model.serializing.SubmodelComponentParams;
38 import net.mograsim.logic.model.serializing.SubmodelComponentSerializer;
39 import net.mograsim.logic.model.util.JsonHandler;
40
41 public class ComponenetSerializer
42 {
43         public static void main(String[] args) throws IOException
44         {
45                 IdentifierGetter idGetter = new IdentifierGetter();
46                 // we know we only use components where this works
47                 idGetter.componentIDs = c -> c.getClass().getSimpleName();
48
49                 ViewModelModifiable model = new ViewModelModifiable();
50                 SubmodelComponent[] components = { new GUIAm2901(model), new GUIAm2901ALUFuncDecode(model), new GUIAm2901ALUInclDecode(model),
51                                 new GUIAm2901ALUInclSourceDecodeInclFunctionDecode(model), new GUIAm2901ALUOneBit(model), new GUIAm2901DestDecode(model),
52                                 new GUIAm2901QReg(model), new GUIAm2901SourceDecode(model), new GUI_rsLatch(model), new GUIand(model), new GUIand41(model),
53                                 new GUIandor414(model), new GUIdemux2(model), new GUIdff(model), new GUIdlatch(model), new GUIdlatch4(model),
54                                 new GUIfulladder(model), new GUIhalfadder(model), new GUImux1(model), new GUImux1_4(model), new GUInand3(model),
55                                 new GUInot4(model), new GUIor4(model), new GUIor_4(model), new GUIram2(model), new GUIram4(model), new GUIsel2_4(model),
56                                 new GUIsel3_4(model), new GUIxor(model) };
57
58                 for (SubmodelComponent comp : components)
59                 {
60                         SubmodelComponentParams params = SubmodelComponentSerializer.serialize(comp, idGetter);
61                         String shortClassName = comp.getClass().getName().substring("net.mograsim.logic.model.model.components.mi.nandbased.".length());
62                         String path = "components/" + shortClassName.replace('.', '/') + ".json";
63                         JsonHandler.writeJson(params, path);
64                 }
65         }
66 }