Namespace System Namespace Collections Namespace Generic Class List items As *T size As Long Sub Realloc( allocateSize As Long ) items = realloc( items, allocateSize * SizeOf(VoidPtr) ) End Sub Public Sub List() items = GC_malloc( 1 ) End Sub Sub ~List() End Sub /*! @brief インデクサ @author Daisuke Yamamoto @date 2007/08/22 @param インデックス */ Function Operator[] ( index As Long ) As T Return items[index] End Function '---------------------------------------------------------------- ' パブリック プロパティ '---------------------------------------------------------------- /*! @brief Listに格納されている要素の数を取得する @author Daisuke Yamamoto @date 2007/08/22 */ Function Count() As Long Return size End Function '---------------------------------------------------------------- ' パブリック メソッド '---------------------------------------------------------------- /*! @brief Listの末端に要素を追加する @author Daisuke Yamamoto @date 2007/08/22 @param 追加するオブジェクト */ Sub Add( item As T ) Realloc( size + 1 ) items[size] = item size++ End Sub /*! @brief Listからすべての要素を削除する @author Daisuke Yamamoto @date 2007/08/22 */ Sub Clear() size = 0 End Sub /*! @brief List内から、最初に出現する値のインデックスを取得する @author Daisuke Yamamoto @date 2007/08/22 @return インデックス(見つからなかったときは-1) */ Function IndexOf( item As T ) As Long Dim i As Long For i = 0 To ELM(size) If items[i].Equals(item) Then Return i End If Next Return -1 End Function /*! @brief List内の指定したインデックスの位置に要素を挿入する @author Daisuke Yamamoto @date 2007/08/22 */ Sub Insert( index As Long, item As T ) Realloc( size + 1 ) memmove( items + (index+1)*SizeOf(VoidPtr), items + index*SizeOf(VoidPtr), (size-index)*SizeOf(VoidPtr) ) items[index] = item size++ End Sub End Class End Namespace End Namespace End Namespace