예제 #1
0
        //////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////

        public static void Write(DataWriter writer, int fieldSymbId, BinaryTable[] tables, bool flipCols, int indentation, bool indentFirstLine, bool writeSeparator)
        {
            string baseWs  = new string(Array.Repeat(' ', indentation));
            string entryWs = new string(Array.Repeat(' ', indentation + 2));

            int count = 0;

            for (int i = 0; i < tables.Length; i++)
            {
                count += tables[i].Size();
            }

            if (indentFirstLine)
            {
                writer.Write(baseWs);
            }
            writer.Write(SymbObj.IdxToStr(fieldSymbId));
            writer.Write(": [");

            if (count > 0)
            {
                writer.Write("\n");

                int written = 0;
                for (int i = 0; i < tables.Length; i++)
                {
                    BinaryTable      table   = tables[i];
                    SurrObjMapper    mapper1 = table.mapper1;
                    SurrObjMapper    mapper2 = table.mapper2;
                    BinaryTable.Iter it      = table.GetIter();
                    while (!it.Done())
                    {
                        writer.Write(entryWs);
                        Obj obj1 = mapper1(it.Get1());
                        Obj obj2 = mapper2(it.Get2());
                        if (flipCols)
                        {
                            Obj tmp = obj1;
                            obj1 = obj2;
                            obj2 = tmp;
                        }
                        ObjPrinter.PrintNoFlush(obj1, writer);
                        writer.Write(", ");
                        ObjPrinter.PrintNoFlush(obj2, writer);
                        written++;
                        writer.Write(written < count || count == 1 ? ";\n" : "\n");
                        it.Next();
                    }
                }
                Debug.Assert(written == count);

                writer.Write(baseWs);
            }

            writer.Write(writeSeparator ? "],\n" : "]\n");
        }
예제 #2
0
        public static void Write(DataWriter writer, int fieldSymbId, UnaryTable[] tables, int indentation, bool indentFirstLine, bool writeSeparator)
        {
            string baseWs  = new string(Array.Repeat(' ', indentation));
            string entryWs = new string(Array.Repeat(' ', indentation + 2));

            int count = 0;

            for (int i = 0; i < tables.Length; i++)
            {
                count += tables[i].Size();
            }

            if (indentFirstLine)
            {
                writer.Write(baseWs);
            }
            writer.Write(SymbObj.IdxToStr(fieldSymbId));
            writer.Write(": [");

            if (count > 0)
            {
                writer.Write("\n");

                int written = 0;
                for (int i = 0; i < tables.Length; i++)
                {
                    UnaryTable      table  = tables[i];
                    SurrObjMapper   mapper = table.mapper;
                    UnaryTable.Iter it     = table.GetIter();
                    while (!it.Done())
                    {
                        writer.Write(entryWs);
                        Obj obj = mapper(it.Get());
                        ObjPrinter.PrintNoFlush(obj, writer);
                        written++;
                        writer.Write(written < count ? ",\n" : "\n");
                        it.Next();
                    }
                }
                Debug.Assert(written == count);

                writer.Write(baseWs);
            }

            writer.Write(writeSeparator ? "],\n" : "]\n");
        }
예제 #3
0
        //////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////

        public static void Write(DataWriter writer, int fieldSymbId, ColumnBase[] columns, bool flipCols, int indentation, bool indentFirstLine, bool writeSeparator)
        {
            string baseWs  = new string(Array.Repeat(' ', indentation));
            string entryWs = new string(Array.Repeat(' ', indentation + 2));

            int count = 0;

            for (int i = 0; i < columns.Length; i++)
            {
                count += columns[i].Size();
            }

            if (indentFirstLine)
            {
                writer.Write(baseWs);
            }
            writer.Write(SymbObj.IdxToStr(fieldSymbId));
            writer.Write(": [");

            if (count > 0)
            {
                writer.Write("\n");

                int written = 0;
                for (int i = 0; i < columns.Length; i++)
                {
                    ColumnBase    col    = columns[i];
                    SurrObjMapper mapper = col.mapper;

                    if (col is IntColumn)
                    {
                        IntColumn      intCol = (IntColumn)col;
                        IntColumn.Iter it     = intCol.GetIter();
                        while (!it.Done())
                        {
                            writer.Write(entryWs);
                            Obj  key   = mapper(it.GetIdx());
                            long value = it.GetValue();
                            if (flipCols)
                            {
                                writer.Write(value);
                                writer.Write(", ");
                                ObjPrinter.PrintNoFlush(key, writer);
                                written++;
                                writer.Write(written == 1 | written < count ? ";\n" : "\n");
                            }
                            else
                            {
                                ObjPrinter.PrintNoFlush(key, writer);
                                writer.Write(" -> ");
                                writer.Write(value);
                                written++;
                                writer.Write(written < count ? ",\n" : "\n");
                            }
                            it.Next();
                        }
                    }
                    else if (col is FloatColumn)
                    {
                        FloatColumn      floatCol = (FloatColumn)col;
                        FloatColumn.Iter it       = floatCol.GetIter();
                        while (!it.Done())
                        {
                            writer.Write(entryWs);
                            Obj    key   = mapper(it.GetIdx());
                            double value = it.GetValue();
                            if (flipCols)
                            {
                                writer.Write(FloatObjPrinter.Print(value));
                                writer.Write(", ");
                                ObjPrinter.PrintNoFlush(key, writer);
                                written++;
                                writer.Write(written == 1 | written < count ? ";\n" : "\n");
                            }
                            else
                            {
                                ObjPrinter.PrintNoFlush(key, writer);
                                writer.Write(" -> ");
                                writer.Write(FloatObjPrinter.Print(value));
                                written++;
                                writer.Write(written < count ? ",\n" : "\n");
                            }
                            it.Next();
                        }
                    }
                    else
                    {
                        ObjColumn      objCol = (ObjColumn)col;
                        ObjColumn.Iter it     = objCol.GetIter();
                        while (!it.Done())
                        {
                            writer.Write(entryWs);
                            Obj key   = mapper(it.GetIdx());
                            Obj value = it.GetValue();
                            if (flipCols)
                            {
                                ObjPrinter.PrintNoFlush(value, writer);
                                writer.Write(", ");
                                ObjPrinter.PrintNoFlush(key, writer);
                                written++;
                                writer.Write(written == 1 | written < count ? ";\n" : "\n");
                            }
                            else
                            {
                                ObjPrinter.PrintNoFlush(key, writer);
                                writer.Write(" -> ");
                                ObjPrinter.PrintNoFlush(value, writer);
                                written++;
                                writer.Write(written < count ? ",\n" : "\n");
                            }
                            it.Next();
                        }
                    }
                }
                Debug.Assert(written == count);

                writer.Write(baseWs);
            }

            writer.Write(writeSeparator ? "],\n" : "]\n");
        }