Private
Public Access
Better stack management
This commit is contained in:
1 parent
3b6bfa11a6
commit
d397454c00
4 files changed
+46
-27
No files matched your search
@@ -12,7 +12,7 @@ namespace Advanced_Software_Engineering {
|
||||
/// </summary>
|
||||
public class Drawer {
|
||||
|
||||
protected static Dictionary<int, ValueStorage> ValueStorages = new Dictionary<int, ValueStorage>();
|
||||
private ValueStorage valueStorage = new ValueStorage();
|
||||
|
||||
/// <summary>
|
||||
/// The starting color of the pen / brush
|
||||
@@ -67,7 +67,7 @@ namespace Advanced_Software_Engineering {
|
||||
pen = new Pen(defaultColor, defaultWidth);
|
||||
brush = new SolidBrush(defaultColor);
|
||||
fill = false;
|
||||
foreach (int valueStorage in ValueStorages.Keys) ValueStorages[valueStorage].Reset();
|
||||
valueStorage = new ValueStorage();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -189,16 +189,8 @@ namespace Advanced_Software_Engineering {
|
||||
graphics.FillRectangle(new SolidBrush(pen.Color), penPosition.X, penPosition.Y, 1, 1);
|
||||
}
|
||||
|
||||
public void SetStack(int name, ValueStorage value) {
|
||||
ValueStorages[name] = value;
|
||||
}
|
||||
|
||||
public ValueStorage GetStack(int name) {
|
||||
return ValueStorages[name];
|
||||
}
|
||||
|
||||
public bool CheckStackExists(int name) {
|
||||
return ValueStorages.ContainsKey(name);
|
||||
public ValueStorage GetValueStorage() {
|
||||
return valueStorage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+13
-3
@@ -1,12 +1,22 @@
|
||||
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||
|
||||
public class VerbChunk : IVerb {
|
||||
private readonly IVerb[] verbs;
|
||||
private readonly List<IVerb> verbs;
|
||||
|
||||
public VerbChunk(IVerb[] verbs) {
|
||||
public VerbChunk(List<IVerb> verbs) {
|
||||
this.verbs = verbs;
|
||||
}
|
||||
|
||||
public VerbChunk() {
|
||||
verbs = new List<IVerb> { };
|
||||
}
|
||||
|
||||
public void AddVerb(IVerb verb) {
|
||||
verbs.Add(verb);
|
||||
}
|
||||
|
||||
public void ExecuteVerb() {
|
||||
foreach (IVerb verb in verbs) verb.ExecuteVerb();
|
||||
}
|
||||
|
||||
+28
-5
@@ -3,7 +3,8 @@
|
||||
namespace Advanced_Software_Engineering.Verbs.Value {
|
||||
public class ValueStorage {
|
||||
|
||||
protected Dictionary<string, IValue> Variables = new Dictionary<string, IValue>();
|
||||
protected int currentStack;
|
||||
protected Dictionary<int,Dictionary<string, IValue>> Variables = new Dictionary<int,Dictionary<string, IValue>>();
|
||||
|
||||
public ValueStorage() {
|
||||
Reset();
|
||||
@@ -11,19 +12,41 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
||||
|
||||
public void Reset() {
|
||||
Variables.Clear();
|
||||
SetStack(0);
|
||||
}
|
||||
|
||||
public void Reset(int stack) {
|
||||
Variables[stack].Clear();
|
||||
}
|
||||
|
||||
public void SetStack(int stack) {
|
||||
currentStack = stack;
|
||||
if (!Variables.ContainsKey(stack)) Variables.Add(currentStack, new Dictionary<string, IValue>());
|
||||
}
|
||||
|
||||
public void SetVariable(string name, int stack, IValue value) {
|
||||
Variables[stack][name] = value;
|
||||
}
|
||||
|
||||
public void SetVariable(string name, IValue value) {
|
||||
Variables[name] = value;
|
||||
SetVariable(name, currentStack, value);
|
||||
}
|
||||
|
||||
public IValue GetVariable(string name, int stack) {
|
||||
return Variables[stack][name];
|
||||
}
|
||||
|
||||
public IValue GetVariable(string name) {
|
||||
return Variables[name];
|
||||
return GetVariable(name, currentStack);
|
||||
}
|
||||
|
||||
public bool CheckVariableExists(string name, int stack) {
|
||||
if (name == null) return false;
|
||||
return Variables[stack].ContainsKey(name);
|
||||
}
|
||||
|
||||
public bool CheckVariableExists(string name) {
|
||||
if (name == null) return false;
|
||||
return Variables.ContainsKey(name);
|
||||
return CheckVariableExists(name, currentStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,7 @@ namespace Advanced_Software_Engineering {
|
||||
public static IVerb MakeVerb(Drawer drawer, string fullCommand) {
|
||||
int stackLevel = 0;
|
||||
|
||||
ValueStorage rootValueStorage;
|
||||
if (drawer.CheckStackExists(stackLevel)) {
|
||||
rootValueStorage = drawer.GetStack(stackLevel);
|
||||
} else {
|
||||
rootValueStorage = new ValueStorage();
|
||||
drawer.SetStack(stackLevel, rootValueStorage);
|
||||
}
|
||||
ValueStorage rootValueStorage = drawer.GetValueStorage();
|
||||
|
||||
CommandAndParameterParserResult result = HelperFunctions.CommandAndParameterParser(fullCommand);
|
||||
|
||||
|
||||
Reference in new issue
Block a user