From aa4a7b04ecf907bb9609cb7e99db2b18e03a2832 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 17 Nov 2017 15:08:35 -0800 Subject: [PATCH] [DatFile, Reports/, Utilities] Make reports also in a factory --- SabreTools.Library/DatFiles/DatFile.cs | 20 +----------- SabreTools.Library/Reports/Html.cs | 2 +- SabreTools.Library/Reports/SeparatedValue.cs | 2 +- SabreTools.Library/Reports/Textfile.cs | 2 +- SabreTools.Library/Tools/Utilities.cs | 32 ++++++++++++++++++-- 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index c61160e6..29015324 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -5702,25 +5702,7 @@ namespace SabreTools.Library.DatFiles // Loop through and output based on the inputs foreach (KeyValuePair kvp in outputs) { - // Create the proper report for this format - BaseReport report = null; - switch (kvp.Key) - { - case StatReportFormat.Textfile: - report = new Textfile(null, kvp.Value, baddumpCol, nodumpCol); - break; - case StatReportFormat.CSV: - report = new Reports.SeparatedValue(null, kvp.Value, ',', baddumpCol, nodumpCol); - break; - case StatReportFormat.HTML: - report = new Html(null, kvp.Value, baddumpCol, nodumpCol); - break; - case StatReportFormat.TSV: - report = new Reports.SeparatedValue(null, kvp.Value, '\t', baddumpCol, nodumpCol); - break; - } - - reports.Add(report); + reports.Add(Utilities.CreateBaseReportFromType(kvp.Key, kvp.Value, baddumpCol, nodumpCol)); } // Write the header, if any diff --git a/SabreTools.Library/Reports/Html.cs b/SabreTools.Library/Reports/Html.cs index 0563a033..08325797 100644 --- a/SabreTools.Library/Reports/Html.cs +++ b/SabreTools.Library/Reports/Html.cs @@ -19,7 +19,7 @@ namespace SabreTools.Library.Reports /// HTML report format /// /// TODO: Make output standard width, without making the entire thing a table - public class Html : BaseReport + internal class Html : BaseReport { /// /// Create a new report from the input DatFile and the filename diff --git a/SabreTools.Library/Reports/SeparatedValue.cs b/SabreTools.Library/Reports/SeparatedValue.cs index 3b386fc1..945d3b0c 100644 --- a/SabreTools.Library/Reports/SeparatedValue.cs +++ b/SabreTools.Library/Reports/SeparatedValue.cs @@ -15,7 +15,7 @@ namespace SabreTools.Library.Reports /// /// Separated-Value report format /// - public class SeparatedValue : BaseReport + internal class SeparatedValue : BaseReport { private char _separator; diff --git a/SabreTools.Library/Reports/Textfile.cs b/SabreTools.Library/Reports/Textfile.cs index 950e1101..94dcb6e1 100644 --- a/SabreTools.Library/Reports/Textfile.cs +++ b/SabreTools.Library/Reports/Textfile.cs @@ -16,7 +16,7 @@ namespace SabreTools.Library.Reports /// /// Textfile report format /// - public class Textfile : BaseReport + internal class Textfile : BaseReport { /// /// Create a new report from the input DatFile and the filename diff --git a/SabreTools.Library/Tools/Utilities.cs b/SabreTools.Library/Tools/Utilities.cs index 69a30e47..fcc5e572 100644 --- a/SabreTools.Library/Tools/Utilities.cs +++ b/SabreTools.Library/Tools/Utilities.cs @@ -11,9 +11,10 @@ using System.Xml.Schema; using SabreTools.Library.Data; using SabreTools.Library.DatFiles; +using SabreTools.Library.DatItems; using SabreTools.Library.External; using SabreTools.Library.FileTypes; -using SabreTools.Library.DatItems; +using SabreTools.Library.Reports; using SabreTools.Library.Skippers; #if MONO @@ -552,7 +553,7 @@ namespace SabreTools.Library.Tools case DatFormat.ClrMamePro: return new ClrMamePro(baseDat); case DatFormat.CSV: - return new SeparatedValue(baseDat, ','); + return new DatFiles.SeparatedValue(baseDat, ','); case DatFormat.DOSCenter: return new DosCenter(baseDat); case DatFormat.Listroms: @@ -582,7 +583,32 @@ namespace SabreTools.Library.Tools case DatFormat.SoftwareList: return new SoftwareList(baseDat); case DatFormat.TSV: - return new SeparatedValue(baseDat, '\t'); + return new DatFiles.SeparatedValue(baseDat, '\t'); + } + + return null; + } + + /// + /// Create a specific type of BaseReport to be used based on a format and user inputs + /// + /// Format of the Statistics Report to be created + /// Name of the file to write out to + /// True if baddumps should be included in output, false otherwise + /// True if nodumps should be included in output, false otherwise + /// BaseReport of the specific internal type that corresponds to the inputs + public static BaseReport CreateBaseReportFromType(StatReportFormat statReportFormat, string filename, bool baddumpCol, bool nodumpCol) + { + switch (statReportFormat) + { + case StatReportFormat.Textfile: + return new Textfile(null, filename, baddumpCol, nodumpCol); + case StatReportFormat.CSV: + return new Reports.SeparatedValue(null, filename, ',', baddumpCol, nodumpCol); + case StatReportFormat.HTML: + return new Html(null, filename, baddumpCol, nodumpCol); + case StatReportFormat.TSV: + return new Reports.SeparatedValue(null, filename, '\t', baddumpCol, nodumpCol); } return null;