Exemplo n.º 1
0
		public override IBELObject Expose(ExecutionContext ctx)
		{
			BELArray a = new BELArray();
			foreach (ExposableParseTreeNode each in _Array)
				a.Add(each.Expose(ctx));
			return a;
		}
Exemplo n.º 2
0
		public BELArray Snip(int maxCount)
		{
			BELArray answer = new BELArray();			
			foreach (IBELObject each in Array)
			{
				answer.Add(each);
				if (answer.Count >= maxCount)
					return answer;
			}
			return answer;
		}
Exemplo n.º 3
0
		public BELArray Select(ExecutionContext ctx, Block block)
		{
			BELArray answer = new BELArray();
			
			foreach (IBELObject each in Array)
			{
				ArrayList parms = new ArrayList();
				parms.Add(each);
				IBELObject objValue = block.Value(ctx, parms);
				BELBoolean test = objValue as BELBoolean;
				if (test == null)
					throw new ExecutionException("Select block must evaluate to a boolean.  Got " + BELType.BELTypeForType(objValue.GetType()).ExternalTypeName + " instead.");
				if (test.Value)
					answer.Add(each);
			}
			return answer;
		}
Exemplo n.º 4
0
		public BELArray Collect(ExecutionContext ctx, Block block)
		{
			BELArray answer = new BELArray();
			
			foreach (IBELObject each in Array)
			{
				ArrayList parms = new ArrayList();
				parms.Add(each);
				answer.Add(block.Value(ctx, parms));
			}
			return answer;
		}
Exemplo n.º 5
0
        public BELArray SortBy(ExecutionContext ctx, Block block)
        {
            // This code formerly sorted the list by having the IComparer do the comparison.
            // This was resulting in lots of superficial comparisons, as the block was being
            // evaluated lots of extra times - for the left and the right item on every comparison.
            // Instead, I changed it to rip through the array, evaluate the block exaclty once
            // for each item, and then do the sort on just the values.
            List<BelArrayEntry> entries = new List<BelArrayEntry>();

            try
            {
                foreach (IBELObject entry in Array)
                {
                    ArrayList a1 = new ArrayList();
                    a1.Add(entry);
                    IBELObject value = block.Value(ctx, a1);

                    IComparable comparable = value as IComparable;
                    if (comparable == null)
                    {
                        throw new ExecutionException(null, "Can not compare objects of type " + BELType.ExternalTypeNameForType(value.GetType()));
                    }

                    entries.Add(new BelArrayEntry(entry, comparable));
                }

                entries.Sort(new BelArrayEntry.Comparer());

            }
            catch (InvalidOperationException e)
            {
                throw e.InnerException;
            }

            BELArray results = new BELArray();
            foreach (BelArrayEntry entry in entries)
            {
                results.Add(entry.Entry);
            }
            return results;
        }