/// <summary> /// 获取32位单精度浮点数记录 /// </summary> /// <param name="index">记录索引(从1开始计数,2字节单位)</param> /// <returns>记录内容</returns> private Single GetSingleRecord(Int16 index) { return(C3DBitConverter.ToSingle(this._data, (index - 1) * 2)); }
/// <summary> /// 获取指定索引的参数数据 /// </summary> /// <typeparam name="T">参数类型</typeparam> /// <param name="index">指定索引(从0开始计数)</param> /// <exception cref="C3DException">数据类型错误</exception> /// <returns>参数数据</returns> public T GetData <T>(Int32 index) { #region Base Type if (typeof(T) == typeof(Char)) { return((T)(Object)(Char)this._parameterData[index]); } if (typeof(T) == typeof(Byte)) { return((T)(Object)this._parameterData[index]); } if (typeof(T) == typeof(Int16)) { return((T)(Object)C3DBitConverter.ToInt16(this._parameterData, index * sizeof(Int16))); } if (typeof(T) == typeof(UInt16)) { return((T)(Object)(UInt16)C3DBitConverter.ToInt16(this._parameterData, index * sizeof(UInt16))); } if (typeof(T) == typeof(Single)) { return((T)(Object)C3DBitConverter.ToSingle(this._parameterData, index * sizeof(Single))); } if (typeof(T) == typeof(String)) { if (this._dimensions == null || this._dimensions.Length != 1 || this._parameterType != C3DParameterType.Char) { throw new C3DException("Parameter \"" + this.Name + "\" is not string type."); } return((T)(Object)this.ReadStringFromBytes(this._parameterData, 0, this._dimensions[0])); } #endregion #region 1D-Array if (typeof(T) == typeof(Char[])) { return((T)(Object)this.Get1DArray <Char>()); } if (typeof(T) == typeof(Byte[])) { return((T)(Object)this.Get1DArray <Byte>()); } if (typeof(T) == typeof(Int16[])) { return((T)(Object)this.Get1DArray <Int16>()); } if (typeof(T) == typeof(UInt16[])) { return((T)(Object)this.Get1DArray <UInt16>()); } if (typeof(T) == typeof(Single[])) { return((T)(Object)this.Get1DArray <Single>()); } if (typeof(T) == typeof(String[])) { if (this._dimensions == null || this._dimensions.Length != 2 || this._parameterType != C3DParameterType.Char) { throw new C3DException("Parameter \"" + Name + "\" is not string array type."); } String[] ret = new String[this._dimensions[1]]; for (Int32 i = 0; i < this._dimensions[1]; i++) { ret[i] = this.ReadStringFromBytes(this._parameterData, i * this._dimensions[0], this._dimensions[0]); } return((T)(Object)ret); } #endregion #region 2D-Array if (typeof(T) == typeof(Char[, ])) { return((T)(Object)this.Get2DArray <Char>()); } if (typeof(T) == typeof(Byte[, ])) { return((T)(Object)this.Get2DArray <Byte>()); } if (typeof(T) == typeof(Int16[, ])) { return((T)(Object)this.Get2DArray <Int16>()); } if (typeof(T) == typeof(UInt16[, ])) { return((T)(Object)this.Get2DArray <UInt16>()); } if (typeof(T) == typeof(Single[, ])) { return((T)(Object)this.Get2DArray <Single>()); } #endregion #region 3D-Array if (typeof(T) == typeof(Char[, , ])) { return((T)(Object)this.Get3DArray <Char>()); } if (typeof(T) == typeof(Byte[, , ])) { return((T)(Object)this.Get3DArray <Byte>()); } if (typeof(T) == typeof(Int16[, , ])) { return((T)(Object)this.Get3DArray <Int16>()); } if (typeof(T) == typeof(UInt16[, , ])) { return((T)(Object)this.Get3DArray <UInt16>()); } if (typeof(T) == typeof(Single[, , ])) { return((T)(Object)this.Get3DArray <Single>()); } #endregion throw new C3DException("Parameter type is unknown."); }
/// <summary> /// 更新参数内数据 /// </summary> /// <param name="parameterType">参数类型</param> /// <param name="processorType">处理器类型</param> /// <param name="dimensionCount">维数</param> private void UpdateData(C3DParameterType parameterType, C3DProcessorType processorType, Int32 dimensionCount) { #region Basic Type if (dimensionCount == 0) { if (parameterType == C3DParameterType.Int16) { this.InternalSetData <Int16>(C3DBitConverter.ToInt16(processorType, this._parameterData)); } else if (parameterType == C3DParameterType.Single) { this.InternalSetData <Single>(C3DBitConverter.ToSingle(processorType, this._parameterData)); } return; } #endregion #region 1D-Array if (dimensionCount == 1) { if (parameterType == C3DParameterType.Int16) { Byte[][] datas = this.Get1DByteArray(sizeof(Int16)); Int16[] newdata = new Int16[datas.Length]; for (Int32 i = 0; i < datas.Length; i++) { newdata[i] = C3DBitConverter.ToInt16(processorType, datas[i]); } this.InternalSetData <Int16[]>(newdata); } else if (parameterType == C3DParameterType.Single) { Byte[][] datas = this.Get1DByteArray(sizeof(Single)); Single[] newdata = new Single[datas.Length]; for (Int32 i = 0; i < datas.Length; i++) { newdata[i] = C3DBitConverter.ToSingle(processorType, datas[i]); } this.InternalSetData <Single[]>(newdata); } return; } #endregion #region 2D-Array if (dimensionCount == 2) { if (parameterType == C3DParameterType.Int16) { Byte[, ][] datas = this.Get2DByteArray(sizeof(Int16)); Int16[,] newdata = new Int16[datas.GetLength(0), datas.GetLength(1)]; for (Int32 x = 0; x < datas.GetLength(0); x++) { for (Int32 y = 0; y < datas.GetLength(1); y++) { newdata[x, y] = C3DBitConverter.ToInt16(processorType, datas[x, y]); } } this.InternalSetData <Int16[, ]>(newdata); } else if (parameterType == C3DParameterType.Single) { Byte[, ][] datas = this.Get2DByteArray(sizeof(Single)); Single[,] newdata = new Single[datas.GetLength(0), datas.GetLength(1)]; for (Int32 x = 0; x < datas.GetLength(0); x++) { for (Int32 y = 0; y < datas.GetLength(1); y++) { newdata[x, y] = C3DBitConverter.ToSingle(processorType, datas[x, y]); } } this.InternalSetData <Single[, ]>(newdata); } return; } #endregion #region 3D-Array if (dimensionCount == 3) { if (parameterType == C3DParameterType.Int16) { Byte[, , ][] datas = this.Get3DByteArray(sizeof(Int16)); Int16[, ,] newdata = new Int16[datas.GetLength(0), datas.GetLength(1), datas.GetLength(2)]; for (Int32 x = 0; x < datas.GetLength(0); x++) { for (Int32 y = 0; y < datas.GetLength(1); y++) { for (Int32 z = 0; z < datas.GetLength(2); z++) { newdata[x, y, z] = C3DBitConverter.ToInt16(processorType, datas[x, y, z]); } } } this.InternalSetData <Int16[, , ]>(newdata); } else if (parameterType == C3DParameterType.Single) { Byte[, , ][] datas = this.Get3DByteArray(sizeof(Single)); Single[, ,] newdata = new Single[datas.GetLength(0), datas.GetLength(1), datas.GetLength(2)]; for (Int32 x = 0; x < datas.GetLength(0); x++) { for (Int32 y = 0; y < datas.GetLength(1); y++) { for (Int32 z = 0; z < datas.GetLength(2); z++) { newdata[x, y, z] = C3DBitConverter.ToSingle(processorType, datas[x, y, z]); } } } this.InternalSetData <Single[, , ]>(newdata); } return; } #endregion }
/// <summary> /// 从当前流中读取下一个32位单精度浮点数 /// </summary> /// <returns>下一个32位单精度浮点数</returns> internal Single ReadSingle() { Byte[] data = this.ReadBytes(4); return(C3DBitConverter.ToSingle(this._processorType, data)); }