-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathArrayClass.cs
134 lines (113 loc) · 3.63 KB
/
ArrayClass.cs
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace PatcherYRpp
{
[StructLayout(LayoutKind.Sequential)]
public struct DynamicVectorClass<T> : IEnumerable<T>
{
static public ref DynamicVectorClass<T> GetDynamicVector(IntPtr ptr)
{
return ref Helpers.GetUnmanagedRef<DynamicVectorClass<T>>(ptr);
}
public ref T this[int index] { get => ref Get(index); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T Get(int index) => ref Helpers.GetUnmanagedRef<T>(Items, index);
public Span<T> GetSpan()
{
return Helpers.GetSpan<T>(Items, Count);
}
public unsafe bool OperatorEqual(Pointer<DynamicVectorClass<T>> pOther)
{
var func = (delegate* unmanaged[Thiscall]<IntPtr, IntPtr, Bool>)this.GetVirtualFunctionPointer(1);
return func(this.GetThisPointer(), pOther);
}
public unsafe bool SetCapacity(int capacity, Pointer<T> pMem = default)
{
var func = (delegate* unmanaged[Thiscall]<IntPtr, int, IntPtr, Bool>)this.GetVirtualFunctionPointer(2);
return func(this.GetThisPointer(), capacity, pMem);
}
public unsafe void Clear()
{
var func = (delegate* unmanaged[Thiscall]<IntPtr, void>)this.GetVirtualFunctionPointer(3);
func(this.GetThisPointer());
}
public unsafe int FindItemIndex(Pointer<T> pItem)
{
var func = (delegate* unmanaged[Thiscall]<IntPtr, IntPtr, int>)this.GetVirtualFunctionPointer(4);
return func(this.GetThisPointer(), pItem);
}
public unsafe int GetItemIndex(Pointer<T> pItem)
{
var func = (delegate* unmanaged[Thiscall]<IntPtr, IntPtr, int>)this.GetVirtualFunctionPointer(5);
return func(this.GetThisPointer(), pItem);
}
public bool AddItem(T item)
{
if (Count >= Capacity)
{
if (!IsAllocated && Capacity != 0)
return false;
if (CapacityIncrement <= 0)
return false;
if (!SetCapacity(Capacity + CapacityIncrement))
return false;
}
this[Count++] = item;
return true;
}
public bool AddUnique(Pointer<T> pItem)
{
int idx = FindItemIndex(pItem);
return idx < 0 && AddItem(pItem.Ref);
}
class Enumerator : IEnumerator<T>, IEnumerator
{
internal Enumerator(Pointer<T> items, int count)
{
this.items = items;
this.count = count;
Reset();
}
public void Dispose() { }
public bool MoveNext()
{
if (index < count)
{
current = items[index];
index++;
return true;
}
return false;
}
public T Current => current;
object IEnumerator.Current => Current;
public void Reset()
{
index = 0;
current = default(T);
}
private Pointer<T> items;
private int count;
private int index;
private T current;
}
public IEnumerator<T> GetEnumerator()
{
return new Enumerator(Items, Count);
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
private IntPtr Vfptr;
public IntPtr Items;
public int Capacity;
public Bool IsInitialized;
public Bool IsAllocated;
public int Count;
public int CapacityIncrement;
}
}