diff options
Diffstat (limited to 'OpenSim/Framework/UndoStack.cs')
-rw-r--r-- | OpenSim/Framework/UndoStack.cs | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/OpenSim/Framework/UndoStack.cs b/OpenSim/Framework/UndoStack.cs deleted file mode 100644 index fde63b1..0000000 --- a/OpenSim/Framework/UndoStack.cs +++ /dev/null | |||
@@ -1,114 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace OpenSim.Framework | ||
31 | { | ||
32 | /// <summary> | ||
33 | /// Undo stack. Deletes entries beyond a certain capacity | ||
34 | /// </summary> | ||
35 | /// <typeparam name="T"></typeparam> | ||
36 | [Serializable] | ||
37 | public class UndoStack<T> | ||
38 | { | ||
39 | private int m_new = 1; | ||
40 | private int m_old = 0; | ||
41 | private T[] m_Undos; | ||
42 | |||
43 | public UndoStack(int capacity) | ||
44 | { | ||
45 | m_Undos = new T[capacity + 1]; | ||
46 | } | ||
47 | |||
48 | public bool IsFull | ||
49 | { | ||
50 | get { return m_new == m_old; } | ||
51 | } | ||
52 | |||
53 | public int Capacity | ||
54 | { | ||
55 | get { return m_Undos.Length - 1; } | ||
56 | } | ||
57 | |||
58 | public int Count | ||
59 | { | ||
60 | get | ||
61 | { | ||
62 | int count = m_new - m_old - 1; | ||
63 | if (count < 0) | ||
64 | count += m_Undos.Length; | ||
65 | return count; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | public void Push(T item) | ||
70 | { | ||
71 | if (IsFull) | ||
72 | { | ||
73 | m_old++; | ||
74 | if (m_old >= m_Undos.Length) | ||
75 | m_old -= m_Undos.Length; | ||
76 | } | ||
77 | if (++m_new >= m_Undos.Length) | ||
78 | m_new -= m_Undos.Length; | ||
79 | m_Undos[m_new] = item; | ||
80 | } | ||
81 | |||
82 | public T Pop() | ||
83 | { | ||
84 | if (Count > 0) | ||
85 | { | ||
86 | T deleted = m_Undos[m_new]; | ||
87 | m_Undos[m_new--] = default(T); | ||
88 | if (m_new < 0) | ||
89 | m_new += m_Undos.Length; | ||
90 | return deleted; | ||
91 | } | ||
92 | else | ||
93 | throw new InvalidOperationException("Cannot pop from empty stack"); | ||
94 | } | ||
95 | |||
96 | public T Peek() | ||
97 | { | ||
98 | return m_Undos[m_new]; | ||
99 | } | ||
100 | |||
101 | public void Clear() | ||
102 | { | ||
103 | if (Count > 0) | ||
104 | { | ||
105 | for (int i = 0; i < m_Undos.Length; i++) | ||
106 | { | ||
107 | m_Undos[i] = default(T); | ||
108 | } | ||
109 | m_new = 1; | ||
110 | m_old = 0; | ||
111 | } | ||
112 | } | ||
113 | } | ||
114 | } | ||