srecord: srecord::input_file Class Reference

srecord 1.65.0

Loading...
Searching...
No Matches
srecord::input_file Class Referenceabstract

The srecord::input_file class is used to represent an generic input file. More...

`#include <file.h>`

Inheritance diagram for srecord::input_file:
[legend]
Collaboration diagram for srecord::input_file:
[legend]

## Public Types
typedef std::shared_ptr< input_file > | pointer
Public Types inherited from srecord::input
typedef std::shared_ptr< input > | pointer

## Public Member Functions
virtual | ~input_file ()
| The destructor.
virtual int | format_option_number (void) const =0
| The format_option_number method is used to obtain the option number, which can then be turned into text via the arglex::token_name method.
Public Member Functions inherited from srecord::input
virtual | ~input ()
| The destructor.
virtual bool | read (class record &rec)=0
| The read method is used to read one record from the input.
virtual void | fatal_error (const char *,...) const FORMAT_PRINTF(2
| The fatal_error method is used to report problems parsing the file.
virtual void virtual void | fatal_error_errno (const char *,...) const FORMAT_PRINTF(2
| The fatal_error_errno method is used to report problems reading the input file.
virtual void virtual void virtual void | warning (const char *,...) const FORMAT_PRINTF(2
| The warning method is used to report potential (but non-fatal) problems parsing the file.
virtual const char * | get_file_format_name (void) const =0
| The get_file_format_name method is used to find out the name of the file format being read.
void | set_quit (quit &)
| The set_quit method is used to set the disposition of the error messages, and the "exit" implementation.
void | reset_quit (void)
| The reset_quit method is used to cause the disposition of the error messages, and the "exit" back to the default.
virtual void | command_line (srecord::arglex_tool *cmdln)
| The command_line method is used by arglex_srec::get_input when parsing the command line, to give a format or filter an opportunity to grab extra arguments off the command line.

## Static Public Member Functions
static pointer | guess (const std::string &file_name, arglex &cmdln)
| The guess class method is used to open a file of an unknown type.
static void | ignore_all_checksums (void)
| The ignore_all_checksums method is used to set the global ignore checksums flag.

## Protected Member Functions
virtual std::string | filename (void) const
| The filename method is used to get the name of the input file being processed.
virtual std::string | filename_and_line (void) const
| The filename_and_line method is used to get the name and current line number within the file.
void | disable_checksum_validation (void)
| The disable_checksum_validation method is used to have this input stream ignore checksum errors.
| input_file (const std::string &file_name)
| The constructor.
virtual int | get_char (void)
| The get_char method is used to fetch a character from the input.
virtual void | get_char_undo (int)
| The get_char_undo method is used to return a character to the input.
int | peek_char (void)
| The peek_char method is used to look at the next character of input, without actually consuming it (a later get_char or peak_char method will still see it).
virtual int | get_nibble (void)
| The get_nibble method is used to fetch one hexadecimal digit from the input, via the get_char method.
virtual int | get_byte (void)
| The get_byte method is used to fetch a byte value from the input.
unsigned | get_word_be (void)
| The get_word_be method is used to fetch a 16-bit value from the input.
unsigned | get_word_le (void)
| The get_word_le method is used to fetch a 16-bit value from the input.
unsigned long | get_3bytes_be (void)
| The get_3bytes_be method is used to fetch a 24-bit value from the input.
unsigned long | get_3bytes_le (void)
| The get_3bytes_le method is used to fetch a 24-bit value from the input.
unsigned long | get_4bytes_be (void)
| The get_4bytes_be method is used to fetch a 32-bit value from the input.
unsigned long | get_4bytes_le (void)
| The get_4bytes_le method is used to fetch a 32-bit value from the input.
int | checksum_get (void) const
| The checksum_get method is used to get the current value of the running checksum (added to by the checksum_add method, usually called by the get_byte method).
int | checksum_get16 (void) const
| The checksum_get16 method is used to get the current value of the running checksum (added to by the checksum_add method, usually called by the get_byte method).
virtual void | checksum_add (unsigned char n)
| The checksum_add method is used to add another 8-bit value to the running checksum.
void | checksum_reset (void)
| The checksum_rest method is used to set the running checksum to zero.
void | seek_to_end (void)
| The seek_to_end method is used to move the input position to the end of the file.
virtual bool | is_binary (void) const
| The is_binary method is used to to determine whether or not a file format is binary (true) of text (false).
bool | use_checksums (void) const
| The use_checksums method is used to determine whether or not to validate checksums when data is read.
Protected Member Functions inherited from srecord::input
| input ()
| The default constructor.

## Static Protected Member Functions
static int | get_nibble_value (int c)
| The get_nibble_value class method is used to translate a character into its hexadecimal value.

## Protected Attributes
int | checksum
| The checksum instance variable is used record the running checksum.

## Detailed Description

The srecord::input_file class is used to represent an generic input file.

It provides many helper methods common to most file input classes.

Definition at line 35 of file file.h.

## Member Typedef Documentation

## ◆ pointer

typedef std::shared_ptr<input_file> srecord::input_file::pointer

Definition at line 39 of file file.h.

## Constructor & Destructor Documentation

## ◆ ~input_file()

virtual srecord::input_file::~input_file | ( |  | ) |
| virtual

The destructor.

## ◆ input_file()

srecord::input_file::input_file | ( | const std::string & | file_name | ) |
| protected

The constructor.

The input will be taken from the named file (or the standard input if the filename is "-").

Only derived classes may use this constructor.

Parameters

  file_name | The name of the file to be read.

Referenced by srecord::input_file_ti_tagged::format_option_number(), and srecord::input_file_ti_tagged_16::format_option_number().

## Member Function Documentation

## ◆ guess()

pointer srecord::input_file::guess | ( | const std::string & | file_name,
|  | arglex & | cmdln )
| static

The guess class method is used to open a file of an unknown type.

It attempts all of the know formats one after the other.

Parameters

  file_name | The name of the file to be opened.
  cmdln | The command line for context

## ◆ ignore_all_checksums()

void srecord::input_file::ignore_all_checksums | ( | void |  | ) |
| inlinestatic

The ignore_all_checksums method is used to set the global ignore checksums flag.

This is usually the result of an –ignore-checksums command line option.

Definition at line 62 of file file.h.

## ◆ format_option_number()

virtual int srecord::input_file::format_option_number | ( | void |  | ) | const
| pure virtual

The format_option_number method is used to obtain the option number, which can then be turned into text via the arglex::token_name method.

Implemented in srecord::input_file_aomf, srecord::input_file_ascii_hex, srecord::input_file_atmel_generic, srecord::input_file_binary, srecord::input_file_brecord, srecord::input_file_cosmac, srecord::input_file_dec_binary, srecord::input_file_emon52, srecord::input_file_fairchild, srecord::input_file_fastload, srecord::input_file_formatted_binary, srecord::input_file_four_packed_code, srecord::input_file_hexdump, srecord::input_file_hp64k, srecord::input_file_idt, srecord::input_file_intel16, srecord::input_file_intel, srecord::input_file_logisim, srecord::input_file_mif, srecord::input_file_mips_flash, srecord::input_file_mos_tech, srecord::input_file_motorola, srecord::input_file_msbin, srecord::input_file_needham, srecord::input_file_os65v, srecord::input_file_ppb, srecord::input_file_ppx, srecord::input_file_signetics, srecord::input_file_spasm, srecord::input_file_spectrum, srecord::input_file_stewie, srecord::input_file_tektronix, srecord::input_file_tektronix_extended, srecord::input_file_ti_tagged, srecord::input_file_ti_tagged_16, srecord::input_file_ti_txt, srecord::input_file_trs80, srecord::input_file_vmem, and srecord::input_file_wilson.

## ◆ filename()

virtual std::string srecord::input_file::filename | ( | void |  | ) | const
| protectedvirtual

The filename method is used to get the name of the input file being processed.

Derived classes must supply this method.

Implements srecord::input.

Referenced by srecord::input_file_hexdump::create(), srecord::input_file_ppb::create(), srecord::input_file_ppx::create(), srecord::input_file_hexdump::format_option_number(), srecord::input_file_ppb::format_option_number(), and srecord::input_file_ppx::format_option_number().

## ◆ filename_and_line()

virtual std::string srecord::input_file::filename_and_line | ( | void |  | ) | const
| protectedvirtual

The filename_and_line method is used to get the name and current line number within the file.

The default implementation simply calls the filename method and returns that. Text formats should be cleverer.

Reimplemented from srecord::input.

## ◆ disable_checksum_validation()

void srecord::input_file::disable_checksum_validation | ( | void |  | ) |
| protectedvirtual

The disable_checksum_validation method is used to have this input stream ignore checksum errors.

Implements srecord::input.

## ◆ get_char()

virtual int srecord::input_file::get_char | ( | void |  | ) |
| protectedvirtual

The get_char method is used to fetch a character from the input.

Usually, this is sufficient, however derived classes may over-ride it if they have a special case. Over-ride with caution, as it affects many other methods.

The line_number instance variable is maintained, so that the filename_and_line method may report the current file location. This makes for more informative error messages.

Reimplemented in srecord::input_file_ti_tagged_16.

## ◆ get_char_undo()

virtual void srecord::input_file::get_char_undo | ( | int |  | ) |
| protectedvirtual

The get_char_undo method is used to return a character to the input.

(a later get_char or peak_char method will see it again). Only one character may be pushed back.

## ◆ peek_char()

int srecord::input_file::peek_char | ( | void |  | ) |
| protected

The peek_char method is used to look at the next character of input, without actually consuming it (a later get_char or peak_char method will still see it).

## ◆ get_nibble_value()

int srecord::input_file::get_nibble_value | ( | int | c | ) |
| staticprotected

The get_nibble_value class method is used to translate a character into its hexadecimal value.

Parameters

  c | The character to translate

Returns
  int; 0..9 for '0'..'9', 10..15 for 'a'..'f', 10..15 for 'A-Z', and -1 for everything else.

## ◆ get_nibble()

virtual int srecord::input_file::get_nibble | ( | void |  | ) |
| protectedvirtual

The get_nibble method is used to fetch one hexadecimal digit from the input, via the get_char method.

It is not case sensitive. It returns a value for 0 to 15. Characters which are not hexadecimal digits will result in a fatal error, and the method call will not return.

Reimplemented in srecord::input_file_tektronix_extended.

## ◆ get_byte()

virtual int srecord::input_file::get_byte | ( | void |  | ) |
| protectedvirtual

The get_byte method is used to fetch a byte value from the input.

The default implementation is to call the get_nibble method twice, and assemble them big-endian (most significant nibble first).

The value of the byte will be added to the running checksum, via the checksum_add method.

Usually, this get_byte method implementation is sufficient for most input classes, however derived classes may over-ride it if they have a special case. Over-ride with caution, as it affects many other methods.

Reimplemented in srecord::input_file_stewie, and srecord::input_file_wilson.

## ◆ get_word_be()

unsigned srecord::input_file::get_word_be | ( | void |  | ) |
| protected

The get_word_be method is used to fetch a 16-bit value from the input.

The get_byte method is called twice, and the two byte values are assembled big-endian (most significant byte first).

## ◆ get_word_le()

unsigned srecord::input_file::get_word_le | ( | void |  | ) |
| protected

The get_word_le method is used to fetch a 16-bit value from the input.

The get_byte method is called twice, and the two byte values are assembled little-endian (least significant byte first).

## ◆ get_3bytes_be()

unsigned long srecord::input_file::get_3bytes_be | ( | void |  | ) |
| protected

The get_3bytes_be method is used to fetch a 24-bit value from the input.

The get_byte method is called three times, and the three byte values are assembles big-endian (most significant byte first).

## ◆ get_3bytes_le()

unsigned long srecord::input_file::get_3bytes_le | ( | void |  | ) |
| protected

The get_3bytes_le method is used to fetch a 24-bit value from the input.

The get_byte method is called three times, and the three byte values are assembled little-endian (least significant byte first).

## ◆ get_4bytes_be()

unsigned long srecord::input_file::get_4bytes_be | ( | void |  | ) |
| protected

The get_4bytes_be method is used to fetch a 32-bit value from the input.

The get_byte method is called four times, and the four byte values are assembled big-endian (most significant byte first).

## ◆ get_4bytes_le()

unsigned long srecord::input_file::get_4bytes_le | ( | void |  | ) |
| protected

The get_4bytes_le method is used to fetch a 32-bit value from the input.

The get_byte method is called four times, and the four byte values are assembled little-endian (least significant byte first).

## ◆ checksum_get()

int srecord::input_file::checksum_get | ( | void |  | ) | const
| protected

The checksum_get method is used to get the current value of the running checksum (added to by the checksum_add method, usually called by the get_byte method).

Only the lower 8 bits of the sum are returned.

## ◆ checksum_get16()

int srecord::input_file::checksum_get16 | ( | void |  | ) | const
| protected

The checksum_get16 method is used to get the current value of the running checksum (added to by the checksum_add method, usually called by the get_byte method).

Only the lower 16 bits of the sum are returned.

## ◆ checksum_add()

virtual void srecord::input_file::checksum_add | ( | unsigned char | n | ) |
| protectedvirtual

The checksum_add method is used to add another 8-bit value to the running checksum.

Reimplemented in srecord::input_file_signetics.

## ◆ checksum_reset()

void srecord::input_file::checksum_reset | ( | void |  | ) |
| protected

The checksum_rest method is used to set the running checksum to zero.

## ◆ seek_to_end()

void srecord::input_file::seek_to_end | ( | void |  | ) |
| protected

The seek_to_end method is used to move the input position to the end of the file.

## ◆ is_binary()

virtual bool srecord::input_file::is_binary | ( | void |  | ) | const
| protectedvirtual

The is_binary method is used to to determine whether or not a file format is binary (true) of text (false).

The default implementation always returns false (text).

Reimplemented in srecord::input_file_aomf, srecord::input_file_dec_binary, srecord::input_file_formatted_binary, srecord::input_file_idt, srecord::input_file_ppb, srecord::input_file_stewie, srecord::input_file_trs80, and srecord::input_file_wilson.

## ◆ use_checksums()

bool srecord::input_file::use_checksums | ( | void |  | ) | const
| inlineprotected

The use_checksums method is used to determine whether or not to validate checksums when data is read.

Returns
  bool; true if need to check checksums, false to ignore checksums.

Definition at line 296 of file file.h.

## Member Data Documentation

## ◆ checksum

int srecord::input_file::checksum
| protected

The checksum instance variable is used record the running checksum.

NEVER access this variable directly. Always use the checksum_reset method to set it mack to its initial state. Always use the checksum_add method to add a byte to it. Always use the checksum_get or checksum_get16 methods to read its value.

Definition at line 287 of file file.h.

The documentation for this class was generated from the following file:

- input/file.h