/// <summary> /// Initializes a new instance of the <see cref="IntegerArray"/> struct. /// </summary> /// <param name="source">The array range to wrap.</param> /// <param name="byteOffset">The zero-based index of the first <see cref="Byte"/> in <paramref name="source"/>.</param> /// <param name="itemsCount">The number of <see cref="UInt32"/> items in <paramref name="source"/>.</param> /// <param name="encoding">Byte encoding.</param> public IntegerArray(BYTES source, int byteOffset, int itemsCount, ENCODING encoding) { _Data = source.Slice(byteOffset); _ByteStride = encoding.ByteLength(); this._Setter = null; this._Getter = null; if (itemsCount < this.Count) { _Data = _Data.Slice(0, itemsCount * _ByteStride); } switch (encoding) { case ENCODING.UNSIGNED_BYTE: { this._Setter = this._SetValueU8; this._Getter = this._GetValueU8; break; } case ENCODING.UNSIGNED_SHORT: { this._Setter = this._SetValueU16; this._Getter = this._GetValueU16; break; } case ENCODING.UNSIGNED_INT: { this._Setter = this._SetValue <UInt32>; this._Getter = this._GetValue <UInt32>; break; } default: throw new ArgumentException(nameof(encoding)); } }
public FloatingAccessor(BYTES source, int byteOffset, int itemsCount, int byteStride, int dimensions, ENCODING encoding, Boolean normalized) { var enclen = encoding.ByteLength(); this._Data = source.Slice(byteOffset); this._Getter = null; this._Setter = null; this._ByteStride = Math.Max(byteStride, enclen * dimensions); this._EncodedLen = enclen; this._ItemCount = this._Data.Count / this._ByteStride; // strided buffers usually have room for an extra item if ((_Data.Count % _ByteStride) >= enclen * dimensions) { ++_ItemCount; } _ItemCount = Math.Min(itemsCount, _ItemCount); if (encoding == ENCODING.FLOAT) { this._Setter = this._SetValue <Single>; this._Getter = this._GetValue <Single>; return; } if (normalized) { switch (encoding) { case ENCODING.BYTE: { this._Setter = this._SetNormalizedS8; this._Getter = this._GetNormalizedS8; break; } case ENCODING.UNSIGNED_BYTE: { this._Setter = this._SetNormalizedU8; this._Getter = this._GetNormalizedU8; break; } case ENCODING.SHORT: { this._Setter = this._SetNormalizedS16; this._Getter = this._GetNormalizedS16; break; } case ENCODING.UNSIGNED_SHORT: { this._Setter = this._SetNormalizedU16; this._Getter = this._GetNormalizedU16; break; } default: throw new ArgumentException(nameof(encoding)); } } else { switch (encoding) { case ENCODING.BYTE: { this._Setter = this._SetValueS8; this._Getter = this._GetValueS8; break; } case ENCODING.UNSIGNED_BYTE: { this._Setter = this._SetValueU8; this._Getter = this._GetValueU8; break; } case ENCODING.SHORT: { this._Setter = this._SetValueS16; this._Getter = this._GetValueS16; break; } case ENCODING.UNSIGNED_SHORT: { this._Setter = this._SetValueU16; this._Getter = this._GetValueU16; break; } case ENCODING.UNSIGNED_INT: { this._Setter = this._SetValueU32; this._Getter = this._GetValueU32; break; } case ENCODING.FLOAT: break; default: throw new ArgumentException(nameof(encoding)); } } }