-
Notifications
You must be signed in to change notification settings - Fork 0
/
iff.h
89 lines (68 loc) · 1.91 KB
/
iff.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// vim: set ft=cpp:
#ifndef ZTERP_IFF_H
#define ZTERP_IFF_H
#include <exception>
#include <memory>
#include <string>
#include <vector>
#include "io.h"
#include "types.h"
class IFF {
public:
class TypeID {
public:
TypeID(unsigned char a, unsigned char b, unsigned char c, unsigned char d) :
m_type((static_cast<uint32_t>(a) << 24) |
(static_cast<uint32_t>(b) << 16) |
(static_cast<uint32_t>(c) << 8) |
(static_cast<uint32_t>(d) << 0)) {
}
TypeID() : m_type(0) {
}
explicit TypeID(uint32_t type) : m_type(type) {
}
explicit TypeID(const char (*type)[5]) : TypeID((*type)[0], (*type)[1], (*type)[2], (*type)[3]) {
}
uint32_t val() const {
return m_type;
}
std::string name() const {
std::string name;
name.push_back((m_type >> 24) & 0xff);
name.push_back((m_type >> 16) & 0xff);
name.push_back((m_type >> 8) & 0xff);
name.push_back((m_type >> 0) & 0xff);
return name;
}
bool empty() const {
return m_type == 0;
}
bool operator==(const TypeID &rhs) const {
return val() == rhs.val();
}
bool operator!=(const TypeID &rhs) const {
return !operator==(rhs);
}
private:
uint32_t m_type;
};
struct Entry {
Entry(TypeID type_, long offset_, uint32_t size_) :
type(type_), offset(offset_), size(size_) {
}
TypeID type;
long offset;
uint32_t size;
};
class InvalidFile : std::exception {
};
IFF(std::shared_ptr<IO> io, TypeID type);
bool find(TypeID type, uint32_t &size);
std::shared_ptr<IO> io() {
return m_io;
}
private:
std::shared_ptr<IO> m_io;
std::vector<Entry> m_entries;
};
#endif