Changeset 4068 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Collections/StackBase.cs
- Timestamp:
- 07/22/10 00:44:01 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Collections/StackBase.cs
r2768 r4068 2 2 using System.Collections; 3 3 using System.Collections.Generic; 4 using System.Diagnostics;5 4 6 5 7 namespace Netron.Diagramming.Core 8 { 6 namespace Netron.Diagramming.Core { 7 /// <summary> 8 /// This is a wrapper around the <see cref="Stack"/> which communicates Push and Pop events 9 /// </summary> 10 /// <typeparam name="T"></typeparam> 11 public class StackBase<T> { 12 #region Fields 9 13 /// <summary> 10 /// This is a wrapper around the <see cref="Stack"/> which communicates Push and Pop events14 /// the internal stack based on the .Net <see cref="Stack"/> implementation 11 15 /// </summary> 12 /// <typeparam name="T"></typeparam> 13 public class StackBase<T> 14 { 15 #region Fields 16 /// <summary> 17 /// the internal stack based on the .Net <see cref="Stack"/> implementation 18 /// </summary> 19 private Stack<T> InnerStack; 20 #endregion 16 private Stack<T> InnerStack; 17 #endregion 21 18 22 23 24 25 26 27 28 29 30 31 19 #region Events 20 /// <summary> 21 /// Occurs when an item is pushed onto the stack 22 /// </summary> 23 public event EventHandler<CollectionEventArgs<T>> OnItemPushed; 24 /// <summary> 25 /// Occurs when an item is popped from the stack 26 /// </summary> 27 public event EventHandler<CollectionEventArgs<T>> OnItemPopped; 28 #endregion; 32 29 33 #region Constructor 34 /// <summary> 35 /// Initializes a new instance of the <see cref="T:StackBase<T>"/> class. 36 /// </summary> 37 public StackBase() 38 { 39 InnerStack = new Stack<T>(); 40 } 41 #endregion 30 #region Constructor 31 /// <summary> 32 /// Initializes a new instance of the <see cref="T:StackBase<T>"/> class. 33 /// </summary> 34 public StackBase() { 35 InnerStack = new Stack<T>(); 36 } 37 #endregion 42 38 43 39 #region Methods 44 40 45 /// <summary> 46 /// Gets the number of elements in the stack 47 /// </summary> 48 /// <value>The count.</value> 49 public int Count 50 { 51 get { return InnerStack.Count; } 52 } 41 /// <summary> 42 /// Gets the number of elements in the stack 43 /// </summary> 44 /// <value>The count.</value> 45 public int Count { 46 get { return InnerStack.Count; } 47 } 53 48 54 49 55 /// <summary> 56 /// Pushes the specified item. 57 /// </summary> 58 /// <param name="item">A parameter of the generics Type T</param> 59 public void Push(T item) 60 { 50 /// <summary> 51 /// Pushes the specified item. 52 /// </summary> 53 /// <param name="item">A parameter of the generics Type T</param> 54 public void Push(T item) { 61 55 62 63 56 this.InnerStack.Push(item); 57 RaiseOnItemPushed(item); 64 58 65 59 } 66 60 67 /// <summary> 68 /// Pops the next item from the stack 69 /// </summary> 70 /// <returns></returns> 71 public T Pop() 72 { 73 T item = 74 InnerStack.Pop(); 75 RaiseOnItemPopped(item); 76 return item; 77 } 61 /// <summary> 62 /// Pops the next item from the stack 63 /// </summary> 64 /// <returns></returns> 65 public T Pop() { 66 T item = 67 InnerStack.Pop(); 68 RaiseOnItemPopped(item); 69 return item; 70 } 78 71 79 /// <summary> 80 /// Peeks the next item in the stack 81 /// </summary> 82 /// <returns></returns> 83 public T Peek() 84 { 85 return InnerStack.Peek(); 86 } 72 /// <summary> 73 /// Peeks the next item in the stack 74 /// </summary> 75 /// <returns></returns> 76 public T Peek() { 77 return InnerStack.Peek(); 78 } 87 79 88 80 89 /// <summary> 90 /// Converts the stack to an array. 91 /// </summary> 92 /// <returns></returns> 93 public T[] ToArray() 94 { 95 return InnerStack.ToArray(); 96 } 81 /// <summary> 82 /// Converts the stack to an array. 83 /// </summary> 84 /// <returns></returns> 85 public T[] ToArray() { 86 return InnerStack.ToArray(); 87 } 97 88 98 89 99 /// <summary> 100 /// Raises the <see cref="OnItemPushed"/>. 101 /// </summary> 102 /// <param name="item">A parameter of the generics Type T</param> 103 private void RaiseOnItemPushed(T item) 104 { 105 EventHandler<CollectionEventArgs<T>> handler = OnItemPushed; 106 handler(this, new CollectionEventArgs<T>(item)); 107 } 90 /// <summary> 91 /// Raises the <see cref="OnItemPushed"/>. 92 /// </summary> 93 /// <param name="item">A parameter of the generics Type T</param> 94 private void RaiseOnItemPushed(T item) { 95 EventHandler<CollectionEventArgs<T>> handler = OnItemPushed; 96 handler(this, new CollectionEventArgs<T>(item)); 97 } 108 98 109 /// <summary> 110 /// Raises the on OnItemPopped event. 111 /// </summary> 112 /// <param name="item">A parameter of the generics Type T</param> 113 private void RaiseOnItemPopped(T item) 114 { 115 EventHandler<CollectionEventArgs<T>> handler = OnItemPopped; 116 handler(this, new CollectionEventArgs<T>(item)); 117 } 99 /// <summary> 100 /// Raises the on OnItemPopped event. 101 /// </summary> 102 /// <param name="item">A parameter of the generics Type T</param> 103 private void RaiseOnItemPopped(T item) { 104 EventHandler<CollectionEventArgs<T>> handler = OnItemPopped; 105 handler(this, new CollectionEventArgs<T>(item)); 106 } 118 107 119 108 120 109 #endregion 121 110 122 111 } 123 112 }
Note: See TracChangeset
for help on using the changeset viewer.