public LogicalTable(string ID, LogicalTable Template) { if (ID.Contains(',')) throw new ArgumentException("Table IDs cannot contain commas"); this.ID = ID; this.ByteWidth = Template.ByteWidth; this.StdDict = new Dictionary<byte[], string>(Template.StdDict, new ByteArrayComparer()); this.ControlCodes = new Dictionary<byte[], ControlCode>(Template.ControlCodes, new ByteArrayComparer()); this.EndTokens = new Dictionary<byte[], EndToken>(Template.EndTokens, new ByteArrayComparer()); this.TableSwitches = new Dictionary<byte[], TableSwitch>(Template.TableSwitches, new ByteArrayComparer()); }
public LogicalTable(string ID, LogicalTable Template) { if (ID.Contains(',')) { throw new ArgumentException("Table IDs cannot contain commas"); } this.ID = ID; this.ByteWidth = Template.ByteWidth; this.StdDict = new Dictionary <byte[], string>(Template.StdDict, new ByteArrayComparer()); this.ControlCodes = new Dictionary <byte[], ControlCode>(Template.ControlCodes, new ByteArrayComparer()); this.EndTokens = new Dictionary <byte[], EndToken>(Template.EndTokens, new ByteArrayComparer()); this.TableSwitches = new Dictionary <byte[], TableSwitch>(Template.TableSwitches, new ByteArrayComparer()); }
public MatchFrame(LogicalTable Table, int MatchCount) { this.Table = Table; this.MatchCount = MatchCount; this.OrigSeq = null; }
public Table(Stream Datastream, string Description = null) { int loaderrors = 0; var errors = new StringBuilder(); this.LogicalTables = new Dictionary <string, LogicalTable>(); // add first logtable as the nameless 'main' table this.LogicalTables.Add("{main}", new LogicalTable("{main}")); LogicalTable WorkTable = this.LogicalTables["{main}"]; var reader = new StreamReader(Datastream); int line = 1; string inBuffer; byte[] identifier = null; while (!reader.EndOfStream) { inBuffer = reader.ReadLine(); if (inBuffer == "" || inBuffer.Substring(0, 1) == "#") { line++; continue; } try { switch (inBuffer.Substring(0, 1)) { case "@": // table ID var newtable = inBuffer.Substring(1).Split(' '); string newname = newtable[0]; if (this.LogicalTables.ContainsKey(newname)) { throw new ArgumentException("A logical table with the name " + newname + " already exists in this table file"); } // if there is more than 1 element (i.e. there was a space followed by text) // check if that text is a directive // if not, ignore it if (newtable.Length > 1) { // inherit directive to use the root table as a template when creating a new logical table if (newtable[1].ToLower() == "inherit") { this.LogicalTables.Add(newname, new LogicalTable(newname, this.LogicalTables["{main}"])); } } else { this.LogicalTables.Add(newname, new LogicalTable(newname)); } WorkTable = this.LogicalTables[newname]; break; case "$": //control code identifier = inBuffer.Substring(1, (inBuffer.IndexOf('=') - 1)).HexStringToByteArray(); WorkTable.AddEntry(identifier, ParseLine_ControlCode(inBuffer)); break; case "/": // end token identifier = inBuffer.Substring(1, (inBuffer.IndexOf('=') - 1)).HexStringToByteArray(); WorkTable.AddEntry(identifier, ParseLine_EndToken(inBuffer)); break; case "!": // table switch identifier = inBuffer.Substring(1, (inBuffer.IndexOf('=') - 1)).HexStringToByteArray(); WorkTable.AddEntry(identifier, ParseLine_TableSwitch(inBuffer)); break; default: //standard dictionary entry identifier = inBuffer.Substring(0, (inBuffer.IndexOf('='))).HexStringToByteArray(); WorkTable.AddEntry(identifier, ParseLine(inBuffer)); break; } if (identifier != null && identifier.Length > WorkTable.ByteWidth) { WorkTable.ByteWidth = identifier.Length; } if (string.IsNullOrEmpty(Description)) { if (Datastream is FileStream) { Description = Path.GetFileName((Datastream as FileStream).Name); } else { Description = "Text table from data stream"; } } this.Description = Description; } catch (Exception ex) { loaderrors++; errors.Append("Line ").Append(line.ToString()).Append(": ").AppendLine(ex.Message); if (loaderrors >= 5) { errors.Append("At least 5 syntax errors detected, loading aborted"); break; } } finally { line++; } } if (loaderrors > 0) { throw new MapParseException(errors.ToString()); } }
public MatchFrame(LogicalTable Table, int MatchCount) { this.Table = Table; this.MatchCount = MatchCount; this.OrigSeq = null; }