/// <summary>
        /// Get the bytes of this IBitWindow as though the bits in the window were a single N-bit integer with a layout that matches
        /// that of the current processor.
        /// Currently restricted to 1,2,4, and 8 byte sized integers.
        /// Currently restricted to unsigned or 2's complement format.
        /// </summary>
        /// <param name="this"></param>
        /// <param name="integerSize">The byte width of the resulting integer.</param>
        /// <param name="signed">Whether or not the resulting integer is signed.</param>
        /// <returns></returns>
        public static Byte[] Crystalize(this IBitWindow @this, IntegerFormat format)
        {
            if (@this == null)
            {
                throw new ArgumentNullException(nameof(@this));
            }
            if (!SupportedIntegerFormats.Contains(format))
            {
                throw new NotSupportedException();
            }

            if (format.BitWidth / 8 < (@this.Length + 7) / 8)
            {
                throw new InvalidOperationException();
            }
            Byte[]    integerBuffer = new Byte[format.BitWidth / 8];
            BitWindow integerView   = new BitWindow(integerBuffer, new EndianBitIndexer(format.ByteOrder, format.BitOrder));

            @this.WriteTo(integerView, 0, 0, @this.Length);
            if (format.Signed)
            {
                if (@this[@this.Length - 1])
                {
                    for (int bitPow = @this.Length; bitPow < integerView.Length; bitPow++)
                    {
                        integerView[bitPow] = true;
                    }
                }
            }
            return(integerBuffer);
        }
 public static AttributeMetadata CreateWholeNumber(IntegerFormat? format = IntegerFormat.None, int? minValue = IntegerAttributeMetadata.MinSupportedValue, int? maxValue = IntegerAttributeMetadata.MaxSupportedValue, string formulaDefinition = null)
 {
     return new IntegerAttributeMetadata
     {
         Format = format,
         MaxValue = maxValue,
         MinValue = minValue,
         FormulaDefinition = formulaDefinition
     };
 }
Beispiel #3
0
        public IntegerAttributeMetadata Create(AttributeMetadata baseMetadata, IntegerFormat integetFormat, int?maxvalue, int?minvalue)
        {
            var integerAttribute = new IntegerAttributeMetadata
            {
                // Set base properties
                SchemaName    = baseMetadata.SchemaName,
                DisplayName   = baseMetadata.DisplayName,
                RequiredLevel = baseMetadata.RequiredLevel,
                Description   = baseMetadata.Description,
                // Set extended properties
                Format   = IntegerFormat.None,
                MaxValue = 100,
                MinValue = 0
            };

            return(integerAttribute);
        }
Beispiel #4
0
 public Object Eva(String str, CalcMode calcMode, IntegerFormat fmt, IntegerBits numBits, bool updateAnswer)
 {
     Int64 result = 0;
     if (str.Length < 1)
         return false;
     try
     {
         m_numFmt = fmt;
         switch (fmt)
         {
             case IntegerFormat.DEC:
                 Object obj = m_calcEngine.Evaluate(str, calcMode, numBits, fmt);
                 if (obj != null && updateAnswer)
                 {
                     if (m_calcEngine.Variables.ContainsKey("ans"))
                         UpdateVariable("ans", obj);
                     else
                         AddVariable("ans", obj);
                 }
                 return obj;
             case IntegerFormat.HEX:
                 return Int64.Parse(str, System.Globalization.NumberStyles.HexNumber);
             case IntegerFormat.BIN:
                 if (ParseBinStr(str, ref result))
                     return result;
                 else
                     throw new ArgumentException();
             default:
                 return null;
         }
     }
     catch (Exception _ex)
     {
         throw _ex;
     }
 }
Beispiel #5
0
 private ExpTool()
 {
     m_numFmt = IntegerFormat.DEC;
     m_calcEngine = new CalcEngine.CalcEngine();
     m_varList = new Dictionary<string, object>();
 }
 /// <summary>
 /// Creates a view into an existing view.
 /// </summary>
 /// <param name="this">The existing view.</param>
 /// <param name="offset">The bit offset relative to the start of the existing view.</param>
 /// <param name="format">A format to follow.</param>
 /// <returns></returns>
 public static IBitWindow Crack(this IBitWindow @this, Int32 offset, IntegerFormat format)
 {
     return(@this.Crack(offset, format.BitWidth, format.GetIndexer()));
 }
Beispiel #7
0
        public object Evaluate(string expression,
			CalcMode calMode,
			IntegerBits intBits,
			IntegerFormat intFmt)
        {
            Expression.CurCalcMode = calMode;
            Expression.CurIntBits = intBits;
            Expression.CurIntFmt = intFmt;
            var x = _cache != null
                ? _cache[expression]
                : Parse(expression);
            return Token.FormatValue(x.Evaluate(), calMode, intBits, intFmt);
        }
Beispiel #8
0
        public EntityAttributeMetadataBuilder IntAttribute(string schemaName, string displayName, string description, AttributeRequiredLevel requiredLevel, IntegerFormat format, int min, int max)
        {
            // Define the primary attribute for the entity
            // Create a integer attribute
            int languageCode     = 1033;
            var integerAttribute = new IntegerAttributeMetadata
            {
                // Set base properties
                SchemaName    = schemaName,
                DisplayName   = new Label(schemaName, languageCode),
                RequiredLevel = new AttributeRequiredLevelManagedProperty(requiredLevel),
                Description   = new Label(description, languageCode),
                // Set extended properties
                Format   = format,
                MaxValue = max,
                MinValue = min
            };

            this.Attributes.Add(integerAttribute);
            return(this);
        }
 public IntegerAttribute(int maxValue, int minValue, Metadata.IntegerFormat format)
 {
     MaxValue = maxValue;
     MinValue = minValue;
     Format   = format.ToSimilarEnum <IntegerFormat>();
 }
Beispiel #10
0
 /// <summary>
 /// Gets a bit indexer for this integer format.
 /// </summary>
 /// <param name="fmt">The existing format</param>
 /// <returns>An indexer for reading an integer in the specified format</returns>
 public static IBitIndexer GetIndexer(this IntegerFormat fmt)
 {
     return(EndianBitIndexer.GetStandard(fmt.BitOrder, fmt.ByteOrder));
 }
Beispiel #11
0
        public static object FormatValue(object val, 
									CalcMode  calcMode, 
									IntegerBits  intBits,
									IntegerFormat  intFmt)
        {
            double v;

            if (val is string)
                return val;

            if (val is double)
            {
                v = (double)val;
            }

            // handle booleans
            if (val is bool)
            {
                v = 1.0;
            }

            // handle nulls
            if (val == null)
            {
                v = 0;
            }

            // handle everything else
            v = (double)Convert.ChangeType(val, typeof(double));

            if (calcMode == CalcMode.FLOAT)
            {
                return (double)v;
            }
            else if (calcMode == CalcMode.INTEGER_SIGNED)
            {
                if (intBits == IntegerBits.BITS_64)
                {
                    return (Int64)v;
                }
                else if (intBits == IntegerBits.BITS_32)
                {
                    return (Int32)v;
                }
                else if (intBits == IntegerBits.BITS_16)
                {
                    return (Int16)v;
                }
                else if (intBits == IntegerBits.BITS_8)
                {
                    return (SByte)v;
                }
                else
                {
                    throw new Exception("Invalid Integer Bits");
                }
            }
            else if (calcMode == CalcMode.INTEGER_UNSIGNED)
            {
                if (intBits == IntegerBits.BITS_64)
                {
                    return (UInt64)v;
                }
                else if (intBits == IntegerBits.BITS_32)
                {
                    return (UInt32)v;
                }
                else if (intBits == IntegerBits.BITS_16)
                {
                    return (UInt16)v;
                }
                else if (intBits == IntegerBits.BITS_8)
                {
                    return (Byte)v;
                }
                else
                {
                    throw new Exception("Invalid Integer Bits");
                }
            }
            else
            {
                throw new Exception("Invalid Calculate Mode");
            }
        }