Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Common/UndoSystem/ActionStack.cs @ 13348

Last change on this file since 13348 was 12503, checked in by aballeit, 10 years ago

#2283 added GUI and charts; fixed MCTS

File size: 958 bytes
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Diagnostics;
6
7namespace Microsoft.Research.DynamicDataDisplay.Common.UndoSystem
8{
9  [DebuggerDisplay("Count = {Count}")]
10  public sealed class ActionStack
11  {
12    private readonly Stack<UndoAction> stack = new Stack<UndoAction>();
13
14    public void Push(UndoAction action)
15    {
16      stack.Push(action);
17
18      if (stack.Count == 1)
19        RaiseIsEmptyChanged();
20    }
21
22    public UndoAction Pop()
23    {
24      var action = stack.Pop();
25
26      if (stack.Count == 0)
27        RaiseIsEmptyChanged();
28
29      return action;
30    }
31
32    public int Count { get { return stack.Count; } }
33
34    public void Clear()
35    {
36      stack.Clear();
37      RaiseIsEmptyChanged();
38    }
39
40    public bool IsEmpty
41    {
42      get { return stack.Count == 0; }
43    }
44
45    private void RaiseIsEmptyChanged()
46    {
47      IsEmptyChanged.Raise(this);
48    }
49    public event EventHandler IsEmptyChanged;
50  }
51}
Note: See TracBrowser for help on using the repository browser.