SoftwareEngineering2/winVCR/VCRlogic/SMtape.cs
2019-04-09 16:14:26 +02:00

122 lines
2.0 KiB
C#

using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using VCRlogic;
namespace VCRlogic
{
public static class SMtape
{
private static StateTape _concreteState;
public delegate void TapeEventHandler();
public static event TapeEventHandler evIntape;
public static event TapeEventHandler evOuttape;
public static void initSMtape()
{
setState(new StapeNoTapeIn());
//evIntape += evIntape;
}
public static void setState(StateTape e)
{
_concreteState = null;
_concreteState = e;
}
public static void insertTape()
{
if (evIntape != null)
{
evIntape();
}
}
public static void ejectTape()
{
if (evOuttape != null)
{
evOuttape();
}
}
}
}
public abstract class StateTape
{
public abstract void evIntape();
public abstract void evOuttape();
}
public class StapeNoTapeIn : StateTape
{
public override void evIntape()
{
Debug.Print("tape is now in\n");
//unsub
SMtape.evIntape -= evIntape;
SMtape.setState(new StapeTapeInNotEnd());
}
public override void evOuttape()
{
}
public StapeNoTapeIn()
{
// sub to event
SMtape.evIntape += evIntape;
}
}
public class StapeTapeInNotEnd : StateTape
{
public override void evIntape()
{
}
public override void evOuttape()
{
Debug.Print("tape is now out\n");
//unsub
SMtape.evOuttape -= evOuttape;
SMtape.setState(new StapeNoTapeIn());
}
public StapeTapeInNotEnd()
{
//sub
SMtape.evOuttape += evOuttape;
}
}
/*
public class StapeTapeInEnd : StateTape
{
public override void setStateText()
{
throw new NotImplementedException();
}
}
*/