Esempio n. 1
0
        //=========================================================================
        /// <summary>
        /// Read the scalar value in the array at the specified index.
        /// </summary>
        /// <param name="initName">Name of the array init property.</param>
        /// <param name="idx">Item index in the array.</param>
        /// <param name="value">The scalar value found at the index. Returns 0 if not found.</param>
        //=========================================================================
        public void readElement(string initName, int idx, ref double value)
        {
            TTypedValue aValue = null;

            aValue = findElementRead(initName, idx);
            if (aValue != null)
            {
                value = aValue.asDouble();
            }
            else
            {
                value = 0.0;
            }
        }
Esempio n. 2
0
        //============================================================================
        /// <summary>
        /// Return the string for the scalar ttypedvalue.
        /// Numeric types are returned without any rounding or escaping.
        /// </summary>
        /// <param name="attrInfo">The scalar TTypedValue</param>
        /// <returns>String represenation of the scalar</returns>
        //============================================================================
        protected String scalarString(TTypedValue attrInfo)
        {
            String strVal;

            if ((attrInfo.baseType() >= TTypedValue.TBaseType.ITYPE_SINGLE) && (attrInfo.baseType() <= TTypedValue.TBaseType.ITYPE_DOUBLE))
            {
                strVal = attrInfo.asDouble().ToString(); //full precision
            }
            else
            {
                if ((attrInfo.baseType() >= TTypedValue.TBaseType.ITYPE_INT1) && (attrInfo.baseType() <= TTypedValue.TBaseType.ITYPE_INT8))
                {
                    strVal = attrInfo.asInt().ToString(); //no need to escape this
                }
                else
                {
                    strVal = attrInfo.asEscapedString();
                }
            }
            return(strVal);
        }
Esempio n. 3
0
        //============================================================================
        /// <summary>
        /// Updates the current value of the variable in the output column. Handles
        /// aggregation within reporting intervals
        /// Assumes:
        ///  * aValue is a scalar of the correct type
        /// </summary>
        /// <param name="aValue"></param>
        //============================================================================
        public void Update(TTypedValue aValue)
        {
            switch (baseType)
            {
            case TTypedValue.TBaseType.ITYPE_INT1:
            case TTypedValue.TBaseType.ITYPE_INT2:
            case TTypedValue.TBaseType.ITYPE_INT4:
            case TTypedValue.TBaseType.ITYPE_INT8:
            {
                if (AggregCount == 0)
                {
                    dVal = aValue.asInt();
                }
                else
                {
                    switch (Aggreg)
                    {
                    case TGenericReporter.AggregType.aggSum: dVal = dVal + aValue.asInt();
                        break;

                    case TGenericReporter.AggregType.aggMax: dVal = Math.Max(dVal, aValue.asInt());
                        break;

                    case TGenericReporter.AggregType.aggMin: dVal = Math.Min(dVal, aValue.asInt());
                        break;
                    }
                }
            }
            break;

            case TTypedValue.TBaseType.ITYPE_SINGLE:
            {
                if (AggregCount == 0)
                {
                    dVal = aValue.asSingle();
                }
                else
                {
                    switch (Aggreg)
                    {
                    case TGenericReporter.AggregType.aggSum: dVal = dVal + aValue.asSingle();
                        break;

                    case TGenericReporter.AggregType.aggAve: dVal = (dVal * AggregCount + aValue.asSingle()) / (AggregCount + 1);
                        break;

                    case TGenericReporter.AggregType.aggMax: dVal = Math.Max(dVal, aValue.asSingle());
                        break;

                    case TGenericReporter.AggregType.aggMin: dVal = Math.Min(dVal, aValue.asSingle());
                        break;
                    }
                }
            }
            break;

            case TTypedValue.TBaseType.ITYPE_DOUBLE:
            {
                if (AggregCount == 0)
                {
                    dVal = aValue.asDouble();
                }
                else
                {
                    switch (Aggreg)
                    {
                    case TGenericReporter.AggregType.aggSum: dVal = dVal + aValue.asDouble();
                        break;

                    case TGenericReporter.AggregType.aggAve: dVal = (dVal * AggregCount + aValue.asDouble()) / (AggregCount + 1);
                        break;

                    case TGenericReporter.AggregType.aggMax: dVal = Math.Max(dVal, aValue.asDouble());
                        break;

                    case TGenericReporter.AggregType.aggMin: dVal = Math.Min(dVal, aValue.asDouble());
                        break;
                    }
                }
            }
            break;

            case TTypedValue.TBaseType.ITYPE_BOOL:
            {
                if (AggregCount == 0)
                {
                    sVal = aValue.asBool().ToString();
                }
                else
                {
                    switch (Aggreg)
                    {
                    case TGenericReporter.AggregType.aggMax:
                    {
                        bool bVal = Convert.ToBoolean(sVal) || aValue.asBool();
                        sVal = bVal.ToString();
                    }
                    break;

                    case TGenericReporter.AggregType.aggMin:
                    {
                        bool bVal = Convert.ToBoolean(sVal) && aValue.asBool();
                        sVal = bVal.ToString();
                    }
                    break;
                    }
                }
            }
            break;

            case TTypedValue.TBaseType.ITYPE_CHAR:
            case TTypedValue.TBaseType.ITYPE_STR:
            {
                if (AggregCount == 0)
                {
                    sVal = aValue.asStr();
                }
            }
            break;
            }
            AggregCount++;
        }