Пример #1
0
        public ValueMapper <TDest, TLabel> GetMapperFrom <TDest>()
        {
            var colType = SchemaHelper.GetColumnType <TDest>();

            if (colType.IsVector())
            {
                throw Contracts.ExceptNotImpl($"Not implemented for type {typeof(TDest)}.");
            }
            switch (colType.RawKind())
            {
            case DataKind.Boolean:
                return(mapperBL as ValueMapper <TDest, TLabel>);

            case DataKind.SByte:
                return(mapperU1 as ValueMapper <TDest, TLabel>);

            case DataKind.UInt16:
                return(mapperU2 as ValueMapper <TDest, TLabel>);

            case DataKind.UInt32:
                return(mapperU4 as ValueMapper <TDest, TLabel>);

            case DataKind.Single:
                return(mapperR4 as ValueMapper <TDest, TLabel>);

            default:
                throw Contracts.ExceptNotSupp("Unsupported kind {0}", colType.RawKind());
            }
        }
Пример #2
0
        public ValueMapper <TLabel, TDest> GetMapper <TDest>()
        {
            var colType = SchemaHelper.GetColumnType <TDest>();

            if (colType.IsVector())
            {
                throw Contracts.ExceptNotImpl($"Not implemented for type {typeof(TDest)}.");
            }
            switch (colType.RawKind())
            {
            case DataKind.BL:
                return(mapperBL as ValueMapper <TLabel, TDest>);

            case DataKind.U1:
                return(mapperU1 as ValueMapper <TLabel, TDest>);

            case DataKind.U2:
                return(mapperU2 as ValueMapper <TLabel, TDest>);

            case DataKind.U4:
                return(mapperU4 as ValueMapper <TLabel, TDest>);

            case DataKind.I4:
                return(mapperI4 as ValueMapper <TLabel, TDest>);

            case DataKind.R4:
                return(mapperR4 as ValueMapper <TLabel, TDest>);

            default:
                throw Contracts.ExceptNotSupp("Unsupported kind {0}", colType.RawKind());
            }
        }
Пример #3
0
        void Init(DataKind destKind)
        {
            _kind     = SchemaHelper.GetColumnType <TLabel>().RawKind();
            _destKind = destKind;

            mapperBL = null;
            mapperU1 = null;
            mapperU2 = null;
            mapperU4 = null;
            mapperI4 = null;
            mapperR4 = null;

            mapperFromBL = null;
            mapperFromU1 = null;
            mapperFromU2 = null;
            mapperFromU4 = null;
            mapperFromI4 = null;
            mapperFromR4 = null;

            switch (destKind)
            {
            case DataKind.Boolean:
                mapperBL     = SchemaHelper.GetConverter <TLabel, bool>(out identity);
                mapperFromBL = SchemaHelper.GetConverter <bool, TLabel>(out identity);
                break;

            case DataKind.SByte:
                mapperU1     = SchemaHelper.GetConverter <TLabel, byte>(out identity);
                mapperFromU1 = SchemaHelper.GetConverter <byte, TLabel>(out identity);
                break;

            case DataKind.UInt16:
                mapperU2     = SchemaHelper.GetConverter <TLabel, ushort>(out identity);
                mapperFromU2 = SchemaHelper.GetConverter <ushort, TLabel>(out identity);
                break;

            case DataKind.UInt32:
                mapperU4     = SchemaHelper.GetConverter <TLabel, uint>(out identity);
                mapperFromU4 = SchemaHelper.GetConverter <uint, TLabel>(out identity);
                break;

            case DataKind.Int32:
                var temp = SchemaHelper.GetConverter <TLabel, float>(out identity);
                mapperI4 = (in TLabel src, ref int dst) =>
                {
                    float v = 0f;
                    temp(in src, ref v);
                    dst = (int)v;
                };
                var temp2 = SchemaHelper.GetConverter <float, TLabel>(out identity);
                mapperFromI4 = (in int src, ref TLabel dst) =>
                {
                    float v = (float)src;
                    temp2(in v, ref dst);
                };
                break;

            case DataKind.Single:
                mapperR4     = SchemaHelper.GetConverter <TLabel, float>(out identity);
                mapperFromR4 = SchemaHelper.GetConverter <float, TLabel>(out identity);
                break;

            default:
                throw Contracts.ExceptNotSupp("Unsupported kinds {0} --> {1}", _kind, _destKind);
            }
        }
Пример #4
0
 public TypedConverters()
 {
     Init(SchemaHelper.GetColumnType <TLabel>().RawKind());
 }