RWFile(3C++)

RWFile - Rogue Wave library class

Showing IRIX 6.5.15. Unchanged since IRIX 6.5.

Name
     RWFile - Rogue Wave library class

Synopsis
              #include <rw/rwfile.h>




          RWFile f("filename");




Description
     Class RWFile encapsulates binary file operations using the Standard C
     stream library (functions fopen(), fread(), fwrite(), etc.).  This class
     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 that it be
     opened using a binary mode.  This is particularly important under MS-DOS
     -- otherwise bytes that happen to match a newline will be expanded to
     (carriage return, line feed).

Persistence
     None

Public Constructors
              RWFile(const char* filename, const char* mode = 0);


     Construct 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 zero (the default) then the constructor will attempt
     to open an existing file with the given filename for update (mode "rb+").
     If this is not possible, then it will attempt to create a new file with
     the given filename (mode "wb+").  The resultant object should be checked
     for validity using function isValid().

              ~RWFile();


     Performs any pending I/O operations and closes the file.

Public Member Functions
              const char*
          Access();


     Returns the access mode with which the underlying FILE* was opened.

              void
          ClearErr();


     Reset error state so that neither Eof() nor Error() returns TRUE.  Calls
     C library function clearerr().

              RWoffset
          CurOffset();


     Returns the current position, in bytes from the start of the file, of the
     file pointer.

              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 was successful.

              RWBoolean
          Error();


     Returns TRUE if a file I/O error has occurred as determined by a call to
     the C library function ferror().

              RWBoolean
          Exists();


     Returns TRUE if the file exists.

              RWBoolean
          Flush();


     Perform 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,
     etc.  Do not use to alter the state of the file!

              RWBoolean
          IsEmpty();


     Returns TRUE if the file contains no data, FALSE otherwise.

              RWBoolean
          isValid() const;


     Returns TRUE if the file was successfully opened, FALSE otherwise.

              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.

              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 non-terminated strings when using this function.

Static Public Member Functions
              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, then mode X_OK will always return FALSE.