Last change
on this file since 333 was 305, checked in by dai, 17 years ago |
ListクラスをSystem.Collections.Generic名前空間に移動した
|
File size:
2.0 KB
|
Rev | Line | |
---|
[298] | 1 |
|
---|
| 2 | Namespace System
|
---|
| 3 | Namespace Collections
|
---|
[305] | 4 | Namespace Generic
|
---|
[298] | 5 |
|
---|
| 6 | Class List<T>
|
---|
| 7 | items As *T
|
---|
| 8 | size As Long
|
---|
| 9 |
|
---|
| 10 | Sub Realloc( allocateSize As Long )
|
---|
| 11 | items = realloc( items, allocateSize * SizeOf(VoidPtr) )
|
---|
| 12 | End Sub
|
---|
| 13 |
|
---|
| 14 | Public
|
---|
| 15 | Sub List()
|
---|
| 16 | items = GC_malloc( 1 )
|
---|
| 17 | End Sub
|
---|
| 18 | Sub ~List()
|
---|
| 19 | End Sub
|
---|
| 20 |
|
---|
| 21 | /*!
|
---|
| 22 | @brief インデクサ
|
---|
| 23 | @author Daisuke Yamamoto
|
---|
| 24 | @date 2007/08/22
|
---|
| 25 | @param インデックス
|
---|
| 26 | */
|
---|
| 27 | Function Operator[] ( index As Long ) As T
|
---|
| 28 | Return items[index]
|
---|
| 29 | End Function
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | '----------------------------------------------------------------
|
---|
| 33 | ' パブリック プロパティ
|
---|
| 34 | '----------------------------------------------------------------
|
---|
| 35 |
|
---|
| 36 | /*!
|
---|
| 37 | @brief Listに格納されている要素の数を取得する
|
---|
| 38 | @author Daisuke Yamamoto
|
---|
| 39 | @date 2007/08/22
|
---|
| 40 | */
|
---|
| 41 | Function Count() As Long
|
---|
| 42 | Return size
|
---|
| 43 | End Function
|
---|
| 44 |
|
---|
| 45 |
|
---|
| 46 | '----------------------------------------------------------------
|
---|
| 47 | ' パブリック メソッド
|
---|
| 48 | '----------------------------------------------------------------
|
---|
| 49 |
|
---|
| 50 | /*!
|
---|
| 51 | @brief Listの末端に要素を追加する
|
---|
| 52 | @author Daisuke Yamamoto
|
---|
| 53 | @date 2007/08/22
|
---|
| 54 | @param 追加するオブジェクト
|
---|
| 55 | */
|
---|
| 56 | Sub Add( item As T )
|
---|
| 57 | Realloc( size + 1 )
|
---|
| 58 |
|
---|
| 59 | items[size] = item
|
---|
| 60 | size++
|
---|
| 61 | End Sub
|
---|
| 62 |
|
---|
| 63 | /*!
|
---|
| 64 | @brief Listからすべての要素を削除する
|
---|
| 65 | @author Daisuke Yamamoto
|
---|
| 66 | @date 2007/08/22
|
---|
| 67 | */
|
---|
| 68 | Sub Clear()
|
---|
| 69 | size = 0
|
---|
| 70 | End Sub
|
---|
| 71 |
|
---|
| 72 | /*!
|
---|
| 73 | @brief List内から、最初に出現する値のインデックスを取得する
|
---|
| 74 | @author Daisuke Yamamoto
|
---|
| 75 | @date 2007/08/22
|
---|
| 76 | @return インデックス(見つからなかったときは-1)
|
---|
| 77 | */
|
---|
| 78 | Function IndexOf( item As T ) As Long
|
---|
| 79 | Dim i As Long
|
---|
| 80 | For i = 0 To ELM(size)
|
---|
| 81 | If items[i].Equals(item) Then
|
---|
| 82 | Return i
|
---|
| 83 | End If
|
---|
| 84 | Next
|
---|
| 85 | Return -1
|
---|
| 86 | End Function
|
---|
| 87 |
|
---|
| 88 | /*!
|
---|
| 89 | @brief List内の指定したインデックスの位置に要素を挿入する
|
---|
| 90 | @author Daisuke Yamamoto
|
---|
| 91 | @date 2007/08/22
|
---|
| 92 | */
|
---|
| 93 | Sub Insert( index As Long, item As T )
|
---|
| 94 | Realloc( size + 1 )
|
---|
| 95 | memmove( items + (index+1)*SizeOf(VoidPtr), items + index*SizeOf(VoidPtr), (size-index)*SizeOf(VoidPtr) )
|
---|
| 96 | items[index] = item
|
---|
| 97 | size++
|
---|
| 98 | End Sub
|
---|
| 99 | End Class
|
---|
| 100 |
|
---|
| 101 | End Namespace
|
---|
| 102 | End Namespace
|
---|
[305] | 103 | End Namespace
|
---|
Note:
See
TracBrowser
for help on using the repository browser.