opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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.Generic; |
||
33 | |||
34 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog |
||
35 | { |
||
36 | public class Functor3 : IUnifiable |
||
37 | { |
||
38 | public readonly Atom _name; |
||
39 | public readonly object _arg1; |
||
40 | public readonly object _arg2; |
||
41 | public readonly object _arg3; |
||
42 | |||
43 | public Functor3(Atom name, object arg1, object arg2, object arg3) |
||
44 | { |
||
45 | _name = name; |
||
46 | _arg1 = arg1; |
||
47 | _arg2 = arg2; |
||
48 | _arg3 = arg3; |
||
49 | } |
||
50 | |||
51 | public Functor3(string name, object arg1, object arg2, object arg3) |
||
52 | : this(Atom.a(name), arg1, arg2, arg3) |
||
53 | { |
||
54 | } |
||
55 | |||
56 | // disable warning on l1, don't see how we can |
||
57 | // code this differently |
||
58 | #pragma warning disable 0168, 0219 |
||
59 | /// If arg is another Functor3, then succeed (yield once) if this and arg have the |
||
60 | /// same name and all functor args unify, otherwise fail (don't yield). |
||
61 | /// If arg is a Variable, then call its unify to unify with this. |
||
62 | /// Otherwise fail (don't yield). |
||
63 | public IEnumerable<bool> unify(object arg) |
||
64 | { |
||
65 | arg = YP.getValue(arg); |
||
66 | if (arg is Functor3) |
||
67 | { |
||
68 | Functor3 argFunctor = (Functor3)arg; |
||
69 | if (_name.Equals(argFunctor._name)) |
||
70 | { |
||
71 | foreach (bool l1 in YP.unify(_arg1, argFunctor._arg1)) |
||
72 | { |
||
73 | foreach (bool l2 in YP.unify(_arg2, argFunctor._arg2)) |
||
74 | { |
||
75 | foreach (bool l3 in YP.unify(_arg3, argFunctor._arg3)) |
||
76 | yield return false; |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | else if (arg is Variable) |
||
82 | { |
||
83 | foreach (bool l1 in ((Variable)arg).unify(this)) |
||
84 | yield return false; |
||
85 | } |
||
86 | } |
||
87 | #pragma warning restore 0168, 0219 |
||
88 | |||
89 | public override string ToString() |
||
90 | { |
||
91 | return _name + "(" + YP.getValue(_arg1) + ", " + YP.getValue(_arg2) + ", " + |
||
92 | YP.getValue(_arg3) + ")"; |
||
93 | } |
||
94 | |||
95 | public bool termEqual(object term) |
||
96 | { |
||
97 | term = YP.getValue(term); |
||
98 | if (term is Functor3) |
||
99 | { |
||
100 | Functor3 termFunctor = (Functor3)term; |
||
101 | return _name.Equals(termFunctor._name) && YP.termEqual(_arg1, termFunctor._arg1) |
||
102 | && YP.termEqual(_arg2, termFunctor._arg2) |
||
103 | && YP.termEqual(_arg3, termFunctor._arg3); |
||
104 | } |
||
105 | return false; |
||
106 | } |
||
107 | |||
108 | public bool lessThan(Functor3 functor) |
||
109 | { |
||
110 | // Do the equal check first since it is faster. |
||
111 | if (!_name.Equals(functor._name)) |
||
112 | return _name.lessThan(functor._name); |
||
113 | |||
114 | if (!YP.termEqual(_arg1, functor._arg1)) |
||
115 | return YP.termLessThan(_arg1, functor._arg1); |
||
116 | |||
117 | if (!YP.termEqual(_arg2, functor._arg2)) |
||
118 | return YP.termLessThan(_arg2, functor._arg2); |
||
119 | |||
120 | return YP.termLessThan(_arg3, functor._arg3); |
||
121 | } |
||
122 | |||
123 | public bool ground() |
||
124 | { |
||
125 | return YP.ground(_arg1) && YP.ground(_arg2) && YP.ground(_arg3); |
||
126 | } |
||
127 | |||
128 | public void addUniqueVariables(List<Variable> variableSet) |
||
129 | { |
||
130 | YP.addUniqueVariables(_arg1, variableSet); |
||
131 | YP.addUniqueVariables(_arg2, variableSet); |
||
132 | YP.addUniqueVariables(_arg3, variableSet); |
||
133 | } |
||
134 | |||
135 | public object makeCopy(Variable.CopyStore copyStore) |
||
136 | { |
||
137 | return new Functor3(_name, YP.makeCopy(_arg1, copyStore), |
||
138 | YP.makeCopy(_arg2, copyStore), YP.makeCopy(_arg3, copyStore)); |
||
139 | } |
||
140 | } |
||
141 | } |