PTLib
Version 2.10.4
|
This class is used to allow a block of memory to substitute for a disk file. More...
#include <memfile.h>
Public Member Functions | |
Construction | |
PMemoryFile () | |
Create a new, empty, memory file. | |
PMemoryFile (const PBYTEArray &data) | |
Create a new memory file initialising to the specified content. | |
~PMemoryFile () | |
Destroy the memory file. | |
Overrides from class PObject | |
Comparison | Compare (const PObject &obj) const |
Determine the relative rank of the two objects. | |
Overrides from class PChannel | |
virtual PBoolean | Open (OpenMode mode=ReadWrite, int opts=ModeDefault) |
Open the current file in the specified mode and with the specified options. | |
virtual PBoolean | Open (const PFilePath &name, OpenMode mode=ReadWrite, int opts=ModeDefault) |
Open the specified file name in the specified mode and with the specified options. | |
virtual PBoolean | Close () |
Close the channel, shutting down the link to the data source. | |
virtual PBoolean | Read (void *buf, PINDEX len) |
Low level read from the memory file channel. | |
virtual PBoolean | Write (const void *buf, PINDEX len) |
Low level write to the memory file channel. | |
Overrides from class PFile | |
virtual off_t | GetLength () const |
Get the current size of the file. | |
virtual PBoolean | SetLength (off_t len) |
Set the size of the file, padding with 0 bytes if it would require expanding the file, or truncating it if being made shorter. | |
virtual PBoolean | SetPosition (off_t pos, FilePositionOrigin origin=Start) |
Set the current active position in the file for the next read or write operation. | |
virtual off_t | GetPosition () const |
Get the current active position in the file for the next read or write operation. | |
const PBYTEArray & | GetData () const |
Get the memory data the file has operated with. | |
Protected Attributes | |
PBYTEArray | m_data |
off_t | m_position |
This class is used to allow a block of memory to substitute for a disk file.
Create a new, empty, memory file.
PMemoryFile::PMemoryFile | ( | const PBYTEArray & | data | ) |
Create a new memory file initialising to the specified content.
data | New content filr memory file. |
Destroy the memory file.
virtual PBoolean PMemoryFile::Close | ( | ) | [virtual] |
Close the channel, shutting down the link to the data source.
Reimplemented from PFile.
Comparison PMemoryFile::Compare | ( | const PObject & | obj | ) | const [virtual] |
const PBYTEArray& PMemoryFile::GetData | ( | ) | const [inline] |
Get the memory data the file has operated with.
References m_data.
virtual off_t PMemoryFile::GetLength | ( | ) | const [virtual] |
Get the current size of the file.
The size of the file corresponds to the size of the data array.
Reimplemented from PFile.
virtual off_t PMemoryFile::GetPosition | ( | ) | const [virtual] |
Get the current active position in the file for the next read or write operation.
Reimplemented from PFile.
virtual PBoolean PMemoryFile::Open | ( | OpenMode | mode = ReadWrite , |
int | opts = ModeDefault |
||
) | [virtual] |
Open the current file in the specified mode and with the specified options.
If the file object already has an open file then it is closed.
If there has not been a filename attached to the file object (via SetFilePath()
, the name
parameter or a previous open) then a new unique temporary filename is generated.
Reimplemented from PFile.
virtual PBoolean PMemoryFile::Open | ( | const PFilePath & | name, |
OpenMode | mode = ReadWrite , |
||
int | opts = ModeDefault |
||
) | [virtual] |
Open the specified file name in the specified mode and with the specified options.
If the file object already has an open file then it is closed.
Note: if mode
is StandardInput, StandardOutput or StandardError, then the name
parameter is ignored.
Reimplemented from PFile.
virtual PBoolean PMemoryFile::Read | ( | void * | buf, |
PINDEX | len | ||
) | [virtual] |
Low level read from the memory file channel.
The read timeout is ignored. The GetLastReadCount() function returns the actual number of bytes read.
The GetErrorCode() function should be consulted after Read() returns false to determine what caused the failure.
buf | Pointer to a block of memory to receive the read bytes. |
len | Maximum number of bytes to read into the buffer. |
Reimplemented from PFile.
virtual PBoolean PMemoryFile::SetLength | ( | off_t | len | ) | [virtual] |
Set the size of the file, padding with 0 bytes if it would require expanding the file, or truncating it if being made shorter.
len | New length of file. |
Reimplemented from PFile.
virtual PBoolean PMemoryFile::SetPosition | ( | off_t | pos, |
FilePositionOrigin | origin = Start |
||
) | [virtual] |
Set the current active position in the file for the next read or write operation.
The pos
variable is a signed number which is added to the specified origin. For origin == PFile::Start
only positive values for pos
are meaningful. For origin == PFile::End
only negative values for pos
are meaningful.
pos | New position to set. |
origin | Origin for position change. |
Reimplemented from PFile.
virtual PBoolean PMemoryFile::Write | ( | const void * | buf, |
PINDEX | len | ||
) | [virtual] |
Low level write to the memory file channel.
The write timeout is ignored. The GetLastWriteCount() function returns the actual number of bytes written.
The GetErrorCode() function should be consulted after Write() returns false to determine what caused the failure.
buf | Pointer to a block of memory to write. |
len | Number of bytes to write. |
Reimplemented from PFile.
PBYTEArray PMemoryFile::m_data [protected] |
Referenced by GetData().
off_t PMemoryFile::m_position [protected] |