/// <summary> /// Checks if a state is the child of another. This method returns true if <paramref name="parentState"/> and <paramref name="state"/> are the same. /// </summary> /// <param name="parentState">The parent state.</param> /// <param name="state">The state to check.</param> /// <param name="firstIndex">The first index in the chain leading from the parent to the child. Null if they are the same.</param> /// <returns>True if <paramref name="parentState"/> is <paramref name="state"/> or a parent; Otherwise, false.</returns> public virtual bool IsChildState(IReadOnlyNodeState parentState, IReadOnlyNodeState state, out IReadOnlyIndex firstIndex) { firstIndex = null; while (state != null) { if (state == parentState) { return(true); } if (state is IReadOnlyPatternState AsPatternState) { IReadOnlyBlockState BlockState = AsPatternState.ParentBlockState; Debug.Assert(BlockState.StateList.Count > 0); IReadOnlyPlaceholderNodeState FirstState = BlockState.StateList[0]; firstIndex = FirstState.ParentIndex; } else if (state is IReadOnlySourceState AsSourceState) { IReadOnlyBlockState BlockState = AsSourceState.ParentBlockState; Debug.Assert(BlockState.StateList.Count > 0); IReadOnlyPlaceholderNodeState FirstState = BlockState.StateList[0]; firstIndex = FirstState.ParentIndex; } else { firstIndex = state.ParentIndex; } state = state.ParentState; } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyBlockListInner{IIndex}"/> class. /// </summary> /// <param name="owner">Parent containing the inner.</param> /// <param name="propertyName">Property name of the inner in <paramref name="owner"/>.</param> public ReadOnlyBlockListInner(IReadOnlyNodeState owner, string propertyName) : base(owner, propertyName) { BlockType = NodeTreeHelperBlockList.BlockListBlockType(Owner.Node, PropertyName); _BlockStateList = CreateBlockStateList(); BlockStateList = _BlockStateList.ToReadOnly(); }
/// <summary> /// Handler called every time a state is removed in the controller. /// </summary> /// <param name="state">The state removed.</param> public virtual void OnNodeStateRemoved(IReadOnlyNodeState state) { Debug.Assert(state != null); Debug.Assert(StateViewTable.ContainsKey(state)); StateViewTable.Remove(state); }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyBlockListInner{IIndex}"/> class. /// </summary> /// <param name="owner">Parent containing the inner.</param> protected ReadOnlyBlockListInner(IReadOnlyNodeState owner) : base(owner) { BlockType = Type.FromTypeof <object>(); _BlockStateList = CreateBlockStateList(); BlockStateList = _BlockStateList.ToReadOnly(); }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyBrowseContext"/> class. /// </summary> /// <param name="state">The state that will be browsed.</param> public ReadOnlyBrowseContext(IReadOnlyNodeState state) { State = state; InternalIndexCollectionList = CreateIndexCollectionList(); IndexCollectionList = InternalIndexCollectionList.ToReadOnly(); _ValuePropertyTypeTable = new Dictionary <string, ValuePropertyType>(); }
/// <summary> /// Handler called every time a state is removed in the controller. /// </summary> /// <param name="state">The state removed.</param> public virtual void OnNodeStateRemoved(IReadOnlyNodeState state) { Contract.RequireNotNull(state, out IReadOnlyNodeState State); Debug.Assert(StateViewTable.ContainsKey(State)); StateViewTable.Remove(State); }
private protected virtual bool IsChildrenEqual(CompareEqual comparer, IReadOnlyNodeState nodeState) { if (!comparer.VerifyEqual(InnerTable, nodeState.InnerTable)) { return(comparer.Failed()); } if (!comparer.IsSameCount(ValuePropertyTypeTable.Count, nodeState.ValuePropertyTypeTable.Count)) { return(comparer.Failed()); } foreach (KeyValuePair <string, ValuePropertyType> Entry in ValuePropertyTypeTable) { if (!comparer.IsTrue(nodeState.ValuePropertyTypeTable.ContainsKey(Entry.Key))) { return(comparer.Failed()); } if (!comparer.IsTrue(nodeState.ValuePropertyTypeTable[Entry.Key] == Entry.Value)) { return(comparer.Failed()); } } return(true); }
/// <summary> /// Handler called every time a state is created in the controller. /// </summary> /// <param name="state">The state created.</param> public virtual void OnNodeStateCreated(IReadOnlyNodeState state) { Debug.Assert(state != null); Debug.Assert(!StateViewTable.ContainsKey(state)); IReadOnlyNodeStateView StateView = null; switch (state) { case IReadOnlyPatternState AsPatternState: StateView = CreatePatternStateView(AsPatternState); break; case IReadOnlySourceState AsSourceState: StateView = CreateSourceStateView(AsSourceState); break; case IReadOnlyPlaceholderNodeState AsPlaceholderState: StateView = CreatePlaceholderNodeStateView(AsPlaceholderState); break; case IReadOnlyOptionalNodeState AsOptionalState: StateView = CreateOptionalNodeStateView(AsOptionalState); break; } Debug.Assert(StateView != null); StateViewTable.Add(state, StateView); }
private protected virtual void InitParentState(IReadOnlyNodeState parentState) { Debug.Assert(parentState != null); Debug.Assert(ParentState == null); ParentState = parentState; }
private protected virtual IReadOnlyInner BuildInner(IReadOnlyNodeState parentState, IReadOnlyIndexCollection nodeIndexCollection) { IReadOnlyInner Result = null; switch (nodeIndexCollection) { case IReadOnlyIndexCollection <IReadOnlyBrowsingPlaceholderNodeIndex> AsPlaceholderNodeIndexCollection: Result = (IReadOnlyPlaceholderInner)CreatePlaceholderInner(parentState, AsPlaceholderNodeIndexCollection); break; case IReadOnlyIndexCollection <IReadOnlyBrowsingOptionalNodeIndex> AsOptionalNodeIndexCollection: Result = (IReadOnlyOptionalInner)CreateOptionalInner(parentState, AsOptionalNodeIndexCollection); break; case IReadOnlyIndexCollection <IReadOnlyBrowsingListNodeIndex> AsListNodeIndexCollection: Stats.ListCount++; Result = (IReadOnlyListInner)CreateListInner(parentState, AsListNodeIndexCollection); break; case IReadOnlyIndexCollection <IReadOnlyBrowsingBlockNodeIndex> AsBlockNodeIndexCollection: Stats.BlockListCount++; IReadOnlyBlockListInner Inner = (IReadOnlyBlockListInner)CreateBlockListInner(parentState, AsBlockNodeIndexCollection); NotifyBlockListInnerCreated(Inner as IReadOnlyBlockListInner); Result = Inner; break; } Debug.Assert(Result != null); return(Result); }
private protected virtual ReadOnlyInnerReadOnlyDictionary <string> BuildInnerTable(ReadOnlyBrowseContext browseContext) { IReadOnlyNodeState State = browseContext.State; Debug.Assert(State.InnerTable == null); ReadOnlyIndexCollectionReadOnlyList IndexCollectionList = browseContext.IndexCollectionList; ReadOnlyInnerDictionary <string> InnerTable = CreateInnerTable(); foreach (IReadOnlyIndexCollection NodeIndexCollection in IndexCollectionList) { string PropertyName = NodeIndexCollection.PropertyName; Debug.Assert(!InnerTable.ContainsKey(PropertyName)); IReadOnlyInner Inner = BuildInner(State, NodeIndexCollection); InnerTable.Add(PropertyName, Inner); } if (InnerTable.Count > 0) { DebugObjects.AddReference(InnerTable); } return(InnerTable.ToReadOnly()); }
bool IDictionary <IReadOnlyNodeState, IReadOnlyNodeStateView> .TryGetValue(IReadOnlyNodeState key, out IReadOnlyNodeStateView value) { bool Result = TryGetValue((IFocusNodeState)key, out IFocusNodeStateView Value); value = Value; return(Result); }
/// <summary> /// Handler called every time a state is initialized in the controller. /// </summary> /// <param name="state">The state initialized.</param> public virtual void OnNodeStateInitialized(IReadOnlyNodeState state) { Contract.RequireNotNull(state, out IReadOnlyNodeState State); Debug.Assert(StateViewTable.ContainsKey(State)); IReadOnlyNodeStateView StateView = StateViewTable[State]; }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyInner{IIndex}"/> class. /// </summary> /// <param name="owner">Parent containing the inner.</param> /// <param name="propertyName">Property name of the inner in <paramref name="owner"/>.</param> public ReadOnlyInner(IReadOnlyNodeState owner, string propertyName) { Debug.Assert(owner != null); Debug.Assert(!string.IsNullOrEmpty(propertyName)); Owner = owner; PropertyName = propertyName; }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyNodeStateView"/> class. /// </summary> /// <param name="controllerView">The controller view to which this object belongs.</param> /// <param name="state">The node state.</param> public ReadOnlyNodeStateView(IReadOnlyControllerView controllerView, IReadOnlyNodeState state) { Debug.Assert(controllerView != null); Debug.Assert(state != null); ControllerView = controllerView; State = state; }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyNodeStateView"/> class. /// </summary> /// <param name="controllerView">The controller view to which this object belongs.</param> /// <param name="state">The node state.</param> public ReadOnlyNodeStateView(ReadOnlyControllerView controllerView, IReadOnlyNodeState state) { Contract.RequireNotNull(controllerView, out ReadOnlyControllerView ControllerView); Contract.RequireNotNull(state, out IReadOnlyNodeState State); this.ControllerView = ControllerView; this.State = State; }
private void AddChildStates(IReadOnlyNodeStateList stateList, IReadOnlyNodeState state) { stateList.Add(state); foreach (KeyValuePair <string, IReadOnlyInner> Entry in state.InnerTable) { AddChildInner(stateList, Entry.Value); } }
/// <summary> /// Initializes a new instance of the <see cref="ReadOnlyInner{IIndex}"/> class. /// </summary> /// <param name="owner">Parent containing the inner.</param> /// <param name="propertyName">Property name of the inner in <paramref name="owner"/>.</param> public ReadOnlyInner(IReadOnlyNodeState owner, string propertyName) { Contract.RequireNotNull(owner, out IReadOnlyNodeState Owner); Contract.RequireNotNull(propertyName, out string PropertyName); Debug.Assert(PropertyName.Length > 0); this.Owner = Owner; this.PropertyName = PropertyName; }
/// <summary> /// Handler called every time a state is initialized in the controller. /// </summary> /// <param name="state">The state initialized.</param> public virtual void OnNodeStateInitialized(IReadOnlyNodeState state) { Debug.Assert(state != null); Debug.Assert(StateViewTable.ContainsKey(state)); IReadOnlyNodeStateView StateView = StateViewTable[state]; Debug.Assert(StateView.ToString() != null); // For code coverage. }
private protected virtual void BrowseStateChildren(ReadOnlyBrowseContext browseContext, IReadOnlyInner <IReadOnlyBrowsingChildIndex> parentInner) { Debug.Assert(browseContext.IndexCollectionList.Count == 0); IReadOnlyNodeState State = browseContext.State; ((IReadOnlyNodeState <IReadOnlyInner <IReadOnlyBrowsingChildIndex> >)State).BrowseChildren(browseContext, parentInner); CheckContextConsistency(browseContext); }
/// <summary> /// Returns the value of an enum or boolean. /// </summary> /// <param name="index">Index of the node.</param> /// <param name="propertyName">Name of the property to read.</param> /// <param name="minValue">Minimum valid value for this property upon return.</param> /// <param name="maxValue">Maximum valid value for this property upon return.</param> public virtual int GetDiscreteValue(IReadOnlyIndex index, string propertyName, out int minValue, out int maxValue) { Debug.Assert(Contains(index)); IReadOnlyNodeState State = StateTable[index]; Debug.Assert(State.ValuePropertyTypeTable.ContainsKey(propertyName)); Debug.Assert(State.ValuePropertyTypeTable[propertyName] == Constants.ValuePropertyType.Boolean || State.ValuePropertyTypeTable[propertyName] == Constants.ValuePropertyType.Enum); return(NodeTreeHelper.GetEnumValueAndRange(State.Node, propertyName, out minValue, out maxValue)); }
private protected virtual void AddState(IReadOnlyIndex index, IReadOnlyNodeState state) { Debug.Assert(!StateTable.ContainsKey(index)); _StateTable.Add(index, state); Stats.NodeCount++; NotifyNodeStateCreated(StateTable[index]); Debug.Assert(Stats.NodeCount == StateTable.Count); }
/// <summary> /// Returns the value of a guid. /// </summary> /// <param name="index">Index of the node.</param> /// <param name="propertyName">Name of the property to read.</param> public virtual Guid GetGuidValue(IReadOnlyIndex index, string propertyName) { Debug.Assert(Contains(index)); IReadOnlyNodeState State = StateTable[index]; Debug.Assert(State.ValuePropertyTypeTable.ContainsKey(propertyName)); Debug.Assert(State.ValuePropertyTypeTable[propertyName] == Constants.ValuePropertyType.Guid); Guid Value = NodeTreeHelper.GetGuid(State.Node, propertyName); return(Value); }
private bool IsEqualMatchTable(CompareEqual comparer, ReadOnlyController other, IDictionary <IReadOnlyIndex, IReadOnlyIndex> matchTable) { foreach (KeyValuePair <IReadOnlyIndex, IReadOnlyIndex> Entry in matchTable) { IReadOnlyNodeState State = StateTable[Entry.Key]; IReadOnlyNodeState OtherState = other.StateTable[Entry.Value]; if (!comparer.VerifyEqual(State, OtherState)) { return(comparer.Failed()); } } return(true); }
private protected virtual ReadOnlyNodeStateDictionary BuildChildrenStateTable(ReadOnlyBrowseContext browseContext) { IReadOnlyNodeState State = browseContext.State; ReadOnlyInnerReadOnlyDictionary <string> InnerTable = State.InnerTable; ReadOnlyIndexCollectionReadOnlyList IndexCollectionList = browseContext.IndexCollectionList; ReadOnlyNodeStateDictionary ChildStateTable = CreateChildStateTable(); foreach (IReadOnlyIndexCollection <IReadOnlyBrowsingChildIndex> NodeIndexCollection in IndexCollectionList) { // List of indexes for this property (one for placeholder and optional node, several for lists and block lists) IReadOnlyList <IReadOnlyBrowsingChildIndex> NodeIndexList = NodeIndexCollection.NodeIndexList; string PropertyName = NodeIndexCollection.PropertyName; Debug.Assert(InnerTable.ContainsKey(PropertyName)); IReadOnlyInner <IReadOnlyBrowsingChildIndex> Inner = (IReadOnlyInner <IReadOnlyBrowsingChildIndex>)InnerTable[PropertyName]; for (int i = 0; i < NodeIndexList.Count; i++) { IReadOnlyBrowsingChildIndex ChildIndex = NodeIndexList[i]; // If the inner is that of a block list, and the index is for the first node in the block, add block-specific states if (Inner is IReadOnlyBlockListInner <IReadOnlyBrowsingBlockNodeIndex> AsBlockListInner && ChildIndex is IReadOnlyBrowsingNewBlockNodeIndex AsNewBlockIndex) { IReadOnlyBlockState BlockState = AsBlockListInner.InitNewBlock(AsNewBlockIndex); ((IReadOnlyBlockState <IReadOnlyInner <IReadOnlyBrowsingChildIndex> >)BlockState).InitBlockState(); Stats.BlockCount++; IReadOnlyBrowsingPatternIndex PatternIndex = BlockState.PatternIndex; IReadOnlyPatternState PatternState = BlockState.PatternState; AddState(PatternIndex, PatternState); Stats.PlaceholderNodeCount++; IReadOnlyBrowsingSourceIndex SourceIndex = BlockState.SourceIndex; IReadOnlySourceState SourceState = BlockState.SourceState; AddState(SourceIndex, SourceState); Stats.PlaceholderNodeCount++; ChildIndex = AsNewBlockIndex.ToExistingBlockIndex(); } IReadOnlyNodeState ChildState = BuildChildState(Inner, ChildIndex); ChildStateTable.Add(NodeIndexList[i], ChildState); } } return(ChildStateTable); }
private protected virtual void InitState(ReadOnlyBrowseContext browseContext, IReadOnlyInner <IReadOnlyBrowsingChildIndex> parentInner, IReadOnlyIndex nodeIndex, ReadOnlyInnerReadOnlyDictionary <string> innerTable) { Debug.Assert(Contains(nodeIndex)); Debug.Assert(parentInner != null || nodeIndex == RootIndex); IReadOnlyNodeState State = browseContext.State; Debug.Assert(IndexToState(nodeIndex) == State); Debug.Assert(State.ParentInner == null); Debug.Assert(State.ParentIndex == nodeIndex); Debug.Assert(State.ParentState == null); Debug.Assert(State.InnerTable == null); Debug.Assert(State.IsEmptyValuePropertyTypeTable || State.ValuePropertyTypeTable.Count == 0); ((IReadOnlyNodeState <IReadOnlyInner <IReadOnlyBrowsingChildIndex> >)State).Init(parentInner, innerTable, browseContext.ValuePropertyTypeTable); NotifyNodeStateInitialized(State); }
private protected virtual IReadOnlyNodeState GetState(Node node) { IReadOnlyNodeState Result = null; foreach (KeyValuePair <IReadOnlyIndex, IReadOnlyNodeState> Entry in StateTable) { IReadOnlyNodeState State = Entry.Value; if (State.Node == node) { Result = State; break; } } Debug.Assert(Result != null); return(Result); }
private protected virtual IReadOnlyInner <IReadOnlyBrowsingChildIndex> GetInner(Node parentNode, string propertyName) { IReadOnlyInner <IReadOnlyBrowsingChildIndex> Result = null; foreach (KeyValuePair <IReadOnlyIndex, IReadOnlyNodeState> Entry in StateTable) { IReadOnlyNodeState State = Entry.Value; if (State.Node == parentNode) { Result = State.PropertyToInner(propertyName) as IReadOnlyInner <IReadOnlyBrowsingChildIndex>; break; } } Debug.Assert(Result != null); return(Result); }
private protected virtual IReadOnlyNodeState BuildChildState(IReadOnlyInner <IReadOnlyBrowsingChildIndex> inner, IReadOnlyBrowsingChildIndex nodeIndex) { IReadOnlyNodeState ChildState = inner.InitChildState(nodeIndex); AddState(nodeIndex, ChildState); // For debugging: count nodes according to their type if (inner is IReadOnlyOptionalInner <IReadOnlyBrowsingOptionalNodeIndex> AsOptionalInner) { Stats.OptionalNodeCount++; if (AsOptionalInner.IsAssigned) { Stats.AssignedOptionalNodeCount++; } } else { Stats.PlaceholderNodeCount++; } return(ChildState); }
private protected virtual void BuildChildrenStates(ReadOnlyBrowseContext browseContext, ReadOnlyNodeStateDictionary childrenStateTable) { IReadOnlyNodeState State = browseContext.State; ReadOnlyInnerReadOnlyDictionary <string> InnerTable = State.InnerTable; ReadOnlyIndexCollectionReadOnlyList IndexCollectionList = browseContext.IndexCollectionList; // Build states for children in the order they have been reported when browsing the parent state foreach (IReadOnlyIndexCollection <IReadOnlyBrowsingChildIndex> NodeIndexCollection in IndexCollectionList) { IReadOnlyList <IReadOnlyBrowsingChildIndex> NodeIndexList = NodeIndexCollection.NodeIndexList; string PropertyName = NodeIndexCollection.PropertyName; IReadOnlyInner <IReadOnlyBrowsingChildIndex> Inner = (IReadOnlyInner <IReadOnlyBrowsingChildIndex>)InnerTable[PropertyName]; for (int i = 0; i < NodeIndexList.Count; i++) { IReadOnlyBrowsingChildIndex ChildNodeIndex = NodeIndexList[i]; IReadOnlyNodeState ChildState = childrenStateTable[ChildNodeIndex]; BuildStateTable(Inner, browseContext, ChildState.ParentIndex, ChildState); } } }