Debian Codegraph @

terps/bocfel/iff.h

raw symbols SCIP
1 // vim: set ft=cpp:
2
3 #ifndef ZTERP_IFF_H
4 #define ZTERP_IFF_H
5
6 #include <exception>
7 #include <memory>
8 #include <string>
9 #include <vector>
10
11 #include "io.h"
12 #include "types.h"
13
14 class IFF {
15 public:
16 class TypeID {
17 public:
18 TypeID(unsigned char a, unsigned char b, unsigned char c, unsigned char d) :
19 m_type((static_cast<uint32_t>(a) << 24) |
20 (static_cast<uint32_t>(b) << 16) |
21 (static_cast<uint32_t>(c) << 8) |
22 (static_cast<uint32_t>(d) << 0)) {
23 }
24
25 TypeID() : m_type(0) {
26 }
27
28 explicit TypeID(uint32_t type) : m_type(type) {
29 }
30
31 explicit TypeID(const char (&type)[5]) : TypeID(type[0], type[1], type[2], type[3]) {
32 }
33
34 uint32_t val() const {
35 return m_type;
36 }
37
38 std::string name() const {
39 std::string name;
40
41 name.push_back((m_type >> 24) & 0xff);
42 name.push_back((m_type >> 16) & 0xff);
43 name.push_back((m_type >> 8) & 0xff);
44 name.push_back((m_type >> 0) & 0xff);
45
46 return name;
47 }
48
49 bool empty() const {
50 return m_type == 0;
51 }
52
53 bool operator==(const TypeID &rhs) const {
54 return val() == rhs.val();
55 }
56
57 bool operator!=(const TypeID &rhs) const {
58 return !operator==(rhs);
59 }
60
61 private:
62 uint32_t m_type;
63 };
64
65 struct Entry {
66 Entry(TypeID type_, long offset_, uint32_t size_) :
67 type(type_), offset(offset_), size(size_) {
68 }
69 TypeID type;
70 long offset;
71 uint32_t size;
72 };
73
74 class InvalidFile : public std::exception {
75 };
76
77 IFF(std::shared_ptr<IO> io, TypeID type);
78 bool find(TypeID type, uint32_t &size);
79
80 std::shared_ptr<IO> io() {
81 return m_io;
82 }
83
84 private:
85 std::shared_ptr<IO> m_io;
86 std::vector<Entry> m_entries;
87 };
88
89 #endif