Private
Public Access
Documented IfChunk
This commit is contained in:
1 parent
ab37eaf3d0
commit
54edb0cec2
1 file changed
+17
-1
@@ -2,23 +2,39 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Advanced_Software_Engineering.Verbs.Flow {
|
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||||
|
/// <summary>
|
||||||
|
/// A simple If Object
|
||||||
|
/// </summary>
|
||||||
public class IfChunk : VerbChunk, IVerbChunk, IVerb {
|
public class IfChunk : VerbChunk, IVerbChunk, IVerb {
|
||||||
private readonly IValue conditional;
|
private readonly IValue conditional;
|
||||||
private readonly ValueStorage valueStorage;
|
private readonly ValueStorage valueStorage;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new if object
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="valueStorage">The ValueStorage for increasing and decreasing the stack</param>
|
||||||
|
/// <param name="conditional">Preferably <see cref="Value.ValueTypes.BoolValue"/>, if the chunk should execute.</param>
|
||||||
public IfChunk(ValueStorage valueStorage, IValue conditional) : base() {
|
public IfChunk(ValueStorage valueStorage, IValue conditional) : base() {
|
||||||
this.conditional = conditional;
|
this.conditional = conditional;
|
||||||
this.valueStorage = valueStorage;
|
this.valueStorage = valueStorage;
|
||||||
valueStorage.IncreaseStack();
|
valueStorage.IncreaseStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new if object
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="valueStorage">The ValueStorage for increasing and decreasing the stack</param>
|
||||||
|
/// <param name="conditional">Preferably <see cref="Value.ValueTypes.BoolValue"/>, if the chunk should execute.</param>
|
||||||
|
/// <param name="oneLineVerb">A verb to execute in a single line</param>
|
||||||
public IfChunk(ValueStorage valueStorage, IValue conditional, IVerb oneLineVerb) : base(new List<IVerb> { oneLineVerb }) {
|
public IfChunk(ValueStorage valueStorage, IValue conditional, IVerb oneLineVerb) : base(new List<IVerb> { oneLineVerb }) {
|
||||||
this.conditional = conditional;
|
this.conditional = conditional;
|
||||||
this.valueStorage = valueStorage;
|
this.valueStorage = valueStorage;
|
||||||
valueStorage.IncreaseStack();
|
valueStorage.IncreaseStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes the chunk if the conditional is true
|
||||||
|
/// </summary>
|
||||||
public new void ExecuteVerb() {
|
public new void ExecuteVerb() {
|
||||||
valueStorage.IncreaseStack();
|
valueStorage.IncreaseStack();
|
||||||
if (conditional.ToBool()) base.ExecuteVerb();
|
if (conditional.ToBool()) base.ExecuteVerb();
|
||||||
|
|||||||
Reference in new issue
Block a user