1 | #pragma once |
2 | |
3 | #include <ore/BinaryFile.h> |
4 | #include <ore/EnumUtil.h> |
5 | #include <ore/ResDic.h> |
6 | #include <ore/StringView.h> |
7 | #include <ore/Types.h> |
8 | |
9 | namespace ore { |
10 | |
11 | struct ResDic; |
12 | struct ResEndian; |
13 | |
14 | struct ResMetaData { |
15 | struct ActorIdentifier { |
16 | BinTPtr<BinString> name; |
17 | BinTPtr<BinString> sub_name; |
18 | }; |
19 | |
20 | union Value { |
21 | BinTPtr<ResMetaData> container; |
22 | // Also used for booleans. Anything that is != 0 is treated as true. |
23 | int i; |
24 | float f; |
25 | BinTPtr<BinString> str; |
26 | BinTPtr<BinWString> wstr; |
27 | ActorIdentifier actor; |
28 | }; |
29 | |
30 | ORE_ENUM(DataType, kArgument, kContainer, kInt, kBool, kFloat, kString, kWString, kIntArray, kBoolArray, kFloatArray, kStringArray, kWStringArray, kActorIdentifier) |
31 | |
32 | /// @warning Only usable if type == kContainer. |
33 | const ResMetaData* Get(const StringView& key, DataType::Type expected_type) const { |
34 | const int idx = dictionary.Get()->FindIndex(key); |
35 | if (idx == -1) |
36 | return nullptr; |
37 | |
38 | const auto* meta = (&value.container + idx)->Get(); |
39 | if (meta->type != expected_type) |
40 | return nullptr; |
41 | |
42 | return meta; |
43 | } |
44 | |
45 | SizedEnum<DataType::Type, u8> type; |
46 | u16 num_items; |
47 | BinTPtr<ResDic> dictionary; |
48 | Value value; |
49 | }; |
50 | |
51 | // XXX: is this unused? |
52 | struct ResUserData { |
53 | ORE_ENUM(DataType, kInt, kFloat, kString, kWString, kStream) |
54 | }; |
55 | |
56 | void SwapEndian(ResEndian* endian, ResMetaData* res); |
57 | |
58 | } // namespace ore |
59 | |