![]() |
Public API Reference |
![]() |
An implementation of the abstract iFile interface for real files within the physical filesystem. More...
#include <csutil/physfile.h>
Public Member Functions | |
virtual bool | AtEOF () |
Return true if at end of buffer. | |
csPhysicalFile (char const *path, char const *mode) | |
Construct from a filename using fopen() access flags (i.e. | |
csPhysicalFile (FILE *, bool take_ownership, char const *path=0) | |
Construct from an existing FILE*. | |
virtual void | Flush () |
Flush the stream. | |
virtual csPtr< iDataBuffer > | GetAllData (bool nullterm=false) |
Get entire file data in one go. | |
virtual csPtr< iDataBuffer > | GetAllData (CS::Memory::iAllocator *allocator) |
Request whole content of the file as a single data buffer. | |
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< iFile > | GetPartialView (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. |
An implementation of the abstract iFile interface for real files within the physical filesystem.
Definition at line 37 of file physfile.h.
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.
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 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.
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.
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. |
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.