openMSX
FileBase.hh
Go to the documentation of this file.
1 #ifndef FILEBASE_HH
2 #define FILEBASE_HH
3 
4 #include "MemBuffer.hh"
5 #include "span.hh"
6 #include <cstdint>
7 #include <string>
8 
9 namespace openmsx {
10 
11 class FileBase
12 {
13 public:
14  virtual ~FileBase() = default;
15 
16  virtual void read(void* buffer, size_t num) = 0;
17  virtual void write(const void* buffer, size_t num) = 0;
18 
19  // If you override mmap(), make sure to call munmap() in
20  // your destructor.
21  [[nodiscard]] virtual span<const uint8_t> mmap();
22  virtual void munmap();
23 
24  [[nodiscard]] virtual size_t getSize() = 0;
25  virtual void seek(size_t pos) = 0;
26  [[nodiscard]] virtual size_t getPos() = 0;
27  virtual void truncate(size_t size);
28  virtual void flush() = 0;
29 
30  [[nodiscard]] virtual const std::string& getURL() const = 0;
31  [[nodiscard]] virtual std::string getLocalReference();
32  [[nodiscard]] virtual std::string_view getOriginalName();
33  [[nodiscard]] virtual bool isReadOnly() const = 0;
34  [[nodiscard]] virtual time_t getModificationDate() = 0;
35 
36 private:
37  MemBuffer<uint8_t> mmapBuf;
38 };
39 
40 } // namespace openmsx
41 
42 #endif
virtual size_t getSize()=0
virtual std::string getLocalReference()
Definition: FileBase.cc:51
virtual void read(void *buffer, size_t num)=0
virtual void write(const void *buffer, size_t num)=0
virtual std::string_view getOriginalName()
Definition: FileBase.cc:58
virtual void flush()=0
virtual void seek(size_t pos)=0
virtual ~FileBase()=default
virtual bool isReadOnly() const =0
virtual const std::string & getURL() const =0
virtual size_t getPos()=0
virtual time_t getModificationDate()=0
virtual void truncate(size_t size)
Definition: FileBase.cc:31
virtual span< const uint8_t > mmap()
Definition: FileBase.cc:10
virtual void munmap()
Definition: FileBase.cc:26
This file implemented 3 utility functions:
Definition: Autofire.cc:9
size_t size(std::string_view utf8)