Example #1
0
        void verifyGridEq(HGrid grid, HDict meta, Object[] cols, HVal[][] rows)
        {
            // meta
            Assert.IsTrue(grid.meta.hequals(meta));

            // cols
            Assert.AreEqual(grid.numCols, cols.Length / 2);
            for (int i = 0; i < grid.numCols; ++i)
            {
                Assert.AreEqual(grid.col(i).Name, cols[i * 2 + 0]);
                Assert.IsTrue(grid.col(i).meta.hequals(cols[i * 2 + 1]));
            }

            // rows
            Assert.AreEqual(grid.numRows, rows.Length);
            for (int ri = 0; ri < rows.Length; ++ri)
            {
                HVal[] expected = rows[ri];
                HRow   actual   = grid.row(ri);
                for (int ci = 0; ci < expected.Length; ++ci)
                {
                    Assert.AreEqual(expected[ci], actual.get(grid.col(ci).Name, false));
                }
            }
        }
Example #2
0
        HCol verifyCol(HGrid g, int i, string n)
        {
            HCol col = g.col(i);

            Assert.IsTrue(g.col(i).hequals(g.col(n)));
            Assert.AreEqual(col.Name, n);
            return(col);
        }
        //////////////////////////////////////////////////////////////////////////
        // HGridWriter
        //////////////////////////////////////////////////////////////////////////

        // Write a grid
        public override void writeGrid(HGrid grid)
        {
            // meta
            p("ver:\"").p(m_iVersion).p(".0\"").writeMeta(grid.meta).nl();

            // cols
            if (grid.numCols == 0)
            {
                // technically this shoudl be illegal, but
                // for robustness handle it here
                throw new ArgumentException("Grid has no cols", "grid");
            }
            else
            {
                for (int i = 0; i < grid.numCols; ++i)
                {
                    if (i > 0)
                    {
                        p(',');
                    }
                    writeCol(grid.col(i));
                }
            }
            nl();

            // rows
            for (int i = 0; i < grid.numRows; ++i)
            {
                writeRow(grid, grid.row(i));
                nl();
            }
            flush();
        }
Example #4
0
 private void writeRow(HGrid grid, HRow row)
 {
     for (int i = 0; i < grid.numCols; ++i)
     {
         HVal val = row.get(grid.col(i), false);
         if (i > 0)
         {
             m_swOut.Write(m_cDelimiter);
         }
         writeCell(valToString(val));
     }
 }
        //////////////////////////////////////////////////////////////////////////
        // HGridWriter
        //////////////////////////////////////////////////////////////////////////

        // Write a grid
        public override void writeGrid(HGrid grid)
        {
            // grid begin
            m_swOut.Write("{\n");

            // meta
            m_swOut.Write("\"meta\": {\"ver\":\"2.0\"");
            writeDictTags(grid.meta, false);
            m_swOut.Write("},\n");

            // columns
            m_swOut.Write("\"cols\":[\n");
            for (int i = 0; i < grid.numCols; i++)
            {
                if (i > 0)
                {
                    m_swOut.Write(",\n");
                }
                HCol col = grid.col(i);
                m_swOut.Write("{\"name\":");
                m_swOut.Write(HStr.toCode(col.Name));
                writeDictTags(col.meta, false);
                m_swOut.Write("}");
            }
            m_swOut.Write("\n],\n");

            // rows
            m_swOut.Write("\"rows\":[\n");
            for (int i = 0; i < grid.numRows; i++)
            {
                if (i > 0)
                {
                    m_swOut.Write(",\n");
                }
                writeDict(grid.row(i));
            }
            m_swOut.Write("\n]\n");

            // grid end
            m_swOut.Write("}\n");
            m_swOut.Flush();
        }
Example #6
0
        //////////////////////////////////////////////////////////////////////////
        // HGridWriter
        //////////////////////////////////////////////////////////////////////////

        // Write a grid
        public override void writeGrid(HGrid grid)
        {
            // cols
            for (int i = 0; i < grid.numCols; ++i)
            {
                if (i > 0)
                {
                    m_swOut.Write(m_cDelimiter);
                }
                writeCell(grid.col(i).dis());
            }
            m_swOut.Write('\n');

            // rows
            for (int i = 0; i < grid.numRows; ++i)
            {
                writeRow(grid, grid.row(i));
                m_swOut.Write('\n');
            }
        }
 private void writeRow(HGrid grid, HRow row)
 {
     for (int i = 0; i < grid.numCols; ++i)
     {
         HVal val = row.get(grid.col(i), false);
         if (i > 0)
         {
             m_swOut.Write(',');
         }
         if (val == null)
         {
             if (i == 0)
             {
                 m_swOut.Write('N');
             }
         }
         else
         {
             m_swOut.Write(val.toZinc());
         }
     }
     flush();
 }