1
2
3
4
5
6 using System.Os;
7
8 namespace System
9 {
10 public ResourcePtr GetResource(const char* resourceName)
11 {
12 return ResourcePtr(OpenResource(resourceName));
13 }
14
15 public class ResourcePtr
16 {
17 public ResourcePtr(int rd_) : rd(rd_), size(GetResourceSize(rd))
18 {
19 data = cast<byte*>(MemAlloc(size));
20 ReadResource(rd, 0, size, data);
21 }
22 suppress ResourcePtr(const ResourcePtr&);
23 suppress void operator=(const ResourcePtr&);
24 public nothrow ResourcePtr(ResourcePtr&& that) : rd(that.rd), size(that.size), data(that.data)
25 {
26 that.rd = -1;
27 that.size = -1;
28 that.data = null;
29 }
30 public default nothrow void operator=(ResourcePtr&& that);
31 public ~ResourcePtr()
32 {
33 if (data != null)
34 {
35 MemFree(data);
36 }
37 if (rd != -1)
38 {
39 close_resource(rd);
40 }
41 }
42 public nothrow int Descriptor() const
43 {
44 return rd;
45 }
46 public nothrow long Size() const
47 {
48 return size;
49 }
50 public nothrow byte* Data() const
51 {
52 return data;
53 }
54 public nothrow byte* ReleaseData()
55 {
56 byte* result = data;
57 data = null;
58 return result;
59 }
60 private int rd;
61 private long size;
62 private byte* data;
63 }
64 }