2 Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft
3 Permission is hereby granted, free of charge, to any person obtaining a copy
4 of this software and associated documentation files (the "Software"), to deal
5 in the Software without restriction, including without limitation the rights
6 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 copies of the Software, and to permit persons to whom the Software is
8 furnished to do so, subject to the following conditions:
10 The above copyright notice and this permission notice shall be included in
11 all copies or substantial portions of the Software.
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 using System.Diagnostics;
24 using SCG = System.Collections.Generic;
29 /// Characterize the mutual position of some view B (other) relative to view A (this)
31 enum MutualViewPosition
34 /// B contains A(this)
38 /// B is containd in A(this), but not vice versa
42 /// A and B does not overlap
46 /// A and B overlap, but neither is contained in the other
51 #region View List Nested class
53 /// This class is shared between the linked list and array list implementations.
55 /// <typeparam name="V"></typeparam>
57 class WeakViewList<V> where V : class
63 internal WeakReference weakview; internal Node prev, next;
64 internal Node(V view) { weakview = new WeakReference(view); }
66 internal Node Add(V view)
68 Node newNode = new Node(view);
69 if (start != null) { start.prev = newNode; newNode.next = start; }
73 internal void Remove(Node n)
75 if (n == start) { start = start.next; if (start != null) start.prev = null; }
76 else { n.prev.next = n.next; if (n.next != null) n.next.prev = n.prev; }
79 /// Note that it is safe to call views.Remove(view.myWeakReference) if view
80 /// is the currently yielded object
82 /// <returns></returns>
83 public SCG.IEnumerator<V> GetEnumerator()
88 //V view = n.weakview.Target as V; //This provokes a bug in the beta1 verifyer
89 object o = n.weakview.Target;
90 V view = o is V ? (V)o : null;