openMSX
|
#include <File.hh>
Public Types | |
enum class | OpenMode { NORMAL , TRUNCATE , CREATE , LOAD_PERSISTENT , SAVE_PERSISTENT , PRE_CACHE } |
Public Member Functions | |
File () | |
Create a closed file handle. | |
File (std::string filename, OpenMode mode=OpenMode::NORMAL) | |
Create file object and open underlying file. | |
File (const Filename &filename, OpenMode mode=OpenMode::NORMAL) | |
File (Filename &&filename, OpenMode mode=OpenMode::NORMAL) | |
File (std::string filename, const char *mode) | |
This constructor maps very closely on the fopen() libc function. | |
File (const Filename &filename, const char *mode) | |
File (Filename &&filename, const char *mode) | |
File (File &&other) noexcept | |
File (std::unique_ptr< FileBase > file_) | |
~File () | |
File & | operator= (File &&other) noexcept |
bool | is_open () const |
Return true iff this file handle refers to an open file. | |
void | close () |
Close the current file. | |
void | read (std::span< uint8_t > buffer) |
Read from file. | |
template<typename T > | |
void | read (std::span< T > buffer) |
void | write (std::span< const uint8_t > buffer) |
Write to file. | |
template<typename T > | |
void | write (std::span< T > buffer) |
std::span< const uint8_t > | mmap () |
Map file in memory. | |
void | munmap () |
Unmap file from memory. | |
size_t | getSize () |
Returns the size of this file. | |
void | seek (size_t pos) |
Move read/write pointer to the specified position. | |
size_t | getPos () |
Get the current position of the read/write pointer. | |
void | truncate (size_t size) |
Truncate file size. | |
void | flush () |
Force a write of all buffered data to disk. | |
const std::string & | getURL () const |
Returns the URL of this file object. | |
std::string_view | getOriginalName () |
Get Original filename for this object. | |
bool | isReadOnly () const |
Check if this file is readonly. | |
time_t | getModificationDate () |
Get the date/time of last modification. | |
Friends | |
class | LocalFileReference |
|
strong |
|
default |
Create a closed file handle.
The only valid operations on such an object are is_open() and the move-assignment operator.
|
explicit |
Create file object and open underlying file.
filename | Name of the file to be opened. |
mode | Mode to open the file in: |
FileNotFoundException | if file not found |
FileException | for other errors |
|
explicit |
|
explicit |
openmsx::File::File | ( | std::string | filename, |
const char * | mode | ||
) |
This constructor maps very closely on the fopen() libc function.
Compared to constructor above, it does not transparently uncompress files.
filename | Name of the file to be opened. |
mode | Open mode, same meaning as in fopen(), but we assert that it contains a 'b' character. |
openmsx::File::File | ( | const Filename & | filename, |
const char * | mode | ||
) |
openmsx::File::File | ( | Filename && | filename, |
const char * | mode | ||
) |
|
explicit |
|
default |
void openmsx::File::close | ( | ) |
Close the current file.
Equivalent to assigning a default constructed value to this object.
Definition at line 87 of file File.cc.
Referenced by openmsx::IDECDROM::eject(), openmsx::HD::serialize(), openmsx::PrinterPortLogger::unplugHelper(), and openmsx::AviWriter::~AviWriter().
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 132 of file File.cc.
Referenced by openmsx::WavWriter::flush(), and openmsx::PrinterPortLogger::setStrobe().
time_t openmsx::File::getModificationDate | ( | ) |
Get the date/time of last modification.
FileException |
Definition at line 158 of file File.cc.
Referenced by openmsx::FilePoolCore::getSha1Sum().
std::string_view 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.
FileException |
Definition at line 147 of file File.cc.
References getURL().
size_t openmsx::File::getPos | ( | ) |
Get the current position of the read/write pointer.
FileException |
Definition at line 122 of file File.cc.
Referenced by TEST_CASE().
size_t openmsx::File::getSize | ( | ) |
Returns the size of this file.
FileException |
Definition at line 112 of file File.cc.
Referenced by openmsx::WavWriter::flush(), openmsx::HD::HD(), openmsx::XMLDocument::load(), openmsx::SettingsConfig::loadSetting(), openmsx::MSXSCCPlusCart::MSXSCCPlusCart(), openmsx::HD::switchImage(), and TEST_CASE().
const std::string & openmsx::File::getURL | ( | ) | const |
Returns the URL of this file object.
FileException |
Definition at line 137 of file File.cc.
Referenced by openmsx::Rom::getFilename(), openmsx::IDECDROM::getMediaInfo(), openmsx::SCSILS120::getMediaInfo(), getOriginalName(), openmsx::FilePoolCore::getSha1Sum(), openmsx::DiskChanger::serialize(), openmsx::IDECDROM::serialize(), openmsx::SCSILS120::serialize(), and openmsx::AviWriter::~AviWriter().
|
inline |
Return true iff this file handle refers to an open file.
Definition at line 65 of file File.hh.
Referenced by openmsx::IDECDROM::executeCommand(), openmsx::FilePoolCore::getFile(), openmsx::Rom::getFilename(), openmsx::IDECDROM::getMediaInfo(), openmsx::SCSILS120::getMediaInfo(), openmsx::IDECDROM::readBlockStart(), openmsx::HD::serialize(), openmsx::IDECDROM::serialize(), openmsx::SCSILS120::serialize(), openmsx::PrinterPortLogger::setStrobe(), and TEST_CASE().
bool openmsx::File::isReadOnly | ( | ) | const |
Check if this file is readonly.
FileException |
Definition at line 153 of file File.cc.
Referenced by TEST_CASE().
std::span< const uint8_t > openmsx::File::mmap | ( | ) |
Map file in memory.
FileException |
Definition at line 102 of file File.cc.
Referenced by openmsx::GLHQLiteScaler::GLHQLiteScaler(), openmsx::GLHQScaler::GLHQScaler(), openmsx::SymbolManager::loadSymbolFile(), openmsx::MsxChar2Unicode::MsxChar2Unicode(), openmsx::UnicodeKeymap::UnicodeKeymap(), openmsx::WavData::WavData(), and openmsx::XSAExtractor::XSAExtractor().
|
inline |
void openmsx::File::read | ( | std::span< uint8_t > | buffer | ) |
Read from file.
buffer | Destination buffer |
FileException |
Definition at line 92 of file File.cc.
Referenced by openmsx::FirmwareSwitch::FirmwareSwitch(), openmsx::XMLDocument::load(), openmsx::SettingsConfig::loadSetting(), openmsx::MSXSCCPlusCart::MSXSCCPlusCart(), read(), openmsx::IDECDROM::readBlockStart(), and TEST_CASE().
void openmsx::File::seek | ( | size_t | pos | ) |
Move read/write pointer to the specified position.
pos | Position in bytes from the beginning of the file. |
FileException |
Definition at line 117 of file File.cc.
Referenced by openmsx::WavWriter::flush(), openmsx::IDECDROM::readBlockStart(), openmsx::OggReader::seek(), TEST_CASE(), and openmsx::AviWriter::~AviWriter().
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)
FileException |
Definition at line 127 of file File.cc.
Referenced by openmsx::DiskManipulator::create(), and openmsx::HD::HD().
void openmsx::File::write | ( | std::span< const uint8_t > | buffer | ) |
Write to file.
buffer | Source buffer |
FileException |
Definition at line 97 of file File.cc.
Referenced by openmsx::AviWriter::AviWriter(), openmsx::WavWriter::flush(), openmsx::PrinterPortLogger::setStrobe(), TEST_CASE(), openmsx::WavWriter::WavWriter(), openmsx::Wav16Writer::write(), openmsx::Wav16Writer::write(), openmsx::Wav16Writer::write(), openmsx::Wav8Writer::write(), write(), openmsx::Wav16Writer::writeSilence(), openmsx::AviWriter::~AviWriter(), openmsx::FirmwareSwitch::~FirmwareSwitch(), and openmsx::WavWriter::~WavWriter().
|
inline |
|
friend |