bool IDictionary <TKey, IWriteableInner> .TryGetValue(TKey key, out IWriteableInner value)
        {
            bool Result = TryGetValue(key, out IFrameInner Value);

            value = Value;
            return(Result);
        }
        /// <inheritdoc/>
        public override bool IsEqual(CompareEqual comparer, IEqualComparable other)
        {
            Contract.RequireNotNull(other, out IEqualComparable Other);

            if (!comparer.IsSameType(Other, out WriteableInnerDictionary <TKey> AsOtherDictionary))
            {
                return(comparer.Failed());
            }

            if (!comparer.IsSameCount(Count, AsOtherDictionary.Count))
            {
                return(comparer.Failed());
            }

            foreach (TKey Key in Keys)
            {
                IWriteableInner Value = (IWriteableInner)this[Key];

                if (!comparer.IsTrue(AsOtherDictionary.ContainsKey(Key)))
                {
                    return(comparer.Failed());
                }

                if (!comparer.VerifyEqual(Value, AsOtherDictionary[Key]))
                {
                    return(comparer.Failed());
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Replace an existing node with a new one.
        /// </summary>
        /// <param name="inner">The inner where the node is replaced.</param>
        /// <param name="replaceIndex">Index for the replace operation.</param>
        /// <param name="nodeIndex">Index of the replacing node upon return.</param>
        public void Replace(IWriteableInner inner, IWriteableInsertionChildIndex replaceIndex, out IWriteableBrowsingChildIndex nodeIndex)
        {
            Contract.RequireNotNull(inner, out IWriteableInner Inner);
            Contract.RequireNotNull(replaceIndex, out IWriteableInsertionChildIndex ReplaceIndex);
            IWriteableNodeState Owner       = Inner.Owner;
            IWriteableIndex     ParentIndex = Owner.ParentIndex;

            Debug.Assert(Contains(ParentIndex));
            Debug.Assert(IndexToState(ParentIndex) == Owner);
            WriteableInnerReadOnlyDictionary <string> InnerTable = Owner.InnerTable;

            Debug.Assert(InnerTable.ContainsKey(Inner.PropertyName));
            Debug.Assert(InnerTable[Inner.PropertyName] == Inner);

            IndexToPositionAndNode(ReplaceIndex, out int BlockIndex, out int Index, out bool ClearNode, out Node NewNode);

            Action <IWriteableOperation> HandlerRedo = (IWriteableOperation operation) => RedoReplace(operation);
            Action <IWriteableOperation> HandlerUndo = (IWriteableOperation operation) => UndoReplace(operation);
            IWriteableReplaceOperation   Operation   = CreateReplaceOperation(Inner.Owner.Node, Inner.PropertyName, BlockIndex, Index, ClearNode, NewNode, HandlerRedo, HandlerUndo, isNested: false);

            Operation.Redo();
            SetLastOperation(Operation);
            CheckInvariant();

            nodeIndex = Operation.NewBrowsingIndex;
        }
Exemplo n.º 4
0
        private protected virtual void PruneStateChildren(IWriteableNodeState state)
        {
            foreach (string Key in state.InnerTable.Keys)
            {
                IWriteableInner Value     = (IWriteableInner)state.InnerTable[Key];
                bool            IsHandled = false;

                if (Value is IWriteablePlaceholderInner <IWriteableBrowsingPlaceholderNodeIndex> AsPlaceholderInner)
                {
                    PrunePlaceholderInner(AsPlaceholderInner);
                    IsHandled = true;
                }
                else if (Value is IWriteableOptionalInner <IWriteableBrowsingOptionalNodeIndex> AsOptionalInner)
                {
                    PruneOptionalInner(AsOptionalInner);
                    IsHandled = true;
                }
                else if (Value is IWriteableListInner <IWriteableBrowsingListNodeIndex> AsListInner)
                {
                    PruneListInner(AsListInner);
                    IsHandled = true;
                }
                else if (Value is IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex> AsBlockListInner)
                {
                    PruneBlockListInner(AsBlockListInner);
                    IsHandled = true;
                }

                Debug.Assert(IsHandled);
            }
        }
        bool IReadOnlyDictionary <TKey, IWriteableInner> .TryGetValue(TKey key, out IWriteableInner value)
        {
            bool Result = TryGetValue(key, out ILayoutInner Value);

            value = Value;
            return(Result);
        }
Exemplo n.º 6
0
        private protected virtual void ExecuteReplace(IWriteableReplaceOperation operation)
        {
            Node   ParentNode   = operation.ParentNode;
            string PropertyName = operation.PropertyName;
            IWriteableInner <IWriteableBrowsingChildIndex> Inner = GetInner(ParentNode, PropertyName) as IWriteableInner <IWriteableBrowsingChildIndex>;

            ReplaceState(operation, Inner);
            Debug.Assert(Contains(operation.NewBrowsingIndex));

            NotifyStateReplaced(operation);
        }
Exemplo n.º 7
0
        private protected virtual void CanonicalizeChildren(IWriteableNodeState state, WriteableOperationList operationList)
        {
            List <IWriteableNodeState> ChildStateList = new List <IWriteableNodeState>();

            foreach (string Key in state.InnerTable.Keys)
            {
                IWriteableInner Value = (IWriteableInner)state.InnerTable[Key];

                switch (Value)
                {
                case IWriteablePlaceholderInner <IWriteableBrowsingPlaceholderNodeIndex> AsPlaceholderInner:
                    ChildStateList.Add(AsPlaceholderInner.ChildState);
                    break;

                case IWriteableOptionalInner <IWriteableBrowsingOptionalNodeIndex> AsOptionalInner:
                    if (AsOptionalInner.IsAssigned)
                    {
                        CanonicalizeChildren(AsOptionalInner.ChildState, operationList);
                    }
                    break;

                case IWriteableListInner <IWriteableBrowsingListNodeIndex> AsListlInner:
                    foreach (IWriteablePlaceholderNodeState ChildState in AsListlInner.StateList)
                    {
                        ChildStateList.Add(ChildState);
                    }
                    break;

                case IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex> AsBlockListlInner:
                    foreach (IWriteableBlockState BlockState in AsBlockListlInner.BlockStateList)
                    {
                        foreach (IWriteablePlaceholderNodeState ChildState in BlockState.StateList)
                        {
                            ChildStateList.Add(ChildState);
                        }
                    }
                    break;
                }
            }

            foreach (IWriteableNodeState ChildState in ChildStateList)
            {
                Canonicalize(ChildState, operationList);
            }
        }
Exemplo n.º 8
0
        private protected virtual void Expand(IWriteableNodeIndex expandedIndex, WriteableOperationList operationList)
        {
            IWriteablePlaceholderNodeState State = StateTable[expandedIndex] as IWriteablePlaceholderNodeState;

            State = FindBestExpandReduceState(State);
            Debug.Assert(State != null);

            WriteableInnerReadOnlyDictionary <string> InnerTable = State.InnerTable;

            foreach (string Key in InnerTable.Keys)
            {
                IWriteableInner Value = (IWriteableInner)InnerTable[Key];

                if (Value is IWriteableOptionalInner <IWriteableBrowsingOptionalNodeIndex> AsOptionalInner)
                {
                    ExpandOptional(AsOptionalInner, operationList);
                }
                else if (Value is IWriteableBlockListInner <IWriteableBrowsingBlockNodeIndex> AsBlockListInner)
                {
                    ExpandBlockList(AsBlockListInner, operationList);
                }
            }
        }
 void IDictionary <TKey, IWriteableInner> .Add(TKey key, IWriteableInner value)
 {
     Add(key, value);
 }
 void IDictionary <TKey, IWriteableInner> .Add(TKey key, IWriteableInner value)
 {
     Add(key, (ILayoutInner)value);
 }
Exemplo n.º 11
0
        private protected virtual void ReplaceState(IWriteableReplaceOperation operation, IWriteableInner <IWriteableBrowsingChildIndex> inner)
        {
            Contract.RequireNotNull(inner, out IWriteableInner <IWriteableBrowsingChildIndex> Inner);
            IWriteableNodeState Owner       = Inner.Owner;
            IWriteableIndex     ParentIndex = Owner.ParentIndex;

            Debug.Assert(Contains(ParentIndex));
            Debug.Assert(IndexToState(ParentIndex) == Owner);
            WriteableInnerReadOnlyDictionary <string> InnerTable = Owner.InnerTable;

            Debug.Assert(InnerTable.ContainsKey(Inner.PropertyName));
            Debug.Assert(InnerTable[Inner.PropertyName] == Inner);

            IWriteableOptionalInner <IWriteableBrowsingOptionalNodeIndex> AsOptionalInner = Inner as IWriteableOptionalInner <IWriteableBrowsingOptionalNodeIndex>;

            if (AsOptionalInner != null)
            {
                IWriteableNodeState OldState = AsOptionalInner.ChildState;
                PruneStateChildren(OldState);

                if (AsOptionalInner.IsAssigned)
                {
                    Stats.AssignedOptionalNodeCount--;
                }
            }

            Inner.Replace(operation);

            IWriteableBrowsingChildIndex OldBrowsingIndex = operation.OldBrowsingIndex;
            IWriteableBrowsingChildIndex NewBrowsingIndex = operation.NewBrowsingIndex;
            IWriteableNodeState          ChildState       = operation.NewChildState;

            if (AsOptionalInner != null)
            {
                if (AsOptionalInner.IsAssigned)
                {
                    Stats.AssignedOptionalNodeCount++;
                }
            }
            else
            {
                Debug.Assert(Contains(OldBrowsingIndex));
                IWriteableNodeState OldState = (IWriteableNodeState)StateTable[OldBrowsingIndex];

                PruneStateChildren(OldState);
            }

            RemoveState(OldBrowsingIndex);
            AddState(NewBrowsingIndex, ChildState);

            BuildStateTable(Inner, null, NewBrowsingIndex, ChildState);
        }
 void IDictionary <TKey, IWriteableInner> .Add(TKey key, IWriteableInner value)
 {
     throw new NotSupportedException("Collection is read-only.");
 }