The LAP library: LexerBin

Derived from: Lexer

Declared in: LexerBin.h


Overview

The LexerBin object is meant to perform the lexical analysis on binary files, that is... well non-ASCII files. A particularly interesssting feature of this class is that both little endian and big endian platforms or files are supported. This is of interest with the upcoming release of the BeOS on Intel-based platforms, which are little endian.

At construction time, the object detects whether bytes will have to be reversed or not. Then, it will respond to the request to read a 8, 16 or 32-bit integer, a 32 or 64-bit float, read or skip n bytes...
One again, bytes will be reversed if needed, it remains almost transparent to the user. Two symbols are defined to take the endianness of a platform or file:

  P_BIG_ENDIAN
  P_LITTLE_ENDIAN
See LexerBin() and SetInput()


Constructor and D estructor


LexerBin()

 
      LexerBin(int32 BufferLength, int32 LexemeLength) 

Creates a LexerBin object. Buffers are allocated through the call of Lexer::Lexer. As the allocations may have failed, the user should always check the status of the object after creation (see GetStatus()).
In the constructor the endian-ness of the platform is tested.


~LexerBin()

 
      ~LexerBin(void) 

Nothing much happens in here.


Member Functions


SetInput()

 
      virtual bool SetInput(entry_ref& Ref, tEndian FileEndianness)

Sets the input for the lexer to the entry Ref. The file endianness is given by the second argument. Whether the bytes are to be reversed or not is determined here, given the platform endianness computed in the constructor and the file endianness provided here as the second parameter.


ReadInt8()

 
      bool ReadInt8(int8& Out)

Reads a byte in the file. This function returns false if no more byte is available, true otherwise. The 8-bit integer referenced by Out is written with the value read from the file.
In case of error, the output value is undetermined and should not be used.


ReadInt16()

 
      bool ReadInt16(int16& Out)

Reads a 2-bytes integer in the file. This function returns false if one or more bytes are missing, true otherwise. The 16-bit integer referenced by Out is written with the value read from the file.
The bytes are reversed if necessary.
In case of error, the output value is undetermined and should not be used.


ReadInt32()

 
      bool ReadInt32(int32& Out)

Reads a 4-bytes integer in the file. This function returns false if one or more bytes are missing, true otherwise. The 32-bit integer referenced by Out is written with the value read from the file.
The bytes are reversed if necessary.
In case of error, the output value is undetermined and should not be used.


ReadFloat()

 
      bool ReadFloat(float& Out)

Reads a 4-bytes float in the file. This function returns false if one or more bytes are missing, true otherwise. The 32-bit float referenced by Out is written with the value read from the file.
The bytes are reversed if necessary.
In case of error, the output value is undetermined and should not be used.


ReadDouble()

 
      bool ReadDouble(double& Out)

Reads a 8-bytes float in the file. This function returns false if one or more bytes are missing, true otherwise. The 64-bit float referenced by Out is written with the value read from the file.
The bytes are reversed if necessary.
In case of error, the output value is undetermined and should not be used.


ReadBytes()

 
      bool ReadBytes(uint32 NbBytes, char* Out)

Reads NbBytes from the input file. This function returns false if one or more bytes are missing, true otherwise. The contents of the string given by Out are modified by the value of the bytes read from the file.
The output is deemed to be allocated, hence, the user must be aware of the actual number of bytes to be fetched.
In case of error, the output value is undetermined and should not be used.


ReadString()

 
      bool ReadString(uint32 MaxBytes, char* Out)

Reads at most MaxBytes from the input file. If a NULL character is encountered, it is skipped and the function returns. This function doesn't fail. The contents of the string given by Out are modified by the value of the bytes read from the file.
The output is deemed to be allocated, hence, the user must be aware of the actual number of bytes to be fetched.


SkipBytes()

 
      bool SkipBytes(uint32 NbBytes

Skips NbBytes from the input file. This function returns false if one or more bytes are missing, true otherwise.


LexString()

 
      bool LexString(uint32 MaxBytes, char* Out)

Reads at most MaxBytes from the input file. If a character whose type is different from LX_CHAR_DIGIT and LX_CHAR_ALPHA is encountered, the function returns the so-lexed lexeme. This function doesn't fail. The contents of the string given by Out are modified by the value of the bytes read from the file.
The output is deemed to be allocated, hence, the user must be aware of the actual number of bytes to be fetched.
In case of error, the output value is undetermined and should not be used.


The LAP library, V0.7, November 3rd 1997, First public release