示例#1
0
 private Entry ReadEntry(CalithaBinReader reader)
 {
     Entry entry = EntryFactory.CreateEntry(reader);
     if (entry == null)
         throw new CGTStructureException("Invalid entry type at byte "+(stream.Position-1));
     return entry;
 }
示例#2
0
 /// <summary>
 /// Reads a CGT and creates all the objects needed to create
 /// a tokenizer and parser at a later time.
 /// </summary>
 /// <param name="stream">The CGT stream.</param>
 private void ReadFile(Stream stream)
 {
     try
     {
         Reset();
         this.stream = stream;
         CalithaBinReader reader = new CalithaBinReader(stream);
         string header = "";
         try
         {
             header = reader.ReadUnicodeString();
             if (! header.StartsWith("GOLD"))
                 throw new CGTStructureException("File header is invalid");
         }
         catch (EndOfStreamException e)
         {
             throw new CGTStructureException("File header is invalid",e);
         }
         RecordCollection records = new RecordCollection();
         while (!(stream.Position == stream.Length))
         {
             records.Add(ReadRecord(reader));
         }
         structure = new CGTStructure(header,records);
         content = new CGTContent(structure);
         dfaStates = CreateDFAStates(content);
         parserStates = CreateParserStates(content);
     }
     finally
     {
         stream.Close();
     }
 }
        static public Entry CreateEntry(CalithaBinReader reader)
        {
            Entry entry     = null;
            byte  entryType = reader.ReadByte();

            switch (entryType)
            {
            case 69:                     // 'E'
                entry = new EmptyEntry();
                break;

            case 98:                     // 'b'
                entry = new ByteEntry(reader);
                break;

            case 66:                     // 'B'
                entry = new BooleanEntry(reader);
                break;

            case 73:                     // 'I'
                entry = new IntegerEntry(reader);
                break;

            case 83:                     // 'S'
                entry = new StringEntry(reader);
                break;

            default:                     //Unknown
                throw new CGTStructureException("Unknown entry type");
            }
            return(entry);
        }
示例#4
0
        private Record ReadRecord(CalithaBinReader reader)
        {
            Record record = new Record();
            byte entriesHeader = reader.ReadByte();
            if (entriesHeader != 77) // 'M'
            {
                throw new CGTStructureException("Invalid entries header at byte "+(stream.Position-1));
            }
            ushort entriesCount = reader.ReadUInt16();

            for (int i=0;i<entriesCount;i++)
            {
                record.Entries.Add(ReadEntry(reader));
            }
            return record;
        }
示例#5
0
 public StringEntry(CalithaBinReader reader)
 {
     value = reader.ReadUnicodeString();
 }
示例#6
0
 public IntegerEntry(CalithaBinReader reader)
 {
     value = reader.ReadInt16();
 }
示例#7
0
 public BooleanEntry(CalithaBinReader reader)
 {
     value = reader.ReadBoolean();
 }
示例#8
0
 public ByteEntry(CalithaBinReader reader)
 {
     value = reader.ReadByte();
 }