private static Int32 parseList(Int32 eox, Int32 offset, ref Byte[] buffer, ref Rexp x) { Rlist rl = new Rlist(); Rexp tmp; rl.Tag = null; offset = parseREXP(out tmp, ref buffer, offset); // CAR rl.Head = tmp; offset = parseREXP(out tmp, ref buffer, offset); // CDR rl.Body = tmp; if (offset != eox) { // if there is more data then it's presumably the TAG entry offset = parseREXP(out tmp, ref buffer, offset); rl.Tag = tmp; if (offset != eox) { //System.out.println("Warning: list SEXP size mismatch\n"); offset = eox; } } x.Data = rl; return(offset); }
private static Int32 parseVector(Int32 eox, Int32 offset, ref Byte[] buffer, ref Rexp x) { List <Rexp> v = new List <Rexp>(); while (offset < eox) { Rexp xx; offset = parseREXP(out xx, ref buffer, offset); v.Add(xx); } if (offset != eox) { //System.out.println("Warning: int vector SEXP size mismatch\n"); offset = eox; } x.Data = v; // fixup for lists since they're stored as attributes of vectors if ((x.Attrib != null) && (x.Attrib.Xtype == Xpression.XT_LIST) && (x.Attrib.Data != null)) { Rlist l = new Rlist(); l.Head = ((Rlist)x.Attrib.Data).Head; l.Body = new Rexp(Xpression.XT_VECTOR, v); x.Data = l; x.Xtype = Xpression.XT_LIST; x.Attrib = x.Attrib.Attrib; if (l.Head.Xtype == Xpression.XT_STR) { List <Rexp> sv = new List <Rexp>(); sv.Add(l.Head); l.Head = new Rexp(Xpression.XT_VECTOR, sv, l.Head.Attrib); l.Head.Attrib = null; } } return(offset); }
/// <summary> /// Converts the Rexp value of this instance to string representation /// </summary> /// <returns>string representation</returns> public override string ToString() { StringBuilder sb = new StringBuilder("[" + type.ToString() + " "); if (rattribute != null) { sb.Append("\nattr=" + rattribute.ToString() + "\n "); } switch (type) { case Xpression.XT_DOUBLE: sb.Append(((Double)data).ToString()); break; case Xpression.XT_INT: sb.Append(((Int32)data).ToString()); break; case Xpression.XT_BOOL: sb.Append(((Rbool)data).ToString()); break; case Xpression.XT_FACTOR: sb.Append(((Rfactor)data).ToString()); break; case Xpression.XT_ARRAY_DOUBLE: Double[] Dvalues = (Double[])data; sb.Append("("); for (int i = 0; i < Dvalues.Length; i++) { sb.Append(Dvalues[i].ToString()); if (i < (Dvalues.Length - 1)) { sb.Append(", "); } if (i == 99) { sb.Append("... (" + (Dvalues.Length - 100) + " more values follow)"); break; } } sb.Append(")"); break; case Xpression.XT_ARRAY_INT: Int32[] Ivalues = (Int32[])data; sb.Append("("); for (int i = 0; i < Ivalues.Length; i++) { sb.Append(Ivalues[i]); if (i < (Ivalues.Length - 1)) { sb.Append(", "); } if (i == 99) { sb.Append("... (" + (Ivalues.Length - 100) + " more values follow)"); break; } } sb.Append(")"); break; case Xpression.XT_ARRAY_BOOL: Rbool[] values = (Rbool[])data; sb.Append("("); for (int i = 0; i < values.Length; i++) { sb.Append(values[i]); if (i < (values.Length - 1)) { sb.Append(", "); } if (i == 99) { sb.Append("... (" + (values.Length - 100) + " more values follow)"); break; } } sb.Append(")"); break; case Xpression.XT_STR: sb.Append("\""); sb.Append((String)data); sb.Append("\""); break; case Xpression.XT_SYM: sb.Append((String)data); break; case Xpression.XT_LIST: case Xpression.XT_LANG: Rlist l = (Rlist)data; sb.Append(l.Head.ToString()); sb.Append(" <-> "); sb.Append(l.Body.ToString()); break; case Xpression.XT_UNKNOWN: sb.Append((Int32)data); break; case Xpression.XT_VECTOR: List <Rexp> Lvalues = (List <Rexp>)data; sb.Append("("); for (Int32 i = 0; i < Lvalues.Count; i++) { sb.Append(Lvalues[i].ToString()); if (i < (Lvalues.Count - 1)) { sb.Append(", "); } } sb.Append(")"); break; } sb.Append("]"); return(sb.ToString()); }
private static Int32 parseVector(Int32 eox, Int32 offset, ref Byte[] buffer, ref Rexp x) { List<Rexp> v = new List<Rexp>(); while (offset < eox) { Rexp xx; offset = parseREXP(out xx, ref buffer, offset); v.Add(xx); } if (offset != eox) { //System.out.println("Warning: int vector SEXP size mismatch\n"); offset = eox; } x.Data = v; // fixup for lists since they're stored as attributes of vectors if ((x.Attrib != null) && (x.Attrib.Xtype == Xpression.XT_LIST) && (x.Attrib.Data != null)) { Rlist l = new Rlist(); l.Head = ((Rlist)x.Attrib.Data).Head; l.Body = new Rexp(Xpression.XT_VECTOR, v); x.Data = l; x.Xtype = Xpression.XT_LIST; x.Attrib = x.Attrib.Attrib; if (l.Head.Xtype == Xpression.XT_STR) { List<Rexp> sv = new List<Rexp>(); sv.Add(l.Head); l.Head = new Rexp(Xpression.XT_VECTOR, sv, l.Head.Attrib); l.Head.Attrib = null; } } return offset; }
private static Int32 parseList(Int32 eox, Int32 offset, ref Byte[] buffer, ref Rexp x) { Rlist rl = new Rlist(); Rexp tmp; rl.Tag = null; offset = parseREXP(out tmp, ref buffer, offset); // CAR rl.Head = tmp; offset = parseREXP(out tmp, ref buffer, offset); // CDR rl.Body = tmp; if (offset != eox) { // if there is more data then it's presumably the TAG entry offset = parseREXP(out tmp, ref buffer, offset); rl.Tag = tmp; if (offset != eox) { //System.out.println("Warning: list SEXP size mismatch\n"); offset = eox; } } x.Data = rl; return offset; }