Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LazyCopyIndexDefinition" /> class.
 /// </summary>
 /// <param name="writeableSnapshotStrucure">The writeable snapshot strucure.</param>
 /// <param name="indexDefinition">The index definition.</param>
 public LazyCopyIndexDefinition(IWriteableSnapshotStructure writeableSnapshotStrucure, LazyCopyIndexDefinition indexDefinition)
 {
     this.aliases             = indexDefinition.aliases;
     this.objects             = indexDefinition.objects;
     this.arrayValue          = indexDefinition.arrayValue;
     this.associatedStructure = writeableSnapshotStrucure;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Assigns the must memory index.
        /// </summary>
        /// <param name="mustIndex">Index of the must.</param>
        /// <param name="composedValues">The composed values.</param>
        private void assignMust(MemoryIndex mustIndex, CollectComposedValuesVisitor composedValues)
        {
            IIndexDefinition data   = snapshot.Structure.Readonly.GetIndexDefinition(mustIndex);
            HashSet <Value>  values = new HashSet <Value>(composedValues.Values);

            if (snapshot.CurrentMode == SnapshotMode.MemoryLevel)
            {
                if (data.Array != null)
                {
                    values.Add(data.Array);
                }

                if (composedValues.Objects.Count > 0)
                {
                    IObjectValueContainer objects = Factories.StructuralContainersFactories.ObjectValueContainerFactory.CreateObjectValueContainer(snapshot.Structure.Writeable, composedValues.Objects);
                    snapshot.Structure.Writeable.SetObjects(mustIndex, objects);
                    if (data.Objects != null)
                    {
                        CollectionMemoryUtils.AddAll(values, data.Objects);
                    }
                }
            }

            snapshot.CurrentData.Writeable.SetMemoryEntry(mustIndex, snapshot.CreateMemoryEntry(values));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Processes the source objects.
 /// </summary>
 /// <param name="node">The node.</param>
 /// <param name="objects">The objects.</param>
 private void processSourceObjects(MemoryCollectorNode node, IObjectValueContainer objects)
 {
     if (objects != null && objects.Count > 0)
     {
         IObjectValueContainer targetObjects = Factories.StructuralContainersFactories.ObjectValueContainerFactory.CreateObjectValueContainer(Structure, objects);
         Structure.SetObjects(node.TargetIndex, targetObjects);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Collects all objects from given collection of objects.
 /// </summary>
 /// <param name="obejcts">The obejcts.</param>
 public void collectSourceObjects(IObjectValueContainer obejcts)
 {
     if (obejcts != null && obejcts.Count > 0)
     {
         hasObjects = true;
         CollectionMemoryUtils.AddAll(objectValues, obejcts.Values);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Processes the objects stored within this operation.
        /// </summary>
        protected void processObjects()
        {
            if (Node.Objects != null && Node.Objects.Count > 0)
            {
                IObjectValueContainer objects = Worker.Factories.StructuralContainersFactories.ObjectValueContainerFactory.CreateObjectValueContainer(Worker.Structure, Node.Objects);
                Worker.Structure.SetObjects(TargetIndex, objects);

                CollectionMemoryUtils.AddAll(Values, Node.Objects);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Stores collected objects into the structure and clear inner container.
        /// </summary>
        /// <param name="targetIndex">Index of the target.</param>
        public void MergeObjectsAndClear(MemoryIndex targetIndex)
        {
            if (hasObjects)
            {
                IObjectValueContainer objectsContainer = worker.Factories.StructuralContainersFactories.ObjectValueContainerFactory.CreateObjectValueContainer(writeableTargetStructure, objectValues);
                writeableTargetStructure.SetObjects(targetIndex, objectsContainer);

                hasObjects = false;
                objectValues.Clear();
            }
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        public override void SetObjects(MemoryIndex index, IObjectValueContainer objects)
        {
            IIndexDefinition data;

            if (!indexDefinitions.TryGetValue(index, out data))
            {
                data = new CopyIndexDefinition();
            }

            IIndexDefinitionBuilder builder = data.Builder(this);

            builder.SetObjects(objects);

            indexDefinitions[index] = builder.Build(this);
        }
Exemplo n.º 8
0
        /// <inheritdoc />
        public override void SetObjects(MemoryIndex index, IObjectValueContainer objects)
        {
            IIndexDefinition data;

            if (!indexDefinitions.TryGetValue(index, out data))
            {
                data = Factories.StructuralContainersFactories.IndexDefinitionFactory.CreateIndexDefinition(this);
            }

            IIndexDefinitionBuilder builder = data.Builder(this);

            builder.SetObjects(objects);

            indexDefinitions[index] = builder.Build(this);

            changeTracker.ModifiedIndex(index);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Collects the index of the field from memory.
        /// </summary>
        /// <param name="collector">The collector.</param>
        /// <param name="fieldSegment">The field segment.</param>
        /// <param name="index">The index.</param>
        protected void collectFieldFromMemoryIndex(TreeIndexCollector collector, FieldPathSegment fieldSegment, MemoryIndex index)
        {
            MemoryEntry entry = collector.GetMemoryEntry(index);

            this.ContainsUndefinedValue = entry.ContainsUndefinedValue;
            bool processOtherValues = false;

            IObjectValueContainer objects = collector.Structure.GetObjects(index);

            if (objects.Count > 0)
            {
                processOtherValues = entry.Count > objects.Count ||
                                     entry.ContainsUndefinedValue && entry.Count > objects.Count + 1;

                bool isMustObject = objects.Count == 1 && !processOtherValues && !entry.ContainsUndefinedValue;
                foreach (var objectValue in objects)
                {
                    collector.RootNode.CollectObject(collector, objectValue, fieldSegment);
                }

                if (entry.ContainsUndefinedValue)
                {
                    AddNewImplicitObjectNode(false);
                    collector.CollectSegmentWithoutStructure(fieldSegment, ImplicitObjectNode, false);
                }
            }
            else if (entry.ContainsUndefinedValue)
            {
                processOtherValues = entry.Count > 1;

                AddNewImplicitObjectNode(!processOtherValues);
                collector.CollectSegmentWithoutStructure(fieldSegment, ImplicitObjectNode, !processOtherValues);
            }
            else
            {
                processOtherValues = true;
            }

            if (processOtherValues)
            {
                collector.CollectFieldSegmentFromValues(fieldSegment, this, entry.PossibleValues, true);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Assigns the may memory index.
        /// </summary>
        /// <param name="mayIndex">Index of the may.</param>
        /// <param name="composedValues">The composed values.</param>
        private void assignMay(MemoryIndex mayIndex, CollectComposedValuesVisitor composedValues)
        {
            IIndexDefinition data   = snapshot.Structure.Readonly.GetIndexDefinition(mayIndex);
            HashSet <Value>  values = new HashSet <Value>(composedValues.Values);

            if (composedValues.Objects.Count > 0)
            {
                HashSet <ObjectValue> objectsSet = new HashSet <ObjectValue>(data.Objects);
                CollectionMemoryUtils.AddAll(objectsSet, composedValues.Objects);
                IObjectValueContainer objects = Factories.StructuralContainersFactories.ObjectValueContainerFactory.CreateObjectValueContainer(snapshot.Structure.Writeable, composedValues.Objects);
                snapshot.Structure.Writeable.SetObjects(mayIndex, objects);

                //if (data.Objects != null)
                CollectionMemoryUtils.AddAll(values, data.Objects);
            }

            MemoryEntry entry = SnapshotDataUtils.GetMemoryEntry(snapshot, snapshot.CurrentData.Readonly, mayIndex);

            CollectionMemoryUtils.AddAll(values, entry.PossibleValues);
            snapshot.CurrentData.Writeable.SetMemoryEntry(mayIndex, snapshot.CreateMemoryEntry(values));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Stores objects in given container to this node and process them
        /// </summary>
        /// <param name="objects">The objects.</param>
        protected void processObjects(IObjectValueContainer objects)
        {
            if (objects != null && objects.Count > 0)
            {
                IObjectValueContainerBuilder builder = Worker.Factories.StructuralContainersFactories.ObjectValueContainerFactory.CreateObjectValueContainer(Worker.Structure, objects).Builder(Worker.Structure);

                if (Node.Objects != null)
                {
                    builder.AddAll(Node.Objects);
                    CollectionMemoryUtils.AddAll(Values, Node.Objects);
                }

                Worker.Structure.SetObjects(TargetIndex, builder.Build(Worker.Structure));

                CollectionMemoryUtils.AddAll(Values, objects.Values);
            }
            else
            {
                processObjects();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Processes the field - traverse thru all containing objects or sets path to undefined.
        /// </summary>
        /// <param name="parentIndex">Index of the parent.</param>
        /// <param name="fieldSegment">The field segment.</param>
        /// <param name="visitor">The visitor to process scalar values.</param>
        private void processField(MemoryIndex parentIndex, FieldPathSegment fieldSegment, ProcessValueAsLocationVisitor visitor)
        {
            MemoryEntry entry;

            if (snapshot.Data.Readonly.TryGetMemoryEntry(parentIndex, out entry))
            {
                bool processOtherValues            = false;
                IObjectValueContainer objectValues = snapshot.Structure.Readonly.GetObjects(parentIndex);
                if (objectValues.Count > 0)
                {
                    foreach (ObjectValue objectValue in objectValues)
                    {
                        IObjectDescriptor descriptor = snapshot.Structure.Readonly.GetDescriptor(objectValue);
                        process(fieldSegment, descriptor);
                    }

                    processOtherValues = entry.Count > objectValues.Count;
                }
                else if (entry.Count > 0)
                {
                    processOtherValues = true;
                }
                else
                {
                    IsDefined = false;
                }

                if (processOtherValues)
                {
                    visitor.ProcessValues(parentIndex, entry.PossibleValues, true);
                }
            }
            else
            {
                IsDefined = false;
            }
        }
Exemplo n.º 13
0
        private MemoryEntry setNewMemoryEntry(MemoryIndex index, MemoryEntry currentEntry, MemoryEntry modifiedEntry)
        {
            CollectComposedValuesVisitor currentVisitor = new CollectComposedValuesVisitor();

            currentVisitor.VisitMemoryEntry(currentEntry);

            CollectComposedValuesVisitor modifiedVisitor = new CollectComposedValuesVisitor();

            modifiedVisitor.VisitMemoryEntry(modifiedEntry);

            if (currentVisitor.Arrays.Count != modifiedVisitor.Arrays.Count)
            {
                snapshot.DestroyArray(index);
            }

            if (modifiedVisitor.Objects.Count != currentVisitor.Objects.Count)
            {
                IObjectValueContainer objects = Factories.StructuralContainersFactories.ObjectValueContainerFactory.CreateObjectValueContainer(newStructure.Writeable, currentVisitor.Objects);
                snapshot.Structure.Writeable.SetObjects(index, objects);
            }

            newData.Writeable.SetMemoryEntry(index, modifiedEntry);
            return(modifiedEntry);
        }
Exemplo n.º 14
0
 /// <inheritdoc />
 public abstract void SetObjects(MemoryIndex index, IObjectValueContainer objects);
Exemplo n.º 15
0
 /// <inheritdoc />
 public void SetObjects(IObjectValueContainer objects)
 {
     this.objects = objects;
 }
Exemplo n.º 16
0
        /// <summary>
        /// Processes the field - traverse thru all containing objects. When there is possibility undefined
        /// value in location new object is created.
        /// </summary>
        /// <param name="segment">The segment.</param>
        /// <param name="parentIndex">Index of the parent.</param>
        /// <param name="visitor">The visitor to process scalar values.</param>
        /// <param name="isMust">if set to <c>true</c> [is must].</param>
        private void processField(PathSegment segment, MemoryIndex parentIndex, FieldLocationVisitor visitor, bool isMust)
        {
            bool        processOtherValues = false;
            MemoryEntry entry;

            if (snapshot.Data.Readonly.TryGetMemoryEntry(parentIndex, out entry))
            {
                IObjectValueContainer objects = snapshot.Structure.Readonly.GetObjects(parentIndex);
                if (objects.Count > 0)
                {
                    processOtherValues = entry.Count > objects.Count;
                }
                else if (entry.Count > 0)
                {
                    processOtherValues = true;
                }
                else
                {
                    entry = snapshot.EmptyEntry;
                    processOtherValues = true;
                }
            }
            else
            {
                entry = snapshot.EmptyEntry;
                processOtherValues = true;
            }

            if (!snapshot.Structure.Locked && processOtherValues)
            {
                if (entry.Count > 1)
                {
                    isMust = false;
                }

                visitor.ProcessValues(parentIndex, entry.PossibleValues, isMust);
                ReadFieldVisitor valueVisitor    = visitor.LastValueVisitor;
                bool             removeUndefined = isMust;

                if (valueVisitor.ContainsDefinedValue || valueVisitor.ContainsAnyValue)
                {
                    isMust = false;
                }

                if (valueVisitor.ContainsUndefinedValue && snapshot.CurrentMode == SnapshotMode.MemoryLevel)
                {
                    ObjectValue objectValue = snapshot.CreateObject(parentIndex, isMust, removeUndefined);
                }
            }

            IObjectValueContainer objectValues = snapshot.Structure.Readonly.GetObjects(parentIndex);

            if (objectValues.Count == 1 && snapshot.HasMustReference(parentIndex))
            {
                IObjectDescriptor descriptor = snapshot.Structure.Readonly.GetDescriptor(objectValues.First());
                creatorVisitor.ObjectValue = objectValues.First();
                processSegment(segment, descriptor, isMust);
            }
            else
            {
                foreach (ObjectValue value in objectValues)
                {
                    IObjectDescriptor descriptor = snapshot.Structure.Readonly.GetDescriptor(value);
                    creatorVisitor.ObjectValue = value;
                    processSegment(segment, descriptor, false);
                }
            }
        }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CopyIndexDefinition"/> class.
 /// </summary>
 /// <param name="indexDefinition">The index definition.</param>
 public CopyIndexDefinition(CopyIndexDefinition indexDefinition)
 {
     this.aliases    = indexDefinition.aliases;
     this.objects    = indexDefinition.objects;
     this.arrayValue = indexDefinition.arrayValue;
 }