Example #1
0
        public void Timezones(RCRunner runner, RCClosure closure, RCBlock right)
        {
            RCCube   result = new RCCube("S");
            DateTime now    = DateTime.UtcNow;
            ReadOnlyCollection <TimeZoneInfo> timezones = TimeZoneInfo.GetSystemTimeZones();

            foreach (TimeZoneInfo timezone in timezones)
            {
                RCSymbolScalar sym = RCSymbolScalar.From("timezones", timezone.Id);
                result.WriteCell("displayName", sym, timezone.DisplayName);
                result.WriteCell("standardName", sym, timezone.StandardName);
                result.WriteCell("daylightName", sym, timezone.DaylightName);
                result.WriteCell("utcOffset", sym, new RCTimeScalar(timezone.GetUtcOffset(now)));
                result.WriteCell("isDaylightSavingTime", sym, timezone.IsDaylightSavingTime(now));
                result.WriteCell("supportsDaylightSavingTime", sym, timezone.SupportsDaylightSavingTime);
                result.Axis.Write(sym);
            }
            runner.Yield(closure, result);
        }
Example #2
0
 protected void DoChart <T> (RCCube result,
                             RCSymbolScalar name,
                             long row,
                             long col,
                             RCVector <T> right)
 {
     for (int i = 0; i < right.Count; ++i)
     {
         string         val = right[i].ToString();
         RCSymbolScalar s   = RCSymbolScalar.From(row, (long)col + i, 0L);
         RCSymbolScalar k   = new RCSymbolScalar(name, (long)i);
         result.WriteCell("r", s, row);
         result.WriteCell("c", s, (long)col + i);
         result.WriteCell("l", s, 0L);
         result.WriteCell("k", s, k);
         result.WriteCell("v", s, val);
         result.Write(s);
     }
 }
Example #3
0
        public void EvalDiff(RCRunner runner, RCClosure closure, RCString left, RCString right)
        {
            diff_match_patch dmp    = new diff_match_patch();
            List <Diff>      diffs  = dmp.diff_main(left[0], right[0], true);
            List <Patch>     patch  = dmp.patch_make(diffs);
            RCCube           result = new RCCube(new RCArray <string> ());

            for (int i = 0; i < patch.Count; ++i)
            {
                for (int j = 0; j < patch[i].diffs.Count; ++j)
                {
                    string operation = patch[i].diffs[j].operation.ToString();
                    string text      = patch[i].diffs[j].text;
                    result.WriteCell("op", null, operation);
                    result.WriteCell("text", null, text);
                    result.Axis.Write(null);
                }
            }
            runner.Yield(closure, result);
        }
Example #4
0
 public ReadCounter(RCCube cube)
 {
     if (cube.Axis.Symbol == null) // no S col
     {
     }
     else if (cube.Axis.Global == null) // no G col
     {
         for (int i = 0; i < cube.Axis.Count; i++)
         {
             Write(cube.Axis.Symbol[i], i);
         }
     }
     else // S and G cols
     {
         for (int i = 0; i < cube.Axis.Count; i++)
         {
             Write(cube.Axis.Symbol[i], (int)cube.Axis.Global[i]);
         }
     }
 }
Example #5
0
        public void EvalThrottle(RCRunner runner, RCClosure closure, RCSymbol symbol, RCLong right)
        {
            int limit = (int)right[0];

            lock (_readWriteLock)
            {
                Section  s          = GetSection(symbol);
                ReadSpec spec       = s._counter.GetReadSpec(symbol, limit, false, true);
                Satisfy  canSatisfy = s._counter.CanSatisfy(spec);
                RCCube   result     = s._blackboard.Read(spec,
                                                         s._counter,
                                                         true,
                                                         s._blackboard.Count);

                if ((spec.SymbolUnlimited && result.Count > 0) ||
                    (!spec.SymbolUnlimited && result.Count >= symbol.Count * Math.Abs(spec.SymbolLimit)))
                {
                    // If dispatch would yield, suspend.
                    if (canSatisfy != Satisfy.Yes)
                    {
                        throw new Exception();
                    }
                    s._throttleWaiters.Enqueue(symbol, closure);
                }
                else
                {
                    // Return the count of the result set for now.
                    // wny not just return the whole thing?
                    // Because I want to write a version of this that can
                    // know, in near constant time whether dispatch would yield,
                    // without actually producing a result set.
                    // That method can be used by dispatch, peek, and throttle.
                    // So keep the interface locked down.
                    if (canSatisfy != Satisfy.No)
                    {
                        throw new Exception();
                    }
                    runner.Yield(closure, new RCLong(result.Lines));
                }
            }
        }
Example #6
0
        public void Operators(RCRunner runner, RCClosure closure, RCBlock right)
        {
            RCCube result = new RCCube("S");

            result.ReserveColumn("module");
            result.ReserveColumn("name");
            result.ReserveColumn("method");
            result.ReserveColumn("left");
            result.ReserveColumn("right");
            foreach (KeyValuePair <RCActivator.OverloadKey,
                                   RCActivator.OverloadValue> kv in Activator._dispatch)
            {
                RCSymbolScalar sym;
                if (kv.Key.Left == null)
                {
                    sym = RCSymbolScalar.From("operator",
                                              kv.Value.Module.Name,
                                              kv.Key.Name,
                                              RCValue.TypeNameForType(kv.Key.Right));
                }
                else
                {
                    sym = RCSymbolScalar.From("operator",
                                              kv.Value.Module.Name,
                                              kv.Key.Name,
                                              RCValue.TypeNameForType(kv.Key.Left),
                                              RCValue.TypeNameForType(kv.Key.Right));
                }
                result.WriteCell("name", sym, kv.Key.Name);
                result.WriteCell("module", sym, kv.Value.Module.Name);
                result.WriteCell("method", sym, kv.Value.Implementation.Name);
                if (kv.Key.Left != null)
                {
                    result.WriteCell("left", sym, RCValue.TypeNameForType(kv.Key.Left));
                }
                result.WriteCell("right", sym, RCValue.TypeNameForType(kv.Key.Right));
                result.Axis.Write(sym);
            }
            runner.Yield(closure, result);
        }
Example #7
0
        public void EvalAssert(RCRunner runner, RCClosure closure, RCBoolean right)
        {
            for (int i = 0; i < right.Count; ++i)
            {
                if (!right[i])
                {
                    RCCube         target = new RCCube(new RCArray <string> ("S"));
                    Stack <object> names  = new Stack <object> ();
                    RCBlock        block  = new RCBlock("", ":", closure.Code);
                    block.Cubify(target, names);
                    ColumnBase column = target.GetColumn("r");

                    string expression;
                    if (column != null)
                    {
                        RCArray <string> refNames = (RCArray <string>)column.Array;
                        // Only display the variables whose values are referenced in the assert
                        // expression
                        RCBlock displayVars = RCBlock.Empty;
                        for (int j = 0; j < refNames.Count; ++j)
                        {
                            RCArray <string> nameParts = RCName.MultipartName(refNames[j], '.');
                            RCValue          val       = Eval.Resolve(null, closure, nameParts, null, returnNull: true);
                            if (val != null)
                            {
                                displayVars = new RCBlock(displayVars, refNames[j], ":", val);
                            }
                        }
                        expression = string.Format("{0}, {1}", closure.Code.ToString(), displayVars);
                    }
                    else
                    {
                        expression = string.Format("{0}", closure.Code.ToString());
                    }
                    throw new RCException(closure, RCErrors.Assert, "Failed: " + expression);
                }
            }
            runner.Yield(closure, new RCBoolean(true));
        }
Example #8
0
        public void EvalDispatch(RCRunner runner, RCClosure closure, RCSymbol symbol, RCLong right)
        {
            int limit = (int)right[0];

            lock (_readWriteLock)
            {
                Section  s          = GetSection(symbol);
                ReadSpec spec       = s._counter.GetReadSpec(symbol, limit, false, true);
                Satisfy  canSatisfy = s._counter.CanSatisfy(spec);
                RCCube   result     = s._blackboard.Read(spec,
                                                         s._counter,
                                                         true,
                                                         s._blackboard.Count);

                if ((spec.SymbolUnlimited && result.Count > 0) ||
                    (!spec.SymbolUnlimited && result.Count >= symbol.Count * Math.Abs(spec.SymbolLimit)))
                {
                    if (canSatisfy != Satisfy.Yes)
                    {
                        throw new Exception();
                    }
                    s._counter.Dispatch(s._blackboard, result.AcceptedLines);
                    runner.Yield(closure, result);
                    Dictionary <long, RCClosure> throttlers = null;
                    s._throttleWaiters.GetReadersForSymbol(ref throttlers,
                                                           result.AcceptedSymbols);
                    ContinueWaiters(runner, throttlers);
                }
                else
                {
                    if (canSatisfy != Satisfy.No)
                    {
                        throw new Exception();
                    }
                    s._dispatchWaiters.Enqueue(symbol, closure);
                }
            }
        }
Example #9
0
        public static void ListVars(RCRunner runner, RCClosure closure)
        {
            RCArray <Variable> modules = new RCArray <Variable> ();
            RCArray <long>     keys    = new RCArray <long> ();

            lock (runner._botLock)
            {
                foreach (KeyValuePair <long, RCBot> kv in runner._bots)
                {
                    keys.Write(kv.Key);
                    modules.Write((Variable)runner._bots[kv.Key].GetModule(typeof(Variable)));
                }
            }
            RCCube result = new RCCube("S");

            for (int i = 0; i < modules.Count; ++i)
            {
                lock (modules[i]._lock)
                {
                    foreach (KeyValuePair <object, Dictionary <RCSymbolScalar,
                                                               RCValue> > section in modules[i]._sections)
                    {
                        RCSymbolScalar botsym = RCSymbolScalar.From("var", keys[i]);
                        foreach (KeyValuePair <RCSymbolScalar, RCValue> kv in section.Value)
                        {
                            RCSymbolScalar varsym = RCSymbolScalar.From(botsym, kv.Key);
                            result.WriteCell("bot", varsym, keys[i]);
                            result.WriteCell("section", varsym, section.Key);
                            result.WriteCell("name", varsym, kv.Key);
                            result.WriteCell("value", varsym, kv.Value.ToString());
                            result.Write(varsym);
                        }
                    }
                }
            }
            runner.Yield(closure, result);
        }
Example #10
0
 protected void Write(RCRunner runner, RCClosure closure, RCCube right, bool force)
 {
     try
     {
         RCArray <RCSymbolScalar> symbols;
         long line;
         // Merge all waiters into this collection to avoid readers being
         // fired multiple times.
         if (right.Count == 0)
         {
             runner.Yield(closure, new RCLong(0));
             return;
         }
         RCSymbol symbol = new RCSymbol(right.Axis.Symbol);
         Dictionary <long, RCClosure> all = null;
         lock (_readWriteLock)
         {
             Section s = GetSection(symbol);
             symbols = s._blackboard.Write(s._counter, right, false, force, s._g);
             line    = s._g + s._blackboard.Count;
             // write should always return the last G value and that G value needs
             // to be the correct one. This is not the case. Need to fix it.
             s._readWaiters.GetReadersForSymbol(ref all, symbols);
             s._dispatchWaiters.GetReadersForSymbol(ref all, symbols);
         }
         ContinueWaiters(runner, all);
         // I really want to see what was written including G and T and i cols.
         // Not only what was passed in.
         RCSystem.Log.Record(closure, "board", 0, "write", right);
         runner.Yield(closure, new RCLong(line));
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #11
0
        public void ToString(StringBuilder builder, int indent, bool firstOnTop)
        {
            RCClosure      closure = this;
            Stack <string> lines   = new Stack <string> ();

            // Do not include the global namespace in the stack trace.
            while (closure != null && closure.Parent != null)
            {
                if (closure.Code != null)
                {
                    RCOperator op = closure.Code as RCOperator;
                    if (op != null)
                    {
                        lines.Push(string.Format("-- {0}", op.ToString()));
                    }
                }
                RCBlock result = closure.Result;
                while (result != null)
                {
                    if (result.Value != null)
                    {
                        RCCube acube = result.Value as RCCube;
                        if (acube != null)
                        {
                            string value = acube.FlatPack().Format(RCFormat.Default);
                            lines.Push(value);
                        }
                        else
                        {
                            string value = result.Value.Format(RCFormat.Default);
                            value = string.Format("{0}:{1}", result.Name, value);
                            value = value.Substring(0, Math.Min(80, value.Length));
                            lines.Push(value);
                        }
                    }
                    result = result.Previous;
                }
                closure = closure.Parent;
            }
            if (firstOnTop)
            {
                builder.AppendFormat("--- BEGIN STACK (bot:{0},fiber:{1},lines:{2}) ---\n",
                                     closure.Bot,
                                     closure.Fiber,
                                     lines.Count);
                while (lines.Count > 0)
                {
                    builder.AppendLine(lines.Pop());
                }
                builder.AppendFormat("--- END STACK ---\n");
            }
            else
            {
                builder.AppendFormat("--- END STACK (bot:{0},fiber:{1},lines:{2}) ---\n",
                                     closure.Bot,
                                     closure.Fiber,
                                     lines.Count);
                string[] linesInOrder = lines.ToArray();
                for (int i = linesInOrder.Length - 1; i >= 0; --i)
                {
                    builder.AppendLine(linesInOrder[i]);
                }
                builder.AppendFormat("--- BEGIN STACK ---\n");
            }
        }
Example #12
0
        public void Format(RCCube source)
        {
            if (source.Count == 0)
            {
                if (_args.Syntax == "RCL")
                {
                    _builder.Append("[]");
                }
                return;
            }
            _names     = new List <string> ();
            _columns   = new List <List <string> > ();
            _max       = new List <int> ();
            _leftAlign = new List <bool> ();
            int  tcols    = 0;
            bool useGRows = false;

            if (source.Axis.Has("G") && _args.Showt)
            {
                _names.Add("G");
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(false);
                ++tcols;
                useGRows = true;
            }
            if (source.Axis.Has("E") && _args.Showt)
            {
                _names.Add("E");
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(false);
                ++tcols;
            }
            if (source.Axis.Has("T") && _args.Showt)
            {
                _names.Add("T");
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(false);
                ++tcols;
            }
            if (source.Axis.Has("S"))
            {
                _names.Add("S");
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(true);
                ++tcols;
            }
            for (int i = 0; i < source.Cols; ++i)
            {
                string name = source.ColumnAt(i);
                char   type = source.GetTypeCode(name);
                _names.Add(source.NameAt(i));
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(type == 'y' || type == 's');
            }
            // Populate _columns and _max.
            if (_args.CanonicalCubes)
            {
                source.VisitCellsCanonical(this, 0, source.Axis.Count);
            }
            else
            {
                source.VisitCellsForward(this, 0, source.Axis.Count);
            }
            if (_args.Syntax == "RCL")
            {
                FormatRC(tcols);
            }
            else if (_args.Syntax == "HTML")
            {
                FormatHtml(tcols, useGRows);
            }
            else if (_args.Syntax == "CSV")
            {
                FormatCsv(tcols, useGRows, CSV_ESCAPE_CHARS, true);
            }
            else if (_args.Syntax == "LOG")
            {
                FormatCsv(tcols, useGRows, LOG_ESCAPE_CHARS, false);
            }
            else
            {
                throw new Exception("Unknown syntax for format:" + _args.Syntax);
            }
        }
Example #13
0
        protected RCCube Compare(string left, string right, bool breakLines)
        {
            diff_match_patch dmp    = new diff_match_patch();
            List <Diff>      diffs  = dmp.diff_main(left, right, true);
            List <Patch>     patch  = dmp.patch_make(diffs);
            RCCube           result = new RCCube(new RCArray <string> ());
            int start = 0;
            int end   = 0;

            for (int i = 0; i < patch.Count; ++i)
            {
                // int hunkStart = start;
                for (int j = 0; j < patch[i].diffs.Count; ++j)
                {
                    Operation op   = patch[i].diffs[j].operation;
                    string    text = patch[i].diffs[j].text;
                    if (op == Operation.EQUAL)
                    {
                        end = left.IndexOf(text, start);
                        if (end < 0)
                        {
                            throw new Exception(
                                      "cannot find string \"" + text + "\" after position " + start + " in \"" +
                                      left + "\"");
                        }
                        end += text.Length;
                        string section = left.Substring(start, (end - start));
                        start = end; // + text.Length;
                        string[] lines = section.Split('\n');
                        if (breakLines && lines.Length > 1)
                        {
                            for (int k = 0; k < lines.Length; ++k)
                            {
                                if (!(k == lines.Length - 1 && lines[k] == ""))
                                {
                                    result.WriteCell("op", null, op.ToString());
                                    result.WriteCell("old", null, lines[k] + "\n");
                                    result.WriteCell("new", null, lines[k] + "\n");
                                    result.Axis.Write(null);
                                }
                            }
                        }
                        else
                        {
                            result.WriteCell("op", null, op.ToString());
                            result.WriteCell("old", null, section);
                            result.WriteCell("new", null, section);
                            result.Axis.Write(null);
                        }
                    }
                    else if (op == Operation.INSERT)
                    {
                        // start = Math.Max (0, start - text.Length);
                        // end = start;
                        // end = start;
                        if (breakLines)
                        {
                            string[] lines = text.Split('\n');
                            if (lines.Length > 1)
                            {
                                for (int k = 0; k < lines.Length; ++k)
                                {
                                    if (!(k == lines.Length - 1 && lines[k] == ""))
                                    {
                                        result.WriteCell("op", null, op.ToString());
                                        result.WriteCell("new", null, lines[k] + "\n");
                                        result.Axis.Write(null);
                                    }
                                }
                            }
                            else
                            {
                                result.WriteCell("op", null, op.ToString());
                                result.WriteCell("new", null, text);
                                result.Axis.Write(null);
                            }
                        }
                        else
                        {
                            result.WriteCell("op", null, op.ToString());
                            result.WriteCell("new", null, text);
                            result.Axis.Write(null);
                        }
                    }
                    else // DELETE
                    {
                        end  += patch[i].diffs[j].text.Length;
                        start = end;
                        if (breakLines)
                        {
                            string[] lines = text.Split('\n');
                            if (lines.Length > 1)
                            {
                                for (int k = 0; k < lines.Length; ++k)
                                {
                                    if (!(k == lines.Length - 1 && lines[k] == ""))
                                    {
                                        result.WriteCell("op", null, op.ToString());
                                        result.WriteCell("old", null, lines[k] + "\n");
                                        result.Axis.Write(null);
                                    }
                                }
                            }
                            else
                            {
                                result.WriteCell("op", null, op.ToString());
                                result.WriteCell("old", null, text);
                                result.Axis.Write(null);
                            }
                        }
                        else
                        {
                            result.WriteCell("op", null, op.ToString());
                            result.WriteCell("old", null, text);
                            result.Axis.Write(null);
                        }
                    }
                }
            }
            return(result);
        }
Example #14
0
        protected void DoChart(RCCube result,
                               RCSymbolScalar parent,
                               ref long row,
                               long col,
                               RCBlock
                               right)
        {
            for (int i = 0; i < right.Count; ++i)
            {
                RCBlock current   = right.GetName(i);
                object  shortName = current.Name;
                if (shortName.Equals(""))
                {
                    shortName = (long)i;
                }
                RCSymbolScalar name = new RCSymbolScalar(parent, shortName);
                RCSymbolScalar cell = RCSymbolScalar.From(row, col, 0L);
                result.WriteCell("r", cell, row);
                result.WriteCell("c", cell, col);
                result.WriteCell("l", cell, 0L);
                result.WriteCell("k", cell, name);
                result.WriteCell("v", cell, shortName is long?shortName.ToString() : shortName);
                result.Axis.Write(cell);
                RCVectorBase vector = current.Value as RCVectorBase;
                if (vector != null)
                {
                    ++col;
                    switch (vector.TypeCode)
                    {
                    case 'l': DoChart <long> (result, name, row, col, (RCVector <long>)vector); break;

                    case 'd': DoChart <double> (result, name, row, col, (RCVector <double>)vector); break;

                    case 'm': DoChart <decimal> (result, name, row, col, (RCVector <decimal>)vector); break;

                    case 's': DoChart <string> (result, name, row, col, (RCVector <string>)vector); break;

                    case 'x': DoChart <byte> (result, name, row, col, (RCVector <byte>)vector); break;

                    case 'y': DoChart <RCSymbolScalar> (result,
                                                        name,
                                                        row,
                                                        col,
                                                        (RCVector <RCSymbolScalar>)vector); break;

                    case 'b': DoChart <bool> (result, name, row, col, (RCVector <bool>)vector); break;

                    default: throw new Exception("Unknown typecode: " + vector.TypeCode);
                    }
                    --col;
                    ++row;
                    continue;
                }
                RCBlock block = current.Value as RCBlock;
                if (block != null)
                {
                    ++col;
                    ++row;
                    DoChart(result, name, ref row, col, block);
                    --col;
                    continue;
                }
                RCOperator oper = current.Value as RCOperator;
                if (oper != null)
                {
                    ++col;
                    string val = oper.ToString();
                    cell = RCSymbolScalar.From(row, col, 0L);
                    result.WriteCell("r", cell, (long)row);
                    result.WriteCell("c", cell, (long)col);
                    result.WriteCell("l", cell, 0L);
                    result.WriteCell("k", cell, new RCSymbolScalar(name, 0L));
                    result.WriteCell("v", cell, val);
                    result.Write(cell);
                    ++row;
                    --col;
                    continue;
                }
                RCReference reference = current.Value as RCReference;
                if (reference != null)
                {
                    ++col;
                    string val = reference.ToString();
                    cell = RCSymbolScalar.From(row, col, 0L);
                    result.WriteCell("r", cell, (long)row);
                    result.WriteCell("c", cell, (long)col);
                    result.WriteCell("l", cell, 0L);
                    result.WriteCell("k", cell, new RCSymbolScalar(name, 0L));
                    result.WriteCell("v", cell, val);
                    result.Write(cell);
                    ++row;
                    --col;
                    continue;
                }
                RCCube cube = current.Value as RCCube;
                if (cube != null)
                {
                    ++col;
                    ++row;
                    DoChart(result, name, ref row, col, cube);
                    ++row;
                    --col;
                    continue;
                }
            }
        }
Example #15
0
 public void EvalSort(RCRunner runner, RCClosure closure, RCCube right)
 {
     runner.Yield(closure,
                  SortCubeByDirectionAndColumn(new RCSymbol(RCSymbolScalar.From("asc", "S")),
                                               right));
 }
Example #16
0
        protected RCCube SortCubeByDirectionAndColumn(RCSymbol left, RCCube right)
        {
            if (right.Count == 0)
            {
                return(right);
            }
            SortDirection        direction = Sort.ToDir(left);
            string               name      = (string)left[0].Part(1);
            ColumnBase           sortCol   = right.GetColumn(name);
            RCArray <ColumnBase> columns   = new RCArray <ColumnBase> ((int)right.Cols);

            long[] rank;
            if (sortCol == null)
            {
                switch (name)
                {
                case "G": rank = RankUtils.DoRank <long> (direction, 'l', right.Axis.Global); break;

                case "E": rank = RankUtils.DoRank <long> (direction, 'l', right.Axis.Event); break;

                case "T": rank = RankUtils.DoRank <RCTimeScalar> (direction, 't', right.Axis.Time); break;

                case "S": rank = RankUtils.DoRank <RCSymbolScalar> (direction, 's', right.Axis.Symbol);
                    break;

                default: throw new Exception("Unknown timeline column: " + name);
                }
            }
            else
            {
                switch (sortCol.TypeCode)
                {
                case 'x': rank = RankUtils.DoRank <byte> (direction,
                                                          sortCol.TypeCode,
                                                          (RCArray <byte>)sortCol.Array); break;

                case 'l': rank = RankUtils.DoRank <long> (direction,
                                                          sortCol.TypeCode,
                                                          (RCArray <long>)sortCol.Array); break;

                case 'd': rank = RankUtils.DoRank <double> (direction,
                                                            sortCol.TypeCode,
                                                            (RCArray <double>)sortCol.Array); break;

                case 'm': rank = RankUtils.DoRank <decimal> (direction,
                                                             sortCol.TypeCode,
                                                             (RCArray <decimal>)sortCol.Array); break;

                case 's': rank = RankUtils.DoRank <string> (direction,
                                                            sortCol.TypeCode,
                                                            (RCArray <string>)sortCol.Array); break;

                case 'b': rank = RankUtils.DoRank <bool> (direction,
                                                          sortCol.TypeCode,
                                                          (RCArray <bool>)sortCol.Array); break;

                case 'y': rank = RankUtils.DoRank <RCSymbolScalar> (direction,
                                                                    sortCol.TypeCode,
                                                                    (RCArray <RCSymbolScalar>)sortCol.Array);
                    break;

                case 't': rank = RankUtils.DoRank <RCTimeScalar> (direction,
                                                                  sortCol.TypeCode,
                                                                  (RCArray <RCTimeScalar>)sortCol.Array);
                    break;

                default: throw new Exception("Type:" + sortCol.TypeCode + " is not supported by sort");
                }
            }
            int[] rowRank = new int[rank.Length];
            if (sortCol == null)
            {
                for (int i = 0; i < rowRank.Length; ++i)
                {
                    rowRank[i] = (int)rank[i];
                }
            }
            else
            {
                for (int i = 0; i < rowRank.Length; ++i)
                {
                    rowRank[i] = sortCol.Index[(int)rank[i]];
                }
            }
            Dictionary <long, int> map = new Dictionary <long, int> ();

            for (int i = 0; i < rowRank.Length; ++i)
            {
                map[rowRank[i]] = i;
            }
            Timeline axis    = ApplyAxisRank(right.Axis, map);
            int      lastRow = map.Count;

            for (int i = 0; i < axis.Count; ++i)
            {
                if (!map.ContainsKey(i))
                {
                    map[i] = lastRow;
                    ++lastRow;
                }
            }
            for (int col = 0; col < right.Cols; ++col)
            {
                ColumnBase oldcol = right.GetColumn(col);
                ColumnBase newcol = null;
                switch (oldcol.TypeCode)
                {
                case 'x': newcol = DoColumn <byte> (oldcol, map, axis); break;

                case 'l': newcol = DoColumn <long> (oldcol, map, axis); break;

                case 'd': newcol = DoColumn <double> (oldcol, map, axis); break;

                case 'm': newcol = DoColumn <decimal> (oldcol, map, axis); break;

                case 's': newcol = DoColumn <string> (oldcol, map, axis); break;

                case 'b': newcol = DoColumn <bool> (oldcol, map, axis); break;

                case 'y': newcol = DoColumn <RCSymbolScalar> (oldcol, map, axis); break;

                case 't': newcol = DoColumn <RCTimeScalar> (oldcol, map, axis); break;

                case '0': newcol = oldcol; break;

                default: throw new Exception("Type:" + newcol.TypeCode + " is not supported by sort");
                }
                columns.Write(newcol);
            }
            RCArray <string> names = new RCArray <string> (columns.Count);

            for (int i = 0; i < right.Cols; ++i)
            {
                names.Write(right.NameAt(i));
            }
            RCCube result = new RCCube(axis, names, columns);

            return(result);
        }
Example #17
0
 public Filler(RCCube target)
 {
     _target = target;
 }
Example #18
0
 public WhereIndicator(RCCube source, RCArray <bool> indicator)
 {
     _source    = source;
     _indicator = indicator;
     _target    = new RCCube(source.Axis.Match());
 }
Example #19
0
        public void EvalAppend(RCRunner runner, RCClosure closure, RCBlock right)
        {
            if (right.Count == 0)
            {
                runner.Yield(closure, RCBlock.Empty);
            }
            RCValue      first  = right.Get(0);
            RCVectorBase vector = first as RCVectorBase;

            if (vector != null)
            {
                RCVectorBase result;
                switch (vector.TypeCode)
                {
                case 'x': result = new RCByte(DoAppend <byte> (right)); break;

                case 'l': result = new RCLong(DoAppend <long> (right)); break;

                case 'd': result = new RCDouble(DoAppend <double> (right)); break;

                case 'm': result = new RCDecimal(DoAppend <decimal> (right)); break;

                case 's': result = new RCString(DoAppend <string> (right)); break;

                case 'b': result = new RCBoolean(DoAppend <bool> (right)); break;

                case 'y': result = new RCSymbol(DoAppend <RCSymbolScalar> (right)); break;

                case 't': result = new RCTime(DoAppend <RCTimeScalar> (right)); break;

                default: throw new Exception("Type:" + vector.TypeCode + " is not supported by sort");
                }
                runner.Yield(closure, result);
                return;
            }
            RCCube cube = first as RCCube;

            if (cube != null)
            {
                RCCube result = new RCCube(cube);
                for (int i = 1; i < right.Count; ++i)
                {
                    Writer writer = new Writer(result, null, true, true, 0);
                    writer.Write((RCCube)right.Get(i));
                }
                runner.Yield(closure, result);
                return;
            }
            // Individual values are now appended to the result just like the children of
            // blocks.
            {
                RCBlock result = RCBlock.Empty;
                for (int i = 0; i < right.Count; ++i)
                {
                    RCBlock top = right.GetName(i);
                    if (top.Value is RCBlock)
                    {
                        RCBlock list = (RCBlock)right.Get(i);
                        for (int j = 0; j < list.Count; ++j)
                        {
                            RCBlock item = list.GetName(j);
                            result = new RCBlock(result, item.Name, ":", item.Value);
                        }
                    }
                    else
                    {
                        result = new RCBlock(result, top.Name, ":", top.Value);
                    }
                }
                runner.Yield(closure, result);
            }
        }
Example #20
0
 public virtual void Cubify(RCCube target, Stack <object> names)
 {
 }
Example #21
0
        protected static void ListFilesCube(object obj)
        {
            RCAsyncState state = (RCAsyncState)obj;
            ListArgs     args  = (ListArgs)state.Other;

            try
            {
                RCCube         result   = new RCCube(new RCArray <string> ("S"));
                Queue <string> todo     = new Queue <string> ();
                string         top      = args.Path;
                string[]       topParts = top.Split(Path.DirectorySeparatorChar);
                int            startPart;
                RCSymbolScalar prefix;
                if (args.Spec != null)
                {
                    startPart = (int)(topParts.Length - args.Spec.Length) + 1;
                    prefix    = RCSymbolScalar.From(args.Spec.Part(0));
                }
                else
                {
                    startPart = 1;
                    prefix    = RCSymbolScalar.From(topParts[0]);
                }
                todo.Enqueue(top);
                while (todo.Count > 0)
                {
                    string   path  = todo.Dequeue();
                    string[] files = Directory.GetFiles(path);
                    for (int i = 0; i < files.Length; ++i)
                    {
                        FileInfo file = new FileInfo(files[i]);
                        if (args.All || file.Name[0] != '.')
                        {
                            string []      parts  = files[i].Split(Path.DirectorySeparatorChar);
                            RCSymbolScalar symbol = RCSymbolScalar.From(startPart, prefix, parts);
                            result.WriteCell("name", symbol, file.Name);
                            result.WriteCell("size", symbol, file.Length);
                            result.WriteCell("type", symbol, "f");
                            result.WriteCell("ext", symbol, file.Extension);
                            result.WriteCell("access",
                                             symbol,
                                             new RCTimeScalar(file.LastAccessTime,
                                                              RCTimeType.Datetime));
                            result.WriteCell("write",
                                             symbol,
                                             new RCTimeScalar(file.LastWriteTime,
                                                              RCTimeType.Datetime));
                            result.Axis.Write(symbol);
                        }
                    }
                    RCArray <string> dirs = new RCArray <string> (Directory.GetDirectories(path));
                    for (int i = 0; i < dirs.Count; ++i)
                    {
                        DirectoryInfo dir = new DirectoryInfo(dirs[i]);
                        if (args.All || dir.Name[0] != '.')
                        {
                            string []      parts  = dirs[i].Split(Path.DirectorySeparatorChar);
                            RCSymbolScalar symbol = RCSymbolScalar.From(startPart, prefix, parts);
                            result.WriteCell("name", symbol, dir.Name);
                            result.WriteCell("type", symbol, "d");
                            result.WriteCell("access",
                                             symbol,
                                             new RCTimeScalar(dir.LastAccessTime,
                                                              RCTimeType.Datetime));
                            result.WriteCell("write",
                                             symbol,
                                             new RCTimeScalar(dir.LastWriteTime,
                                                              RCTimeType.Datetime));
                            result.Axis.Write(symbol);
                            if (args.Deep)
                            {
                                todo.Enqueue(dirs[i]);
                            }
                        }
                    }
                }
                state.Runner.Yield(state.Closure, result);
            }
            catch (DirectoryNotFoundException ex)
            {
                state.Runner.Finish(state.Closure,
                                    new RCException(state.Closure, RCErrors.File, ex.Message),
                                    1);
            }
            catch (Exception ex)
            {
                state.Runner.Report(state.Closure, ex);
            }
        }
Example #22
0
 public Plugger(RCCube target, object defaultValue, System.Collections.IComparer comparer)
 {
     _target       = target;
     _defaultValue = defaultValue;
     _comparer     = comparer;
 }
Example #23
0
 public RCCube Plug(RCCube source)
 {
     _source = source;
     _source.VisitCellsCanonical(this, 0, _source.Axis.Count);
     return(_target);
 }
Example #24
0
 public void EvalColofb(RCRunner runner, RCClosure closure, RCCube right)
 {
     runner.Yield(closure, new RCBoolean(right.DoColof <bool> (0, false, false)));
 }
Example #25
0
 public void EvalSort(RCRunner runner, RCClosure closure, RCSymbol left, RCCube right)
 {
     runner.Yield(closure, SortCubeByDirectionAndColumn(left, right));
 }
Example #26
0
        protected RCCube CompareNew(string left, string right, bool breakLines)
        {
            diff_match_patch dmp    = new diff_match_patch();
            List <Diff>      diffs  = dmp.diff_main(left, right, true);
            RCCube           result = new RCCube(new RCArray <string> ());
            int start = 0;
            int end   = 0;

            for (int i = 0; i < diffs.Count; ++i)
            {
                Operation op   = diffs[i].operation;
                string    text = diffs[i].text;
                if (op == Operation.EQUAL)
                {
                    int match = left.IndexOf(text, start);
                    if (match < 0)
                    {
                        throw new Exception(
                                  "cannot find string \"" + text + "\" after position " + start + " in \"" +
                                  left + "\"");
                    }
                    end = match + text.Length;
                    string section = left.Substring(start, end - start);
                    start = end;

                    if (breakLines)
                    {
                        int lineStart = 0;
                        while (true)
                        {
                            int lineEnd = section.IndexOf('\n', lineStart);
                            if (lineEnd >= 0)
                            {
                                result.WriteCell("op", null, op.ToString());
                                string line = section.Substring(lineStart, 1 + (lineEnd - lineStart));
                                result.WriteCell("old", null, line);
                                result.WriteCell("new", null, line);
                                result.Axis.Write(null);
                                lineStart = lineEnd + 1;
                            }
                            else if (lineStart < section.Length)
                            {
                                result.WriteCell("op", null, op.ToString());
                                string rest = section.Substring(lineStart, section.Length - lineStart);
                                result.WriteCell("old", null, rest);
                                result.WriteCell("new", null, rest);
                                result.Axis.Write(null);
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        result.WriteCell("op", null, op.ToString());
                        result.WriteCell("old", null, section);
                        result.WriteCell("new", null, section);
                        result.Axis.Write(null);
                    }

                    // string[] lines = section.Split ('\n');
                    // if (lines.Length > 1 && section.Length == 1) continue;

                    /*
                     * if (breakLines && lines.Length > 1)
                     * {
                     * for (int k = 0; k < lines.Length; ++k)
                     * {
                     *  if (k < lines.Length - 1)
                     *  {
                     *    result.WriteCell ("op", null, op.ToString ());
                     *    result.WriteCell ("old", null, lines[k] + "\n");
                     *    result.WriteCell ("new", null, lines[k] + "\n");
                     *    result.Axis.Write (null);
                     *  }
                     *  else if (lines[k] != "")
                     *  {
                     *    result.WriteCell ("op", null, op.ToString ());
                     *    result.WriteCell ("old", null, lines[k]);
                     *    result.WriteCell ("new", null, lines[k]);
                     *    result.Axis.Write (null);
                     *  }
                     *  else
                     *  {
                     *    result.WriteCell ("op", null, op.ToString ());
                     *    result.WriteCell ("old", null, "\n");
                     *    result.WriteCell ("new", null, "\n");
                     *    result.Axis.Write (null);
                     *  }
                     *  if (lines[k] == "")
                     *  {
                     *    result.WriteCell ("op", null, op.ToString ());
                     *    result.WriteCell ("old", null, "\n");
                     *    result.WriteCell ("new", null, "\n");
                     *    result.Axis.Write (null);
                     *  }
                     *  if (!(k == lines.Length - 1 && lines[k] == ""))
                     *  {
                     *    result.WriteCell ("op", null, op.ToString ());
                     *    result.WriteCell ("old", null, lines[k] + "\n");
                     *    result.WriteCell ("new", null, lines[k] + "\n");
                     *    result.Axis.Write (null);
                     *  }
                     * }
                     * }
                     * else
                     * {
                     * result.WriteCell ("op", null, op.ToString ());
                     * result.WriteCell ("old", null, section);
                     * result.WriteCell ("new", null, section);
                     * result.Axis.Write (null);
                     * }
                     */
                }
                else if (op == Operation.INSERT)
                {
                    string   section = text;
                    string[] lines   = section.Split('\n');
                    if (breakLines && lines.Length > 1)
                    {
                        for (int k = 0; k < lines.Length; ++k)
                        {
                            if (!(k == lines.Length - 1 && lines[k] == ""))
                            {
                                result.WriteCell("op", null, op.ToString());
                                result.WriteCell("new", null, lines[k] + "\n");
                                result.Axis.Write(null);
                            }
                        }
                    }
                    else
                    {
                        result.WriteCell("op", null, op.ToString());
                        result.WriteCell("new", null, section);
                        result.Axis.Write(null);
                    }
                }
                else if (op == Operation.DELETE)
                {
                    start += text.Length;
                    string   section = text;
                    string[] lines   = section.Split('\n');
                    if (breakLines && lines.Length > 1)
                    {
                        for (int k = 0; k < lines.Length; ++k)
                        {
                            if (!(k == lines.Length - 1 && lines[k] == ""))
                            {
                                result.WriteCell("op", null, op.ToString());
                                result.WriteCell("old", null, lines[k] + "\n");
                                result.Axis.Write(null);
                            }
                        }
                    }
                    else
                    {
                        result.WriteCell("op", null, op.ToString());
                        result.WriteCell("old", null, section);
                        result.Axis.Write(null);
                    }
                }
            }
            return(result);
        }
Example #27
0
 protected void DoTree(TreeNode parent, RCCube right, ref double a, ref double g)
 {
     if (right.Axis.ColCount > 1)
     {
         // throw new NotImplementedException ("Cannot handle time cols on cubes yet.");
         // But we will still handle them as if the time col didn't exist.
     }
     if (right.Axis.Symbol != null)
     {
         Dictionary <RCSymbolScalar, TreeNode> map = new Dictionary <RCSymbolScalar, TreeNode> ();
         for (int i = 0; i < right.Cols; ++i)
         {
             string   colName = right.ColumnAt(i);
             TreeNode colNode = new TreeNode(parent, colName, i);
             colNode.v = colName;
             colNode.n = 0;
             ColumnBase col     = right.GetColumn(i);
             bool       numeric = typeof(long).IsAssignableFrom(col.GetElementType());
             for (int j = 0; j < col.Count; ++j)
             {
                 RCSymbolScalar symbol  = right.Axis.SymbolAt(col.Index[j]);
                 TreeNode       rowNode = new TreeNode(colNode, symbol.Key.ToString(), col.Index[j]);
                 object         box     = col.BoxCell(j);
                 if (numeric)
                 {
                     rowNode.n = (long)box;
                     rowNode.m = (long)box;
                     rowNode.g = Math.Abs((long)box);
                 }
                 else
                 {
                     rowNode.n = 1;
                     rowNode.m = 1;
                     rowNode.g = 1;
                 }
                 rowNode.v      = box.ToString();
                 colNode.n     += rowNode.n;
                 colNode.g     += Math.Abs(rowNode.n);
                 map[rowNode.s] = rowNode;
             }
             a += colNode.n;
             g += Math.Abs(colNode.g);
         }
     }
     else
     {
         for (int i = 0; i < right.Cols; ++i)
         {
             string   colName = right.ColumnAt(i);
             TreeNode colNode = new TreeNode(parent, colName, i);
             colNode.v = colName;
             colNode.n = 0;
             ColumnBase col     = right.GetColumn(i);
             bool       numeric = typeof(long).IsAssignableFrom(col.GetElementType());
             for (int j = 0; j < right.Count; ++j)
             {
                 TreeNode rowNode = new TreeNode(colNode, null, col.Index[j]);
                 object   box     = col.BoxCell(j);
                 if (numeric)
                 {
                     rowNode.n = (long)box;
                     rowNode.m = (long)box;
                     rowNode.g = Math.Abs((long)box);
                 }
                 else
                 {
                     rowNode.n = 1;
                     rowNode.m = 1;
                     rowNode.g = 1;
                 }
                 rowNode.v  = box.ToString();
                 colNode.n += rowNode.n;
                 colNode.g += Math.Abs(rowNode.n);
             }
             a += colNode.n;
             g += Math.Abs(colNode.g);
         }
     }
 }
Example #28
0
        protected void DoChart(RCCube result,
                               RCSymbolScalar name,
                               ref long row,
                               long col,
                               RCCube cube)
        {
            for (int i = 0; i < cube.Cols; ++i)
            {
                string         colname = cube.NameAt(i);
                ColumnBase     data    = cube.GetColumn(i);
                RCSymbolScalar cell    = RCSymbolScalar.From(row, (long)col, 0L);
                RCSymbolScalar parent  = new RCSymbolScalar(name, colname);
                result.WriteCell("r", cell, (long)row);
                result.WriteCell("c", cell, (long)col);
                result.WriteCell("l", cell, 0L);
                result.WriteCell("k", cell, parent);
                result.WriteCell("v", cell, colname);
                result.Write(cell);

                for (int j = 0; j < data.Count; ++j)
                {
                    string val = data.BoxCell(j).ToString();
                    cell = RCSymbolScalar.From(row, (long)col + data.Index[j] + 1, 0L);
                    RCSymbolScalar child = new RCSymbolScalar(parent, (long)j);
                    result.WriteCell("r", cell, (long)row);
                    result.WriteCell("c", cell, (long)col + data.Index[j] + 1);
                    result.WriteCell("l", cell, 0L);
                    result.WriteCell("k", cell, child);
                    result.WriteCell("v", cell, val);
                    result.Write(cell);
                }
                ++row;
            }
            if (cube.Axis.Global != null)
            {
                RCSymbolScalar cell   = RCSymbolScalar.From(row, col, 0L);
                RCSymbolScalar parent = new RCSymbolScalar(name, "G");
                result.WriteCell("r", cell, (long)row);
                result.WriteCell("c", cell, (long)col);
                result.WriteCell("l", cell, 0L);
                result.WriteCell("k", cell, parent);
                result.WriteCell("v", cell, "G");
                result.Write(cell);
                for (int i = 0; i < cube.Axis.Global.Count; ++i)
                {
                    string val = cube.Axis.Global[i].ToString();
                    cell = RCSymbolScalar.From(row, col + i + 1, 0L);
                    RCSymbolScalar child = new RCSymbolScalar(parent, (long)i);
                    result.WriteCell("r", cell, (long)row);
                    result.WriteCell("c", cell, (long)col + i + 1);
                    result.WriteCell("l", cell, 0L);
                    result.WriteCell("k", cell, child);
                    result.WriteCell("v", cell, val);
                    result.Write(cell);
                }
                ++row;
            }
            if (cube.Axis.Event != null)
            {
                RCSymbolScalar cell   = RCSymbolScalar.From(row, col, 0L);
                RCSymbolScalar parent = new RCSymbolScalar(name, "E");
                result.WriteCell("r", cell, (long)row);
                result.WriteCell("c", cell, (long)col);
                result.WriteCell("l", cell, 0L);
                result.WriteCell("k", cell, parent);
                result.WriteCell("v", cell, "E");
                result.Write(cell);
                for (int i = 0; i < cube.Axis.Event.Count; ++i)
                {
                    string val = cube.Axis.Event[i].ToString();
                    cell = RCSymbolScalar.From(row, col + i + 1, 0L);
                    RCSymbolScalar child = new RCSymbolScalar(parent, (long)i);
                    result.WriteCell("r", cell, (long)row);
                    result.WriteCell("c", cell, (long)col + i + 1);
                    result.WriteCell("l", cell, 0L);
                    result.WriteCell("k", cell, child);
                    result.WriteCell("v", cell, val);
                    result.Write(cell);
                }
                ++row;
            }
            if (cube.Axis.Time != null)
            {
                RCSymbolScalar cell   = RCSymbolScalar.From(row, col, 0L);
                RCSymbolScalar parent = new RCSymbolScalar(name, "T");
                result.WriteCell("r", cell, (long)row);
                result.WriteCell("c", cell, (long)col);
                result.WriteCell("l", cell, 0L);
                result.WriteCell("k", cell, parent);
                result.WriteCell("v", cell, "T");
                result.Write(cell);
                for (int i = 0; i < cube.Axis.Time.Count; ++i)
                {
                    string val = cube.Axis.Time[i].ToString();
                    cell = RCSymbolScalar.From(row, col + i + 1, 0L);
                    RCSymbolScalar child = new RCSymbolScalar(parent, (long)i);
                    result.WriteCell("r", cell, (long)row);
                    result.WriteCell("c", cell, (long)col + i + 1);
                    result.WriteCell("l", cell, 0L);
                    result.WriteCell("k", cell, child);
                    result.WriteCell("v", cell, val);
                    result.Write(cell);
                }
                ++row;
            }
            if (cube.Axis.Symbol != null)
            {
                RCSymbolScalar cell   = RCSymbolScalar.From(row, col, 0L);
                RCSymbolScalar parent = new RCSymbolScalar(name, "S");
                result.WriteCell("r", cell, (long)row);
                result.WriteCell("c", cell, (long)col);
                result.WriteCell("l", cell, 0L);
                result.WriteCell("k", cell, parent);
                result.WriteCell("v", cell, "S");
                result.Write(cell);
                for (int i = 0; i < cube.Axis.Symbol.Count; ++i)
                {
                    string val = cube.Axis.Symbol[i].ToString();
                    cell = RCSymbolScalar.From(row, col + i + 1, 0L);
                    RCSymbolScalar child = new RCSymbolScalar(parent, (long)i);
                    result.WriteCell("r", cell, (long)row);
                    result.WriteCell("c", cell, (long)col + i + 1);
                    result.WriteCell("l", cell, 0L);
                    result.WriteCell("k", cell, child);
                    result.WriteCell("v", cell, val);
                    result.Write(cell);
                }
                ++row;
            }
        }
Example #29
0
 public Deltafier(RCCube before, RCCube after)
 {
     _before = before;
     _after  = after;
     _target = new RCCube(after.Axis.Match());
 }
Example #30
0
        protected void DoTree(TreeNode parent, RCBlock right, ref double a, ref double g)
        {
            for (int i = 0; i < right.Count; ++i)
            {
                RCBlock current   = right.GetName(i);
                object  shortName = current.Name;
                if (shortName.Equals(""))
                {
                    shortName = (long)i;
                }
                RCSymbolScalar s    = new RCSymbolScalar(parent.s, (long)i);
                RCSymbolScalar n    = new RCSymbolScalar(parent.k, shortName);
                TreeNode       node = new TreeNode(s, n);
                node.v        = current.Name;
                node.children = new RCArray <TreeNode> ();
                RCVectorBase vector = current.Value as RCVectorBase;
                if (vector != null)
                {
                    switch (vector.TypeCode)
                    {
                    case 'l': DoTree <long> (node,
                                             (RCVector <long>)vector,
                                             ref node.n,
                                             ref node.g,
                                             Areal,
                                             Formatl); break;

                    case 'd': DoTree <double> (node,
                                               (RCVector <double>)vector,
                                               ref node.n,
                                               ref node.g,
                                               Aread,
                                               Formatd); break;

                    case 'm': DoTree <decimal> (node,
                                                (RCVector <decimal>)vector,
                                                ref node.n,
                                                ref node.g,
                                                Aream,
                                                Formatm); break;

                    case 's': DoTree <string> (node,
                                               (RCVector <string>)vector,
                                               ref node.n,
                                               ref node.g,
                                               Areas,
                                               Formats); break;

                    case 'x': DoTree <byte> (node,
                                             (RCVector <byte>)vector,
                                             ref node.n,
                                             ref node.g,
                                             Areax,
                                             Formatx); break;

                    case 'y': DoTree <RCSymbolScalar> (node,
                                                       (RCVector <RCSymbolScalar>)vector,
                                                       ref node.n,
                                                       ref
                                                       node.g,
                                                       Areay,
                                                       Formaty); break;

                    case 'b': DoTree <bool> (node,
                                             (RCVector <bool>)vector,
                                             ref node.n,
                                             ref node.g,
                                             Areab,
                                             Formatb); break;

                    default: throw new Exception("Unknown typecode: " + vector.TypeCode);
                    }
                    a += node.n;
                    g += Math.Abs(node.g);
                    parent.children.Write(node);
                    continue;
                }
                RCBlock block = current.Value as RCBlock;
                if (block != null)
                {
                    DoTree(node, block, ref node.n, ref node.g);
                    a += node.n;
                    g += Math.Abs(node.g);
                    parent.children.Write(node);
                    continue;
                }
                RCCube cube = current.Value as RCCube;
                if (cube != null)
                {
                    DoTree(node, cube, ref node.n, ref node.g);
                    a += node.n;
                    g += Math.Abs(node.g);
                    parent.children.Write(node);
                    continue;
                }
                RCOperator oper = current.Value as RCOperator;
                if (oper != null)
                {
                    DoTree(node, oper, ref node.n, ref node.g);
                    a += node.n;
                    g += Math.Abs(node.g);
                    parent.children.Write(node);
                    continue;
                }
                RCReference reference = current.Value as RCReference;
                if (reference != null)
                {
                    DoTree(node, reference, ref node.n, ref node.g);
                    a += node.n;
                    g += Math.Abs(node.g);
                    parent.children.Write(node);
                    continue;
                }
            }
        }