Private
Public Access
Documented MethodChunk
This commit is contained in:
1 parent
81b0335555
commit
e84fed3f8c
1 file changed
+55
-5
+55
-5
@@ -3,7 +3,9 @@ using System.Collections.Generic;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
namespace Advanced_Software_Engineering.Verbs.Flow {
|
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||||
|
/// <summary>
|
||||||
|
/// The method chunk class
|
||||||
|
/// </summary>
|
||||||
public class MethodChunk : VerbChunk, IVerb, IValue {
|
public class MethodChunk : VerbChunk, IVerb, IValue {
|
||||||
private readonly ValueStorage valueStorage;
|
private readonly ValueStorage valueStorage;
|
||||||
private readonly DeclareVariable[] variables;
|
private readonly DeclareVariable[] variables;
|
||||||
@@ -11,25 +13,38 @@ namespace Advanced_Software_Engineering.Verbs.Flow {
|
|||||||
private bool init = false;
|
private bool init = false;
|
||||||
private IValue result;
|
private IValue result;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The method chunk
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="valueStorage">The ValueStorage for increasing and decreasing the stack</param>
|
||||||
|
/// <param name="variables">The variables to pass into the method</param>
|
||||||
public MethodChunk(ValueStorage valueStorage, DeclareVariable[] variables) : base() {
|
public MethodChunk(ValueStorage valueStorage, DeclareVariable[] variables) : base() {
|
||||||
this.valueStorage = valueStorage;
|
this.valueStorage = valueStorage;
|
||||||
this.variables = variables;
|
this.variables = variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all of the variable names
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The names of all the variables</returns>
|
||||||
public List<string> GetVariableNames() {
|
public List<string> GetVariableNames() {
|
||||||
List<string> VariableNames = new List<string>();
|
List<string> VariableNames = new List<string>();
|
||||||
foreach (DeclareVariable variable in variables) VariableNames.Add(variable.GetName());
|
foreach (DeclareVariable variable in variables) VariableNames.Add(variable.GetName());
|
||||||
return VariableNames;
|
return VariableNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeclareVariable[] GetVariables() {
|
/// <summary>
|
||||||
return variables;
|
/// MUST BE CALLED. This method is really important for setting the updated values into the method's stack.
|
||||||
}
|
/// </summary>
|
||||||
|
/// <param name="updateVariables">The new values of the method</param>
|
||||||
public void SetVariableValues(UpdateVariable[] updateVariables) {
|
public void SetVariableValues(UpdateVariable[] updateVariables) {
|
||||||
this.updateVariables = updateVariables;
|
this.updateVariables = updateVariables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This method allows the method chunk to replicate itself before being ran. Essential for recursion.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A method chunk with the exact same values and verbs</returns>
|
||||||
public MethodChunk DuplicateForExecution() {
|
public MethodChunk DuplicateForExecution() {
|
||||||
MethodChunk method = new MethodChunk(valueStorage, variables);
|
MethodChunk method = new MethodChunk(valueStorage, variables);
|
||||||
method.SetVariableValues(updateVariables);
|
method.SetVariableValues(updateVariables);
|
||||||
@@ -39,6 +54,9 @@ namespace Advanced_Software_Engineering.Verbs.Flow {
|
|||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes the method chunk.
|
||||||
|
/// </summary>
|
||||||
public new void ExecuteVerb() {
|
public new void ExecuteVerb() {
|
||||||
init = false;
|
init = false;
|
||||||
result = null;
|
result = null;
|
||||||
@@ -60,34 +78,66 @@ namespace Advanced_Software_Engineering.Verbs.Flow {
|
|||||||
valueStorage.DecreaseStack();
|
valueStorage.DecreaseStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a result from the method. (Experimental)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>the result</returns>
|
||||||
public IValue GetResult() {
|
public IValue GetResult() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clones the result of the method (Experimental)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
public IValue Clone() {
|
public IValue Clone() {
|
||||||
return GetResult().Clone();
|
return GetResult().Clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the original type of the result of the method (Experimental)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
public string GetOriginalType() {
|
public string GetOriginalType() {
|
||||||
return GetResult().GetOriginalType();
|
return GetResult().GetOriginalType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the result is initilised (Experimental)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
public bool isInitialised() {
|
public bool isInitialised() {
|
||||||
return init;
|
return init;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts the result to boolean (Experimental)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>boolean representation of the result</returns>
|
||||||
public bool ToBool() {
|
public bool ToBool() {
|
||||||
return GetResult().ToBool();
|
return GetResult().ToBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts the result to color (Experimental)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>color representation of the result</returns>
|
||||||
public Color ToColor() {
|
public Color ToColor() {
|
||||||
return GetResult().ToColor();
|
return GetResult().ToColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts the result to double (Experimental)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>double representation of the result</returns>
|
||||||
public double ToDouble() {
|
public double ToDouble() {
|
||||||
return GetResult().ToDouble();
|
return GetResult().ToDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts the result to integer (Experimental)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>integer representation of the result</returns>
|
||||||
public int ToInt() {
|
public int ToInt() {
|
||||||
return GetResult().ToInt();
|
return GetResult().ToInt();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user