using System; using System.IO; using SabreTools.Library.DatFiles; using SabreTools.Library.Tools; namespace SabreTools.Library.Reports { /// /// Base class for a report output format /// public abstract class BaseReport { protected DatFile _datFile; protected StreamWriter _writer; protected bool _baddumpCol; protected bool _nodumpCol; /// /// Create a new report from the input DatFile and the filename /// /// DatFile to write out statistics for /// 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 public BaseReport(DatFile datfile, string filename, bool baddumpCol = false, bool nodumpCol = false) { _datFile = datfile; _writer = new StreamWriter(Utilities.TryCreate(filename)); _baddumpCol = baddumpCol; _nodumpCol = nodumpCol; } /// /// Create a new report from the input DatFile and the stream /// /// DatFile to write out statistics for /// Output stream to write to /// True if baddumps should be included in output, false otherwise /// True if nodumps should be included in output, false otherwise public BaseReport(DatFile datfile, Stream stream, bool baddumpCol = false, bool nodumpCol = false) { _datFile = datfile; if (!stream.CanWrite) throw new ArgumentException(nameof(stream)); _writer = new StreamWriter(stream); _baddumpCol = baddumpCol; _nodumpCol = nodumpCol; } /// /// Replace the DatFile that is being output /// /// public void ReplaceDatFile(DatFile datfile) { _datFile = datfile; } /// /// Write the report to the output stream /// /// Number of games to use, -1 means use the number of keys public abstract void Write(long game = -1); /// /// Write out the header to the stream, if any exists /// public abstract void WriteHeader(); /// /// Write out the mid-header to the stream, if any exists /// public abstract void WriteMidHeader(); /// /// Write out the separator to the stream, if any exists /// public abstract void WriteMidSeparator(); /// /// Write out the footer-separator to the stream, if any exists /// public abstract void WriteFooterSeparator(); /// /// Write out the footer to the stream, if any exists /// public abstract void WriteFooter(); } }