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:

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 (CS::Memory::iAllocator *allocator)
 Request whole content of the file as a single data buffer.
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*.
csPtr< iFileGetPartialView (size_t offset, size_t size=(size_t)~0)
 Request whole or part of the content of the file as a file object.
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.

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 ( CS::Memory::iAllocator allocator  )  [virtual]

Request whole content of the file as a single data buffer.

Uses the allocator allocator if memory allocations are necessary.

Returns:
The complete data contained in the file; or an invalidated pointer if this object does not support this function (e.g. write-only VFS files). Check for an invalidated result via csRef<>::IsValid(). Do not modify the contained data!

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.

csPtr<iFile> csPhysicalFile::GetPartialView ( size_t  offset,
size_t  size = (size_t)~0 
) [virtual]

Request whole or part of the content of the file as a file object.

Parameters:
offset Offset of data to return.
size Size of data to return. If ~0 all the data starting at offset up to the end of the file is returned.
Returns:
A file object operating on a part of the original file.
Remarks:
Note that the returned file will not support writing.

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 2.1 by doxygen 1.6.1