Overrides MfEnumerableBase._NewEnum()
OutPutVar := instance._NewEnum()
Returns a new enumerator to enumerate this object's key-value pairs. This method is usually not called directly, but by the for-loop or by GetEnumerator()
Protected Abstract Method.
Must be overridden in derived classes.
class TheList extends MfEnumerableBase
{
m_InnerList := Null
m_Enum := Null
__New() {
base.__New()
this.m_isInherited := this.__Class != "TheList"
this.m_InnerList := []
this.m_InnerList.Count := 0
this.m_Enum := Null
}
Add(obj) {
_newCount := this.m_InnerList.Count + 1
this.m_InnerList[_newCount] := obj
this.m_InnerList.Count := _newCount
retval := _newCount - 1
return retval
}
Clear() {
this.m_InnerList := Null
this.m_InnerList := []
this.m_InnerList.Count := 0
this.m_Enum := Null
}
Insert(index, obj) {
_index := MfInteger.GetValue(index)
if ((_index < 0) || (_index > this.m_InnerList.Count))
{
ex := new MfArgumentOutOfRangeException("index", MfEnvironment.Instance.GetResourceString("ArgumentOutOfRange_Index"))
ex.SetProp(A_LineFile, A_LineNumber, A_ThisFunc)
throw ex
}
If (_index = this.m_InnerList.Count)
{
this.Add(obj)
return
}
i := _index + 1 ; step up to one based index for AutoHotkey array
this.m_InnerList.InsertAt(i, obj)
this.m_InnerList.Count ++
}
RemoveAt(index) {
_index := MfInteger.GetValue(index)
if ((_index < 0) || (_index >= this.m_InnerList.Count)) {
ex := new MfArgumentOutOfRangeException("index", MfEnvironment.Instance.GetResourceString("ArgumentOutOfRange_Index"))
ex.SetProp(A_LineFile, A_LineNumber, A_ThisFunc)
throw ex
}
i := _index + 1 ; step up to one based index for AutoHotkey array
vRemoved := this.m_InnerList.RemoveAt(i)
if (vRemoved) {
this.m_InnerList.Count -- ; lower the count by one
} else {
ex := new MfException(MfEnvironment.Instance.GetResourceString("Exception_FailedToRemove"))
ex.SetProp(A_LineFile, A_LineNumber, A_ThisFunc)
throw ex
}
}
Count[]
{
get {
return this.m_InnerList.Count
}
set {
ex := new MfNotSupportedException(MfEnvironment.Instance.GetResourceString("NotSupportedException_readonly_Property"))
ex.SetProp(A_LineFile, A_LineNumber, A_ThisFunc)
throw ex
}
}
Item[index]
{
get {
_index := MfInteger.GetValue(Index)
if (_index < 0 || _index >= this.Count) {
ex := new MfArgumentOutOfRangeException(MfEnvironment.Instance.GetResourceString("ArgumentOutOfRange_Index"))
ex.SetProp(A_LineFile, A_LineNumber, A_ThisFunc)
throw ex
}
_index ++ ; increase value for one based array
return this.m_InnerList[_index]
}
set {
_index := MfInteger.GetValue(Index)
if (_index < 0 || _index >= this.Count) {
ex := new MfArgumentOutOfRangeException(MfEnvironment.Instance.GetResourceString("ArgumentOutOfRange_Index"))
ex.SetProp(A_LineFile, A_LineNumber, A_ThisFunc)
throw ex
}
_index ++ ; increase value for one based array
this.m_InnerList[_index] := value
return this.m_InnerList[_index]
}
}
_NewEnum() {
return new TheList.Enumerator(this)
}
class Enumerator
{
m_Parent := Null
m_KeyEnum := Null
m_index := 0
m_count := 0
__new(ParentClass) {
this.m_Parent := ParentClass
this.m_count := this.m_Parent.Count
}
Next(ByRef key, ByRef value)
{
if (this.m_index < this.m_count) {
key := this.m_index
value := this.m_Parent.Item[key]
}
this.m_index++
if (this.m_index > (this.m_count)) {
return 0
} else {
return true
}
}
}
}