Overview
The RoseOutputFile class is a subclass of RoseOutputStream used to generalize file writing. It holds a FILE* and writes blocks of data using fwrite(). Opening and closing the file is the responsibility of the calling code. It does nothing with the file handle except write to it when the buffer is full. Call flush() to write any remaining partial buffer when you are finished.
FILE * f = fopen ("out.txt", "w"); RoseOutputFile stream; stream.file(f) stream.put("Hello World\n"); stream.flush(); // always flush when done. fclose (f);
ctor()
RoseOutputFile(); RoseOutputFile( FILE * f, const char * nm = 0 );
The RoseOutputFile() 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 flushes the buffer and then returns the file pointer so that you can write to the file via some other function. 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. These calls do not flush, open or close the file pointer. Use the as_file() call described above if you want to write to the file by some other means.
flush()
virtual int flush(); // return ferror()
The flush() function writes the contents of the I/O memory buffer to the destination file and returns ferror(), which is also the error_state(). This is called automatically by put() when the buffer is full. You must also call it manually when you are done to write the last partial buffer of data out to the destination.