MfEnumerableBase

Namespace ›› System ››
Parent Previous Next

MfEnumerableBase Class

( Inherits from MfObject )

Abstract Class
MfEnumerableBase exposes the enumerator, which supports a simple iteration over a collection.

MfEnumerableBase is an abstract class and must be inherited by other classes such as MfList.

Links

Methods, Example

Constructors


Name

Description

Constructor()

Constructor for Abstract MfEnumerableBase Class

Methods


Name

Description

_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()

AddAttribute()

Adds MfAttribute extended items to extended classes. Inherited from MfObject.

CompareTo()

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. Inherited from MfObject.

Equals(obj)

Compares obj to current instance to see if they are the same. Inherited from MfObject.

GetAttribute(index)

Gets an MfAttribute of the class. Inherited from MfObject.

GetAttributes()

Gets a MfGenericList of MfAttribute that Contains the attributes for the current class instance. Inherited from MfObject.

GetEnumerator()

Gets an enumerator

GetIndexOfAttribute(attrib)

Gets the zero-based index value of the position of MfAttribute within the instance of the class. Inherited from MfObject.

GetType()

Gets the Type for the for the Class .Inherited from MfObject.

HasAttribute(attrib)

Gets if the current instance of class derived from MfSystemException has MfAttribute. Inherited from MfObject.

Is(type)

Gets if current instance of object is of the same type. Inherited from MfObject. Inherited from MfObject.

IsInstance()

Get if the current class is an instance. Inherited from MfObject.

MemberwiseClone()

Creates a shallow copy of the current MfObject instance. Inherited from MfObject.

ToString()

Gets a string representation of the MfObject. Inherited from MfObject.

VerifyIsInstance([ClassName, LineFile, LineNumber, Source])

Verifies the the current object is set to an instance. Inherited from MfObject.

VerifyIsNotInstance([MethodName, LineFile, LineNumber, Source])

Verifies the the current object is NOT set to an instance. Used in Static methods. Inherited from MfObject.

Example

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
           }
       }
   }
}