Changeset 543
- Timestamp:
- Jul 13, 2008, 5:03:44 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/Classes/System/Collections/Generic/List.ab
r531 r543 17 17 End Interface 18 18 19 20 Class ICollection<T> 21 Implements IEnumerable<T>, IEnumerator<T> 22 Public 23 ' Property 24 Abstract Function Count() As Long 25 Abstract Function IsReadOnly() As Boolean 26 27 ' Methods 28 Abstract Sub Add( item As T ) 29 Abstract Sub Clear() 30 ' Abstract Function Contains ( item As T ) As Boolean 31 ' Abstract Sub CopyTo (ByRef array As List<T>, arrayIndex As Long ) 32 Abstract Function Remove( item As T ) As Boolean 33 End Class 34 35 36 Class IList<T> 37 Inherits ICollection<T> 38 Public 39 ' Property 40 Abstract Sub Operator[] ( index As Long, item As T ) 41 Abstract Function Operator[] ( index As Long ) As T 42 ' Methods 43 ' Abstract Function Item ( index As Long ) As T 44 Abstract Function IndexOf( item As T ) As Long 45 Abstract Sub Insert( index As Long, item As T ) 46 Abstract Sub RemoveAt( index As Long ) 47 End Class 48 49 19 50 Class List<T> 20 Implements IEnumerable<T>, IEnumerator<T> 51 Inherits IList<T> 52 21 53 items As *T 22 54 size As Long … … 35 67 Reset() 36 68 End Sub 69 70 /*! 71 @brief 予め要素数を指定してList<T>を初期化 72 @author NoWest 73 @date 2008/07/13 74 @param リストの要素数 75 */ 76 Sub List( capacity As Long ) 77 This.List() 78 This.Realloc( capacity ) 79 End Sub 80 81 /*! 82 @brief 既存の配列List<T>を初期化 83 @author NoWest 84 @date 2008/07/13 85 @param インデックス 86 */ 87 Sub List( array As *T, count As Long ) 88 This.List( count ) 89 memmove( This.items, array, count * SizeOf(T) ) 90 This.size = count 91 End Sub 37 92 Sub ~List() 38 93 End Sub … … 44 99 @param インデックス 45 100 */ 46 Function Operator[] ( index As Long ) As T 101 Override Sub Operator[] ( index As Long, item As T ) 102 items[index]=item 103 End Sub 104 Override Function Operator[] ( index As Long ) As T 47 105 Return items[index] 48 106 End Function … … 68 126 @date 2007/08/22 69 127 */ 70 Function Count() As Long128 Override Function Count() As Long 71 129 Return size 72 130 End Function 73 131 132 /*! 133 @brief Listが読み込み専用かどうかを取得する 134 @author NoWest 135 @date 2008/07/12 136 */ 137 Override Function IsReadOnly() As Boolean 138 Return False 139 End Function 74 140 75 141 '---------------------------------------------------------------- … … 83 149 @param 追加するオブジェクト 84 150 */ 85 Sub Add( item As T )151 Override Sub Add( item As T ) 86 152 Realloc( size + 1 ) 87 153 … … 90 156 End Sub 91 157 158 ' Function AsReadOnly() As ReadOnlyCollection 159 92 160 /*! 93 161 @brief Listからすべての要素を削除する … … 95 163 @date 2007/08/22 96 164 */ 97 Sub Clear()165 Override Sub Clear() 98 166 size = 0 99 167 End Sub 100 168 169 /* Override Function Contains ( item As T ) As Boolean 170 TODO 171 End Function*/ 172 101 173 /*! 102 174 @brief List内から、最初に出現する値のインデックスを取得する … … 105 177 @return インデックス(見つからなかったときは-1) 106 178 */ 107 Function IndexOf( item As T ) As Long179 Override Function IndexOf( item As T ) As Long 108 180 Dim i As Long 109 181 For i = 0 To ELM(size) … … 120 192 @date 2007/08/22 121 193 */ 122 Sub Insert( index As Long, item As T )194 Override Sub Insert( index As Long, item As T ) 123 195 Realloc( size + 1 ) 124 196 memmove( items + (index+1)*SizeOf(T), items + index*SizeOf(T), (size-index)*SizeOf(T) ) … … 133 205 @return 値が削除されたときはTrue、されなかったときはFlaseが返る 134 206 */ 135 Function Remove( item As T ) As Boolean207 Override Function Remove( item As T ) As Boolean 136 208 Dim index = IndexOf( item ) 137 209 If index = -1 Then … … 149 221 @return 値が削除されたときはTrue、されなかったときはFlaseが返る 150 222 */ 151 Sub RemoveAt( index As Long )223 Override Sub RemoveAt( index As Long ) 152 224 memmove( items + index*SizeOf(T), items + (index+1)*SizeOf(T), (size-(index+1))*SizeOf(T) ) 153 225 Realloc( size - 1 ) … … 176 248 @return IEnumeratorインターフェイスが返る 177 249 */ 178 Function GetEnumerator() As IEnumerator<T>250 Override Function GetEnumerator() As IEnumerator<T> 179 251 Return This 180 252 End Function … … 186 258 @return 上限に達していなければTrueが、達していればFalseが返る 187 259 */ 188 Function MoveNext() As Boolean260 Override Function MoveNext() As Boolean 189 261 If currentIndexForEnumerator + 1 >= size Then 190 262 ' 上限に達した … … 201 273 @date 2007/11/19 202 274 */ 203 Sub Reset()275 Override Sub Reset() 204 276 currentIndexForEnumerator = -1 205 277 End Sub … … 211 283 @return カレントオブジェクトが返る 212 284 */ 213 Function Current() As T285 Override Function Current() As T 214 286 If currentIndexForEnumerator = -1 Then 215 287 ' MoveNextメソッドがReset後、一度も呼び出されなかった … … 220 292 End Class 221 293 294 222 295 End Namespace 223 296 End Namespace
Note:
See TracChangeset
for help on using the changeset viewer.