Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Collections/StackBase.cs @ 15405

Last change on this file since 15405 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 2.8 KB
RevLine 
[2768]1using System;
2using System.Collections;
3using System.Collections.Generic;
4
5
[4068]6namespace 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
[2768]13    /// <summary>
[4068]14    /// the internal stack based on the .Net <see cref="Stack"/> implementation
[2768]15    /// </summary>
[4068]16    private Stack<T> InnerStack;
17    #endregion
[2768]18
[4068]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;
[2768]29
[4068]30    #region Constructor
31    /// <summary>
32    /// Initializes a new instance of the <see cref="T:StackBase&lt;T&gt;"/> class.
33    /// </summary>
34    public StackBase() {
35      InnerStack = new Stack<T>();
36    }
37    #endregion
[2768]38
[4068]39    #region Methods
[2768]40
[4068]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    }
[2768]48
49
[4068]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) {
[2768]55
[4068]56      this.InnerStack.Push(item);
57      RaiseOnItemPushed(item);
[2768]58
[4068]59    }
[2768]60
[4068]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    }
[2768]71
[4068]72    /// <summary>
73    /// Peeks the next item in the stack
74    /// </summary>
75    /// <returns></returns>
76    public T Peek() {
77      return InnerStack.Peek();
78    }
[2768]79
80
[4068]81    /// <summary>
82    /// Converts the stack to an array.
83    /// </summary>
84    /// <returns></returns>
85    public T[] ToArray() {
86      return InnerStack.ToArray();
87    }
[2768]88
89
[4068]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    }
[2768]98
[4068]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    }
[2768]107
108
[4068]109    #endregion
[2768]110
[4068]111  }
[2768]112}
Note: See TracBrowser for help on using the repository browser.