openMSX
Public Types | Public Member Functions | Friends | List of all members
openmsx::File Class Reference

#include <File.hh>

Inheritance diagram for openmsx::File:
Inheritance graph
[legend]
Collaboration diagram for openmsx::File:
Collaboration graph
[legend]

Public Types

enum  OpenMode {
  NORMAL, TRUNCATE, CREATE, LOAD_PERSISTENT,
  SAVE_PERSISTENT, PRE_CACHE
}
 

Public Member Functions

 File (string_ref filename, OpenMode mode=NORMAL)
 Create file object and open underlying file. More...
 
 File (const Filename &filename, OpenMode mode=NORMAL)
 
 File (string_ref filename, const char *mode)
 This constructor maps very closely on the fopen() libc function. More...
 
 File (const Filename &filename, const char *mode)
 
 ~File ()
 
void read (void *buffer, size_t num)
 Read from file. More...
 
void write (const void *buffer, size_t num)
 Write to file. More...
 
const bytemmap (size_t &size)
 Map file in memory. More...
 
void munmap ()
 Unmap file from memory. More...
 
size_t getSize ()
 Returns the size of this file. More...
 
void seek (size_t pos)
 Move read/write pointer to the specified position. More...
 
size_t getPos ()
 Get the current position of the read/write pointer. More...
 
void truncate (size_t size)
 Truncate file size. More...
 
void flush ()
 Force a write of all buffered data to disk. More...
 
const std::string getURL () const
 Returns the URL of this file object. More...
 
const std::string getOriginalName ()
 Get Original filename for this object. More...
 
bool isReadOnly () const
 Check if this file is readonly. More...
 
time_t getModificationDate ()
 Get the date/time of last modification. More...
 
Sha1Sum getSha1Sum ()
 Calculate sha1sum of this file. More...
 
void setFilePool (FilePool &filepool)
 Set FilePool, see also getSha1Sum() FilePool is used to lookup/store sha1sum<->filename mappings. More...
 

Friends

class LocalFileReference
 

Detailed Description

Definition at line 17 of file File.hh.

Member Enumeration Documentation

Enumerator
NORMAL 
TRUNCATE 
CREATE 
LOAD_PERSISTENT 
SAVE_PERSISTENT 
PRE_CACHE 

Definition at line 20 of file File.hh.

Constructor & Destructor Documentation

openmsx::File::File ( string_ref  filename,
OpenMode  mode = NORMAL 
)
explicit

Create file object and open underlying file.

Parameters
filenameName of the file to be opened.
modeMode to open the file in:
Exceptions
FileNotFoundExceptionif file not found
FileExceptionfor other errors

Definition at line 46 of file File.cc.

openmsx::File::File ( const Filename filename,
OpenMode  mode = NORMAL 
)
explicit

Definition at line 40 of file File.cc.

openmsx::File::File ( string_ref  filename,
const char *  mode 
)

This constructor maps very closely on the fopen() libc function.

Compared to constructor above, it does not transparantly uncompress files.

Parameters
filenameName of the file to be opened.
modeOpen mode, same meaning as in fopen(), but we assert that it contains a 'b' character.

Definition at line 52 of file File.cc.

openmsx::File::File ( const Filename filename,
const char *  mode 
)

Definition at line 58 of file File.cc.

openmsx::File::~File ( )

Definition at line 64 of file File.cc.

Member Function Documentation

void openmsx::File::flush ( )

Force a write of all buffered data to disk.

There is no need to call this function before destroying a File object.

Definition at line 112 of file File.cc.

time_t openmsx::File::getModificationDate ( )

Get the date/time of last modification.

Exceptions
FileException

Definition at line 138 of file File.cc.

Referenced by openmsx::FilePool::getSha1Sum().

const string openmsx::File::getOriginalName ( )

Get Original filename for this object.

This will usually just return the filename portion of the URL. However for compressed files this will be different.

Returns
Original file name
Exceptions
FileException

Definition at line 127 of file File.cc.

References getURL().

size_t openmsx::File::getPos ( )

Get the current position of the read/write pointer.

Returns
Position in bytes from the beginning of the file.
Exceptions
FileException

Definition at line 102 of file File.cc.

Sha1Sum openmsx::File::getSha1Sum ( )

Calculate sha1sum of this file.

If the FilePool was set (see setFilePool()), the calculation can possibly be avoided by using the pool as a cache. Note that currently it's even an error to call this method without first having called setFilePool(), we might change this in the future.

Definition at line 143 of file File.cc.

References openmsx::Sha1Sum::empty(), and openmsx::FilePool::getSha1Sum().

Referenced by openmsx::WavImage::WavImage().

size_t openmsx::File::getSize ( )

Returns the size of this file.

Returns
The size of this file
Exceptions
FileException

Definition at line 92 of file File.cc.

Referenced by openmsx::XMLLoader::load().

const string openmsx::File::getURL ( ) const

Returns the URL of this file object.

Exceptions
FileException

Definition at line 117 of file File.cc.

Referenced by getOriginalName(), openmsx::FilePool::getSha1Sum(), and openmsx::FilePool::removeSha1Sum().

bool openmsx::File::isReadOnly ( ) const

Check if this file is readonly.

Returns
true iff file is readonly
Exceptions
FileException

Definition at line 133 of file File.cc.

const byte * openmsx::File::mmap ( size_t &  size)

Map file in memory.

Parameters
sizeFilled in with filesize.
Returns
Pointer to memory block.
Exceptions
FileException

Definition at line 82 of file File.cc.

Referenced by openmsx::UnicodeKeymap::UnicodeKeymap(), and openmsx::XSAExtractor::XSAExtractor().

void openmsx::File::munmap ( )

Unmap file from memory.

Definition at line 87 of file File.cc.

void openmsx::File::read ( void *  buffer,
size_t  num 
)

Read from file.

Parameters
bufferDestination address
numNumber of bytes to read
Exceptions
FileException

Definition at line 68 of file File.cc.

Referenced by openmsx::FirmwareSwitch::FirmwareSwitch(), openmsx::IPSPatch::IPSPatch(), and openmsx::XMLLoader::load().

void openmsx::File::seek ( size_t  pos)

Move read/write pointer to the specified position.

Parameters
posPosition in bytes from the beginning of the file.
Exceptions
FileException

Definition at line 97 of file File.cc.

void openmsx::File::setFilePool ( FilePool filepool)

Set FilePool, see also getSha1Sum() FilePool is used to lookup/store sha1sum<->filename mappings.

But also to invalidate these mappings on writes to this file (the file modification date is used as well to detect writes).

Definition at line 152 of file File.cc.

Referenced by openmsx::WavImage::WavImage().

void openmsx::File::truncate ( size_t  size)

Truncate file size.

Enlarging file size always works, but making file smaller doesn't work on some platforms (windows)

Exceptions
FileException

Definition at line 107 of file File.cc.

void openmsx::File::write ( const void *  buffer,
size_t  num 
)

Write to file.

Parameters
bufferSource address
numNumber of bytes to write
Exceptions
FileException

Definition at line 73 of file File.cc.

References openmsx::Sha1Sum::clear(), and openmsx::FilePool::removeSha1Sum().

Referenced by openmsx::SettingsConfig::saveSetting().

Friends And Related Function Documentation

friend class LocalFileReference
friend

Definition at line 146 of file File.hh.


The documentation for this class was generated from the following files: