Overview

The RoseInputFile class is a subclass of RoseInputStream used to feed parsing code with data from files. It holds a FILE* and reads blocks of data using fread(). Opening and closing the file is the responsibility of the calling code. It does nothing with the file handle except read more from it when the buffer is finished.

FILE * f = fopen ("input.txt", "r");
int c;

RoseInputFile stream;
stream.file(f)

while ((c=stream.get()) != EOF)
{
    // process the characters
}

fclose (f);

ctor()

RoseInputFile();
RoseInputFile(
	FILE * f,
	const char * nm = 0
	);

The RoseInputFile() constructor has two versions. The default contructor leaves the name and file fields unset, while the second constructor initializes both fields.

as_file()

virtual FILE * as_file();

The as_file() function returns the file pointer so that you can close the file or do some other stdio operation. Be careful when switching between the get() function and direct calls via the FILE*. The next read from FILE* will return the data after the last character in the IO buffer, not the next character returned by get().

This function is defined in the base class so that you can call it without casting the stream.

file()

FILE * file();
void file (FILE* f);

The file() function gets and sets the file pointer kept by the stream.

refill()

virtual size_t refill();

The refill() function simply calls fread() to read at most io_size() characters. It returns the number of characters read.

This is called automatically by get() when it reaches the end of the buffer. This is a virtual function that is overridden by each stream subtype.