Encapsulates embedded files, i.e. More...
#include <OSDLEmbeddedFile.h>
Public Member Functions | |
virtual | ~EmbeddedFile () throw () |
Destroys the embedded file reference object, does not remove the file itself. | |
virtual bool | isOpen () const |
Returns true iff this file is open. | |
virtual bool | close () |
Closes the file for read/write actions. | |
virtual void | saveAs (const std::string &newName) |
Saves the file under a new name. | |
virtual void | lockForReading () const |
Locks the file for reading. | |
virtual void | unlockForReading () const |
Unlocks the file for reading. | |
virtual void | lockForWriting () const |
Locks the file for writing. | |
virtual void | unlockForWriting () const |
Unlocks the file for writing. | |
virtual bool | isLocked () const |
Tells whether the file is locked. | |
virtual time_t | getLastChangeTime () const |
Returns the latest change time of this embedded file. | |
virtual Ceylan::System::Size | read (Ceylan::Byte *buffer, Ceylan::System::Size maxLength) |
Reads up to maxLength bytes from this file to specified buffer. | |
virtual Ceylan::System::Size | write (const std::string &message) |
Writes message to this file. | |
virtual Ceylan::System::Size | write (const Ceylan::Byte *buffer, Ceylan::System::Size maxLength) |
Writes up to maxLength bytes from the specified buffer to this file. | |
virtual Ceylan::System::Position | tell () |
Determines current position within this embedded file. | |
virtual void | seek (Ceylan::System::Position targetPosition) |
Seeks to specified position within this embedded file. | |
virtual Ceylan::System::Size | size () const |
Returns the file size, in bytes. | |
virtual void | serialize (PHYSFS_File &handle) |
Sends the file content to the fd PhysicsFS handle stream. | |
PHYSFS_File & | getPhysicsFSHandle () const |
Returns the stream id, its PhysicsFS handle. | |
virtual Ceylan::System::StreamID | getStreamID () const |
Returns this file's ID. | |
virtual const std::string | toString (Ceylan::VerbosityLevels level=Ceylan::high) const |
Returns an user-friendly description of the state of this object. | |
Static Public Member Functions | |
static void | CypherBuffer (Ceylan::Byte *buffer, Ceylan::System::Size size) |
Cyphers specified buffer. | |
static void | DecypherBuffer (Ceylan::Byte *buffer, Ceylan::System::Size size) |
Decyphers specified buffer. | |
static EmbeddedFile & | Create (const std::string &filename, Ceylan::System::OpeningFlag createFlag=Ceylan::System::File::CreateToWriteBinary, Ceylan::System::PermissionFlag permissionFlag=Ceylan::System::File::OwnerReadWrite) |
Returns an EmbeddedFile reference on a newly created file. | |
static EmbeddedFile & | Open (const std::string &filename, Ceylan::System::OpeningFlag openFlag=Ceylan::System::File::OpenToReadBinary) |
Returns an EmbeddedFile reference on specified already-existing file, in platform-independent notation, which will be opened with specified settings. | |
Protected Member Functions | |
EmbeddedFile (const std::string &name, Ceylan::System::OpeningFlag openFlag=Ceylan::System::File::CreateToWriteBinary, Ceylan::System::PermissionFlag permissionFlag=Ceylan::System::File::OwnerReadWrite) | |
Constructs an Embedded file reference object. | |
virtual Ceylan::System::FileSystemManager & | getCorrespondingFileSystemManager () const |
Returns the embedded filesystem manager. | |
virtual void | reopen () |
Tries to reopen file. | |
virtual std::string | interpretState () const |
Interprets the current state of this file. | |
Private Member Functions | |
EmbeddedFile (const EmbeddedFile &source) | |
Copy constructor made private to ensure that it will be never called. | |
EmbeddedFile & | operator= (const EmbeddedFile &source) |
Assignment operator made private to ensure that it will be never called. | |
Static Private Member Functions | |
static void | FromHandletoHandle (PHYSFS_File &from, PHYSFS_File &to, Ceylan::System::Size length) |
Transfers bytes from a PhysicsFS handle to another. | |
Private Attributes | |
PHYSFS_File * | _physfsHandle |
Internal PhysicsFS handle. | |
bool | _cypher |
Tells whether reads and writes to this file should be cyphered. |
Encapsulates embedded files, i.e.
files in a virtual filesystem stored in an actual standard file, as provided by the PhysicsFS back-end.
Actual files should be created and opened with respectively the File::Create and File::Open factories, that allow the user program to be cross-platform by hiding each filesystem-related per-platform specificity.
Definition at line 81 of file OSDLEmbeddedFile.h.
EmbeddedFile::~EmbeddedFile | ( | ) | throw () [virtual] |
Destroys the embedded file reference object, does not remove the file itself.
To remove the file from disk, use remove().
Definition at line 107 of file OSDLEmbeddedFile.cc.
OSDL::EmbeddedFile::EmbeddedFile | ( | const std::string & | name, | |
Ceylan::System::OpeningFlag | openFlag = Ceylan::System::File::CreateToWriteBinary , |
|||
Ceylan::System::PermissionFlag | permissionFlag = Ceylan::System::File::OwnerReadWrite | |||
) | [explicit, protected] |
Constructs an Embedded file reference object.
By default, it creates a new file on disk, if the name corresponds to an already-existing file, it will be truncated and overwritten.
name | the name of the file. | |
openFlag | the flag describing the opening mode. | |
permissionFlag | the flag describing the requested permissions, if this file is to be created. Otherwise (if the file already exists), this parameter is ignored. |
FileManagementException | if the operation failed. |
OSDL::EmbeddedFile::EmbeddedFile | ( | const EmbeddedFile & | source | ) | [private] |
Copy constructor made private to ensure that it will be never called.
The compiler should complain whenever this undefined constructor is called, implicitly or not.
bool EmbeddedFile::close | ( | ) | [virtual] |
Closes the file for read/write actions.
Stream::CloseException | if the close operation failed. |
Definition at line 159 of file OSDLEmbeddedFile.cc.
References _physfsHandle, OSDL::EmbeddedFileSystemManager::GetBackendLastError(), and isOpen().
Referenced by OSDL::EmbeddedFileSystemManager::copyFile(), and ~EmbeddedFile().
static EmbeddedFile& OSDL::EmbeddedFile::Create | ( | const std::string & | filename, | |
Ceylan::System::OpeningFlag | createFlag = Ceylan::System::File::CreateToWriteBinary , |
|||
Ceylan::System::PermissionFlag | permissionFlag = Ceylan::System::File::OwnerReadWrite | |||
) | [static] |
Returns an EmbeddedFile reference on a newly created file.
By default, it creates a new file on disk. If the name corresponds to an already-existing file, it will be truncated and overwritten.
filename | the name of the file to be created. | |
createFlag | the flag describing the creation mode. Only binary access is performed. | |
permissionFlag | the flag describing the requested permissions. |
FileException,including | FileCreationFailed if the operation failed or is not supported on this platform. |
Referenced by OSDL::EmbeddedFileSystemManager::copyFile(), and saveAs().
void EmbeddedFile::CypherBuffer | ( | Ceylan::Byte * | buffer, | |
Ceylan::System::Size | size | |||
) | [static] |
Cyphers specified buffer.
buffer | the buffer to update. | |
size | the number of bytes to cypher. |
EmbeddedFileException | if the operation failed. |
Definition at line 592 of file OSDLEmbeddedFile.cc.
References OSDL::EmbeddedFileSystemManager::GetXORByte().
static void OSDL::EmbeddedFile::DecypherBuffer | ( | Ceylan::Byte * | buffer, | |
Ceylan::System::Size | size | |||
) | [static] |
Decyphers specified buffer.
buffer | the buffer to update. | |
size | the number of bytes to decypher. |
EmbeddedFileException | if the operation failed. |
static void OSDL::EmbeddedFile::FromHandletoHandle | ( | PHYSFS_File & | from, | |
PHYSFS_File & | to, | |||
Ceylan::System::Size | length | |||
) | [static, private] |
Transfers bytes from a PhysicsFS handle to another.
from | the source PhysicsFS handle. | |
to | the target PhysicsFS handle. | |
length | the length of the transfer, in bytes. |
EmbeddedFileException | in all cases. |
Referenced by serialize().
FileSystemManager & EmbeddedFile::getCorrespondingFileSystemManager | ( | ) | const [protected, virtual] |
Returns the embedded filesystem manager.
FileDelegatingException | if the operation failed. |
Definition at line 731 of file OSDLEmbeddedFile.cc.
References OSDL::EmbeddedFileSystemManager::GetEmbeddedFileSystemManager().
Referenced by getLastChangeTime().
time_t EmbeddedFile::getLastChangeTime | ( | ) | const [virtual] |
Returns the latest change time of this embedded file.
FileLastChangeTimeRequestFailed | if the operation failed, or is not supported. |
Definition at line 281 of file OSDLEmbeddedFile.cc.
References getCorrespondingFileSystemManager().
PHYSFS_File & EmbeddedFile::getPhysicsFSHandle | ( | ) | const |
Returns the stream id, its PhysicsFS handle.
EmbeddedFileException | if the operation failed or if the PhysicsFS handle feature is not available. |
Definition at line 569 of file OSDLEmbeddedFile.cc.
Referenced by getStreamID().
StreamID EmbeddedFile::getStreamID | ( | ) | const [virtual] |
Returns this file's ID.
Definition at line 625 of file OSDLEmbeddedFile.cc.
References getPhysicsFSHandle().
std::string EmbeddedFile::interpretState | ( | ) | const [protected, virtual] |
Interprets the current state of this file.
Definition at line 818 of file OSDLEmbeddedFile.cc.
bool EmbeddedFile::isLocked | ( | ) | const [virtual] |
Tells whether the file is locked.
Definition at line 272 of file OSDLEmbeddedFile.cc.
bool EmbeddedFile::isOpen | ( | ) | const [virtual] |
Returns true iff this file is open.
Definition at line 142 of file OSDLEmbeddedFile.cc.
References _physfsHandle.
Referenced by close(), and ~EmbeddedFile().
void EmbeddedFile::lockForReading | ( | ) | const [virtual] |
Locks the file for reading.
No locking offered by PhysicsFS.
FileReadLockingFailed | if the operation failed or if the file lock feature is not available. |
Definition at line 232 of file OSDLEmbeddedFile.cc.
void EmbeddedFile::lockForWriting | ( | ) | const [virtual] |
Locks the file for writing.
FileWriteLockingFailed | if the operation failed or if the file lock feature is not available. |
Definition at line 252 of file OSDLEmbeddedFile.cc.
static EmbeddedFile& OSDL::EmbeddedFile::Open | ( | const std::string & | filename, | |
Ceylan::System::OpeningFlag | openFlag = Ceylan::System::File::OpenToReadBinary | |||
) | [static] |
Returns an EmbeddedFile reference on specified already-existing file, in platform-independent notation, which will be opened with specified settings.
If the file is open for writing or appending, then the write directory will be taken as the root of the writable filesystem.
When a file is opened for writing, the specifiedfile is created if it does not exist. Otherwise it is truncated to zero bytes, and the writing offset is set to the start.
When a file is opened for appending, the specified file is created if it does not exist. Otherwise the writing offset is set to the end of the file, so the first write will be the byte after the end.
If the file is open for reading, then the search path will be checked one at a time until a matching file is found. The reading offset is set to the first byte of the file.
filename | the name of the file to open. | |
openFlag | the flag describing the opening mode. |
FileException,including | FileOpeningFailed if the operation failed or is not supported on this platform. |
Note that, depending on the archive type, opening the same file more than once may or may not work (read content apparently could be scrambled when opened twice).
Referenced by OSDL::EmbeddedFileSystemManager::copyFile().
EmbeddedFile& OSDL::EmbeddedFile::operator= | ( | const EmbeddedFile & | source | ) | [private] |
Assignment operator made private to ensure that it will be never called.
The compiler should complain whenever this undefined operator is called, implicitly or not.
virtual Ceylan::System::Size OSDL::EmbeddedFile::read | ( | Ceylan::Byte * | buffer, | |
Ceylan::System::Size | maxLength | |||
) | [virtual] |
Reads up to maxLength bytes from this file to specified buffer.
The file must be opened for reading.
buffer | the buffer where to store read bytes. Its size must be at least maxLength bytes. | |
maxLength | the maximum number of bytes that should be read. |
InputStream::ReadFailedException | if a read error occurred. Note that this is not a child class of FileException, as it comes from an inherited interface. |
Referenced by OSDL::EmbeddedFileSystemManager::copyFile().
void EmbeddedFile::reopen | ( | ) | [protected, virtual] |
Tries to reopen file.
FileOpeningFailed | if the operation failed. |
Definition at line 753 of file OSDLEmbeddedFile.cc.
References OSDL::EmbeddedFileSystemManager::GetBackendLastError().
void EmbeddedFile::saveAs | ( | const std::string & | newName | ) | [virtual] |
Saves the file under a new name.
newName | the name of the newly copied file. |
FileException | in all cases. |
Definition at line 199 of file OSDLEmbeddedFile.cc.
References _physfsHandle, Create(), and serialize().
virtual void OSDL::EmbeddedFile::seek | ( | Ceylan::System::Position | targetPosition | ) | [virtual] |
Seeks to specified position within this embedded file.
targetPosition | this position corresponds to the number of bytes from start of file to seek to. |
FileException | if the operation failed. |
void EmbeddedFile::serialize | ( | PHYSFS_File & | handle | ) | [virtual] |
Sends the file content to the fd PhysicsFS handle stream.
EmbeddedFileException | if the operation failed or if the PhysicsFS handle feature is not available. |
Definition at line 559 of file OSDLEmbeddedFile.cc.
References FromHandletoHandle(), and size().
Referenced by saveAs().
Size EmbeddedFile::size | ( | ) | const [virtual] |
Returns the file size, in bytes.
FileException,including | FileLookupFailed if the file metadata could not be accessed or if the operation is not supported on this platform, and FileDelegatingException if the corresponding filesystem manager could not be used as expected. |
Definition at line 522 of file OSDLEmbeddedFile.cc.
References OSDL::EmbeddedFileSystemManager::GetBackendLastError().
Referenced by serialize().
Position EmbeddedFile::tell | ( | ) | [virtual] |
Determines current position within this embedded file.
FileException | if the operation failed. |
Definition at line 451 of file OSDLEmbeddedFile.cc.
References _physfsHandle, and OSDL::EmbeddedFileSystemManager::GetBackendLastError().
const std::string EmbeddedFile::toString | ( | Ceylan::VerbosityLevels | level = Ceylan::high |
) | const [virtual] |
Returns an user-friendly description of the state of this object.
level | the requested verbosity level. |
Definition at line 645 of file OSDLEmbeddedFile.cc.
void EmbeddedFile::unlockForReading | ( | ) | const [virtual] |
Unlocks the file for reading.
FileReadUnlockingFailed | if the operation failed or if the file lock feature is not available. |
Definition at line 242 of file OSDLEmbeddedFile.cc.
void EmbeddedFile::unlockForWriting | ( | ) | const [virtual] |
Unlocks the file for writing.
FileWriteUnlockingFailed | if the operation failed or if the file lock feature is not available. |
Definition at line 262 of file OSDLEmbeddedFile.cc.
virtual Ceylan::System::Size OSDL::EmbeddedFile::write | ( | const Ceylan::Byte * | buffer, | |
Ceylan::System::Size | maxLength | |||
) | [virtual] |
Writes up to maxLength bytes from the specified buffer to this file.
buffer | the buffer where to find bytes that must be written to this file. Its size must be at least maxLength bytes. |
OutputStream::WriteFailedException | if a write error occurred. Note that this is not a child class of FileException, as it comes from an inherited interface. |
Size EmbeddedFile::write | ( | const std::string & | message | ) | [virtual] |
Writes message to this file.
The file must be opened for writing.
message | the message to write to this file. |
OutputStream::WriteFailedException | if a write error occurred. Note that this is not a child class of FileException, as it comes from an inherited interface. |
Definition at line 385 of file OSDLEmbeddedFile.cc.
Referenced by OSDL::EmbeddedFileSystemManager::copyFile().
bool OSDL::EmbeddedFile::_cypher [private] |
Tells whether reads and writes to this file should be cyphered.
Definition at line 634 of file OSDLEmbeddedFile.h.
PHYSFS_File* OSDL::EmbeddedFile::_physfsHandle [private] |