aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/UndoStack.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/UndoStack.cs')
-rw-r--r--OpenSim/Framework/UndoStack.cs44
1 files changed, 17 insertions, 27 deletions
diff --git a/OpenSim/Framework/UndoStack.cs b/OpenSim/Framework/UndoStack.cs
index 0b97644..a49a0cc 100644
--- a/OpenSim/Framework/UndoStack.cs
+++ b/OpenSim/Framework/UndoStack.cs
@@ -26,8 +26,6 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
30using System.Text;
31 29
32namespace OpenSim.Framework 30namespace OpenSim.Framework
33{ 31{
@@ -38,35 +36,39 @@ namespace OpenSim.Framework
38 [Serializable] 36 [Serializable]
39 public class UndoStack<T> 37 public class UndoStack<T>
40 { 38 {
41
42 private int m_new = 1; 39 private int m_new = 1;
43 private int m_old = 0; 40 private int m_old = 0;
44 private T[] m_Undos; 41 private T[] m_Undos;
45 42
43 public UndoStack(int capacity)
44 {
45 m_Undos = new T[capacity + 1];
46 }
47
46 public bool IsFull 48 public bool IsFull
47 { 49 {
48 get 50 get { return m_new == m_old; }
49 {
50 return m_new == m_old;
51 }
52 } 51 }
53 52
54 53
55 public int Capacity 54 public int Capacity
56 { 55 {
56 get { return m_Undos.Length - 1; }
57 }
58
59 public int Count
60 {
57 get 61 get
58 { 62 {
59 return m_Undos.Length - 1; 63 int count = m_new - m_old - 1;
64 if (count < 0)
65 count += m_Undos.Length;
66 return count;
60 } 67 }
61 } 68 }
62 69
63
64 public UndoStack(int capacity)
65 {
66 m_Undos = new T[capacity + 1];
67 }
68 70
69 public void Push(T item) 71 public void Push(T item)
70 { 72 {
71 if (IsFull) 73 if (IsFull)
72 { 74 {
@@ -93,24 +95,13 @@ namespace OpenSim.Framework
93 throw new InvalidOperationException("Cannot pop from emtpy stack"); 95 throw new InvalidOperationException("Cannot pop from emtpy stack");
94 } 96 }
95 97
96 public int Count
97 {
98 get
99 {
100 int count = m_new - m_old - 1;
101 if (count < 0)
102 count += m_Undos.Length;
103 return count;
104 }
105 }
106
107 98
108 public T Peek() 99 public T Peek()
109 { 100 {
110 return m_Undos[m_new]; 101 return m_Undos[m_new];
111 } 102 }
112 103
113 104
114 public void Clear() 105 public void Clear()
115 { 106 {
116 if (Count > 0) 107 if (Count > 0)
@@ -123,6 +114,5 @@ namespace OpenSim.Framework
123 m_old = 0; 114 m_old = 0;
124 } 115 }
125 } 116 }
126
127 } 117 }
128} \ No newline at end of file 118} \ No newline at end of file