Exemplo n.º 1
0
        public RingBuffer(int size, int highWater, int lowWater, OverflowBehavior onOverflow)
        {
            if (size <= 0)
            {
                throw new ArgumentOutOfRangeException("Buffer needs to contain at least one member");
            }
            _buffer = new T[size];

            if (highWater > size)
            {
                throw new ArgumentOutOfRangeException("High water point for buffer cannot be greater than buffer size.");
            }

            if (highWater < 0 || lowWater < 0)
            {
                throw new ArgumentOutOfRangeException("Buffer alert points cannot be less than zero.");
            }

            if (lowWater >= highWater)
            {
                throw new ArgumentOutOfRangeException("Low water point for buffer cannot be greater than or equal to the high water point.");
            }

            _highWater = highWater;
            _lowWater  = lowWater;
            _filling   = true;
            _overflow  = onOverflow;
        }
 public TableColumnDefinition(string title, string format, int width, TextAlignment textAlignment, OverflowBehavior overflowBehavior)
 {
     Title = title;
     Format = format;
     Width = width;
     TextAlignment = textAlignment;
     OverflowBehavior = overflowBehavior;
 }
Exemplo n.º 3
0
        public void MudPopover_Property_OverflowBehavior(OverflowBehavior overflowBehavior, string expectedClass)
        {
            var comp = Context.RenderComponent <PopoverPropertyTest>(p => p.Add(
                                                                         x => x.OverflowBehavior, overflowBehavior));

            //Console.WriteLine(comp.Markup);

            var popoverElement = comp.Find(".test-popover-content").ParentElement;

            popoverElement.ClassList.Should().Contain(new[] { "mud-popover-open", $"mud-popover-overflow-{expectedClass}", "my-custom-class" });
        }
Exemplo n.º 4
0
 public RingBuffer(int size, OverflowBehavior onOverflow)
 {
     if (size <= 0)
     {
         throw new ArgumentOutOfRangeException("Buffer needs to contain at least one member");
     }
     _buffer    = new T[size];
     _filling   = false;
     _useEvents = false;
     _overflow  = onOverflow;
 }
Exemplo n.º 5
0
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        /// <param name="obj">The object the metadata is provided for or <c>null</c> for struct fields.</param>
        /// <param name="field">The field the range metadata is provided for or <c>null</c> for arrays.</param>
        /// <param name="overflowBehavior">The overflow behavior.</param>
        protected RangeMetadata(object obj, FieldInfo field, OverflowBehavior overflowBehavior)
        {
            Requires.InRange(overflowBehavior, nameof(overflowBehavior));

            OverflowBehavior = overflowBehavior;

            _obj = obj;

            if (field == null)
            {
                return;
            }

            _declaringType = field.DeclaringType;
            _name          = field.Name;
            _fieldType     = field.FieldType;
        }
Exemplo n.º 6
0
        /// <summary>
        ///   Restricts values that can be stored in the field referenced by the <paramref name="fieldExpression" /> to the range of
        ///   <paramref name="lowerBound" /> and <paramref name="upperBound" />, both inclusive, using the
        ///   <paramref name="overflowBehavior" /> to handle range overflows.
        /// </summary>
        /// <typeparam name="T">The type of the field that is restricted.</typeparam>
        /// <param name="fieldExpression">The expression referencing the field whose range should be restricted.</param>
        /// <param name="lowerBound">The inclusive lower bound.</param>
        /// <param name="upperBound">The inclusive upper bound.</param>
        /// <param name="overflowBehavior">The overflow behavior.</param>
        public static void Restrict <T>(Expression <Func <T> > fieldExpression, object lowerBound, object upperBound,
                                        OverflowBehavior overflowBehavior)
            where T : struct, IComparable
        {
            Requires.NotNull(fieldExpression, nameof(fieldExpression));
            Requires.InRange(overflowBehavior, nameof(overflowBehavior));
            Requires.That(typeof(T).IsNumericType(), nameof(fieldExpression), "Expected a field of numeric type.");
            Requires.OfType <MemberExpression>(fieldExpression.Body, nameof(fieldExpression), "Expected a non-nested reference to a field.");

            var range            = new RangeAttribute(lowerBound, upperBound, overflowBehavior);
            var memberExpression = (MemberExpression)fieldExpression.Body;
            var propertyInfo     = memberExpression.Member as PropertyInfo;
            var fieldInfo        = propertyInfo?.GetBackingField() ?? memberExpression.Member as FieldInfo;
            var objectExpression = memberExpression.Expression as ConstantExpression;

            Requires.That(fieldInfo != null, nameof(fieldExpression), "Expected a non-nested reference to a field or an auto-property.");
            Requires.That(objectExpression != null, nameof(fieldExpression), "Expected a non-nested reference to non-static field of primitive type.");
            Requires.That(((IComparable)range.LowerBound).CompareTo(range.UpperBound) <= 0, nameof(lowerBound),
                          $"lower bound '{range.LowerBound}' is not smaller than upper bound '{range.UpperBound}'.");

            List <RangeMetadata> fields;

            if (_ranges.TryGetValue(objectExpression.Value, out fields))
            {
                var metadata = fields.FirstOrDefault(m => m.DescribesField(objectExpression.Value, fieldInfo));
                if (metadata != null)
                {
                    fields.Remove(metadata);
                }

                fields.Add(RangeMetadata.Create(objectExpression.Value, fieldInfo, range));
            }
            else
            {
                _ranges.Add(objectExpression.Value, new List <RangeMetadata> {
                    RangeMetadata.Create(objectExpression.Value, fieldInfo, range)
                });
            }
        }
Exemplo n.º 7
0
        public static long GetInt64Value(this BigInteger b, OverflowBehavior overflowBehavior)
        {
            if (b >= long.MinValue && b <= long.MaxValue)
            {
                return((long)b);
            }
            else if (b < long.MinValue)
            {
                switch (overflowBehavior)
                {
                case OverflowBehavior.Wraparound:
                    return(unchecked ((long)(b & ulong.MaxValue)));

                case OverflowBehavior.Saturate:
                default:
                    return(long.MinValue);

                case OverflowBehavior.ThrowException:
                    throw new OverflowException();
                }
            }
            else
            {
                switch (overflowBehavior)
                {
                case OverflowBehavior.Wraparound:
                    return(unchecked ((long)(b & ulong.MaxValue)));

                case OverflowBehavior.Saturate:
                default:
                    return(int.MaxValue);

                case OverflowBehavior.ThrowException:
                    throw new OverflowException();
                }
            }
        }
Exemplo n.º 8
0
        public static int GetInt32Value(this BigInteger b, OverflowBehavior overflowBehavior)
        {
            if (b >= int.MinValue && b <= int.MaxValue)
            {
                return((int)b);
            }
            else if (b < int.MinValue)
            {
                switch (overflowBehavior)
                {
                case OverflowBehavior.Wraparound:
                    return(unchecked ((int)(b & 0xFFFFFFFF)));

                case OverflowBehavior.Saturate:
                default:
                    return(int.MinValue);

                case OverflowBehavior.ThrowException:
                    throw new OverflowException();
                }
            }
            else
            {
                switch (overflowBehavior)
                {
                case OverflowBehavior.Wraparound:
                    return(unchecked ((int)(b & uint.MaxValue)));

                case OverflowBehavior.Saturate:
                default:
                    return(int.MaxValue);

                case OverflowBehavior.ThrowException:
                    throw new OverflowException();
                }
            }
        }
Exemplo n.º 9
0
        private BlockingProducerConsumerQueue(
            int?maxSize,
            BlockingImplementationType blockingImplementationType,
            BufferType bufferType,
            OverflowBehavior overflowBehavior)
        {
            _blockingImplementationType = blockingImplementationType;
            _bufferType = bufferType;

            switch (_blockingImplementationType)
            {
            case BlockingImplementationType.Mutex:
            {
                _safeWaitAndAcquireHandle = new MutexWaitAndAcquireHandle();
                break;
            }

            case BlockingImplementationType.Monitor:
            {
                _safeWaitAndAcquireHandle = new MonitorWaitAndAcquireHandle();
                break;
            }

            default: throw new NotSupportedException($"{blockingImplementationType} is not supported");
            }

            _overflowBehavior = overflowBehavior;
            if (bufferType == BufferType.Bounded)
            {
                _itemsContainer = new BoundedFifo <T>(maxSize.Value);
            }
            else
            {
                _itemsContainer = new UnboundedFifo <T>();
            }
        }
Exemplo n.º 10
0
 /// <summary>
 ///   Initializes a new instance.
 /// </summary>
 /// <param name="from">The inclusive lower bound.</param>
 /// <param name="to">The inclusive upper bound.</param>
 /// <param name="overflowBehavior">The overflow behavior.</param>
 public RangeAttribute(object from, object to, OverflowBehavior overflowBehavior)
 {
     LowerBound       = from;
     UpperBound       = to;
     OverflowBehavior = overflowBehavior;
 }
Exemplo n.º 11
0
 /// <summary>
 ///   Restricts values that can be stored in the field referenced by the <paramref name="fieldExpression" /> to the range of
 ///   <paramref name="lowerBound" /> and <paramref name="upperBound" />, both inclusive, using the
 ///   <paramref name="overflowBehavior" /> to handle range overflows.
 /// </summary>
 /// <typeparam name="T">The type of the field that is restricted.</typeparam>
 /// <param name="fieldExpression">The expression referencing the field whose range should be restricted.</param>
 /// <param name="lowerBound">The inclusive lower bound.</param>
 /// <param name="upperBound">The inclusive upper bound.</param>
 /// <param name="overflowBehavior">The overflow behavior.</param>
 public static void Restrict <T>([LiftExpression] T fieldExpression, object lowerBound, object upperBound, OverflowBehavior overflowBehavior)
     where T : struct, IComparable
 {
     Requires.CompilationTransformation();
 }
Exemplo n.º 12
0
        public void BitPivotShouldRepectLinkFormatClasses(Visual visual, LinkFormat linkFormat, LinkSize linkSize, OverflowBehavior overflowBehavior)
        {
            var component = RenderComponent <BitPivotTest>(parameters =>
            {
                parameters.Add(p => p.Visual, visual);
                parameters.Add(p => p.LinkFormat, linkFormat);
                parameters.Add(p => p.LinkSize, linkSize);
                parameters.Add(p => p.OverflowBehavior, overflowBehavior);
            });

            var visualClass = visual.ToString().ToLower();

            var linkFormatClass       = $"bit-pvt-{linkFormat.ToString().ToLower()}-{visualClass}";
            var linkSizeClass         = $"bit-pvt-{linkSize.ToString().ToLower()}-{visualClass}";
            var overflowBehaviorClass = $"bit-pvt-{overflowBehavior.ToString().ToLower()}-{visualClass}";

            var bitPivot = component.Find($".bit-pvt");

            Assert.IsTrue(bitPivot.ClassList.Contains(linkFormatClass));
            Assert.IsTrue(bitPivot.ClassList.Contains(linkSizeClass));
            Assert.IsTrue(bitPivot.ClassList.Contains(overflowBehaviorClass));
        }
Exemplo n.º 13
0
		/// <summary>
		///   Initializes a new instance.
		/// </summary>
		/// <param name="from">The inclusive lower bound.</param>
		/// <param name="to">The inclusive upper bound.</param>
		/// <param name="overflowBehavior">The overflow behavior.</param>
		public RangeAttribute(object from, object to, OverflowBehavior overflowBehavior)
		{
			LowerBound = from;
			UpperBound = to;
			OverflowBehavior = overflowBehavior;
		}
 public TypographDisplayProperties(OverflowBehavior overflowBehavior, float maxWidth = float.MaxValue)
 {
     OverflowBehavior = overflowBehavior;
     MaxWidth         = maxWidth;
     TransformMatrix  = Matrix.Identity;
 }
Exemplo n.º 15
0
        // Constructors

        /// <summary>
        /// Creates new instance of <see cref="ArithmeticRules"/>.
        /// </summary>
        /// <param name="nullBehavior">Null behavior.</param>
        /// <param name="overflowBehavior">Overflow behavior.</param>
        public ArithmeticRules(NullBehavior nullBehavior, OverflowBehavior overflowBehavior)
        {
            this.nullBehavior     = nullBehavior;
            this.overflowBehavior = overflowBehavior;
        }