diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/FindallAnswers.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/FindallAnswers.cs | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/FindallAnswers.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/FindallAnswers.cs new file mode 100644 index 0000000..28709e1 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/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 | |||
31 | using System; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.Shared.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 | } | ||