File: vector.hpp

package info (click to toggle)
higan 098-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 11,904 kB
  • ctags: 13,286
  • sloc: cpp: 108,285; ansic: 778; makefile: 32; sh: 18
file content (37 lines) | stat: -rw-r--r-- 1,171 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once

#include <nall/stream/stream.hpp>
#include <nall/vector.hpp>

namespace nall {

struct vectorstream : stream {
  using stream::read;
  using stream::write;

  vectorstream(vector<uint8_t>& memory) : memory(memory), pwritable(true) {}
  vectorstream(const vector<uint8_t>& memory) : memory((vector<uint8_t>&)memory), pwritable(false) {}

  auto seekable() const -> bool { return true; }
  auto readable() const -> bool { return true; }
  auto writable() const -> bool { return pwritable; }
  auto randomaccess() const -> bool { return true; }

  auto data() const -> uint8_t* { return memory.data(); }
  auto size() const -> uint { return memory.size(); }
  auto offset() const -> uint { return poffset; }
  auto seek(uint offset) const -> void { poffset = offset; }

  auto read() const -> uint8_t { return memory[poffset++]; }
  auto write(uint8_t data) const -> void { memory[poffset++] = data; }

  auto read(uint offset) const -> uint8_t { return memory[offset]; }
  auto write(uint offset, uint8_t data) const -> void { memory[offset] = data; }

protected:
  vector<uint8_t>& memory;
  mutable uint poffset = 0;
  mutable bool pwritable = false;
};

}