using System.Collections.Generic; using System.IO; using System.Linq; using SabreTools.Library.Filtering; using SabreTools.Library.Tools; using Newtonsoft.Json; namespace SabreTools.Library.DatItems { /// /// Represents a single port on a machine /// [JsonObject("port")] public class Port : DatItem { #region Fields /// /// Tag for the port /// [JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore)] public string Tag { get; set; } /// /// List of analogs on the port /// [JsonProperty("analogs", DefaultValueHandling = DefaultValueHandling.Ignore)] public List Analogs { get; set; } #endregion #region Accessors /// /// Set fields with given values /// /// Mappings dictionary public override void SetFields(Dictionary mappings) { // Set base fields base.SetFields(mappings); // Handle Port-specific fields if (mappings.Keys.Contains(Field.DatItem_Tag)) Tag = mappings[Field.DatItem_Tag]; // TODO: Handle DatItem_Analog* } #endregion #region Constructors /// /// Create a default, empty Port object /// public Port() { ItemType = ItemType.Port; } #endregion #region Cloning Methods public override object Clone() { return new Port() { ItemType = this.ItemType, DupeType = this.DupeType, AltName = this.AltName, AltTitle = this.AltTitle, Machine = this.Machine.Clone() as Machine, Source = this.Source.Clone() as Source, Remove = this.Remove, Tag = this.Tag, Analogs = this.Analogs, }; } #endregion #region Comparision Methods public override bool Equals(DatItem other) { // If we don't have a Port, return false if (ItemType != other.ItemType) return false; // Otherwise, treat it as a Port Port newOther = other as Port; // If the Port information matches return (Tag == newOther.Tag); // TODO: Handle DatItem_Analog* } #endregion #region Filtering /// /// Check to see if a DatItem passes the filter /// /// Filter to check against /// True if the item passed the filter, false otherwise public override bool PassesFilter(Filter filter) { // Check common fields first if (!base.PassesFilter(filter)) return false; // Filter on tag if (filter.DatItem_Tag.MatchesPositiveSet(Tag) == false) return false; if (filter.DatItem_Tag.MatchesNegativeSet(Tag) == true) return false; // TODO: Handle DatItem_Analog* return true; } /// /// Remove fields from the DatItem /// /// List of Fields to remove public override void RemoveFields(List fields) { // Remove common fields first base.RemoveFields(fields); // Remove the fields if (fields.Contains(Field.DatItem_Tag)) Tag = null; if (fields.Contains(Field.DatItem_Analogs)) Analogs = null; // TODO: Handle DatItem_Analog* } #endregion #region Sorting and Merging /// /// Replace fields from another item /// /// DatItem to pull new information from /// List of Fields representing what should be updated public override void ReplaceFields(DatItem item, List fields) { // Replace common fields first base.ReplaceFields(item, fields); // If we don't have a Port to replace from, ignore specific fields if (item.ItemType != ItemType.Port) return; // Cast for easier access Port newItem = item as Port; // Replace the fields if (fields.Contains(Field.DatItem_Name)) Tag = newItem.Tag; if (fields.Contains(Field.DatItem_Analogs)) Analogs = newItem.Analogs; // TODO: Handle DatItem_Analog* } #endregion } }