コード例 #1
0
ファイル: StructArray.cs プロジェクト: qianc123/visionnet
        internal StructArray(int[] dimensions, Stream stream, bool swapBytes)
        {
            _values = new Dictionary <string, miMATRIX>();
            miINT32 fieldNameLength = DataElement.Read(stream, swapBytes) as miINT32;

            int length = (int)dimensions.Sum(o => o);

            string[] fieldNames        = new string[length];
            miINT8   fieldNamesElement = DataElement.Read(stream, swapBytes) as miINT8;

            byte[] nameBytes = fieldNamesElement.ToByteArray();
            for (int i = 0; i < length; i++)
            {
                fieldNames[i] = Encoding.ASCII.GetString(nameBytes, i * fieldNameLength[0], fieldNameLength[0]).TrimEnd('\0');
            }

            for (int i = 0; i < length; i++)
            {
                _values[fieldNames[i]] = DataElement.Read(stream, swapBytes) as miMATRIX;
            }
        }
コード例 #2
0
ファイル: miMATRIX.cs プロジェクト: qianc123/visionnet
        /// <summary>
        /// Initializes the data element from the stream
        /// </summary>
        /// <param name="stream">Stream to read from</param>
        /// <param name="numBytes">The total number of bytes to read</param>
        /// <param name="reverseBytes">Whether to reverse bytes before they are converted</param>
        /// <param name="compressed">Whether the element is compressed</param>
        protected override void Init(Stream stream, int numBytes, bool reverseBytes, bool compressed)
        {
            miUINT32 arrayFlags      = DataElement.Read(stream, reverseBytes) as miUINT32;
            miINT32  dimensionsArray = DataElement.Read(stream, reverseBytes) as miINT32;
            miINT8   arrayName       = DataElement.Read(stream, reverseBytes) as miINT8;

            uint flags = (0xFF00 & arrayFlags[0]) >> 8;

            Complex = (flags & 0x04) > 0;
            Global  = (flags & 0x02) > 0;
            Logical = (flags & 0x01) > 0;
            Class   = (ArrayType)(arrayFlags[0] & 0xFF);

            Dimensions = dimensionsArray;

            Name = Encoding.ASCII.GetString(arrayName.ToByteArray());

            switch (Class)
            {
            case ArrayType.miCELL_CLASS:
                Cells = new miMATRIX[(int)Dimensions.Product(o => o)];
                for (int i = 0; i < Cells.Length; i++)
                {
                    Cells[i] = (miMATRIX)DataElement.Read(stream, reverseBytes);
                }
                break;

            case ArrayType.mxSTRUCT_CLASS:
                Array = new StructArray(Dimensions, stream, reverseBytes);
                break;

            case ArrayType.mxCHAR_CLASS:
                Array = new CharacterArray(Dimensions, (miINT8)DataElement.Read(stream, reverseBytes));
                break;

            case ArrayType.mxDOUBLE_CLASS:
                Array = new miDOUBLEArray(Dimensions, DataElement.Read(stream, reverseBytes));
                break;

            case ArrayType.mxSINGLE_CLASS:
                Array = new miSINGLEArray(Dimensions, DataElement.Read(stream, reverseBytes));
                break;

            case ArrayType.mxUINT32_CLASS:
                Array = new miUINT32Array(Dimensions, DataElement.Read(stream, reverseBytes));
                break;

            case ArrayType.mxINT32_CLASS:
                Array = new miINT32Array(Dimensions, DataElement.Read(stream, reverseBytes));
                break;

            case ArrayType.mxUINT16_CLASS:
                Array = new miUINT16Array(Dimensions, DataElement.Read(stream, reverseBytes));
                break;

            case ArrayType.mxINT16_CLASS:
                Array = new miINT16Array(Dimensions, DataElement.Read(stream, reverseBytes));
                break;

            case ArrayType.mxUINT8_CLASS:
                Array = new miUINT8Array(Dimensions, DataElement.Read(stream, reverseBytes));
                break;

            case ArrayType.mxINT8_CLASS:
                Array = new miINT8Array(Dimensions, DataElement.Read(stream, reverseBytes));
                break;
            }
        }