Skip to content

Commit fdcf5fc

Browse files
authored
Merge pull request #4 from Theadd/dev-baseIndex
Custom BaseIndex + Enumerator fix
2 parents 8a8bc12 + 5435080 commit fdcf5fc

11 files changed

Lines changed: 208 additions & 100 deletions

ArrayListLib.twinproj

5.91 KB
Binary file not shown.

ArrayListLib/Settings

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
"optimizer.constantFunctionFolding": true,
55
"project.appTitle": "ArrayList",
66
"project.buildPath": "${SourcePath}\\Build\\${ProjectName}_${Architecture}.${FileExtension}",
7-
"project.buildType": "ActiveX DLL",
7+
"project.buildType": "Package TWINPACK",
88
"project.description": "mscorlib's ArrayList drop-in replacement",
9+
"project.disablePackageVBA": false,
10+
"project.disablePackageVBRUN": true,
911
"project.dllRegisterLocalMachine": false,
1012
"project.exportPathIsV2": true,
1113
"project.id": "{8647345A-521F-4728-84BC-0D28FA583254}",
1214
"project.isConsoleApplication": true,
1315
"project.licence": "Unlicense",
1416
"project.name": "ArrayListLib",
1517
"project.optionExplicit": true,
16-
"project.packageVisibility": "PRIVATE",
18+
"project.packageVisibility": "PUBLIC",
1719
"project.references": [
1820
{
1921
"id": "{00020430-0000-0000-C000-000000000046}",
@@ -29,7 +31,7 @@
2931
"project.settingsVersion": 1,
3032
"project.useProjectIdForTypeLibraryId": true,
3133
"project.versionAutoIncrement": "Build",
32-
"project.versionBuild": 132,
34+
"project.versionBuild": 134,
3335
"project.versionLegalCopyright": "This is free and unencumbered software released into the public domain. For more information, please refer to <https://unlicense.org>",
3436
"project.versionMajor": 1,
3537
"project.versionMinor": 4,

ArrayListLib/Sources/ArrayList.twin

Lines changed: 85 additions & 41 deletions
Large diffs are not rendered by default.

ArrayListLib/Sources/Enumerator.twin

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Public Class Enumerator
3131
Private Items() As Variant
3232
Private CStep As Long
3333
Private NStep As Long
34+
Private IsEnumerating As Boolean
3435
Private Const E_INVALIDARGS As Long = &H80070057
3536
Private Const S_OK As Long = 0
3637
Private Const S_FALSE As Long = 1
@@ -53,6 +54,8 @@ Public Class Enumerator
5354
PutMem4 ArrPtr(Items) + SAFEARRAY_CELEMENTS_OFFSET, Value
5455
End Property
5556

57+
Public Property Get IsAvailable() As Boolean: IsAvailable = Not IsEnumerating: End Property
58+
5659
Public Sub New()
5760
End Sub
5861

@@ -74,8 +77,13 @@ Public Class Enumerator
7477
End With
7578
VBA.PutMemPtr VarPtrArr(Items), VarPtr(sa)
7679
CStep = GetStep
80+
NStep = 0
7781
MaxValue = GetCount
78-
If CStep < 0 Then CIndex = GetCount - 1
82+
If CStep < 0 Then
83+
CIndex = GetCount - 1
84+
Else
85+
CIndex = 0
86+
End If
7987
End Sub
8088

8189
[ Enumerator ]
@@ -98,6 +106,7 @@ Public Class Enumerator
98106
Err.ReturnHResult = S_OK
99107
Else
100108
If VarPtr(pceltFetched) <> 0 Then pceltFetched = 0
109+
IsEnumerating = False
101110
Err.ReturnHResult = S_FALSE
102111
End If
103112
End If
@@ -114,6 +123,8 @@ Public Class Enumerator
114123

115124
Private Sub Reset() Implements IEnumerator.Reset
116125
CIndex = If(CStep < 0, MaxValue - 1, 0)
126+
NStep = 0
127+
IsEnumerating = True
117128
End Sub
118129

119130
Private Sub Clone(ByRef ppenum As IEnumVARIANT) Implements IEnumerator.Clone

ArrayListLib/Sources/IArrayList.twin

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Public Interface IList Extends ICollection
3535
Property Get IsReadOnly() As Boolean
3636
Property Get IsFixedSize() As Boolean
3737
[ Description ("Returns the index of a particular item. Returns -1 if the item isn't in the list.") ]
38-
Function IndexOf(Value As Variant, Optional ByVal Index As Long = 0, Optional ByVal GetCount As Variant) As Long
38+
Function IndexOf(Value As Variant, Optional ByVal Index As Variant, Optional ByVal GetCount As Variant) As Long
3939
[ Description ("Inserts value into the list at position Index. Index must be non-negative and less than or equal to the number of elements in the list. If Index equals the number of items in the list, then value is appended to the end.") ]
4040
Sub Insert(ByVal Index As Long, Value As Variant)
4141
[ Description ("Removes an item from the list.") ]
@@ -54,7 +54,7 @@ Public Interface IListRange Extends IList
5454
Sub SetRange(ByVal Index As Long, Target As Variant)
5555
Function ToArray() As Variant()
5656
[ Description ("Sorts the elements in a section of this list. The sort compares the elements to each other using the given IComparer interface.") ]
57-
Sub Sort(Optional ByVal Index As Long = 0, Optional ByVal GetCount As Variant, Optional ByRef Comparer As IComparer = Nothing)
57+
Sub Sort(Optional ByVal Index As Variant, Optional ByVal GetCount As Variant, Optional ByRef Comparer As IComparer = Nothing)
5858
Function BinarySearch(ByVal Index As Long, ByVal GetCount As Long, ByRef Value As Variant, Optional ByRef Comparer As IComparer = Nothing) As Long
5959
[ Hidden ]
6060
Function GetAddressOfItemAt(Index As Long) As LongPtr
@@ -65,6 +65,8 @@ Public Interface IArrayList Extends IListRange
6565
Implements ICloneable
6666

6767
Function Clone() As Variant Implements ICloneable.Clone
68+
Property Get BaseIndex() As Long
69+
Property Let BaseIndex(Value As Long)
6870
[ Hidden ]
6971
Property Get Version() As Long
7072
Property Get Capacity() As Long
@@ -75,5 +77,5 @@ Public Interface IArrayList Extends IListRange
7577
[ Hidden ]
7678
Sub CloneTo(ByVal Target As IArrayList, ByRef Source As IArrayList, ByVal Index As Long, ByVal GetCount As Long)
7779
Function LastIndexOf(ByRef Value As Variant, Optional ByVal Index As Variant, Optional ByVal GetCount As Variant) As Long
78-
Sub Reverse(Optional ByVal Index As Long = 0, Optional ByVal GetCount As Variant)
80+
Sub Reverse(Optional ByVal Index As Variant, Optional ByVal GetCount As Variant)
7981
End Interface

ArrayListLib/Sources/LibMemoryEx.twin

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ Public Module LibMemoryEx
3030
With sASrc
3131
.cDims = 1
3232
.cbElements = ArrayElementSize
33-
.fFeatures = IIf(ArrayElementSize = VARIANT_SIZE, FADF_VARIANT, 0)
33+
.fFeatures = Iif(ArrayElementSize = VARIANT_SIZE, FADF_VARIANT, 0)
3434
.pvData = SourceAddress
3535
.rgsabound0.cElements = GetCount
3636
End With
3737
With sADst
3838
.cDims = 1
3939
.cbElements = ArrayElementSize
40-
.fFeatures = IIf(ArrayElementSize = VARIANT_SIZE, FADF_VARIANT Or FADF_EMBEDDED, FADF_EMBEDDED)
40+
.fFeatures = Iif(ArrayElementSize = VARIANT_SIZE, FADF_VARIANT Or FADF_EMBEDDED, FADF_EMBEDDED)
4141
.pvData = DestinationAddress
4242
.rgsabound0.cElements = GetCount
4343
End With

0 commit comments

Comments
 (0)