/// <summary>
        /// Returns the next compatible size constraint value from a start
        /// value.The values will be enumerated from lower values to
        /// higher.
        /// </summary>
        /// <param name="start">The initial start value</param>
        /// <returns>The next compatible value, or -1 if none exists</returns>
        public int NextValue(int start)
        {
            IEnumerable <IConstraint> list = this.Values;
            BigInteger val;

            // TODO: the constraint list should be sorted
            foreach (var c in list)
            {
                ValueConstraint vc = c as ValueConstraint;
                if (vc != null)
                {
                    NumberValue nv = vc.Value as NumberValue;
                    if (nv != null)
                    {
                        val = nv.Value;
                    }
                    else
                    {
                        val = 0; // TODO: need to handle this differently
                    }
                }
                else
                {
                    ValueRangeConstraint vrc = c as ValueRangeConstraint;
                    if (vrc != null)
                    {
                        if (vrc.IsCompatible((BigInteger)start))
                        {
                            return(start);
                        }
                        else
                        {
                            NumberValue nv = vrc.LowerBound as NumberValue;
                            if (nv != null)
                            {
                                val = nv.Value;
                            }
                            else
                            {
                                // TODO: fix this
                                throw new NotImplementedException();
                            }
                        }
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }

                if ((BigInteger)start <= val)
                {
                    return((int)val);
                }
            }

            return(-1);
        }
Beispiel #2
0
        /// <summary>
        /// Creates the constraints and symbol map from a list of value
        /// symbols.
        /// </summary>
        /// <param name="values">The list of value symbols</param>
        private void CreateValueConstraints(IList <MibValueSymbol> values)
        {
            ValueConstraint c;

            foreach (MibValueSymbol sym in values)
            {
                this.symbols[sym.Name] = sym;

                // TODO: check value constraint compability
                c = new ValueConstraint(null, sym.Value);
                if (this.constraint == null)
                {
                    this.constraint = c;
                }
                else
                {
                    this.constraint = new CompoundConstraint(this.constraint, c);
                }
            }
        }