Пример #1
0
        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 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);
        }
        public override bool ValueEquals(PackedTuple left, ref PackedFieldDescriptor leftDescriptor,
                                         PackedTuple right, ref PackedFieldDescriptor rightDescriptor)
        {
            var leftValue  = left.Objects[leftDescriptor.ObjectIndex];
            var rightValue = right.Objects[rightDescriptor.ObjectIndex];

            return(leftValue.Equals(rightValue));
        }
 public override void SetUntypedValue(PackedTuple tuple, ref PackedFieldDescriptor descriptor, object value)
 {
     tuple.Objects[descriptor.ObjectIndex] = value;
     if (value != null)
     {
         tuple.SetFieldState(ref descriptor, TupleFieldState.Available);
     }
     else
     {
         tuple.SetFieldState(ref descriptor, TupleFieldState.Available | TupleFieldState.Null);
     }
 }
        public void SetValue <T>(PackedTuple tuple, ref PackedFieldDescriptor descriptor, bool isNullable, T value)
        {
            var setter = (isNullable ? NullableSetter : Setter) as SetValueDelegate <T>;

            if (setter != null)
            {
                setter.Invoke(tuple, ref descriptor, value);
            }
            else
            {
                SetUntypedValue(tuple, ref descriptor, value);
            }
        }
Пример #6
0
        public static void ProvideAccessor(Type valueType, PackedFieldDescriptor descriptor)
        {
            ValueFieldAccessor valueAccessor;

            if (ValueAccessors.TryGetValue(valueType, out valueAccessor))
            {
                descriptor.PackingType   = FieldPackingType.Value;
                descriptor.Accessor      = valueAccessor;
                descriptor.ValueBitCount = valueAccessor.BitCount;
                descriptor.ValueBitMask  = valueAccessor.BitMask;
            }
            else
            {
                descriptor.Accessor    = ObjectAccessor;
                descriptor.PackingType = FieldPackingType.Object;
            }
        }
Пример #7
0
        public static void ConfigureLen2(Type[] fieldTypes, ref PackedFieldDescriptor descriptor1,
                                         ref PackedFieldDescriptor descriptor2, out int valuesLength, out int objectsLength)
        {
            var counters = new Counters();

            ConfigureFieldPhase1(ref descriptor1, ref counters, fieldTypes, 0);
            ConfigureFieldPhase1(ref descriptor2, ref counters, fieldTypes, 1);
            objectsLength = counters.ObjectCounter;
            int val1BitCount, val2BitCount;

            switch (objectsLength)
            {
            case 2:
                valuesLength = 1;
                return;

            case 1: {
                    if (descriptor1.IsObjectField)
                    {
                        descriptor2.DataPosition = Val064BitCount;
                        val1BitCount             = descriptor2.Accessor.ValueBitCount;
                    }
                    else
                    {
                        descriptor1.DataPosition = Val064BitCount;
                        val1BitCount             = descriptor1.Accessor.ValueBitCount;
                    }
                    valuesLength = (val1BitCount + ((Val064BitCount * 2) - 1)) >> Val064Rank;
                    return;
            }
            }
            // Both descriptors are value descriptors
            val1BitCount = descriptor1.Accessor.ValueBitCount;
            val2BitCount = descriptor2.Accessor.ValueBitCount;
            if (val2BitCount > val1BitCount)
            {
                descriptor2.DataPosition = Val064BitCount;
                descriptor1.DataPosition = Val064BitCount + val2BitCount;
            }
            else
            {
                descriptor1.DataPosition = Val064BitCount;
                descriptor2.DataPosition = Val064BitCount + val1BitCount;
            }
            valuesLength = (val1BitCount + val2BitCount + ((Val064BitCount * 2) - 1)) >> Val064Rank;
        }
Пример #8
0
        public static void ConfigureLen1(Type[] fieldTypes, ref PackedFieldDescriptor descriptor, out int valuesLength,
                                         out int objectsLength)
        {
            var valueAccessor = ValueFieldAccessorResolver.GetValue(fieldTypes[0]);

            if (valueAccessor != null)
            {
                descriptor.Accessor     = valueAccessor;
                descriptor.DataPosition = Val064BitCount;

                valuesLength  = (valueAccessor.ValueBitCount + ((Val064BitCount * 2) - 1)) >> Val064Rank;
                objectsLength = 0;
                fieldTypes[0] = valueAccessor.FieldType;
                return;
            }

            descriptor.Accessor = ObjectAccessor;
            valuesLength        = 1;
            objectsLength       = 1;
        }
        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));
        }
 public abstract void CopyValue(PackedTuple source, ref PackedFieldDescriptor sourceDescriptor,
                                PackedTuple target, ref PackedFieldDescriptor targetDescriptor);
 public abstract void SetUntypedValue(PackedTuple tuple, ref PackedFieldDescriptor descriptor, object value);
 public abstract object GetUntypedValue(PackedTuple tuple, ref PackedFieldDescriptor descriptor, out TupleFieldState fieldState);
 public override int GetValueHashCode(PackedTuple tuple, ref PackedFieldDescriptor descriptor)
 {
     return(tuple.Objects[descriptor.ObjectIndex].GetHashCode());
 }
 public override void CopyValue(PackedTuple source, ref PackedFieldDescriptor sourceDescriptor,
                                PackedTuple target, ref PackedFieldDescriptor targetDescriptor)
 {
     target.Objects[targetDescriptor.ObjectIndex] = source.Objects[sourceDescriptor.ObjectIndex];
 }
Пример #15
0
        public TupleFieldState GetFieldState(PackedFieldDescriptor d)
        {
            var block = Values[d.StateIndex];

            return((TupleFieldState)((block >> d.StateBitOffset) & 3));
        }
 public abstract bool ValueEquals(PackedTuple left, ref PackedFieldDescriptor leftDescriptor,
                                  PackedTuple right, ref PackedFieldDescriptor rightDescriptor);
 public abstract int GetValueHashCode(PackedTuple tuple, ref PackedFieldDescriptor descriptor);
Пример #18
0
 public static void ConfigureFieldAccessor(ref PackedFieldDescriptor descriptor, Type fieldType) =>
 descriptor.Accessor = (PackedFieldAccessor)ValueFieldAccessorResolver.GetValue(fieldType) ?? ObjectAccessor;