using System;
using System.Collections;
using System.Collections.Generic;
namespace Netron.Diagramming.Core {
///
/// This is a wrapper around the which communicates Push and Pop events
///
///
public class StackBase {
#region Fields
///
/// the internal stack based on the .Net implementation
///
private Stack InnerStack;
#endregion
#region Events
///
/// Occurs when an item is pushed onto the stack
///
public event EventHandler> OnItemPushed;
///
/// Occurs when an item is popped from the stack
///
public event EventHandler> OnItemPopped;
#endregion;
#region Constructor
///
/// Initializes a new instance of the class.
///
public StackBase() {
InnerStack = new Stack();
}
#endregion
#region Methods
///
/// Gets the number of elements in the stack
///
/// The count.
public int Count {
get { return InnerStack.Count; }
}
///
/// Pushes the specified item.
///
/// A parameter of the generics Type T
public void Push(T item) {
this.InnerStack.Push(item);
RaiseOnItemPushed(item);
}
///
/// Pops the next item from the stack
///
///
public T Pop() {
T item =
InnerStack.Pop();
RaiseOnItemPopped(item);
return item;
}
///
/// Peeks the next item in the stack
///
///
public T Peek() {
return InnerStack.Peek();
}
///
/// Converts the stack to an array.
///
///
public T[] ToArray() {
return InnerStack.ToArray();
}
///
/// Raises the .
///
/// A parameter of the generics Type T
private void RaiseOnItemPushed(T item) {
EventHandler> handler = OnItemPushed;
handler(this, new CollectionEventArgs(item));
}
///
/// Raises the on OnItemPopped event.
///
/// A parameter of the generics Type T
private void RaiseOnItemPopped(T item) {
EventHandler> handler = OnItemPopped;
handler(this, new CollectionEventArgs(item));
}
#endregion
}
}