/// <summary> /// Determines whether container contains specified value. /// </summary> /// <param name="objA">The object aggregate.</param> /// <param name="objB">The object attribute.</param> /// <returns>True whether container contains specified value.</returns> internal static bool AreEqual(ObjectValueContainer objA, ObjectValueContainer objB) { if (objA == objB) { return(true); } if (objA != null) { return(objA.DataEquals(objB)); } else { return(objB.DataEquals(objA)); } }
/// <summary> /// Sets objects for given index. /// </summary> /// <param name="index">The index.</param> /// <param name="objects">The objects.</param> internal void SetObjects(MemoryIndex index, ObjectValueContainer objects) { lockedTest(); IndexData data; if (!IndexData.TryGetValue(index, out data)) { data = new IndexData(null, null, null); } IndexDataBuilder builder = data.Builder(); builder.Objects = objects; IndexData[index] = builder.Build(); }
/// <summary> /// Compares this data structure with the given object. /// </summary> /// <param name="other">The other.</param> /// <returns>True whether this data structure with the given object.</returns> internal bool DataEquals(ObjectValueContainer other) { if (other == null) { return(this.values.Count == 0); } if (this.values.Count != other.values.Count) { return(false); } foreach (ObjectValue value in values) { if (!other.values.Contains(value)) { return(false); } } return(true); }
/// <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.TryGetMemoryEntry(parentIndex, out entry)) { bool processOtherValues = false; ObjectValueContainer objectValues = snapshot.Structure.GetObjects(parentIndex); if (objectValues.Count > 0) { foreach (ObjectValue objectValue in objectValues) { ObjectDescriptor descriptor = snapshot.Structure.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; } }
/// <summary> /// Initializes a new instance of the <see cref="IndexData"/> class. /// </summary> /// <param name="data">The data.</param> public IndexData(IndexDataBuilder data) { Aliases = data.Aliases; Array = data.Array; Objects = data.Objects; }
/// <summary> /// Initializes a new instance of the <see cref="IndexData"/> class. /// </summary> /// <param name="aliases">The aliases.</param> /// <param name="array">The array.</param> /// <param name="objects">The objects.</param> public IndexData(MemoryAlias aliases, AssociativeArray array, ObjectValueContainer objects) { Aliases = aliases; Array = array; Objects = objects; }
/// <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.Structure.TryGetMemoryEntry(parentIndex, out entry)) { ObjectValueContainer objects = snapshot.Structure.GetObjects(parentIndex); if (objects.Count > 0) { processOtherValues = entry.Count > objects.Count; } else if (entry.Count > 0) { processOtherValues = true; } else { entry = snapshot.Data.EmptyEntry; processOtherValues = true; } } else { entry = snapshot.Data.EmptyEntry; processOtherValues = true; } if (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); } } ObjectValueContainer objectValues = snapshot.Structure.GetObjects(parentIndex); if (objectValues.Count == 1 && snapshot.HasMustReference(parentIndex)) { ObjectDescriptor descriptor = snapshot.Structure.GetDescriptor(objectValues.First()); creatorVisitor.ObjectValue = objectValues.First(); processSegment(segment, descriptor, isMust); } else { foreach (ObjectValue value in objectValues) { ObjectDescriptor descriptor = snapshot.Structure.GetDescriptor(value); creatorVisitor.ObjectValue = value; processSegment(segment, descriptor, false); } } }
/// <summary> /// Initializes a new instance of the <see cref="ObjectValueContainerBuilder"/> class. /// </summary> /// <param name="objectValueContainer">The object value container.</param> public ObjectValueContainerBuilder(ObjectValueContainer objectValueContainer) { Values = new HashSet <ObjectValue>(objectValueContainer); }