// Adds a numbered component to the circuit. // Throws NoMoreIdsException if there are no more remaining ids. // Else returns the component's id. // The returned id will be in the range [1,NUM_IDS] public uint AddNumberedComponent(SPLogicComponent component) { Debug.Log("Call to add numbered component made\n"); var InputComponent = component as SPNumberedInputToggler; var OutputComponent = component as SPNumberedOutput; if (InputComponent != null) { for (uint cid = 1; cid <= NUM_IDS; cid++) { if (!NumberedInputs.ContainsKey(cid)) { NumberedInputs.Add(cid, InputComponent); this.Circuit.AddNumberedComponent(component.LogicComponent, cid); return(cid); } } } if (OutputComponent != null) { for (uint cid = 1; cid <= NUM_IDS; cid++) { if (!NumberedOutputs.ContainsKey(cid)) { NumberedOutputs.Add(cid, OutputComponent); this.Circuit.AddNumberedComponent(component.LogicComponent, cid); return(cid); } } } throw new NoMoreIdsException("No more ids for component"); }
// Removes a numbered component from the circuit. public void RemoveNumberedComponent(SPLogicComponent component) { //Debug.Log("RemovedNumberedComponent called"); var InputComponent = component as SPNumberedInputToggler; var OutputComponent = component as SPNumberedOutput; if (InputComponent != null) { Assert.IsTrue(InputComponent.id > 0); NumberedInputs.Remove(InputComponent.id); this.Circuit.RemoveComponent(component.LogicComponent); } else if (OutputComponent != null) { Assert.IsTrue(OutputComponent.id > 0); NumberedOutputs.Remove(OutputComponent.id); this.Circuit.RemoveComponent(component.LogicComponent); } else { // Hack for Assert.Fail() Assert.IsTrue((InputComponent != null) || (OutputComponent != null), "Tried to call remove numbered component on a non numbered component"); } }
internal void Register(SPLogicComponent parentComponent, SPConnectorType connectorType, int connectorId) { // Sanity checks Assert.IsNull(ParentComponent); Assert.AreEqual(connectorType, ConnectorType); ParentComponent = parentComponent; ConnectorId = connectorId; }