public void SetFieldState(PackedFieldDescriptor d, TupleFieldState fieldState) { var bits = (long)fieldState; var block = Values[d.StateIndex]; Values[d.StateIndex] = (block & ~(3L << d.StateBitOffset)) | (bits << d.StateBitOffset); }
public void GetFieldStateTest() { Xtensive.Tuples.Tuple tuple = Xtensive.Tuples.Tuple.Create(typeof(string)); TupleFieldState fieldState = tuple.GetFieldState(0); Assert.IsTrue(Enum.IsDefined(typeof(TupleFieldState), fieldState)); }
/// <summary> /// Gets the value field value by its index, if it is available; /// otherwise returns <see langword="default(T)"/>. /// </summary> /// <param name="fieldIndex">Index of the field to get value of.</param> /// <param name="fieldState">Field state associated with the field.</param> /// <returns>Field value, if it is available; otherwise, <see langword="default(T)"/>.</returns> /// <typeparam name="T">The type of value to get.</typeparam> public T GetValue <T>(int fieldIndex, out TupleFieldState fieldState) { var isNullable = null == default(T); // Is nullable value type or class var packedTuple = this as PackedTuple; if (packedTuple != null) { var descriptor = packedTuple.PackedDescriptor.FieldDescriptors[fieldIndex]; return(descriptor.Accessor.GetValue <T>(packedTuple, descriptor, isNullable, out fieldState)); } var mappedContainer = GetMappedContainer(fieldIndex, false); var mappedTuple = mappedContainer.First as PackedTuple; if (mappedTuple != null) { var descriptor = mappedTuple.PackedDescriptor.FieldDescriptors[mappedContainer.Second]; return(descriptor.Accessor.GetValue <T>(mappedTuple, descriptor, isNullable, out fieldState)); } var value = GetValue(fieldIndex, out fieldState); return(value != null ? (T)value : default(T)); }
protected internal override void SetFieldState(int fieldIndex, TupleFieldState fieldState) { var tuple = difference != null && difference.GetFieldState(fieldIndex).IsAvailable() ? difference : origin; tuple.SetFieldState(fieldIndex, fieldState); }
/// <inheritdoc/> public override object GetValue(int fieldIndex, out TupleFieldState fieldState) { var tuple = difference != null && difference.GetFieldState(fieldIndex).IsAvailable() ? difference : origin; return(tuple.GetValue(fieldIndex, out fieldState)); }
/// <summary> /// Checks if specified field state has <see cref="TupleFieldState.Null"/> flag. /// </summary> /// <param name="fieldState"><see cref="TupleFieldState"/> to check.</param> /// <returns><see langword="true"/> if field state value has <see cref="TupleFieldState.Null"/> flag; otherwise, <see langword="false"/>.</returns> /// <exception cref="InvalidOperationException">Field value is not available.</exception> public static bool IsNull(this TupleFieldState fieldState) { if ((fieldState & TupleFieldState.Available) == 0) { throw new InvalidOperationException(Strings.ExValueIsNotAvailable); } return((fieldState & TupleFieldState.Null) == TupleFieldState.Null); }
/// <summary> /// Gets the value field value by its index, if it is available; /// otherwise returns <see langword="default(T)"/>. /// </summary> /// <param name="fieldIndex">Index of the field to get value of.</param> /// <param name="fieldState">Field state associated with the field.</param> /// <returns>Field value, if it is available; otherwise, <see langword="default(T)"/>.</returns> /// <typeparam name="T">The type of value to get.</typeparam> public T GetValue <T>(int fieldIndex, out TupleFieldState fieldState) { var isNullable = null == default(T); // Is nullable value type or class if (this is PackedTuple packedTuple) { ref var descriptor = ref packedTuple.PackedDescriptor.FieldDescriptors[fieldIndex]; return(descriptor.Accessor.GetValue <T>(packedTuple, ref descriptor, isNullable, out fieldState)); }
public override object GetValue(int i, out TupleFieldState fieldState) { if (i != 0) { throw new ArgumentOutOfRangeException("i"); } fieldState = TupleFieldState.Available; return(value1); }
protected internal override void SetFieldState(int fieldIndex, TupleFieldState fieldState) { if ((fieldState & TupleFieldState.Available) == TupleFieldState.Available) available[fieldIndex] = true; else available[fieldIndex] = false; if ((fieldState & TupleFieldState.Null) == TupleFieldState.Null) values[fieldIndex] = null; }
protected internal override void SetFieldState(int fieldIndex, TupleFieldState fieldState) { int index = GetMappedFieldIndex(fieldIndex); if (index == MapTransform.NoMapping) { return; } tuple.SetFieldState(index, fieldState); }
/// <inheritdoc/> public override object GetValue(int fieldIndex, out TupleFieldState fieldState) { int index = GetMappedFieldIndex(fieldIndex); if (index == MapTransform.NoMapping) { return(TypedTransform.DefaultResult.GetValue(fieldIndex, out fieldState)); } return(tuple.GetValue(index, out fieldState)); }
public T GetValue <T>(int i, out TupleFieldState fieldState) { var func = GetValueGetter(i) as TupleFieldGetter <T>; if (func != null) { return(func.Invoke(this, out fieldState)); } else { return((T)GetValue(i, out fieldState)); } }
protected internal override void SetFieldState(int fieldIndex, TupleFieldState fieldState) { if (fieldState == TupleFieldState.Null) { throw new ArgumentOutOfRangeException("fieldState"); } var descriptor = PackedDescriptor.FieldDescriptors[fieldIndex]; SetFieldState(descriptor, fieldState); if (fieldState != TupleFieldState.Available && descriptor.PackingType == FieldPackingType.Object) { Objects[descriptor.ValueIndex] = null; } }
/// <summary> /// Gets the field state map of the specified <see cref="Tuple"/>. /// </summary> /// <param name="target">The <see cref="Tuple"/> to inspect.</param> /// <param name="requestedState">The state to compare with.</param> /// <returns>Newly created <see cref="BitArray"/> instance which holds inspection result.</returns> public static BitArray GetFieldStateMap(this Tuple target, TupleFieldState requestedState) { var count = target.Descriptor.Count; var result = new BitArray(count); switch (requestedState) { case TupleFieldState.Default: for (int i = 0; i < count; i++) { result[i] = target.GetFieldState(i) == 0; } break; default: for (int i = 0; i < count; i++) { result[i] = (requestedState & target.GetFieldState(i)) != 0; } break; } return(result); }
public override object GetUntypedValue(PackedTuple tuple, ref PackedFieldDescriptor descriptor, out TupleFieldState fieldState) { var state = tuple.GetFieldState(ref descriptor); fieldState = state; return(state == TupleFieldState.Available ? tuple.Objects[descriptor.ObjectIndex] : null); }
/// <inheritdoc/> public override object GetValue(int fieldIndex, out TupleFieldState fieldState) { fieldState = states[fieldIndex]; return(values[fieldIndex]); }
/// <summary> /// Checks if specified field state has <see cref="TupleFieldState.Available"/> flag. /// </summary> /// <param name="fieldState"><see cref="TupleFieldState"/> to check.</param> /// <returns><see langword="true"/> if field state value has <see cref="TupleFieldState.Available"/> flag; otherwise, <see langword="false"/>.</returns> public static bool IsAvailable(this TupleFieldState fieldState) { return((fieldState & TupleFieldState.Available) != 0); }
/// <summary> /// Checks if specified field state has <see cref="TupleFieldState.Available"/> flag and has no <see cref="TupleFieldState.Null"/> flag. /// </summary> /// <param name="fieldState"><see cref="TupleFieldState"/> to check.</param> /// <returns><see langword="true"/> if field state value is equal to <see cref="TupleFieldState.Available"/>; /// otherwise, <see langword="false"/>.</returns> public static bool HasValue(this TupleFieldState fieldState) { return(fieldState == TupleFieldState.Available); }
/// <summary> /// Checks if specified field state has both <see cref="TupleFieldState.Null"/> and <see cref="TupleFieldState.Available"/> flags. /// </summary> /// <param name="fieldState"><see cref="TupleFieldState"/> to check.</param> /// <returns><see langword="true"/> if field state value has both <see cref="TupleFieldState.Null"/> and <see cref="TupleFieldState.Available"/> flags; otherwise, <see langword="false"/>.</returns> public static bool IsAvailableAndNull(this TupleFieldState fieldState) { return(fieldState == (TupleFieldState.Available | TupleFieldState.Null)); }
protected internal override void SetFieldState(int fieldIndex, TupleFieldState fieldState) { var indexes = TypedTransform.map[fieldIndex]; tuples[indexes.First].SetFieldState(indexes.Second, fieldState); }
/// <inheritdoc/> public override object GetValue(int fieldIndex, out TupleFieldState fieldState) { var indexes = TypedTransform.map[fieldIndex]; return(tuples[indexes.First].GetValue(indexes.Second, out fieldState)); }
public override object GetValue(int fieldIndex, out TupleFieldState fieldState) { fieldState = GetFieldState(fieldIndex); return values[fieldIndex]; }
/// <inheritdoc/> public override object GetValue(int fieldIndex, out TupleFieldState fieldState) { return(origin.GetValue(fieldIndex, out fieldState)); }
public override object GetValue(int i, out TupleFieldState fieldState) { fieldState = TupleFieldState.Available; return(values[i]); }
/// <inheritdoc/> public abstract object GetValue(int fieldIndex, out TupleFieldState fieldState);
protected internal override void SetFieldState(int fieldIndex, TupleFieldState fieldState) { InnerTuple.SetFieldState(fieldIndex, fieldState); }
public T GetValue <T>(PackedTuple tuple, ref PackedFieldDescriptor descriptor, bool isNullable, out TupleFieldState fieldState) { var getter = (isNullable ? NullableGetter : Getter) as GetValueDelegate <T>; if (getter != null) { return(getter.Invoke(tuple, ref descriptor, out fieldState)); } var targetType = typeof(T); //Dirty hack of nullable enum reading if (isNullable) { targetType = Nullable.GetUnderlyingType(targetType) ?? targetType; } if (targetType.IsEnum) { return((T)Enum.ToObject(targetType, GetUntypedValue(tuple, ref descriptor, out fieldState))); } return((T)GetUntypedValue(tuple, ref descriptor, out fieldState)); }
protected internal override void SetFieldState(int fieldIndex, TupleFieldState fieldState) { throw Exceptions.ObjectIsReadOnly(null); }
public abstract object GetUntypedValue(PackedTuple tuple, ref PackedFieldDescriptor descriptor, out TupleFieldState fieldState);
protected internal abstract void SetFieldState(int fieldIndex, TupleFieldState fieldState);