Adding to and removing from a system

Once we’ve made a system, we can use it just like a normal object manager.

Every object will get an ID to track, which will be the an incrementing index.

ChemicalSystemAdd[ChemicalSystem[system_Symbol],
 h_[a_Association]
 ]:=With[{ID=system["Index"]},
 system[ID]=h[Merge[{a,<|"ID"ID,"System"system["ID"]|>},Last]];
  system["Index"]=ID+1;
  h[ID,system["ID"]]
  ];

ChemicalSystemDelete[ChemicalSystem[system_Symbol],ID_Integer]:=KeyDropFrom[system,ID];

ChemicalSystemAdd[e:Except[_ChemicalSystem]]:=ChemicalSystemAdd[$DefaultChemicalSystem,e]

ChemicalSystemDelete[e:Except[_ChemicalSystem]]:=ChemicalSystemDelete[$DefaultChemicalSystem,e]

Finally the following will be useful for accessing these objects:

ChemicalSystem[system_Symbol][objectID_Integer]:=system[objectID];

results matching ""

    No results matching ""