forked from uliwitness/stackimport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCResourceFile.h
77 lines (67 loc) · 1.52 KB
/
CResourceFile.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
/*
* CResourceFile.h
* stackimport
*
* Created by Justin Blanchard on 11/11/15.
* License: MIT
*
*/
// If you're not compiling for a platform where the Mac resource manager is
// available, set the following to 0 to remove that code from compilation:
#define MAC_CODE 0
// If you're compiling for 64 bit, you don't have access to QuickTime, which
// we use to create AIFF files from 'snd ' resources. So turn this off.
#define USE_QUICKTIME (!__LP64__)
#include <map>
#include <string>
#include <stdint.h>
#include <stdlib.h>
#if MAC_CODE
#include <Carbon/Carbon.h>
#if USE_QUICKTIME
#include <QuickTime/QuickTime.h>
#endif
#endif
class CResource
{
public:
CResource();
operator bool();
int16_t GetID();
const std::string& GetName();
const char* GetBuffer();
size_t GetSize();
#if MAC_CODE
CResource( Handle handle );
Handle GetHandle();
#else
CResource( int16_t id, const std::string& fpath );
#endif
protected:
int16_t mID;
std::string mName;
std::string mBuffer;
#if MAC_CODE
Handle mHandle;
#else
#endif
};
class CResourceFile
{
public:
CResourceFile();
void LoadFile( const std::string& fpath );
void Close();
int16_t Count( const std::string& type );
CResource GetByID( const std::string& type, int16_t id );
CResource GetByIndex( const std::string& type, int16_t index );
protected:
#if MAC_CODE
OSType MakeOSType( const std::string& type );
SInt16 mResRefNum;
#else
typedef std::map<int16_t, std::string> IDMap;
typedef std::map<std::string, IDMap> TypeMap;
TypeMap mMap;
#endif
};