Example #1
0
        private Int32 setHeaders(out Byte[] buffer, Int32 dataLength, Xpression xTp)
        {
            Int32 position = 8;

            Byte[] allLength;
            Byte[] sexpLength = BitConverter.GetBytes(dataLength);

            if ((dataLength + 8) > 0xfffff0)
            {
                position  = 16;
                buffer    = new Byte[16 + dataLength];
                buffer[0] = (byte)(DataTypes.SEXP | DataTypes.LARGE);
                allLength = BitConverter.GetBytes(dataLength + 8);
                Array.Copy(allLength, 0, buffer, 1, 4);

                buffer[8] = (byte)(xTp | Xpression.XT_LARGE);
                Array.Copy(sexpLength, 0, buffer, 9, 4);
            }
            else
            {
                buffer    = new Byte[8 + dataLength];
                buffer[0] = (byte)DataTypes.SEXP;
                allLength = BitConverter.GetBytes(dataLength + 4);
                Array.Copy(allLength, 0, buffer, 1, 3);

                buffer[4] = (byte)xTp;
                Array.Copy(sexpLength, 0, buffer, 5, 3);
            }

            return(position);
        }
Example #2
0
        public void TestPlusReturnSum()
        {
            Money     five   = Money.Dollar(5);
            Xpression result = five.Plus(five);
            Sum       sum    = (Sum)result;

            Assert.That(five, Is.EqualTo(sum.Augend));
            Assert.That(five, Is.EqualTo(sum.Addend));
        }
Example #3
0
        public void TestSimpleAddition()
        {
            Money     five    = Money.Dollar(5);
            Xpression sum     = five.Plus(five);
            Bank      bank    = new Bank();
            Money     reduced = bank.Reduce(sum, "USD");

            Assert.That(Money.Dollar(10), Is.EqualTo(reduced));
        }
Example #4
0
 /// <summary>
 /// Constructor of Rexp object which we can send to Rserve
 /// </summary>
 /// <param name="input">Array of Doubles values</param>
 public Rexp(Double[] input)
 {
     type = Xpression.XT_ARRAY_DOUBLE;   //set type to XT_ARRAY_DOUBLE
     data = input;                       //copy values
 }
Example #5
0
 /// <summary>
 /// Constructor of Rexp object which we can send to Rserve
 /// </summary>
 /// <param name="input">Double value</param>
 public Rexp(Double input)
 {
     type = Xpression.XT_DOUBLE;  //set type to double
     data = input;                //copy value
 }
Example #6
0
 /// <summary>
 /// Constructor of Rexp object which we can send to Rserve
 /// </summary>
 /// <param name="XT">Xpression type of object</param>
 /// <param name="Xdata">Object to store</param>
 internal Rexp(Xpression XT, Object Xdata)
 {
     type = XT;
     data = Xdata;
 }
Example #7
0
 /// <summary>
 /// Constructor of Rexp object which we can send to Rserve
 /// </summary>
 /// <param name="XT">Xpression type of object</param>
 /// <param name="Xdata">Object to store</param>
 /// <param name="Att">Attribute of object</param>
 internal Rexp(Xpression XT, Object Xdata, Rexp Att)
 {
     type       = XT;
     data       = Xdata;
     rattribute = Att;
 }
Example #8
0
 public Money Reduce(Xpression source, string to)
 {
     return(source.Reduce(this, to));
 }
Example #9
0
 /// <summary>
 /// Constructor of Rexp object which we can send to Rserve
 /// </summary>
 /// <param name="input">Array of Doubles values</param>
 public Rexp(Double[] input)
 {
     type = Xpression.XT_ARRAY_DOUBLE;   //set type to XT_ARRAY_DOUBLE
     data = input;                       //copy values
 }
Example #10
0
        private Int32 setHeaders(out Byte[] buffer, Int32 dataLength, Xpression xTp)
        {
            Int32 position = 8;
            Byte[] allLength;
            Byte[] sexpLength = BitConverter.GetBytes(dataLength);

            if ((dataLength + 8) > 0xfffff0)
            {
                position = 16;
                buffer = new Byte[16 + dataLength];
                buffer[0] = (byte)(DataTypes.SEXP | DataTypes.LARGE);
                allLength = BitConverter.GetBytes(dataLength + 8);
                Array.Copy(allLength, 0, buffer, 1, 4);

                buffer[8] = (byte)(xTp | Xpression.XT_LARGE);
                Array.Copy(sexpLength, 0, buffer, 9, 4);
            }
            else
            {
                buffer = new Byte[8 + dataLength];
                buffer[0] = (byte)DataTypes.SEXP;
                allLength = BitConverter.GetBytes(dataLength + 4);
                Array.Copy(allLength, 0, buffer, 1, 3);

                buffer[4] = (byte)xTp;
                Array.Copy(sexpLength, 0, buffer, 5, 3);
            }

            return (position);
        }
Example #11
0
 /// <summary>
 /// Constructor of Rexp object which we can send to Rserve
 /// </summary>
 /// <param name="input">Double value</param>
 public Rexp(Double input)
 {
     type = Xpression.XT_DOUBLE;  //set type to double
     data = input;                //copy value
 }
Example #12
0
 /// <summary>
 /// Constructor of Rexp object which we can send to Rserve
 /// </summary>
 /// <param name="XT">Xpression type of object</param>
 /// <param name="Xdata">Object to store</param>
 internal Rexp(Xpression XT, Object Xdata)
 {
     type = XT;
     data = Xdata;
 }
Example #13
0
 /// <summary>
 /// Constructor of Rexp object which we can send to Rserve
 /// </summary>
 /// <param name="XT">Xpression type of object</param>
 /// <param name="Xdata">Object to store</param>
 /// <param name="Att">Attribute of object</param>
 internal Rexp(Xpression XT, Object Xdata, Rexp Att)
 {
     type       = XT;
     data       = Xdata;
     rattribute = Att;
 }
Example #14
0
 /// <summary>
 /// Constructor of Rexp object which we can send to Rserve
 /// </summary>
 /// <param name="input">Array of String values</param>
 public Rexp(String[] input)
 {
     type = Xpression.XT_ARRAY_STR;      //set type to XT_ARRAY_STR
     data = input;                       //copy values
 }
Example #15
0
 /// <summary>
 /// Constructor of Rexp object which we can send to Rserve
 /// </summary>
 /// <param name="input">Array of Int32 values</param>
 public Rexp(Int32[] input)
 {
     type = Xpression.XT_ARRAY_INT;      //set type to XT_ARRAY_INT
     data = input;                       //copy values
 }
Example #16
0
 /// <summary>
 /// Constructor of Rexp object which we can send to Rserve
 /// </summary>
 /// <param name="input">Array of Int32 values</param>
 public Rexp(Int32[] input)
 {
     type = Xpression.XT_ARRAY_INT;      //set type to XT_ARRAY_INT
     data = input;                       //copy values
 }
Example #17
0
 /// <summary>
 /// Constructor of Rexp object which we can send to Rserve
 /// </summary>
 /// <param name="input">Array of String values</param>
 public Rexp(String[] input)
 {
     type = Xpression.XT_ARRAY_STR;      //set type to XT_ARRAY_STR
     data = input;                       //copy values
 }
Example #18
0
        /// <summary>
        /// Representation of R-eXpressions.
        /// </summary>
        public static Int32 parseREXP(out Rexp x, ref Byte[] buffer, Int32 offset)
        {
            Int32     xl     = getLength(ref buffer, offset);
            Boolean   isLong = ((buffer[offset] & 64) != 0);
            Boolean   hasAtt = ((buffer[offset] & 128) != 0);
            Xpression xt     = (Xpression)(buffer[offset] & 63);

            if (isLong)
            {
                offset += 4;
            }
            offset += 4;

            Int32 eox = offset + xl;

            x        = new Rexp();
            x.Xtype  = xt;
            x.Attrib = null;

            Rexp xatrr;

            if (hasAtt)
            {
                offset   = parseREXP(out xatrr, ref buffer, offset);
                x.Attrib = xatrr;
            }

            switch (xt)
            {
            case Xpression.XT_NULL:
                x.Data = null;
                return(offset);

            case Xpression.XT_DOUBLE:
                return(parseDouble(eox, offset, ref buffer, ref x));

            case Xpression.XT_ARRAY_DOUBLE:
                return(parseDoubleArray(eox, offset, ref buffer, ref x));

            case Xpression.XT_INT:
                return(parseInt(eox, offset, ref buffer, ref x));

            case Xpression.XT_UNKNOWN:
                x.Data = BitConverter.ToInt32(buffer, offset);
                offset = eox;
                return(offset);

            case Xpression.XT_CLOS:
                return(parseClosure(eox, offset, ref buffer, ref x));

            case Xpression.XT_BOOL:
                return(parseBool(eox, offset, ref buffer, ref x));

            case Xpression.XT_ARRAY_BOOL_UA:
                return(parseBoolArrayUA(eox, offset, ref buffer, ref x));

            case Xpression.XT_ARRAY_BOOL:
                return(parseBoolArray(eox, offset, ref buffer, ref x));

            case Xpression.XT_ARRAY_INT:
                return(parseIntArray(eox, offset, ref buffer, ref x));

            case Xpression.XT_VECTOR:
                return(parseVector(eox, offset, ref buffer, ref x));

            case Xpression.XT_STR:
                return(parseString(eox, offset, ref buffer, ref x));

            case Xpression.XT_SYM:
                return(parseSymbol(eox, offset, ref buffer, ref x));

            case Xpression.XT_LIST:
            case Xpression.XT_LANG:
                return(parseList(eox, offset, ref buffer, ref x));

            default:
                x.Data = null;
                offset = eox;
#if WARNING
                throw new RconnectionException("unhandeld type:" + xt.ToString());
#endif
                return(offset);
            }
        }