示例#1
0
        private void SkipArray()
        {
            int size = ReadInt32();

            Variant.EnumType elementType = (Variant.EnumType)ReadInt32();

            Action skipper;

            switch (elementType)
            {
            case VariantBase.EnumType.Float:
                skipper = SkipFloat;
                break;

            case VariantBase.EnumType.Double:
                skipper = SkipDouble;
                break;

            case VariantBase.EnumType.Boolean:
                skipper = SkipBoolean;
                break;

            case VariantBase.EnumType.String:
                skipper = SkipString;
                break;

            case VariantBase.EnumType.Int32:
                skipper = SkipInt32;
                break;

            case VariantBase.EnumType.UInt32:
                skipper = SkipUInt32;
                break;

            case VariantBase.EnumType.Int64:
                skipper = SkipInt64;
                break;

            case VariantBase.EnumType.UInt64:
                skipper = SkipUInt64;
                break;

            case VariantBase.EnumType.Time:
                skipper = SkipTime;
                break;

            case VariantBase.EnumType.DateTime:
                skipper = SkipDateTime;
                break;

            default:
                throw new VariantException("Case exhaustion: " + elementType);
            }

            for (int i = 0; i < size; ++i)
            {
                skipper();
            }
        }
示例#2
0
 public ElementInfo(string name, Variant attributes, Variant.EnumType variantType)
 {
     m_name       = name;
     m_attributes = attributes;
     m_element    = new Variant(Variant.EnumType.Any);
     m_isTyped    = variantType != Variant.EnumType.Any;
     m_type       = variantType;
     m_data       = "";
     m_rowIndex   = 0;
 }
示例#3
0
        public static Type EnumToType(Variant.EnumType type)
        {
            Type result;

            if (!m_enumToTypeMapping.TryGetValue(type, out result))
            {
                throw new VariantException("Case exhaustion: " + type);
            }

            return(result);
        }
示例#4
0
        public Variant min, max; // range

        public bool isInRange(Variant value)
        {
            Ensure.ensure(value.type == min.type && value.type == max.type);
            Variant.EnumType type = value.type;
            switch (type)
            {
            case Variant.EnumType.FLOAT:
                return(min.valueFloat <= value.valueFloat && value.valueFloat <= max.valueFloat);

            case Variant.EnumType.INT:
                return(min.valueInt <= value.valueInt && value.valueInt <= max.valueInt);

            default:
                throw new Exception(); // soft exception which can be catched by our VM
            }
        }
示例#5
0
文件: Atom.cs 项目: chargen/AGI-X0
        static bool isCastableTo(Variant argument, Variant.EnumType type)
        {
            if (argument.type == type)   // no cast necessary
            {
                return(true);
            }

            if (type == Variant.EnumType.FLOAT && argument.type == Variant.EnumType.INT)
            {
                return(true);
            }
            else if (type == Variant.EnumType.INT && argument.type == Variant.EnumType.FLOAT)
            {
                return(true);
            }

            return(false);
        }
示例#6
0
文件: Atom.cs 项目: chargen/AGI-X0
        static Variant hardCastVariantTo(Variant argument, Variant.EnumType type)
        {
            if (argument.type == type)    // no cast necessary
            {
                return(argument);
            }

            if (type == Variant.EnumType.FLOAT && argument.type == Variant.EnumType.INT)
            {
                return(Variant.makeFloat(argument.valueInt));
            }
            else if (type == Variant.EnumType.INT && argument.type == Variant.EnumType.FLOAT)
            {
                return(Variant.makeInt((long)argument.valueFloat));
            }

            throw new Exception("INTERPRETATIONEXCEPTION Intrnal error while casting, not handled case");
        }
示例#7
0
文件: Atom.cs 项目: chargen/AGI-X0
        static void tryToWidenArithmeticType(ref Variant value, Variant.EnumType type)
        {
            if (value.type == type)
            {
                return; // no widening required
            }

            if (value.type == Variant.EnumType.FLOAT && type == Variant.EnumType.INT)
            {
                // no widening required because it's already "big" enough
                return;
            }

            if (type == Variant.EnumType.FLOAT && value.type == Variant.EnumType.INT)
            {
                value = Variant.makeFloat(value.valueInt);
                return;
            }

            // if we are here then something gone wrong while checking for wrong types
            throw new Exception("INTERPRETATIONEXCEPTION internal error while widening");
        }
示例#8
0
        public int CompareTo(IVariantData value)
        {
#if !DISABLE_DATATABLE
            DataTable rhsValue = ((VariantDataTable)value).Value;

            if (Value.Columns.Count != rhsValue.Columns.Count)
            {
                return(Value.Columns.Count.CompareTo(rhsValue.Columns.Count));
            }
            else if (Value.Rows.Count != rhsValue.Rows.Count)
            {
                return(Value.Rows.Count.CompareTo(rhsValue.Rows.Count));
            }
            else
            {
                CompareDelegate[] comparers = new CompareDelegate[Value.Columns.Count];

                for (int i = 0; i < Value.Columns.Count; ++i)
                {
                    if (Value.Columns[i].ColumnName != rhsValue.Columns[i].ColumnName)
                    {
                        return(Value.Columns[i].ColumnName.CompareTo(rhsValue.Columns[i].ColumnName));
                    }
                    else
                    {
                        Variant.EnumType lhsType = VariantPrimitiveBase.TypeToEnum(Value.Columns[i].DataType);
                        Variant.EnumType rhsType = VariantPrimitiveBase.TypeToEnum(rhsValue.Columns[i].DataType);

                        if (lhsType != rhsType)
                        {
                            return(lhsType.CompareTo(rhsType));
                        }
                        else
                        {
                            switch (lhsType)
                            {
                            case VariantBase.EnumType.Float:
                                comparers[i] = delegate(object lhs, object rhs) { return(((float)lhs).CompareTo((float)rhs)); };
                                break;

                            case VariantBase.EnumType.Double:
                                comparers[i] = delegate(object lhs, object rhs) { return(((double)lhs).CompareTo((double)rhs)); };
                                break;

                            case VariantBase.EnumType.Boolean:
                                comparers[i] = delegate(object lhs, object rhs) { return(((bool)lhs).CompareTo((bool)rhs)); };
                                break;

                            case VariantBase.EnumType.String:
                                comparers[i] = delegate(object lhs, object rhs) { return(((string)lhs).CompareTo((string)rhs)); };
                                break;

                            case VariantBase.EnumType.Int32:
                                comparers[i] = delegate(object lhs, object rhs) { return(((Int32)lhs).CompareTo((Int32)rhs)); };
                                break;

                            case VariantBase.EnumType.UInt32:
                                comparers[i] = delegate(object lhs, object rhs) { return(((UInt32)lhs).CompareTo((UInt32)rhs)); };
                                break;

                            case VariantBase.EnumType.Int64:
                                comparers[i] = delegate(object lhs, object rhs) { return(((Int64)lhs).CompareTo((Int64)rhs)); };
                                break;

                            case VariantBase.EnumType.UInt64:
                                comparers[i] = delegate(object lhs, object rhs) { return(((UInt64)lhs).CompareTo((UInt64)rhs)); };
                                break;

                            case VariantBase.EnumType.Time:
                                comparers[i] = delegate(object lhs, object rhs) { return(((TimeSpan)lhs).CompareTo((TimeSpan)rhs)); };
                                break;

                            case VariantBase.EnumType.DateTime:
                                comparers[i] = delegate(object lhs, object rhs) { return(((DateTime)lhs).CompareTo((DateTime)rhs)); };
                                break;

                            default:
                                throw new VariantException("Case exhaustion: " + lhsType);
                            }
                        }
                    }
                }

                for (int i = 0; i < Value.Rows.Count; ++i)
                {
                    DataRow lhsRow = Value.Rows[i];
                    DataRow rhsRow = rhsValue.Rows[i];
                    for (int j = 0; j < Value.Columns.Count; ++j)
                    {
                        int cmp = comparers[j](lhsRow[j], rhsRow[j]);
                        if (cmp != 0)
                        {
                            return(cmp);
                        }
                    }
                }

                return(0);
            }
#else
            throw new NotSupportedException("Datatables are not supported on this platform.");
#endif
        }
示例#9
0
        private void SkipDataTable()
        {
            int numCols = ReadInt32();
            int numRows = ReadInt32();

            Action[]           columnSkippers = new Action[numCols];
            Variant.EnumType[] colTypes       = new Variant.EnumType[numCols];

            for (int i = 0; i < numCols; ++i)
            {
                colTypes[i] = (Variant.EnumType)ReadInt32();

                switch (colTypes[i])
                {
                case VariantBase.EnumType.Float:
                    columnSkippers[i] = SkipFloat;
                    break;

                case VariantBase.EnumType.Double:
                    columnSkippers[i] = SkipDouble;
                    break;

                case VariantBase.EnumType.Boolean:
                    columnSkippers[i] = SkipBoolean;
                    break;

                case VariantBase.EnumType.String:
                    columnSkippers[i] = SkipString;
                    break;

                case VariantBase.EnumType.Int32:
                    columnSkippers[i] = SkipInt32;
                    break;

                case VariantBase.EnumType.UInt32:
                    columnSkippers[i] = SkipUInt32;
                    break;

                case VariantBase.EnumType.Int64:
                    columnSkippers[i] = SkipInt64;
                    break;

                case VariantBase.EnumType.UInt64:
                    columnSkippers[i] = SkipUInt64;
                    break;

                case VariantBase.EnumType.Time:
                    columnSkippers[i] = SkipTime;
                    break;

                case VariantBase.EnumType.DateTime:
                    columnSkippers[i] = SkipDateTime;
                    break;

                default:
                    throw new VariantException("Case exhaustion: " + colTypes[i]);
                }
            }

            for (int i = 0; i < numCols; ++i)
            {
                SkipString();
            }

            for (int i = 0; i < numRows; ++i)
            {
                for (int j = 0; j < numCols; ++j)
                {
                    columnSkippers[j]();
                }
            }
        }
示例#10
0
        protected void SkipVariant()
        {
            Variant.EnumType type = ReadType();

            switch (type)
            {
            case Variant.EnumType.None:
                break;

            case Variant.EnumType.String:
                SkipString();
                break;

            case Variant.EnumType.Any:
                SkipString();
                break;

            case Variant.EnumType.Float:
                SkipFloat();
                break;

            case Variant.EnumType.Double:
                SkipDouble();
                break;

            case Variant.EnumType.Int32:
                SkipInt32();
                break;

            case Variant.EnumType.UInt32:
                SkipUInt32();
                break;

            case Variant.EnumType.Int64:
                SkipInt64();
                break;

            case Variant.EnumType.UInt64:
                SkipUInt64();
                break;

            case Variant.EnumType.Boolean:
                SkipBoolean();
                break;

            case Variant.EnumType.Time:
                if ((m_mode & BinaryMode.DateTimeAsTicks) == 0)
                {
                    throw new VariantException("Binary data has DateTimeAsTicks mode disabled which is not supported in the protean.NET BinaryReader");
                }
                SkipTime();
                break;

            case Variant.EnumType.DateTime:
                if ((m_mode & BinaryMode.DateTimeAsTicks) == 0)
                {
                    throw new VariantException("Binary data has DateTimeAsTicks mode disabled which is not supported in the protean.NET BinaryReader");
                }
                SkipDateTime();
                break;

            case Variant.EnumType.Date:
                throw new VariantException("Attempt to read Date variant which is no longer supported");

            case Variant.EnumType.Tuple:
            case Variant.EnumType.List:
            {
                int length = ReadInt32();

                for (int i = 0; i < length; ++i)
                {
                    SkipVariant();
                }
            }
            break;

            case Variant.EnumType.Dictionary:
            case Variant.EnumType.Bag:
            {
                int length = ReadInt32();

                for (int i = 0; i < length; ++i)
                {
                    SkipString();
                    SkipVariant();
                }
            }
            break;

            case Variant.EnumType.TimeSeries:
            {
                int length = ReadInt32();

                for (int i = 0; i < length; ++i)
                {
                    SkipDateTime();
                    SkipVariant();
                }
            }
            break;

            case Variant.EnumType.Object:
            {
                SkipString();
                SkipInt32();
                SkipVariant();
            }
            break;

            case Variant.EnumType.Exception:
            {
                SkipString();
                SkipString();
                SkipString();
                SkipString();
            }
            break;

            case Variant.EnumType.Buffer:
            {
                int length = ReadInt32();
                SkipBytes(length, true);
            }
            break;

            case Variant.EnumType.DataTable:
            {
                SkipDataTable();
            }
            break;

            case Variant.EnumType.Array:
            {
                SkipArray();
            }
            break;

            default:
                throw new VariantException("Case exhaustion: " + type.ToString());
            }
        }
示例#11
0
        private TypedArray ReadArray()
        {
            int size = ReadInt32();

            Variant.EnumType elementType = (Variant.EnumType)ReadInt32();

            TypedArray array = new TypedArray(elementType, size);

            ReadDelegate reader = null;

            switch (elementType)
            {
            case VariantBase.EnumType.Float:
                reader = () => ReadFloat();
                break;

            case VariantBase.EnumType.Double:
                reader = () => ReadDouble();
                break;

            case VariantBase.EnumType.Boolean:
                reader = () => ReadBoolean();
                break;

            case VariantBase.EnumType.String:
                reader = () => ReadString();
                break;

            case VariantBase.EnumType.Int32:
                reader = () => ReadInt32();
                break;

            case VariantBase.EnumType.UInt32:
                reader = () => ReadUInt32();
                break;

            case VariantBase.EnumType.Int64:
                reader = () => ReadInt64();
                break;

            case VariantBase.EnumType.UInt64:
                reader = () => ReadUInt64();
                break;

            case VariantBase.EnumType.Time:
                reader = () => ReadTime();
                break;

            case VariantBase.EnumType.DateTime:
                reader = () => ReadDateTime();
                break;

            default:
                throw new VariantException("Case exhaustion: " + array.ElementType);
            }

            for (int i = 0; i < size; ++i)
            {
                array[i] = reader();
            }

            return(array);
        }
示例#12
0
        protected DataTable ReadDataTable()
        {
#if !DISABLE_DATATABLE
            int numCols = ReadInt32();
            int numRows = ReadInt32();

            Variant.EnumType[] colTypes = new Variant.EnumType[numCols];
            for (int i = 0; i < numCols; ++i)
            {
                colTypes[i] = (Variant.EnumType)ReadInt32();
            }

            string[] colNames = new string[numCols];
            for (int i = 0; i < numCols; ++i)
            {
                colNames[i] = ReadString();
            }

            DataTable dt = new DataTable();
            for (int i = 0; i < numCols; ++i)
            {
                dt.Columns.Add(new DataColumn(colNames[i], VariantPrimitiveBase.EnumToType(colTypes[i])));
            }
            ;

            // Write number of rows
            for (int col = 0; col < numCols; ++col)
            {
                ReadDelegate colReader;
                switch (colTypes[col])
                {
                case VariantBase.EnumType.Float:
                    colReader = () => ReadFloat();
                    break;

                case VariantBase.EnumType.Double:
                    colReader = () => ReadDouble();
                    break;

                case VariantBase.EnumType.Boolean:
                    colReader = () => ReadBoolean();
                    break;

                case VariantBase.EnumType.String:
                    colReader = () => ReadString();
                    break;

                case VariantBase.EnumType.Int32:
                    colReader = () => ReadInt32();
                    break;

                case VariantBase.EnumType.UInt32:
                    colReader = () => ReadUInt32();
                    break;

                case VariantBase.EnumType.Int64:
                    colReader = () => ReadInt64();
                    break;

                case VariantBase.EnumType.UInt64:
                    colReader = () => ReadUInt64();
                    break;

                case VariantBase.EnumType.Time:
                    colReader = () => ReadTime();
                    break;

                case VariantBase.EnumType.DateTime:
                    colReader = () => ReadDateTime();
                    break;

                default:
                    throw new VariantException("Case exhaustion: " + colTypes[col]);
                }

                for (int row = 0; row < numRows; ++row)
                {
                    DataRow dr;
                    if (col == 0)
                    {
                        dr = dt.NewRow();
                        dt.Rows.Add(dr);
                    }
                    else
                    {
                        dr = dt.Rows[row];
                    }

                    dr[col] = colReader();
                }
            }

            return(dt);
#else
            throw new NotSupportedException("Datatables not supported on this platform.");
#endif
        }
示例#13
0
        protected Variant ReadVariant()
        {
            Variant.EnumType type = ReadType();

            switch (type)
            {
            case Variant.EnumType.None:
                return(new Variant(Variant.EnumType.None));

            case Variant.EnumType.String:
                return(new Variant(ReadString()));

            case Variant.EnumType.Any:
                return(new Variant(Variant.EnumType.Any, ReadString()));

            case Variant.EnumType.Float:
                return(new Variant(ReadFloat()));

            case Variant.EnumType.Double:
                return(new Variant(ReadDouble()));

            case Variant.EnumType.Int32:
                return(new Variant(ReadInt32()));

            case Variant.EnumType.UInt32:
                return(new Variant(ReadUInt32()));

            case Variant.EnumType.Int64:
                return(new Variant(ReadInt64()));

            case Variant.EnumType.UInt64:
                return(new Variant(ReadUInt64()));

            case Variant.EnumType.Boolean:
                return(new Variant(ReadBoolean()));

            case Variant.EnumType.Time:
                if ((m_mode & BinaryMode.DateTimeAsTicks) == 0)
                {
                    throw new VariantException("Binary data has DateTimeAsTicks mode disabled which is not supported in the protean.NET BinaryReader");
                }
                return(new Variant(ReadTime()));

            case Variant.EnumType.DateTime:
                if ((m_mode & BinaryMode.DateTimeAsTicks) == 0)
                {
                    throw new VariantException("Binary data has DateTimeAsTicks mode disabled which is not supported in the protean.NET BinaryReader");
                }
                return(new Variant(ReadDateTime()));

            case Variant.EnumType.Date:
                throw new VariantException("Attempt to read Date variant which is no longer supported");

            case Variant.EnumType.Tuple:
            {
                int length = ReadInt32();

                Variant result = new Variant(Variant.EnumType.Tuple, length);
                for (int i = 0; i < length; ++i)
                {
                    result[i] = ReadVariant();
                }
                return(result);
            }

            case Variant.EnumType.List:
            {
                int length = ReadInt32();

                Variant result = new Variant(type, length);
                for (int i = 0; i < length; ++i)
                {
                    result.Add(ReadVariant());
                }
                return(result);
            }

            case Variant.EnumType.Dictionary:
            case Variant.EnumType.Bag:
            {
                int length = ReadInt32();

                Variant result = new Variant(type);
                for (int i = 0; i < length; ++i)
                {
                    String  key   = ReadString();
                    Variant value = ReadVariant();

                    result.Add(key, value);
                }
                return(result);
            }

            case Variant.EnumType.TimeSeries:
            {
                Variant result = new Variant(type);

                int length = ReadInt32();

                for (int i = 0; i < length; ++i)
                {
                    DateTime time  = ReadDateTime();
                    Variant  value = ReadVariant();

                    result.Add(time, value);
                }

                return(result);
            }

            case Variant.EnumType.Object:
            {
                string  className = ReadString();
                int     version   = ReadInt32();
                Variant param     = ReadVariant();


                IVariantObject obj = null;
                if (m_factory != null)
                {
                    obj = m_factory.Create(className);

                    if (obj == null && (m_mode & BinaryMode.CreateProxy) == 0)
                    {
                        throw new VariantException("Object of class " + className + " is not regsistered in factory");
                    }
                }

                if (obj == null)
                {
                    obj = new VariantObjectProxy(className);
                }

                obj.Inflate(param, version);

                return(new Variant(obj));
            }

            case Variant.EnumType.Exception:
            {
                string xtype    = ReadString();
                string xmessage = ReadString();
                string xsource  = ReadString();
                string xstack   = ReadString();

                return(new Variant(new VariantExceptionInfo(xtype, xmessage, xsource, xstack)));
            }

            case Variant.EnumType.Buffer:
            {
                int length = ReadInt32();
                return(new Variant(ReadBytes(length, true)));
            }

            case Variant.EnumType.DataTable:
            {
                return(new Variant(ReadDataTable()));
            }

            case Variant.EnumType.Array:
            {
                return(new Variant(ReadArray()));
            }

            default:
                throw new VariantException("Case exhaustion: " + type.ToString());
            }
        }
示例#14
0
 private VariantEnumerator(Variant.EnumType type, System.Collections.IEnumerator enumerator)
 {
     Type         = type;
     m_enumerator = enumerator;
 }
示例#15
0
 public ElementInfo(string name, Variant attributes, Variant.EnumType variantType)
 {
     m_name = name;
     m_attributes = attributes;
     m_element = new Variant(Variant.EnumType.Any);
     m_isTyped = variantType != Variant.EnumType.Any;
     m_type = variantType;
     m_data = "";
     m_rowIndex = 0;
 }
示例#16
0
        public override void StartElement(string name, Variant attributes, Variant.EnumType variantType)
        {
            ElementInfo context = new ElementInfo(name, attributes, variantType);

            if (m_stack.Count != 0)
            {
                ElementInfo parentContext = m_stack.Peek();

                switch (parentContext.m_type)
                {
                case Variant.EnumType.Any:
                    if (!parentContext.m_isTyped)
                    {
                        // Untyped elements with children are converted to Bags
                        parentContext.m_type    = Variant.EnumType.Bag;
                        parentContext.m_element = new Variant(parentContext.m_type);
                    }
                    break;

                case Variant.EnumType.None:
                case Variant.EnumType.String:
                case Variant.EnumType.Int32:
                case Variant.EnumType.UInt32:
                case Variant.EnumType.Int64:
                case Variant.EnumType.UInt64:
                case Variant.EnumType.Float:
                case Variant.EnumType.Double:
                case Variant.EnumType.Boolean:
                case Variant.EnumType.Date:
                case Variant.EnumType.Time:
                case Variant.EnumType.DateTime:
                case Variant.EnumType.Buffer:
                    throw new VariantException("Unexpected start element");

                case Variant.EnumType.TimeSeries:
                    if (context.m_attributes.ContainsKey("time"))
                    {
                        context.m_time = context.m_attributes["time"].As <DateTime>();
                        context.m_attributes.Remove("time");
                    }
                    else
                    {
                        throw new VariantException("Missing 'time' attribute for TimeSeries element");
                    }
                    break;
                }
            }

            m_stack.Push(context);

            // infer type from 'variant' attribute
            if (context.m_attributes.ContainsKey("variant"))
            {
                context.m_type    = Variant.StringToEnum(context.m_attributes["variant"].As <string>());
                context.m_isTyped = true;
                context.m_attributes.Remove("variant");
            }

            switch (context.m_type)
            {
            case Variant.EnumType.Any:
                if (!context.m_isTyped && !context.m_attributes.Empty)
                {
                    // untyped elements with attributes are assumed
                    // to be bags
                    context.m_type    = Variant.EnumType.Bag;
                    context.m_element = new Variant(context.m_type);
                }
                break;

            case Variant.EnumType.None:
            case Variant.EnumType.String:
            case Variant.EnumType.Int32:
            case Variant.EnumType.UInt32:
            case Variant.EnumType.Int64:
            case Variant.EnumType.UInt64:
            case Variant.EnumType.Float:
            case Variant.EnumType.Double:
            case Variant.EnumType.Boolean:
            case Variant.EnumType.Date:
            case Variant.EnumType.Time:
            case Variant.EnumType.DateTime:
            case Variant.EnumType.Buffer:
                break;

            case Variant.EnumType.List:
            case Variant.EnumType.Dictionary:
            case Variant.EnumType.Bag:
            case Variant.EnumType.TimeSeries:
                context.m_element = new Variant(context.m_type);
                break;

            case Variant.EnumType.Exception:
            case Variant.EnumType.Object:
                // Exception and Object are parsed via a dictionary for convenience.
                context.m_element = new Variant(Variant.EnumType.Dictionary);
                break;

            case Variant.EnumType.Tuple:
            {
                if (context.m_attributes.ContainsKey("size"))
                {
                    context.m_element = new Variant(Variant.EnumType.Tuple, context.m_attributes["size"].As <int>());
                    context.m_attributes.Remove("size");
                }
                else
                {
                    throw new VariantException("Missing 'size' attribute for Tuple variant");
                }
                break;
            }

            default:
                throw new VariantException("Case exhaustion: " + context.m_type.ToString());
            }
        }
示例#17
0
        private void SkipDataTable()
        {
            int numCols = ReadInt32();
            int numRows = ReadInt32();

            Action[] columnSkippers = new Action[numCols];
            Variant.EnumType[] colTypes = new Variant.EnumType[numCols];

            for (int i = 0; i < numCols; ++i)
            {
                colTypes[i] = (Variant.EnumType)ReadInt32();

                switch (colTypes[i])
                {
                    case VariantBase.EnumType.Float:
                        columnSkippers[i] = SkipFloat;
                        break;
                    case VariantBase.EnumType.Double:
                        columnSkippers[i] = SkipDouble;
                        break;
                    case VariantBase.EnumType.Boolean:
                        columnSkippers[i] = SkipBoolean;
                        break;
                    case VariantBase.EnumType.String:
                        columnSkippers[i] = SkipString;
                        break;
                    case VariantBase.EnumType.Int32:
                        columnSkippers[i] = SkipInt32;
                        break;
                    case VariantBase.EnumType.UInt32:
                        columnSkippers[i] = SkipUInt32;
                        break;
                    case VariantBase.EnumType.Int64:
                        columnSkippers[i] = SkipInt64;
                        break;
                    case VariantBase.EnumType.UInt64:
                        columnSkippers[i] = SkipUInt64;
                        break;
                    case VariantBase.EnumType.Time:
                        columnSkippers[i] = SkipTime;
                        break;
                    case VariantBase.EnumType.DateTime:
                        columnSkippers[i] = SkipDateTime;
                        break;
                    default:
                        throw new VariantException("Case exhaustion: " + colTypes[i]);
                }
            }

            for (int i = 0; i < numCols; ++i)
            {
                SkipString();
            }

            for (int i = 0; i < numRows; ++i)
            {
                for (int j = 0; j < numCols; ++j)
                {
                    columnSkippers[j]();
                }
            }
        }
示例#18
0
        protected DataTable ReadDataTable()
        {
            #if !DISABLE_DATATABLE
            int numCols = ReadInt32();
            int numRows = ReadInt32();

            Variant.EnumType[] colTypes = new Variant.EnumType[numCols];
            for (int i = 0; i < numCols; ++i)
            {
                colTypes[i] = (Variant.EnumType)ReadInt32();
            }

            string[] colNames = new string[numCols];
            for (int i = 0; i < numCols; ++i)
            {
                colNames[i] = ReadString();
            }

            DataTable dt = new DataTable();
            for (int i = 0; i < numCols; ++i)
            {
                dt.Columns.Add(new DataColumn(colNames[i], VariantPrimitiveBase.EnumToType(colTypes[i])));
            };

            // Write number of rows
            for (int col = 0; col < numCols; ++col)
            {
                ReadDelegate colReader;
                switch (colTypes[col])
                {
                    case VariantBase.EnumType.Float:
                        colReader = () => ReadFloat();
                        break;
                    case VariantBase.EnumType.Double:
                        colReader = () => ReadDouble();
                        break;
                    case VariantBase.EnumType.Boolean:
                        colReader = () => ReadBoolean();
                        break;
                    case VariantBase.EnumType.String:
                        colReader = () => ReadString();
                        break;
                    case VariantBase.EnumType.Int32:
                        colReader = () => ReadInt32();
                        break;
                    case VariantBase.EnumType.UInt32:
                        colReader = () => ReadUInt32();
                        break;
                    case VariantBase.EnumType.Int64:
                        colReader = () => ReadInt64();
                        break;
                    case VariantBase.EnumType.UInt64:
                        colReader = () => ReadUInt64();
                        break;
                    case VariantBase.EnumType.Time:
                        colReader = () => ReadTime();
                        break;
                    case VariantBase.EnumType.DateTime:
                        colReader = () => ReadDateTime();
                        break;
                    default:
                        throw new VariantException("Case exhaustion: " + colTypes[col]);
                }

                for (int row = 0; row < numRows; ++row)
                {
                    DataRow dr;
                    if (col == 0)
                    {
                        dr = dt.NewRow();
                        dt.Rows.Add(dr);
                    }
                    else
                    {
                        dr = dt.Rows[row];
                    }

                    dr[col] = colReader();
                }
            }

            return dt;
            #else
            throw new NotSupportedException("Datatables not supported on this platform.");
            #endif
        }
示例#19
0
        protected DataTable ReadDataTable()
        {
            int numCols = ReadInt32();
            int numRows = ReadInt32();

            ReadDelegate[] colReaders = new ReadDelegate[numCols];
            Variant.EnumType[] colTypes = new Variant.EnumType[numCols];

            for (int i = 0; i < numCols; ++i)
            {
                colTypes[i] = (Variant.EnumType)ReadInt32();

                switch (colTypes[i])
                {
                    case VariantBase.EnumType.Float:
                        colReaders[i] = () => ReadFloat();
                        break;
                    case VariantBase.EnumType.Double:
                        colReaders[i] = () => ReadDouble();
                        break;
                    case VariantBase.EnumType.Boolean:
                        colReaders[i] = () => ReadBoolean();
                        break;
                    case VariantBase.EnumType.String:
                        colReaders[i] = () => ReadString();
                        break;
                    case VariantBase.EnumType.Int32:
                        colReaders[i] = () => ReadInt32();
                        break;
                    case VariantBase.EnumType.UInt32:
                        colReaders[i] = () => ReadUInt32();
                        break;
                    case VariantBase.EnumType.Int64:
                        colReaders[i] = () => ReadInt64();
                        break;
                    case VariantBase.EnumType.UInt64:
                        colReaders[i] = () => ReadUInt64();
                        break;
                    case VariantBase.EnumType.Time:
                        colReaders[i] = () => ReadTime();
                        break;
                    case VariantBase.EnumType.DateTime:
                        colReaders[i] = () => ReadDateTime();
                        break;
                    default:
                        throw new VariantException("Case exhaustion: " + colTypes[i]);
                }
            }

            string[] colNames = new string[numCols];
            for (int i = 0; i < numCols; ++i)
            {
                colNames[i] = ReadString();
            }

            DataTable dt = new DataTable();
            for (int i = 0; i < numCols; ++i)
            {
                dt.Columns.Add(new DataColumn(colNames[i], VariantPrimitiveBase.EnumToType(colTypes[i])));
            };

            // Write number of rows
            for (int i=0; i<numRows; ++i)
            {
                DataRow dr = dt.NewRow();
                for (int j = 0; j < numCols; ++j)
                {
                    dr[j] = colReaders[j]();
                }
                dt.Rows.Add(dr);
            }

            return dt;
        }