Ejemplo n.º 1
0
        // Statics //
        public static CellArray Clone(CellArray A)
        {
            CellArray x = new CellArray();

            foreach (Cell c in A)
            {
                if (c.IsArray)
                {
                    x.Append(CellArray.Clone(c));
                }
                else
                {
                    x.Append(c);
                }
            }
            return(x);
        }
Ejemplo n.º 2
0
        // Matrixes //
        public static CellArray Matrix(int RowLength, int ColumnLength, Cell Value)
        {
            CellArray v = new CellArray();

            for (int i = 0; i < RowLength; i++)
            {
                v.Append(new Cell(CellArray.Vector(ColumnLength, Value)));
            }
            return(v);
        }
Ejemplo n.º 3
0
        // Vectors //
        public static CellArray Vector(int Length, Cell Value)
        {
            CellArray ca = new CellArray();

            for (int i = 0; i < Length; i++)
            {
                ca.Append(Value);
            }
            return(ca);
        }
Ejemplo n.º 4
0
 public CellArray this[int Index, int Length]
 {
     get
     {
         if (Index + Length >= this.Count)
         {
             throw new IndexOutOfRangeException();
         }
         if (Length == 1)
         {
             return(this._Cells[Index]);
         }
         CellArray x = new CellArray();
         for (int i = Index; i < Index + Length; i++)
         {
             x.Append(this[i]);
         }
         return(x);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Value"></param>
        /// <returns></returns>
        public static Cell ToARRAY(Cell Value)
        {
            if (Value.Affinity == CellAffinity.ARRAY)
            {
                return(Value);
            }

            if (Value.IsNull)
            {
                return(CellValues.NullARRAY);
            }

            if (Value.BINARY == null && Value.AFFINITY == CellAffinity.BINARY)
            {
                return(CellValues.NullARRAY);
            }

            if (Value.BSTRING == null && Value.AFFINITY == CellAffinity.BSTRING)
            {
                return(CellValues.NullARRAY);
            }

            if (Value.CSTRING == null && Value.AFFINITY == CellAffinity.CSTRING)
            {
                return(CellValues.NullARRAY);
            }

            if (Value.AFFINITY == CellAffinity.EQUATION)
            {
                return(CellValues.NullARRAY);
            }

            CellArray x = new CellArray();

            x.Append(Value);
            return(new Cell(x));
        }
Ejemplo n.º 6
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);
        }