Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/nall/stream/memory.hpp
2 views
1
#ifdef NALL_STREAM_INTERNAL_HPP
2
3
namespace nall {
4
5
struct memorystream : stream {
6
inline bool seekable() const { return true; }
7
inline bool readable() const { return true; }
8
inline bool writable() const { return pwritable; }
9
inline bool randomaccess() const { return true; }
10
11
inline unsigned size() const { return psize; }
12
inline unsigned offset() const { return poffset; }
13
inline void seek(unsigned offset) const { poffset = offset; }
14
15
inline uint8_t read() const { return pdata[poffset++]; }
16
inline void write(uint8_t data) const { pdata[poffset++] = data; }
17
18
inline uint8_t read(unsigned offset) const { return pdata[offset]; }
19
inline void write(unsigned offset, uint8_t data) const { pdata[offset] = data; }
20
21
inline memorystream() : pdata(nullptr), psize(0), poffset(0), pwritable(true) {}
22
23
inline memorystream(uint8_t *data, unsigned size) {
24
pdata = data, psize = size, poffset = 0;
25
pwritable = true;
26
}
27
28
inline memorystream(const uint8_t *data, unsigned size) {
29
pdata = (uint8_t*)data, psize = size, poffset = 0;
30
pwritable = false;
31
}
32
33
protected:
34
mutable uint8_t *pdata;
35
mutable unsigned psize, poffset, pwritable;
36
};
37
38
}
39
40
#endif
41
42