Ejemplo n.º 1
0
        //////////////////////////////////////////////////////////////////////////////

        public override int InternalOrder(Obj other)
        {
            Debug.Assert(GetSize() == other.GetSize());

            Obj[]       col, otherCol;
            int         size     = GetSize();
            NeBinRelObj otherRel = (NeBinRelObj)other;

            if (other is RecordObj)
            {
                RecordObj otherRecord = (RecordObj)other;

                ushort[] otherFieldIds = otherRecord.fieldIds;
                if (fieldIds != otherFieldIds)
                {
                    for (int i = 0; i < size; i++)
                    {
                        int res = SymbObj.CompSymbs(fieldIds[i], otherFieldIds[i]);
                        if (res != 0)
                        {
                            return(res);
                        }
                    }
                }
            }
            else
            {
                BuildCol1();

                col      = col1;
                otherCol = otherRel.Col1();
                for (int i = 0; i < size; i++)
                {
                    int ord = col[i].QuickOrder(otherCol[i]);
                    if (ord != 0)
                    {
                        return(ord);
                    }
                }
            }

            col      = col2;
            otherCol = otherRel.Col2();
            for (int i = 0; i < size; i++)
            {
                int ord = col[i].QuickOrder(otherCol[i]);
                if (ord != 0)
                {
                    return(ord);
                }
            }

            return(0);
        }
Ejemplo n.º 2
0
        private void Record(NeBinRelObj obj)
        {
            Obj[] values = obj.Col2();
            int   len    = values.Length;

            ushort[] labels;
            if (obj is RecordObj)
            {
                RecordObj recObj = (RecordObj)obj;
                labels = recObj.fieldIds;
            }
            else
            {
                labels = new ushort[len];
                Obj[] fields = obj.Col1();
                for (int i = 0; i < len; i++)
                {
                    labels[i] = fields[i].GetSymbId();
                }
            }

            writer.Write('(');

            if (IsMultiline(obj))
            {
                int maxLabelLen = 0;
                for (int i = 0; i < len; i++)
                {
                    int labelLen = Cell.Runtime.SymbObj.IdxToStr(labels[i]).Length;
                    if (labelLen > maxLabelLen)
                    {
                        maxLabelLen = labelLen;
                    }
                }

                int[] idxs = SortedIdxs(labels, values);

                writer.Indent();
                if (writer.IsNewLine())
                {
                    writer.Write(' ');
                }
                else
                {
                    writer.NewLine();
                }

                for (int i = 0; i < len; i++)
                {
                    int    idx   = idxs[i];
                    string label = Cell.Runtime.SymbObj.IdxToStr(labels[idx]);
                    writer.Write(label);
                    writer.Write(':');

                    Obj value = values[idx];
                    if (IsMultiline(value))
                    {
                        writer.IndentedNewLine();
                        value.Visit(this);
                        writer.Unindent();
                    }
                    else
                    {
                        writer.WriteSpaces(maxLabelLen - label.Length + 1);
                        value.Visit(this);
                    }

                    if (i < len - 1)
                    {
                        writer.Write(',');
                    }
                    else
                    {
                        writer.Unindent();
                    }
                    writer.NewLine();
                }
            }
            else
            {
                for (int i = 0; i < len; i++)
                {
                    if (i > 0)
                    {
                        writer.Write(", ");
                    }
                    writer.Write(Cell.Runtime.SymbObj.IdxToStr(labels[i]));
                    writer.Write(": ");
                    values[i].Visit(this);
                }
            }

            writer.Write(')');
        }