public Impl(Row input, int pyColIndex, int idvColIndex, ColumnType type, ValuePoker <TSrc> poker) : base(input, pyColIndex) { Contracts.AssertValue(input); Contracts.Assert(0 <= idvColIndex && idvColIndex < input.Schema.Count); if (type.IsVector) { _getVec = RowCursorUtils.GetVecGetterAs <TSrc>((PrimitiveType)type.ItemType, input, idvColIndex); } else { _get = RowCursorUtils.GetGetterAs <TSrc>(type, input, idvColIndex); } _poker = poker; }
public Impl(DataViewRow input, int pyColIndex, int idvColIndex, DataViewType type, ValuePoker <TSrc> poker) : base(input, pyColIndex) { Contracts.AssertValue(input); Contracts.Assert(0 <= idvColIndex && idvColIndex < input.Schema.Count); if (type is VectorDataViewType) { _getVec = RowCursorUtils.GetVecGetterAs <TSrc>((PrimitiveDataViewType)type.GetItemType(), input, idvColIndex); } else { _get = RowCursorUtils.GetGetterAs <TSrc>(type, input, idvColIndex); } _poker = poker; _isVarLength = (type.GetValueCount() == 0); }
public static BufferFillerBase Create(EnvironmentBlock *penv, Row input, int pyCol, int idvCol, DataKind dataKind, ColumnType type, void *setter) { var itemType = type.ItemType; // We convert the unsigned types to signed types, with -1 indicating missing in Python. if (itemType.KeyCount > 0) { var keyCount = itemType.KeyCount; uint keyMax = (uint)keyCount; switch (itemType.RawKind) { case DataKind.U1: var fnI1 = MarshalDelegate <I1Setter>(setter); ValuePoker <byte> pokeU1 = (byte value, int col, long index) => fnI1(penv, col, index, value > keyMax ? (sbyte)-1 : (sbyte)(value - 1)); return(new Impl <byte>(input, pyCol, idvCol, type, pokeU1)); case DataKind.U2: var fnI2 = MarshalDelegate <I2Setter>(setter); ValuePoker <ushort> pokeU2 = (ushort value, int col, long index) => fnI2(penv, col, index, value > keyMax ? (short)-1 : (short)(value - 1)); return(new Impl <ushort>(input, pyCol, idvCol, type, pokeU2)); case DataKind.U4: var fnI4 = MarshalDelegate <I4Setter>(setter); ValuePoker <uint> pokeU4 = (uint value, int col, long index) => fnI4(penv, col, index, value > keyMax ? -1 : (int)(value - 1)); return(new Impl <uint>(input, pyCol, idvCol, type, pokeU4)); case DataKind.U8: // We convert U8 key types with key names to I4. fnI4 = MarshalDelegate <I4Setter>(setter); ValuePoker <ulong> pokeU8 = (ulong value, int col, long index) => fnI4(penv, col, index, value > keyMax ? -1 : (int)(value - 1)); return(new Impl <ulong>(input, pyCol, idvCol, type, pokeU8)); } } // Key type with count=0 else if (itemType.IsKey) { switch (itemType.RawKind) { case DataKind.U1: var fnI1 = MarshalDelegate <I1Setter>(setter); ValuePoker <byte> pokeU1 = (byte value, int col, long index) => fnI1(penv, col, index, (sbyte)(value - 1)); return(new Impl <byte>(input, pyCol, idvCol, type, pokeU1)); case DataKind.U2: var fnI2 = MarshalDelegate <I2Setter>(setter); ValuePoker <ushort> pokeU2 = (ushort value, int col, long index) => fnI2(penv, col, index, (short)(value - 1)); return(new Impl <ushort>(input, pyCol, idvCol, type, pokeU2)); case DataKind.U4: var fnI4 = MarshalDelegate <I4Setter>(setter); ValuePoker <uint> pokeU4 = (uint value, int col, long index) => fnI4(penv, col, index, (int)(value - 1)); return(new Impl <uint>(input, pyCol, idvCol, type, pokeU4)); case DataKind.U8: // We convert U8 key types with key names to I4. fnI4 = MarshalDelegate <I4Setter>(setter); ValuePoker <ulong> pokeU8 = (ulong value, int col, long index) => fnI4(penv, col, index, (int)(value - 1)); return(new Impl <ulong>(input, pyCol, idvCol, type, pokeU8)); } } else { switch (dataKind) { case DataKind.R4: var fnR4 = MarshalDelegate <R4Setter>(setter); ValuePoker <float> pokeR4 = (float value, int col, long index) => fnR4(penv, col, index, value); return(new Impl <float>(input, pyCol, idvCol, type, pokeR4)); case DataKind.R8: var fnR8 = MarshalDelegate <R8Setter>(setter); ValuePoker <double> pokeR8 = (double value, int col, long index) => fnR8(penv, col, index, value); return(new Impl <double>(input, pyCol, idvCol, type, pokeR8)); case DataKind.BL: var fnBl = MarshalDelegate <BLSetter>(setter); ValuePoker <bool> pokeBl = (bool value, int col, long index) => fnBl(penv, col, index, !value ? (byte)0 : value ? (byte)1 : (byte)0xFF); return(new Impl <bool>(input, pyCol, idvCol, type, pokeBl)); case DataKind.I1: var fnI1 = MarshalDelegate <I1Setter>(setter); ValuePoker <sbyte> pokeI1 = (sbyte value, int col, long index) => fnI1(penv, col, index, value); return(new Impl <sbyte>(input, pyCol, idvCol, type, pokeI1)); case DataKind.I2: var fnI2 = MarshalDelegate <I2Setter>(setter); ValuePoker <short> pokeI2 = (short value, int col, long index) => fnI2(penv, col, index, value); return(new Impl <short>(input, pyCol, idvCol, type, pokeI2)); case DataKind.I4: var fnI4 = MarshalDelegate <I4Setter>(setter); ValuePoker <int> pokeI4 = (int value, int col, long index) => fnI4(penv, col, index, value); return(new Impl <int>(input, pyCol, idvCol, type, pokeI4)); case DataKind.I8: var fnI8 = MarshalDelegate <I8Setter>(setter); ValuePoker <long> pokeI8 = (long value, int col, long index) => fnI8(penv, col, index, value); return(new Impl <long>(input, pyCol, idvCol, type, pokeI8)); case DataKind.U1: var fnU1 = MarshalDelegate <U1Setter>(setter); ValuePoker <byte> pokeU1 = (byte value, int col, long index) => fnU1(penv, col, index, value); return(new Impl <byte>(input, pyCol, idvCol, type, pokeU1)); case DataKind.U2: var fnU2 = MarshalDelegate <U2Setter>(setter); ValuePoker <ushort> pokeU2 = (ushort value, int col, long index) => fnU2(penv, col, index, value); return(new Impl <ushort>(input, pyCol, idvCol, type, pokeU2)); case DataKind.U4: var fnU4 = MarshalDelegate <U4Setter>(setter); ValuePoker <uint> pokeU4 = (uint value, int col, long index) => fnU4(penv, col, index, value); return(new Impl <uint>(input, pyCol, idvCol, type, pokeU4)); case DataKind.U8: var fnU8 = MarshalDelegate <U8Setter>(setter); ValuePoker <ulong> pokeU8 = (ulong value, int col, long index) => fnU8(penv, col, index, value); return(new Impl <ulong>(input, pyCol, idvCol, type, pokeU8)); case DataKind.TX: var fnTX = MarshalDelegate <TXSetter>(setter); ValuePoker <ReadOnlyMemory <char> > pokeTX = (ReadOnlyMemory <char> value, int col, long index) => { if (value.IsEmpty) { fnTX(penv, col, index, null, 0); } else { byte[] bt = Encoding.UTF8.GetBytes(value.ToString()); fixed(byte *pt = bt) fnTX(penv, col, index, (sbyte *)pt, bt.Length); } }; return(new Impl <ReadOnlyMemory <char> >(input, pyCol, idvCol, type, pokeTX)); default: throw Contracts.Except("Data type not handled"); } } Contracts.Assert(false, "Unhandled type!"); return(null); }