public static bool Parse(SeekableReader r, out System system) { Unit u; if (!Unit.Parse(r, out u)) { throw new InvalidSystemException("No core star"); } system = new System(); system.Core = u; while (r.Peek() == ' ') { while (r.Peek() == ' ') // w+ { r.Read(); } Companion companion; if (!Companion.Parse(r, out companion)) { throw new InvalidSystemException("Expected companion"); } system.Companions.Add(companion); } return(true); }
//private: void Connect() { const int BUFFER_SIZE = 4096; if (m_dpCount == 0) { bool connected = false; try { m_dataFile = new System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.Read, BUFFER_SIZE, System.IO.FileOptions.RandomAccess); Reader = new SeekableReader(m_dataFile); Writer = new SeekableWriter(m_dataFile); Header.Read(Reader); Init(); connected = true; } catch (System.IO.FileNotFoundException) { System.Diagnostics.Debug.WriteLine("Try to create the file {0}.", FilePath); m_dataFile = new System.IO.FileStream(FilePath, System.IO.FileMode.CreateNew, System.IO.FileAccess.ReadWrite, System.IO.FileShare.Read, BUFFER_SIZE, System.IO.FileOptions.RandomAccess); Header.Reset(); Header.CreationTime = DateTime.Now; Writer = new SeekableWriter(m_dataFile); Reader = new SeekableReader(m_dataFile); Header.Write(Writer); Init(); connected = true; } finally { if (!connected) { m_dataFile?.Dispose(); m_dataFile = null; Reader = null; Writer = null; } } } ++m_dpCount; Assert(IsConnected); }
public static bool Parse(SeekableReader r, out System system) { if (!Unit.Parse(r, out Unit? u)) { throw new InvalidSystemException("No core star"); } system = new System() { Core = u }; while (r.Peek() == ' ') { while (r.Peek() == ' ') // w+ { r.Read(); } if (!Companion.Parse(r, out Companion? companion) || companion == null) { throw new InvalidSystemException("Expected companion"); } system.Companions.Add(companion); } return(true); }
public static bool Parse(SeekableReader r, out NearCompanion near) { Unit u; if (Unit.Parse(r, out u)) { near = new NearCompanion(); near.Companion = u; return(true); } near = null; return(false); }
public static bool Parse(SeekableReader r, out NearCompanion?near) { if (Unit.Parse(r, out Unit? u)) { near = new NearCompanion() { Companion = u }; return(true); } near = null; return(false); }
public static bool Parse(SeekableReader r, out Companion companion) { if (NearCompanion.Parse(r, out NearCompanion nc)) { companion = nc; return(true); } #if EXTENDED_SYSTEM_PARSING if (FarCompanion.Parse(r, out FarCompanion fc)) { companion = fc; return(true); } #endif companion = null; return(false); }
public static bool Parse(SeekableReader r, out Unit unit) { #if EXTENDED_SYSTEM_PARSING if (Pair.Parse(r, out Pair p)) { unit = p; return(true); } #endif if (Star.Parse(r, out Star s)) { unit = s; return(true); } unit = null; return(false); }
/// <summary> /// Match one of a set of string options. Will return one of the options or null /// if there is no match. /// </summary> /// <param name="r">Text to parse</param> /// <param name="options">List of accepted options</param> /// <returns>Matched string, or null</returns> private static string Match(SeekableReader r, string[] options) { string found = ""; int pos = r.Position; while (r.Peek() != -1 && IsPrefixIn(found + (char)r.Peek(), options)) { found += (char)r.Read(); } if (options.Any(o => found == o)) { return(found); } r.Position = pos; return(null); }
public static bool Parse(SeekableReader r, out FarCompanion far) { if (r.Peek() != '[') { far = null; return(false); } far = new FarCompanion(); r.Read(); // '[' if (!System.Parse(r, out far.Companion)) { throw new InvalidSystemException("Invalid far companion"); } if (r.Read() != ']') { throw new InvalidSystemException("Unclosed far companion"); } return(true); }
public static bool Parse(SeekableReader r, out Pair pair) { if (r.Peek() != '(') { pair = null; return(false); } pair = new Pair(); r.Read(); // "(" if (!Star.Parse(r, out pair.Star1)) { throw new InvalidSystemException("Invalid star within pair"); } if (r.Peek() != ' ') // w+ { throw new InvalidSystemException("Missing whitespace within pair"); } while (r.Peek() == ' ') { r.Read(); } if (!Star.Parse(r, out pair.Star2)) { throw new InvalidSystemException("Invalid star within pair"); } if (r.Read() != ')') { throw new InvalidSystemException("Unclosed pair"); } return(true); }
public static bool Parse( SeekableReader r, out Pair pair ) { if( r.Peek() != '(' ) { pair = null; return false; } pair = new Pair(); r.Read(); // "(" if( !Star.Parse( r, out pair.Star1 ) ) throw new InvalidSystemException( "Invalid star within pair" ); if( r.Peek() != ' ' ) // w+ throw new InvalidSystemException( "Missing whitespace within pair" ); while( r.Peek() == ' ' ) r.Read(); if( !Star.Parse( r, out pair.Star2 ) ) throw new InvalidSystemException( "Invalid star within pair" ); if( r.Read() != ')' ) throw new InvalidSystemException( "Unclosed pair" ); return true; }
public static bool Parse(SeekableReader r, out Star star) { string m; m = Match(r, OTHER_TYPES); if (m != null) { // Brown Dwarf, Black Hole, Unknown star = new Star(); star.Type = m; return(true); } m = Match(r, STAR_TYPES); if (m != null) { // Regular star = new Star(); star.Type = m; if (r.Peek() == ' ') { while (r.Peek() == ' ') // w* { r.Read(); } if (Match(r, DWARF_SIZE) == null) { throw new InvalidSystemException("Invalid stellar type"); } star.Tenths = 0; star.Size = "D"; } else if (Match(r, DWARF_SIZE) != null) { star.Tenths = 0; star.Size = "D"; } else { m = Match(r, STAR_TENTHS); if (m == null) { throw new InvalidSystemException("Invalid stellar type"); } star.Tenths = (int)m[0] - (int)'0'; while (r.Peek() == ' ') // w* { r.Read(); } m = Match(r, STAR_SIZES); if (m == null) { throw new InvalidSystemException("Invalid stellar size"); } star.Size = m; } #if EXTENDED_SYSTEM_PARSING if (r.Peek() == '*') { r.Read(); star.Main = true; } #endif return(true); } m = Match(r, DWARF_TYPES); if (m != null) { // Dwarf star = new Star(); star.Type = m; return(true); } star = null; return(false); }
/// <summary> /// Match one of a set of string options. Will return one of the options or null /// if there is no match. /// </summary> /// <param name="r">Text to parse</param> /// <param name="options">List of accepted options</param> /// <returns>Matched string, or null</returns> private static string Match(SeekableReader r, string[] options) { string found = ""; int pos = r.Position; while (r.Peek() != -1 && IsPrefixIn(found + (char)r.Peek(), options)) { found += (char)r.Read(); } if (options.Any(o => found == o)) return found; r.Position = pos; return null; }
public static bool Parse(SeekableReader r, out Companion companion) { NearCompanion nc; if (NearCompanion.Parse(r, out nc)) { companion = nc; return true; } #if EXTENDED_SYSTEM_PARSING FarCompanion fc; if( FarCompanion.Parse( r, out fc ) ) { companion = fc; return true; } #endif companion = null; return false; }
public static bool Parse(SeekableReader r, out NearCompanion near) { Unit u; if (Unit.Parse(r, out u)) { near = new NearCompanion(); near.Companion = u; return true; } near = null; return false; }
public static bool Parse(SeekableReader r, out Star star) { string m; m = Match(r, OTHER_TYPES); if (m != null) { // Brown Dwarf, Black Hole, Unknown star = new Star(); star.Type = m; return true; } m = Match(r, STAR_TYPES); if (m != null) { // Regular star = new Star(); star.Type = m; if (r.Peek() == ' ') { while (r.Peek() == ' ') // w* r.Read(); if (Match(r, DWARF_SIZE) == null) throw new InvalidSystemException("Invalid stellar type"); star.Tenths = 0; star.Size = "D"; } else if (Match(r, DWARF_SIZE) != null) { star.Tenths = 0; star.Size = "D"; } else { m = Match(r, STAR_TENTHS); if (m == null) throw new InvalidSystemException("Invalid stellar type"); star.Tenths = (int)m[0] - (int)'0'; while (r.Peek() == ' ') // w* r.Read(); m = Match(r, STAR_SIZES); if (m == null) throw new InvalidSystemException("Invalid stellar size"); star.Size = m; } #if EXTENDED_SYSTEM_PARSING if (r.Peek() == '*') { r.Read(); star.Main = true; } #endif return true; } m = Match(r, DWARF_TYPES); if (m != null) { // Dwarf star = new Star(); star.Type = m; return true; } star = null; return false; }
public static bool Parse( SeekableReader r, out FarCompanion far ) { if( r.Peek() != '[' ) { far = null; return false; } far = new FarCompanion(); r.Read(); // '[' if( !System.Parse(r, out far.Companion) ) throw new InvalidSystemException( "Invalid far companion" ); if( r.Read() != ']' ) throw new InvalidSystemException( "Unclosed far companion" ); return true; }
public static bool Parse(SeekableReader r, out System system) { Unit u; if (!Unit.Parse(r, out u)) throw new InvalidSystemException("No core star"); system = new System(); system.Core = u; while (r.Peek() == ' ') { while (r.Peek() == ' ') // w+ r.Read(); Companion companion; if (!Companion.Parse(r, out companion)) throw new InvalidSystemException("Expected companion"); system.Companions.Add(companion); } return true; }
public static bool Parse(SeekableReader r, out Unit unit) { #if EXTENDED_SYSTEM_PARSING Pair p; if( Pair.Parse( r, out p ) ) { unit = p; return true; } #endif Star s; if (Star.Parse(r, out s)) { unit = s; return true; } unit = null; return false; }