-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedirectTape.h
53 lines (46 loc) · 1.34 KB
/
RedirectTape.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include "Containers/Array.h"
#include "Tape.h"
/**
* Redirects writes to multiple sub-tapes
*/
template <u32 NumTapes>
struct RedirectTape : public Tape {
TArr<Tape*, NumTapes> sub_tapes;
RedirectTape(TArr<Tape*, NumTapes> sub_tapes) : sub_tapes(sub_tapes) {}
// Interface
virtual u64 read(void* destination, u64 amount) override { return 0; }
virtual bool write(const void* src, u64 num_bytes) override
{
for (Tape* t : sub_tapes) {
if (!t->write(src, num_bytes)) {
return false;
}
}
return true;
}
virtual bool end() override { return false; }
virtual void move(i64 offset) override {}
};
template <u32 Count>
struct RedirectWriteTape : public WriteTape {
RedirectWriteTape(TArr<WriteTape*, Count> sub_tapes)
: sub_tapes(sub_tapes), WriteTape(write_proc, (void*)this)
{}
static PROC_WRITE_TAPE_WRITE(write_proc)
{
RedirectWriteTape* self = (RedirectWriteTape*)usr;
switch (mode) {
case WriteTapeMode::Write: {
for (WriteTape* t : self->sub_tapes) {
t->write(src, size);
}
return size;
} break;
default: {
} break;
}
return 0;
}
TArr<WriteTape*, Count> sub_tapes;
};