#include <rw/rwfile.h> RWFile f("filename");
Class RWFile encapsulates binary file operations using the Standard C stream library, which contains functions fopen(), fread(), fwrite(), and so on. Class RWFile is based on class PFile of the Interviews Class Library (1987, Stanford University). The member function names begin with upper case letters in order to maintain compatibility with class PFile.
Because this class is intended to encapsulate binary operations, it is important to open it using a binary mode. This is particularly important under MS-DOS; otherwise, bytes that match a newline are expanded to (carriage return, line feed).
RWFile(const char* filename, const char* mode = 0);
Constructs an RWFile to be used with the file of name filename and with mode mode. The mode is as given by the Standard C library function fopen(). If mode is 0, which is the default, the constructor attempts to open an existing file with the given filename for update (mode rb+). If this is not possible, it attempts to create a new file with the given filename (mode wb+). The resultant object should be checked for validity using function isValid().
Note that Windows users may need to call AnsiToOEM on a Windows character constant for the filename in this constructor, because we use a C function call that may resolve to a DOS system call. In that case, DOS might not be able to recognize Windows character sets.
~RWFile();
Performs any pending I/O operations and closes the file.
const char* Access();
Returns the access mode with which the underlying FILE* was opened.
void ClearErr();
Resets the error state so that neither Eof() nor Error() returns TRUE. Calls the C library function clearerr().
RWoffset CurOffset();
Returns the current position of the file pointer, in bytes from the start of the file.
RWBoolean Eof();
Returns TRUE if an end-of-file has been encountered.
RWBoolean Erase();
Erases the contents but does not close the file. Returns TRUE if the operation is successful.
RWBoolean Error();
Returns TRUE if a file I/O error occurs as determined by a call to the C library function ferror(). Before calling Error(), you should call isValid to determine if the file was opened or created successfully. Failure to do so can result in runtime errors.
RWBoolean Exists();
Returns TRUE if the file exists.
RWBoolean Flush();
Performs any pending I/O operations. Returns TRUE if successful.
const char* GetName();
Returns the file name.
FILE* GetStream();
Returns the FILE* that underlies the RWFile interface. Provided for users who need to "get under the hood" for system-dependent inquiries, for example.
NOTE:Do not use this function to alter the state of the file!
RWBoolean IsEmpty();
Returns TRUE if the file contains no data, otherwise returns FALSE.
RWBoolean Isvalid() const;
Returns TRUE if the file is successfully opened, otherwise returns FALSE.
RWBoolean Read(char& c); RWBoolean Read(wchar_t& wc); RWBoolean Read(short& i); RWBoolean Read(int& i); RWBoolean Read(long& i); RWBoolean Read(unsigned char& c); RWBoolean Read(unsigned short& i); RWBoolean Read(unsigned int& i); RWBoolean Read(unsigned long& i); RWBoolean Read(float& f); RWBoolean Read(double& d);
Reads the indicated built-in type. Returns TRUE if the read is successful. If you are already at the end of a file, this is interpreted as successfully reading a null string, and the function returns TRUE.
RWBoolean Read(char* i, size_t count); RWBoolean Read(wchar_t* i, size_t count); RWBoolean Read(short* i, size_t count); RWBoolean Read(int* i, size_t count); RWBoolean Read(long* i, size_t count); RWBoolean Read(unsigned char* i, size_t count); RWBoolean Read(unsigned short* i, size_t count); RWBoolean Read(unsigned int* i, size_t count); RWBoolean Read(unsigned long* i, size_t count); RWBoolean Read(float* i, size_t count); RWBoolean Read(double* i, size_t count);
Reads count instances of the indicated built-in type into a block pointed to by i. Returns TRUE if the read is successful. Note that you are responsible for declaring i and for allocating the necessary storage before calling this function.
RWBoolean Read(char* string);
Reads a character string, including the terminating null character, into a block pointed to by string. Returns TRUE if the read is successful. Note that you are responsible for declaring string and for allocating the necessary storage before calling this function. Beware of overflow when using this function.
RWBoolean SeekTo(RWoffset offset);
Repositions the file pointer to offset bytes from the start of the file. Returns TRUE if the operation is successful.
RWBoolean SeekToBegin();
Repositions the file pointer to the start of the file. Returns TRUE if the operation is successful.
RWBoolean SeekToEnd();
Repositions the file pointer to the end of the file. Returns TRUE if the operation is successful.
RWBoolean Write(char i); RWBoolean Write(wchar_t i); RWBoolean Write(short i); RWBoolean Write(int i); RWBoolean Write(long i); RWBoolean Write(unsigned char i); RWBoolean Write(unsigned short i); RWBoolean Write(unsigned int i); RWBoolean Write(unsigned long i); RWBoolean Write(float f); RWBoolean Write(double d);
Writes the appropriate built-in type. Returns TRUE if the write is successful.
RWBoolean Write(const char* i, size_t count); RWBoolean Write(const wchar_t* i, size_t count); RWBoolean Write(const short* i, size_t count); RWBoolean Write(const int* i, size_t count); RWBoolean Write(const long* i, size_t count); RWBoolean Write(const unsigned char* i, size_t count); RWBoolean Write(const unsigned short* i, size_t count); RWBoolean Write(const unsigned int* i, size_t count); RWBoolean Write(const unsigned long* i, size_t count); RWBoolean Write(const float* i, size_t count); RWBoolean Write(const double* i, size_t count);
Writes count instances of the indicated built-in type from a block pointed to by i. Returns TRUE if the write is successful.
RWBoolean Write(const char* string);
Writes a character string, including the terminating null character, from a block pointed to by string. Returns TRUE if the write is successful. Beware of nonterminated strings when using this function.
static RWBoolean Exists(const char* filename, int mode = F_OK);
Returns TRUE if a file with name filename exists and may be accessed according to the mode specified. The mode may be ORed together from one or more of:
F_OK: "Exists" (implied by any of the others)
X_OK: "Executable or searchable"
W_OK: "Writable"
R_OK: "Readable"
If your compiler or operating system does not support the POSIX access() function, mode X_OK always returns FALSE.
RWFile& operator<<(RWFile&, const RWCString& str);
Saves string str to a virtual stream or RWFile, respectively.
RWFile& operator<<(RWFile&, const RWDate& date);
Saves the date date to a virtual stream or RWFile, respectively.
RWFile& operator<<(RWFile&, const RWInteger& x);
Saves the RWInteger x to a virtual stream or RWFile, respectively.
RWFile& operator<<(RWFile&, const RWTime& t);
Saves RWTime t to a virtual stream or RWFile, respectively.
RWFile& operator>>(RWFile&, RWTime& t);
Restores an RWTime into t from a virtual stream or RWFile, respectively, replacing the previous contents of t.
RWFile& operator>>(RWFile&, RWCString& str);
Restores a string into str from a virtual stream or RWFile, respectively, replacing the previous contents of str.
RWFile& operator>>(RWFile&, RWDate& date);
Restores the date into date from a virtual stream or RWFile, respectively, replacing the previous contents of date.
RWFile& operator>>(RWFile&, RWInteger& x);
Restores an RWInteger into x from a virtual stream or RWFile, respectively, replacing the previous contents of x.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.