summaryrefslogtreecommitdiff
path: root/include/JSystem/JSupport/JSUInputStream.h
blob: ac36bac1815fbf00b255c6d211de1c42680cdc3b (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef JSUINPUTSTREAM_H
#define JSUINPUTSTREAM_H

#include "JSystem/JSupport/JSUIosBase.h"

enum JSUStreamSeekFrom {
    JSUStreamSeekFrom_SET = 0,  // absolute
    JSUStreamSeekFrom_CUR = 1,  // relative
    JSUStreamSeekFrom_END = 2,  // relative to end
};

class JSUInputStream : public JSUIosBase {
public:
    JSUInputStream() {}
    virtual ~JSUInputStream();

    /* vt[3] */ virtual s32 getAvailable() const = 0;
    /* vt[4] */ virtual s32 skip(s32);
    /* vt[5] */ virtual u32 readData(void*, s32) = 0;

    u32 readU32() {
        u32 val;
        this->read(&val, sizeof(val));
        return val;
    }

    u32 read32b() {
        u32 val;
        this->read(&val, sizeof(val));
        return val;
    }

    s32 readS32() {
        s32 val;
        this->read(&val, sizeof(val));
        return val;
    }

    s16 readS16() {
        s16 val;
        this->read(&val, sizeof(val));
        return val;
    }

    u16 readU16() {
        u16 val;
        this->read(&val, sizeof(val));
        return val;
    }

    u8 readU8() {
        u8 val;
        this->read(&val, sizeof(val));
        return val;
    }

    u8 read8b() {
        u8 val;
        this->read(&val, sizeof(val));
        return val;
    }

    u16 read16b() {
        u16 val;
        this->read(&val, sizeof(val));
        return val;
    }

    // TODO: return value probably wrong
    s32 read(void*, s32);
};  // Size = 0x8

// move?
template <typename T>
T* JSUConvertOffsetToPtr(const void*, const void*);

#endif /* JSUINPUTSTREAM_H */