-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathITL_StructureArray.ahk
102 lines (92 loc) · 2.82 KB
/
ITL_StructureArray.ahk
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
90
91
92
93
94
95
96
97
98
99
100
101
102
; zero-based
class ITL_StructureArray
{
__New(type, count)
{
this[ITL.Properties.ARRAY_ELEMTYPEOBJ] := type
, this[ITL.Properties.ARRAY_ELEMCOUNT] := count
, this[ITL.Properties.ARRAY_MEMBUFFER] := ITL_Mem_Allocate(count * type.GetSize())
, this[ITL.Properties.ARRAY_ELEMSIZE] := type.GetSize()
, this[ITL.Properties.ARRAY_INSTANCEOBJ] := []
}
__Get(property)
{
local buffer, size, index, struct, type
if (property != "base" && !ITL.Properties.IsInternalProperty(property))
{
count := this[ITL.Properties.ARRAY_ELEMCOUNT]
if (property == "")
{
buffer := this[ITL.Properties.ARRAY_MEMBUFFER], size := this[ITL.Properties.ARRAY_ELEMSIZE]
for index, struct in this
{
ITL_Mem_Copy(struct[ITL.Properties.INSTANCE_POINTER], buffer + index * size, size)
}
return buffer
}
else if property is not integer
{
throw Exception(ITL_FormatException("Failed to retrieve an array element."
, """" property """ is not a valid array index."
, ErrorLevel)*)
}
else if (property < 0 || property >= count)
{
throw Exception(ITL_FormatException("Failed to retrieve an array element."
, """" property """ is out of range."
, ErrorLevel)*)
}
struct := this[ITL.Properties.ARRAY_INSTANCEOBJ][property]
if (!IsObject(struct))
{
type := this[ITL.Properties.ARRAY_ELEMTYPEOBJ]
, this[ITL.Properties.ARRAY_INSTANCEOBJ][property] := struct := new type()
}
return struct
}
}
__Set(property, value)
{
local count := this[ITL.Properties.ARRAY_ELEMCOUNT]
if (property != "base" && !ITL.Properties.IsInternalProperty(property))
{
if property is not integer
{
throw Exception(ITL_FormatException("Failed to set an array element."
, """" property """ is not a valid array index."
, ErrorLevel)*)
}
else if (property < 0 || property >= count)
{
throw Exception(ITL_FormatException("Failed to set an array element."
, """" property """ is out of range."
, ErrorLevel)*)
}
if value is integer
{
value := new this[ITL.Properties.ARRAY_ELEMTYPEOBJ](value, true)
}
this[ITL.Properties.ARRAY_INSTANCEOBJ][property] := value
}
}
_NewEnum()
{
return ObjNewEnum(this[ITL.Properties.ARRAY_INSTANCEOBJ])
}
NewEnum()
{
return this._NewEnum()
}
SetCapacity(newCount)
{
local newBuffer := ITL_Mem_Allocate(newCount * this[ITL.Properties.ARRAY_ELEMSIZE])
, oldBuffer := this[ITL.Properties.ARRAY_MEMBUFFER]
, oldCount := this[ITL.Properties.ARRAY_ELEMCOUNT]
ITL_Mem_Copy(oldBuffer, newBuffer, oldCount), ITL_Mem_Release(oldBuffer)
this[ITL.Properties.ARRAY_MEMBUFFER] := newBuffer, this[ITL.Properties.ARRAY_ELEMCOUNT] := newCount
if (newCount < oldCount)
{
this[ITL.Properties.ARRAY_INSTANCEOBJ].Remove(newCount - 1, oldCount - 1)
}
}
}