Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DataStack.cs
Go to the documentation of this file.
1 #region License
2 /* **********************************************************************************
3  * Copyright (c) Roman Ivantsov
4  * This source code is subject to terms and conditions of the MIT License
5  * for Irony. A copy of the license can be found in the License.txt file
6  * at the root of this distribution.
7  * By using this source code in any fashion, you are agreeing to be bound by the terms of the
8  * MIT License.
9  * You must not remove this notice from this software.
10  * **********************************************************************************/
11 #endregion
12 
13 using System;
14 using System.Collections.Generic;
15 using System.Linq;
16 using System.Text;
17 
18 namespace Irony.Interpreter {
19  public class DataStack {
20 
21  List<object> _data = new List<object>(16);
22  object _lastPushedItem;
23  object _unassigned; //Unassigned singleton value
24 
25  public void Init(object unassigned) {
26  _unassigned = unassigned;
27  _lastPushedItem = unassigned;
28  _data.Clear();
29  }
30 
31  public int Count {
32  get {return _data.Count;}
33  }
34  public object this[int index] {
35  get {return _data[_data.Count - 1 - index]; }
36  }
37  public object Top {
38  get { return _data[_data.Count - 1]; }
39  }
40  public object Pop() {
41  if (Count == 0)
43  var result = Top;
44  _data.RemoveAt(_data.Count - 1);
45  return result;
46  }
47  public void Pop(int count) {
48  _data.RemoveRange(_data.Count - count, count);
49  }
50  public void PopUntil(int toCount) {
51  if (toCount >= _data.Count) return;
52  Pop(_data.Count - toCount);
53  }
54  public void Push(object item) {
55  _lastPushedItem = item;
56  _data.Add(item);
57  }
58  public void Replace(int removeCount, object item) {
59  Pop(removeCount);
60  Push(item);
61  }
62  public object LastPushedItem {
63  get { return _lastPushedItem; }
64  }
65  public override string ToString() {
66  return this.GetType().Name + "(Count=" + Count + ")";
67  }
68 
69  }//class
70 }//namespace
A strongly-typed resource class, for looking up localized strings, etc.
static string ErrInternalErrDataPopFailed
Looks up a localized string similar to Interpreter error, DataStack.Pop() operation failed - stack is...
void Init(object unassigned)
Definition: DataStack.cs:25
void Replace(int removeCount, object item)
Definition: DataStack.cs:58
_In_ size_t count
Definition: DirectXTexP.h:174
void Push(object item)
Definition: DataStack.cs:54
void PopUntil(int toCount)
Definition: DataStack.cs:50
void Pop(int count)
Definition: DataStack.cs:47
override string ToString()
Definition: DataStack.cs:65