Exemplo n.º 1
0
        public static Array RRBaseArrayToArray(RRBaseArray i)
        {
            if (i == null)
            {
                return(null);
            }
            DataTypes type = i.GetTypeID();
            Array     o    = null;

            switch (type)
            {
            case DataTypes.double_t: {
                var o2 = new double[i.size()];
                MessageElementDataUtil.RRBaseArrayToDoubles(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.single_t: {
                var o2 = new float[i.size()];
                MessageElementDataUtil.RRBaseArrayToFloats(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.int8_t: {
                var o2 = new sbyte[i.size()];
                MessageElementDataUtil.RRBaseArrayToBytes(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.uint8_t: {
                var o2 = new byte[i.size()];
                MessageElementDataUtil.RRBaseArrayToBytes(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.int16_t: {
                var o2 = new short[i.size()];
                MessageElementDataUtil.RRBaseArrayToShorts(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.uint16_t: {
                var o2 = new ushort[i.size()];
                MessageElementDataUtil.RRBaseArrayToShorts(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.int32_t: {
                var o2 = new int[i.size()];
                MessageElementDataUtil.RRBaseArrayToInts(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.uint32_t: {
                var o2 = new uint[i.size()];
                MessageElementDataUtil.RRBaseArrayToInts(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.int64_t: {
                var o2 = new long[i.size()];
                MessageElementDataUtil.RRBaseArrayToLongs(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.uint64_t: {
                var o2 = new ulong[i.size()];
                MessageElementDataUtil.RRBaseArrayToLongs(i, o2, o2.Length);
                return(o2);
            }

            case DataTypes.cdouble_t: {
                var o2 = new double[i.size() * 2];
                MessageElementDataUtil.RRBaseArrayComplexToDoubles(i, o2, o2.Length);
                var o3 = new CDouble[i.size()];
                for (int j = 0; j < o3.Length; j++)
                {
                    o3[j] = new CDouble(o2[j * 2], o2[j * 2 + 1]);
                }
                return(o3);
            }

            case DataTypes.csingle_t: {
                var o2 = new float[i.size() * 2];
                MessageElementDataUtil.RRBaseArrayComplexToFloats(i, o2, o2.Length);
                var o3 = new CSingle[i.size()];
                for (int j = 0; j < o3.Length; j++)
                {
                    o3[j] = new CSingle(o2[j * 2], o2[j * 2 + 1]);
                }
                return(o3);
            }

            case DataTypes.bool_t: {
                var o2 = new byte[i.size()];
                MessageElementDataUtil.RRBaseArrayBoolToBytes(i, o2, o2.Length);
                var o3 = new bool[o2.Length];
                for (int j = 0; j < o3.Length; j++)
                {
                    o3[j] = o2[j] != 0;
                }
                return(o3);
            }

            default:
                throw new DataTypeException("Invalid RRBaseArray type");
            }
        }