aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/FindallAnswers.cs
diff options
context:
space:
mode:
authorCharles Krinke2008-05-31 17:52:44 +0000
committerCharles Krinke2008-05-31 17:52:44 +0000
commit25b7d9944d5875e1887eed156f31dd5779761265 (patch)
tree2c4f6f066ef2b5f60d399ab4862ed7b9dbe0c78f /OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/FindallAnswers.cs
parent* Implements UserServer logoff in a few situations (diff)
downloadopensim-SC_OLD-25b7d9944d5875e1887eed156f31dd5779761265.zip
opensim-SC_OLD-25b7d9944d5875e1887eed156f31dd5779761265.tar.gz
opensim-SC_OLD-25b7d9944d5875e1887eed156f31dd5779761265.tar.bz2
opensim-SC_OLD-25b7d9944d5875e1887eed156f31dd5779761265.tar.xz
Mantis#1314. Thank you kindly, Kinoc for YieldProlog.
I have added everything *except* the patch to .../LSL/Compiler.cs. The Compiler.cs patch has a namespace issue. Lets make a second patch to close the gap.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/FindallAnswers.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/FindallAnswers.cs103
1 files changed, 103 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/FindallAnswers.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/FindallAnswers.cs
new file mode 100644
index 0000000..2978cee
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/FindallAnswers.cs
@@ -0,0 +1,103 @@
1/*
2 * Copyright (C) 2007-2008, Jeff Thompson
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of the copyright holder nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31using System;
32using System.Collections;
33using System.Collections.Generic;
34
35namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
36{
37 /// <summary>
38 /// A FindallAnswers holds answers for findall.
39 /// </summary>
40 public class FindallAnswers
41 {
42 private object _template;
43 private List<object> _bagArray;
44
45 public FindallAnswers(object Template)
46 {
47 _template = Template;
48 _bagArray = new List<object>();
49 }
50
51 public void add()
52 {
53 _bagArray.Add(YP.makeCopy(_template, new Variable.CopyStore()));
54 }
55
56 public List<object> resultArray()
57 {
58 return _bagArray;
59 }
60
61 /// <summary>
62 /// Unify Bag with the result. This frees the internal answers, so you can only call this once.
63 /// </summary>
64 /// <param name="Bag"></param>
65 /// <returns></returns>
66 public IEnumerable<bool> result(object Bag)
67 {
68 object result = ListPair.make(_bagArray);
69 // Try to free the memory.
70 _bagArray = null;
71 return YP.unify(Bag, result);
72 }
73
74 /// <summary>
75 /// This is a simplified findall when the goal is a single call.
76 /// </summary>
77 /// <param name="Template"></param>
78 /// <param name="goal"></param>
79 /// <param name="Bag"></param>
80 /// <returns></returns>
81 public static IEnumerable<bool> findall(object Template, IEnumerable<bool> goal, object Bag)
82 {
83 FindallAnswers findallAnswers = new FindallAnswers(Template);
84 foreach (bool l1 in goal)
85 findallAnswers.add();
86 return findallAnswers.result(Bag);
87 }
88
89 /// <summary>
90 /// Like findall, except return an array of the results.
91 /// </summary>
92 /// <param name="template"></param>
93 /// <param name="goal"></param>
94 /// <returns></returns>
95 public static List<object> findallArray(object Template, IEnumerable<bool> goal)
96 {
97 FindallAnswers findallAnswers = new FindallAnswers(Template);
98 foreach (bool l1 in goal)
99 findallAnswers.add();
100 return findallAnswers.resultArray();
101 }
102 }
103}