2019-07-21 13:11:00 +01:00
|
|
|
|
// <copyright file="Test.cs" company="Adrian Conlon">
|
|
|
|
|
// Copyright (c) Adrian Conlon. All rights reserved.
|
|
|
|
|
// </copyright>
|
|
|
|
|
namespace Fuse
|
2019-07-19 23:59:32 +01:00
|
|
|
|
{
|
2019-07-21 09:10:45 +01:00
|
|
|
|
using System;
|
2019-07-19 23:59:32 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2019-08-13 18:51:34 +01:00
|
|
|
|
public class Test<T>
|
|
|
|
|
where T : Fuse.IRegisterState, new()
|
2019-07-19 23:59:32 +01:00
|
|
|
|
{
|
2019-07-21 09:28:49 +01:00
|
|
|
|
private readonly List<MemoryDatum> memoryData = new List<MemoryDatum>();
|
2019-07-19 23:59:32 +01:00
|
|
|
|
|
|
|
|
|
public string Description { get; private set; }
|
|
|
|
|
|
2019-08-13 18:51:34 +01:00
|
|
|
|
public T RegisterState { get; } = new T();
|
2019-07-19 23:59:32 +01:00
|
|
|
|
|
2019-07-21 09:10:45 +01:00
|
|
|
|
public IReadOnlyCollection<MemoryDatum> MemoryData => this.memoryData.AsReadOnly();
|
2019-07-19 23:59:32 +01:00
|
|
|
|
|
2019-07-21 09:28:49 +01:00
|
|
|
|
public bool TryParse(Lines lines)
|
2019-07-19 23:59:32 +01:00
|
|
|
|
{
|
2019-07-21 09:10:45 +01:00
|
|
|
|
if (lines == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(lines));
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-21 09:28:49 +01:00
|
|
|
|
while (!lines.EndOfFile && string.IsNullOrEmpty(this.Description))
|
2019-07-19 23:59:32 +01:00
|
|
|
|
{
|
2019-07-20 19:17:08 +01:00
|
|
|
|
this.Description = lines.ReadLine();
|
2019-07-19 23:59:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-21 09:28:49 +01:00
|
|
|
|
if (string.IsNullOrEmpty(this.Description))
|
2019-07-19 23:59:32 +01:00
|
|
|
|
{
|
2019-07-21 09:28:49 +01:00
|
|
|
|
return false;
|
2019-07-19 23:59:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-20 19:17:08 +01:00
|
|
|
|
this.RegisterState.Parse(lines);
|
2019-07-19 23:59:32 +01:00
|
|
|
|
|
2019-08-13 18:51:34 +01:00
|
|
|
|
bool finished;
|
2019-07-19 23:59:32 +01:00
|
|
|
|
do
|
|
|
|
|
{
|
2019-07-20 19:17:08 +01:00
|
|
|
|
var line = lines.ReadLine();
|
2019-07-19 23:59:32 +01:00
|
|
|
|
finished = line == "-1";
|
|
|
|
|
if (!finished)
|
|
|
|
|
{
|
|
|
|
|
var datum = new MemoryDatum();
|
|
|
|
|
datum.Parse(line);
|
2019-07-21 09:10:45 +01:00
|
|
|
|
this.memoryData.Add(datum);
|
2019-07-19 23:59:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (!finished);
|
2019-07-21 09:28:49 +01:00
|
|
|
|
|
|
|
|
|
return true;
|
2019-07-19 23:59:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|