/// <summary> /// Creates a new <see cref="StateConfiguration"/> with identical content. /// </summary> /// <returns> /// A new <see cref="StateConfiguration"/> instance. /// </returns> public object Clone() { StateConfiguration stateConfig = m_stateMachineTemplate.InternalCreateStateConfiguration(null); m_states.CopyTo(stateConfig.m_states, 0); return(stateConfig); }
internal bool IsMatching(StateConfiguration stateConfigurationRhs, Region subRegionToCompare) { bool isSameAs; State stateLhs = this.GetState(subRegionToCompare); State stateRhs = stateConfigurationRhs.GetState(subRegionToCompare); if ((stateLhs != State.Wildcard) && (stateRhs != State.Wildcard)) { if (stateLhs == stateRhs) { isSameAs = true; // Bear in mind that stateLhs and stateRhs are identical, // thus it doesn't matter which of two state's Regions list we take for checking the subregions foreach (Region subRegion in stateLhs.Regions) { isSameAs = this.IsMatching(stateConfigurationRhs, subRegion); if (!isSameAs) { break; } } } else { isSameAs = false; } } else { isSameAs = true; } return(isSameAs); }
internal void CopyTo(StateConfiguration target) { if (target.m_stateMachineTemplate != m_stateMachineTemplate) { throw new ArgumentException("Cannot copy StateConfiguration between different StateMachineTemplate instances.", "target"); } m_states.CopyTo(target.m_states, 0); }
internal void InitializeAndResolve( StateConfiguration stateConfigurationBase, StateConfiguration stateConfigurationTarget, Region regionStart, State[] historyStatesRepository) { if (stateConfigurationBase != null) { // Copy from stateConfigurationBase into this. Array.Copy(stateConfigurationBase.m_states, m_states, m_states.Length); //stateConfigurationBase.m_states.CopyTo(this.m_states, 0); } else { // Initialize this items with null. Array.Clear(m_states, 0, m_states.Length); } this.InitializeAndResolve(stateConfigurationTarget, regionStart, historyStatesRepository); }
private void InitializeAndResolve( StateConfiguration stateConfigurationTarget, Region region, State[] historyStatesRepository) { // Copy the model's states to the target. If the target is a wildcard, then complete the // information by looking in the history states or setting it to the initial state of this region State state = stateConfigurationTarget.GetState(region); if (state == State.Wildcard) { if (region.HasHistory) { // Use previously stored history state state = historyStatesRepository[region.HistoryIndex]; } else { // Use initial state state = region.InitialState; } } if (state == null) { // Logical error: All StateConfigurationIndex elements have to be filled with valid state references throw new InvalidOperationException("Internal error: Either state configuration or initial state/history state not properly initialized."); } m_states[region.StateConfigurationIndex] = state; // Recurse to substates foreach (Region subRegion in state.Regions) { this.InitializeAndResolve(stateConfigurationTarget, subRegion, historyStatesRepository); } }
/// <summary> /// Indicates whether a <see cref="StateConfiguration"/> is compliant with this instance. /// </summary> /// <param name="stateConfiguration"> /// The <see cref="StateConfiguration"/> to be checked. /// </param> /// <returns> /// <c>true</c> if the given <see cref="StateConfiguration"/> is exactly identical or if it /// differs only in those slots where the other <see cref="StateConfiguration"/> isn't specified for a particular <see cref="Region"/>. /// <c>false</c> if there are different states for the same <see cref="Region"/> slot. /// </returns> /// <remarks> /// Every <see cref="Region"/> from the <see cref="StateMachineTemplate"/> occupies a "slot" within the /// <see cref="StateConfiguration"/>. These slots are filled with references to <see cref="State"/> instances or /// may be left unspecified during initialization of the <see cref="StateConfiguration"/>. /// A <see cref="StateConfiguration"/> that contains unspecified slots is partially specified but may /// still be compared for compliance with other <see cref="StateConfiguration"/> instances through the /// <see cref="StateConfiguration.IsMatching(StateConfiguration)"/> method. /// </remarks> public bool IsMatching(StateConfiguration stateConfiguration) { return(this.IsMatching(stateConfiguration, m_stateMachineTemplate.Root)); }