예제 #1
0
 public Surf.Bitmap Or(Surf.Bitmap bitmap)
 {
     if (this.Length != bitmap.Length)
     {
         throw new System.Exception("Bitmaps are not the same size.");
     }
     Surf.Bitmap C = new Surf.Bitmap(this.Length);
     for (int i = 0; i < this.Length; i++)
     {
         C.Set(i, this.Get(i) || bitmap.Get(i));
     }
     return(C);
 }
예제 #2
0
        private static void Print(object value, System.IO.TextWriter writer, ref bool canNewline)
        {
            if (value is Node)
            {
                Node node = (Node)value;

                new Surf.Generator().Generate(node, writer);
            }
            else if (value is Surf.Bitmap)
            {
                Surf.Bitmap bitmap = (Surf.Bitmap)value;

                writer.Write("[");
                for (int i = 0; i < bitmap.Length; i++)
                {
                    writer.Write(bitmap.Get(i) ? "1" : "0");
                }
                writer.Write("]");
            }
            else if (value is Tuple)
            {
                Tuple tuple = (Tuple)value;

                writer.Write("( ");
                for (int i = 0; i < tuple.Count; i++)
                {
                    if (i > 0)
                    {
                        writer.Write(", ");
                    }
                    Print(tuple[i], writer, ref canNewline);
                }
                writer.Write(" )");
            }
            else if (value is Set)
            {
                Set set = (Set)value;

                bool isRelation = (canNewline && set.Count > 0 && set[0] is Surf.Tuple) ? true : false;
                if (isRelation)
                {
                    canNewline = false;
                }

                writer.Write("{ ");
                if (isRelation)
                {
                    writer.Write("\n");
                }
                for (int i = 0; i < set.Count; i++)
                {
                    if (i > 0)
                    {
                        writer.Write(", ");
                        if (isRelation)
                        {
                            writer.Write("\n");
                        }
                    }
                    if (isRelation)
                    {
                        writer.Write("   ");
                    }
                    Print(set[i], writer, ref canNewline);
                }
                if (isRelation)
                {
                    writer.Write("\n");
                }
                writer.Write(" }");
            }
            else if (value is string)
            {
                string s = (string)value;

                writer.Write("\"");
                writer.Write(Escape(s));
                writer.Write("\"");
            }
            else if (value is char)
            {
                char ch = (char)value;

                writer.Write("\'");
                writer.Write(Escape(ch.ToString()));
                writer.Write("\'");
            }
            else if (value == null)
            {
                writer.Write("");
            }
            else
            {
                writer.Write(value.ToString());
            }
        }