Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Value"></param>
        /// <param name="Affinity"></param>
        /// <returns></returns>
        public static Cell Parse(string Value, CellAffinity Affinity)
        {
            if (Affinity == CellAffinity.VARIANT)
            {
                throw new Exception("The variant affinity is invalid");
            }

            if (Value == null || string.Compare(Cell.NULL_STRING_TEXT, Value, true) == 0)
            {
                return(CellValues.Null(Affinity));
            }

            switch (Affinity)
            {
            case CellAffinity.BOOL:
                return(ParseBOOL(Value));

            case CellAffinity.DATE_TIME:
                return(ParseDATE(Value));

            case CellAffinity.BYTE:
                return(ParseBYTE(Value));

            case CellAffinity.SHORT:
                return(ParseSHORT(Value));

            case CellAffinity.INT:
                return(ParseINT(Value));

            case CellAffinity.LONG:
                return(ParseLONG(Value));

            case CellAffinity.SINGLE:
                return(ParseSINGLE(Value));

            case CellAffinity.DOUBLE:
                return(ParseDOUBLE(Value));

            case CellAffinity.BINARY:
                return(ParseBINARY(Value));

            case CellAffinity.BSTRING:
                return(ParseBSTRING(Value));

            case CellAffinity.CSTRING:
                return(ParseCSTRING(Value));
            }

            throw new Exception(string.Format("Affinity '{0}' is invalid", Affinity));
        }
Exemple #2
0
            public CellArray getU()
            {
                CellArray X = CellArray.Matrix(n, n);

                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        if (i <= j)
                        {
                            X[i].ARRAY[j] = LU[i].ARRAY[j];
                        }
                        else
                        {
                            X[i].ARRAY[j] = CellValues.Zero(CellAffinity.DOUBLE);
                        }
                    }
                }
                return(X);
            }
Exemple #3
0
        public static CellArray Identity(int Dimension, CellAffinity Type)
        {
            if (!CellAffinityHelper.IsNumeric(Type))
            {
                return(new CellArray());
            }

            Cell zero = CellValues.Zero(Type);
            Cell one  = CellValues.One(Type);

            CellArray x = CellArray.Matrix(Dimension, Dimension);

            for (int i = 0; i < Dimension; i++)
            {
                for (int j = 0; j < Dimension; j++)
                {
                    x[i].ARRAY[j] = (i == j ? one : zero);
                }
            }

            return(x);
        }
Exemple #4
0
            public CellArray getL()
            {
                CellArray L = CellArray.Matrix(m, n);

                for (int i = 0; i < m; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        if (i > j)
                        {
                            L[i].ARRAY[j] = LU[i].ARRAY[j];
                        }
                        else if (i == j)
                        {
                            L[i].ARRAY[j] = CellValues.One(CellAffinity.DOUBLE);
                        }
                        else
                        {
                            L[i].ARRAY[j] = CellValues.Zero(CellAffinity.DOUBLE);
                        }
                    }
                }
                return(L);
            }
Exemple #5
0
        /// <summary>
        /// Reads a cell form a buffer
        /// </summary>
        /// <param name="Buffer">The memory buffer</param>
        /// <param name="Location">The location to read from</param>
        /// <param name="NewLocation">Outputs the new location</param>
        /// <returns></returns>
        public static int Read(byte[] Buffer, int Location, out Cell Value)
        {
            // Get the meta data //
            byte m = Buffer[Location];

            Location++;
            CellAffinity a = m < 100 ? (CellAffinity)m : (CellAffinity)(m - 100);

            if (m >= 100)
            {
                Value = CellValues.Null(a);
                return(Location);
            }

            Cell C = new Cell(a);

            C.NULL = 0;

            // Booleans //
            if (a == CellAffinity.BOOL)
            {
                C.BOOL = (Buffer[Location] == 1);
                Location++;
            }
            else if (a == CellAffinity.BYTE)
            {
                C.BYTE = Buffer[Location];
                Location++;
            }
            else if (a == CellAffinity.SHORT)
            {
                C.B0      = Buffer[Location];
                C.B1      = Buffer[Location + 1];
                Location += 2;
            }
            else if (a == CellAffinity.INT || a == CellAffinity.SINGLE)
            {
                C.B0      = Buffer[Location];
                C.B1      = Buffer[Location + 1];
                C.B2      = Buffer[Location + 2];
                C.B3      = Buffer[Location + 3];
                Location += 4;
            }
            else if (a == CellAffinity.LONG || a == CellAffinity.DOUBLE || a == CellAffinity.DATE_TIME)
            {
                C.B0      = Buffer[Location];
                C.B1      = Buffer[Location + 1];
                C.B2      = Buffer[Location + 2];
                C.B3      = Buffer[Location + 3];
                C.B4      = Buffer[Location + 4];
                C.B5      = Buffer[Location + 5];
                C.B6      = Buffer[Location + 6];
                C.B7      = Buffer[Location + 7];
                Location += 8;
            }
            else if (a == CellAffinity.BSTRING || a == CellAffinity.BINARY)
            {
                C.B0      = Buffer[Location];
                C.B1      = Buffer[Location + 1];
                Location += 2;

                byte[] b = new byte[C.SHORT];
                for (int i = 0; i < C.SHORT; i++)
                {
                    b[i] = Buffer[Location + i];
                }
                Location += C.SHORT;

                if (a == CellAffinity.BINARY)
                {
                    C.BINARY = b;
                }
                else
                {
                    C.BSTRING = new BString(b);
                }
            }
            else if (a == CellAffinity.CSTRING || a == CellAffinity.TREF)
            {
                C.B0      = Buffer[Location];
                C.B1      = Buffer[Location + 1];
                Location += 2;

                byte[] b = new byte[(int)C.SHORT * 2];
                for (int i = 0; i < (int)C.SHORT * 2; i++)
                {
                    b[i] = Buffer[Location + i];
                }
                Location += (int)C.SHORT * 2;
                C.CSTRING = System.Text.ASCIIEncoding.Unicode.GetString(b);
            }
            else if (a == CellAffinity.ARRAY)
            {
                C.B0      = Buffer[Location];
                C.B1      = Buffer[Location + 1];
                Location += 2;

                CellArray x = new CellArray();
                if (C.SHORT == -1)
                {
                    x = CellArray.MinimumArray;
                }
                else if (C.SHORT == -2)
                {
                    x = CellArray.MximumArray;
                }
                else
                {
                    for (int i = 0; i < (int)C.SHORT; i++)
                    {
                        Cell c;
                        Location = Read(Buffer, Location, out c);
                        x.Append(c);
                    }
                }
                C.ARRAY = x;
            }

            Value = C;

            return(Location);
        }