CrystalSpace

Public API Reference

csPhysicalFile Class Reference

An implementation of the abstract iFile interface for real files within the physical filesystem. More...

#include <csutil/physfile.h>

Inheritance diagram for csPhysicalFile:

Inheritance graph
[legend]
List of all members.

Public Member Functions

virtual bool AtEOF ()
 Return true if at end of buffer.
 csPhysicalFile (FILE *, bool take_ownership, char const *path=0)
 Construct from an existing FILE*.
 csPhysicalFile (char const *path, char const *mode)
 Construct from a filename using fopen() access flags (i.e.
virtual void Flush ()
 Flush the stream.
virtual csPtr< iDataBufferGetAllData (bool nullterm=false)
 Get entire file data in one go.
virtual char const * GetName ()
 Returns the path used to construct the object, or "#csPhysicalFile" if no path was given when constructed from an existing FILE*.
virtual size_t GetPos ()
 Query current cursor position,.
virtual size_t GetSize ()
 Query file size.
virtual int GetStatus ()
 Check (and clear) file last error status.
virtual size_t Read (char *buffer, size_t nbytes)
 Read data from file.
virtual bool SetPos (size_t)
 Set current cursor position.
virtual size_t Write (char const *data, size_t nbytes)
 Write data to buffer.
virtual ~csPhysicalFile ()
 Destructor.

Protected Attributes

FILE * fp
int last_error
bool owner
csString path

Detailed Description

An implementation of the abstract iFile interface for real files within the physical filesystem.

Definition at line 37 of file physfile.h.


Constructor & Destructor Documentation

csPhysicalFile::csPhysicalFile ( char const *  path,
char const *  mode 
)

Construct from a filename using fopen() access flags (i.e.

"r", "rb", "w+", etc.). It is usually a good idea to open files in binary mode (i.e. "rb, "wb", etc.). This ensures that operations on "number of bytes" operate as expected. For instance, requesting 10 bytes with Read() will return 10 bytes in binary mode (assuming end-of-file has not been reached), whereas in text mode, fewer bytes might be returned (if line terminators of the form CFLF have been collapsed to LF at read time).

csPhysicalFile::csPhysicalFile ( FILE *  ,
bool  take_ownership,
char const *  path = 0 
)

Construct from an existing FILE*.

If take_ownership is true, the FILE* will be closed via fclose() when the csPhysicalFile is destroyed. The optional path argument is used only to seed the stored name for use by the GetName() method. If not supplied, then an opaque, essentially meaningless name is returned by GetName(). It is usually a good idea to open files in binary mode (i.e. "rb, "wb", etc.). This ensures that operations on "number of bytes" operate as expected. For instance, requesting 10 bytes with Read() will return 10 bytes in binary mode (assuming end-of-file has not been reached), whereas in text mode, fewer bytes might be returned (if line terminators of the form CFLF have been collapsed to LF at read time).

virtual csPhysicalFile::~csPhysicalFile (  )  [virtual]

Destructor.


Member Function Documentation

virtual bool csPhysicalFile::AtEOF (  )  [virtual]

Return true if at end of buffer.

Implements iFile.

virtual void csPhysicalFile::Flush (  )  [virtual]

Flush the stream.

Implements iFile.

virtual csPtr<iDataBuffer> csPhysicalFile::GetAllData ( bool  nullterm = false  )  [virtual]

Get entire file data in one go.

Creates a copy of the data, so changing the file won't affect any buffers previously returned by this function. Be aware that, for large files, this can allocate a significant amount of memory. If nullterm is true, then a null terminator is appended to the returned data.

Implements iFile.

virtual char const* csPhysicalFile::GetName (  )  [virtual]

Returns the path used to construct the object, or "#csPhysicalFile" if no path was given when constructed from an existing FILE*.

Implements iFile.

virtual size_t csPhysicalFile::GetPos (  )  [virtual]

Query current cursor position,.

Implements iFile.

virtual size_t csPhysicalFile::GetSize (  )  [virtual]

Query file size.

Implements iFile.

virtual int csPhysicalFile::GetStatus (  )  [virtual]

Check (and clear) file last error status.

Implements iFile.

virtual size_t csPhysicalFile::Read ( char *  buffer,
size_t  nbytes 
) [virtual]

Read data from file.

Implements iFile.

virtual bool csPhysicalFile::SetPos ( size_t   )  [virtual]

Set current cursor position.

Implements iFile.

virtual size_t csPhysicalFile::Write ( char const *  data,
size_t  nbytes 
) [virtual]

Write data to buffer.

Implements iFile.


The documentation for this class was generated from the following file:
Generated for Crystal Space by doxygen 1.4.7