Exemplo n.º 1
0
 public override Dictionary<String, Option> match(Dictionary<String, Option> variables,
     TransactionalStreamReader input,
     out List<Option> fields)
 {
     input.startTransaction();
     Dictionary<String, Option> myEnv = variables;
     fields = new List<Option>();
     foreach (Rule rule in rules)
     {
         List<Option> newFields;
         myEnv = rule.match(myEnv, input, out newFields);
         if (myEnv == null)
             break;
         if (newFields != null)
             fields.AddRange(newFields);
     }
     if (myEnv == null)
     {
         input.cancelTransaction();
         if (failSilently)
             return variables;
         else
             return null;
     }
     else
     {
         if (this.name != null)
             myEnv[name] = new OptionArray(name, input.getTransactionData());
         input.commitTransaction();
         return myEnv;
     }
 }
Exemplo n.º 2
0
 public void setValueFromStringTest()
 {
     OptionArray target = new OptionArray("test", "array int 4");
     target.setValueFromString(" 1 ,2 ,3 ");
     Assert.AreEqual(1, ((OptionInt)target.getOption(0)).Value);
     Assert.AreEqual(2, ((OptionInt)target.getOption(1)).Value);
     Assert.AreEqual(3, ((OptionInt)target.getOption(2)).Value);
 }
Exemplo n.º 3
0
 public void getValueAsStringTest()
 {
     OptionArray target = new OptionArray("test", "array int 4");
     target.setValueFromString("0,1,2,3");
     List<OptionInt> elements = new List<OptionInt>();
     for (int i = 0; i < target.Count; i++)
     {
         elements.Add((OptionInt)target.getOption(i));
     }
     target.setValueFromString(target.getValueAsString());
     for (int i = 0; i < target.Count; i++)
     {
         Assert.AreEqual(elements[i], target.getOption(i));
         Assert.AreEqual(i, ((OptionInt)target.getOption(i)).Value);
     }
 }
Exemplo n.º 4
0
 // substr arr start end
 public static Option substr(List<Option> args)
 {
     OptionArray arr = (OptionArray)args[0];
     int start = ((OptionInt)args[1]).Value;
     int end = ((OptionInt)args[2]).Value;
     OptionArray ret = new OptionArray("", "array " + arr.TypeName.Split()[1] + " " + (end - start));
     for (int i = start; i < end; i++)
         ret.setOption(i - start, arr.getOption(i));
     return ret;
 }
Exemplo n.º 5
0
        public static Option pack_bool(List<Option> args)
        {
            OptionArray arr = (OptionArray)args[0];
            List<Byte> data = new List<Byte>();
            byte b = 0;
            for (int i = 0; i < arr.Count; i++)
            {
                if (((OptionBool)arr.getOption(i)).Value)
                    b |= (byte)(1 << (i % 8));
                if (i != 0 && i % 8 == 0) // Full byte done, next please
                {
                    data.Add(b);
                    b = 0;
                }
            }

            OptionArray ret = new OptionArray("", "array bool " + data.Count);
            for(int i = 0; i < data.Count; i ++)
                ret.setOption(i, new OptionInt("", data[i], 0, 255, 1));

            return ret;
        }
Exemplo n.º 6
0
 private OptionArray(String name, OptionArray parent)
     : base(name)
 {
     this.typeName = parent.TypeName;
     this.parent = parent;
 }
Exemplo n.º 7
0
        public override Dictionary<String, Option> match(Dictionary<String, Option> variables,
            out List<byte[]> output,
            out List<Option> fields)
        {
            Dictionary<String, Option> myEnv = new Dictionary<String, Option>(variables);
            output = new List<byte[]>();
            List<byte[]> newOutput;
            fields = new List<Option>();
            foreach (Rule rule in rules)
            {
                List<Option> newFields;
                myEnv = rule.match(myEnv, out newOutput, out newFields);
                if (myEnv == null)
                    return null;
                if (newOutput != null)
                    output.AddRange(newOutput);
                if (newFields != null)
                    fields.AddRange(newFields);
            }

            if (this.name != null)
            {
                List<char> data = new List<char>();
                foreach (byte[] bs in output)
                    foreach (byte b in bs)
                        data.Add((char)b);
                myEnv[name] = new OptionArray(name, data);
            }
            return myEnv;
        }