Changeset 195 for Include/Classes
- Timestamp:
- Mar 30, 2007, 4:22:30 AM (18 years ago)
- Location:
- Include/Classes/System
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Include/Classes/System/Collections/ArrayList.ab
r188 r195 5 5 Class ArrayList 6 6 Inherits IList /*, ICollection, IEnumerable, ICloneable*/ 7 8 pObject As *Object 9 size As Long 10 capacity As Long 11 12 Sub Init( size As Long ) 13 If size < 0 Then 14 ' Error 15 debug 16 End If 17 18 This.size = size 19 This.capacity = size 20 21 pObject = GC_malloc( SizeOf(*Object) * size + 1 ) 22 If pObject = 0 Then 23 ' OutOfMemoryException 24 Debug 25 End If 26 End Sub 27 28 Sub Realloc( size As Long ) 29 If size > capacity Then 30 ' miss! 31 Debug 32 End If 33 34 pObject = realloc( pObject, SizeOf(*Object) * size + 1 ) 35 If pObject = 0 Then 36 ' OutOfMemoryException 37 Debug 38 End If 39 End Sub 40 41 Sub SetLeastCapacity( capacity As Long ) 42 If This.capacity < capacity Then 43 This.capacity = capacity 44 Realloc( capacity ) 45 End If 46 End Sub 47 7 48 Public 8 ' -------------------------------- 49 50 '---------------------------------------------------------------- 9 51 ' Properties 52 '---------------------------------------------------------------- 53 10 54 /*Const*/ Virtual Function Capacity() As Long 11 Return data.Capacity55 Return capacity 12 56 End Function 13 57 14 58 Virtual Sub Capacity(c As Long) 15 If c <> data.Capacity Then16 If c < data.Size Then59 If c <> capacity Then 60 If c < size Then 17 61 'Throw ArgumentOutOfRangeException 18 62 Debug 19 63 Else 20 reallocBuffer(c)64 Realloc(c) 21 65 End If 22 66 End If … … 24 68 25 69 /*Const*/ /*Override*/ Virtual Function Count() As Long 26 Return data.Size70 Return size 27 71 End Function 28 72 … … 41 85 42 86 ' Operators 43 /*Const*/ /*Override*/ Virtual Function Operator [](i As Long) As *Object44 If 0 <= i And i < data.Size Then45 Return data.Elm[i]87 /*Const*/ /*Override*/ Virtual Function Operator [](index As Long) As Object 88 If 0 <= index And index < size Then 89 Return pObject[index] 46 90 Else 47 91 'Throw OutOfRangeException? … … 50 94 End Function 51 95 52 /*Override*/ Virtual Sub Operator []=(i As Long, x As *Object)53 If 0 <= i And i < data.Size Then54 data.Elm[i] = 096 /*Override*/ Virtual Sub Operator []=(index As Long, object As Object) 97 If 0 <= index And index < size Then 98 pObject[i] = object 55 99 Else 56 100 'Throw OutOfRangeException? … … 59 103 End Sub 60 104 61 ' -------------------------------- 105 106 107 '---------------------------------------------------------------- 62 108 ' Methods 109 '---------------------------------------------------------------- 110 63 111 ' Constractors 64 112 Sub ArrayList() 65 data.Init(16)113 Init( 0 ) 66 114 End Sub 67 115 /* … … 72 120 */ 73 121 Sub ArrayList(c As Long) 74 data.Init(c)122 Init( c ) 75 123 End Sub 76 124 … … 81 129 ' Sub Operator =(ByRef a As ArrayList) 82 130 83 /*Override*/ Virtual Function Add(x As *Object) As Long 84 setLeastCapacity(data.Size + 1) 85 data.Elm[data.Size] = x 86 Add = data.Size 87 data.Size++ 88 End Function 89 90 /*Override*/ Virtual Function Add(x As Object) As Long 91 setLeastCapacity(data.Size + 1) 92 data.Elm[data.Size] = VarPtr(x) 93 Add = data.Size 94 data.Size++ 131 /*Override*/ Virtual Function Add( object As Object ) As Long 132 SetLeastCapacity( size + 1 ) 133 pObject[size] = object 134 size++ 135 Return size - 1 95 136 End Function 96 137 … … 112 153 113 154 /*Override*/ Virtual Sub Clear() 114 data.Size = 0 115 End Sub 116 117 Virtual Function Clone() As *ArrayList 118 Dim p As *ArrayList 119 p = New ArrayList(data.Size) 120 p->data.Size = data.Size 121 memcpy(p->data.Elm, This.data.Elm, SizeOf (*Object) * data.Size) 122 Return p 155 size = 0 156 End Sub 157 158 Virtual Function Clone() As ArrayList 159 Dim arrayList = New ArrayList( size ) 160 memcpy( arrayList.pObject, This.pObject, SizeOf(*Object) * size ) 161 Return arrayList 123 162 End Function 124 163 125 164 /*Const*/ /*Override*/ /*Virtual Function Contains(x As *Object) As Boolean 126 165 Dim i As Long 127 For i = 0 To ELM( data.Size)166 For i = 0 To ELM(size) 128 167 If x->Equals(data.Elm[i]) Then 129 168 Return True … … 145 184 End Function 146 185 147 /*Const*/ Override Function IndexOf( x As *Object) As Long148 Return IndexOf( x, 0, data.Size)149 End Function 150 151 /*Const*/ Virtual Function IndexOf( x As *Object, startIndex As Long) As Long152 Return IndexOf( x, startIndex, data.Size - startIndex)153 End Function 154 155 /*Const*/ Virtual Function IndexOf( x As *Object, startIndex As Long, count As Long) As Long186 /*Const*/ Override Function IndexOf(object As Object) As Long 187 Return IndexOf(object, 0, size) 188 End Function 189 190 /*Const*/ Virtual Function IndexOf(object As Object, startIndex As Long) As Long 191 Return IndexOf(object, startIndex, size - startIndex) 192 End Function 193 194 /*Const*/ Virtual Function IndexOf(object As Object, startIndex As Long, count As Long) As Long 156 195 Dim i As Long 157 Dim last = Math.Min(startIndex + count - 1, data.Size)196 Dim last = Math.Min(startIndex + count - 1, size) 158 197 For i = startIndex To last 159 If x->Equals(ByVal data.Elm[i]) Then198 If object.Equals( pObject[i] ) Then 160 199 Return i 161 200 End If 162 201 Next 163 End Function 164 165 Override Sub Insert(i As Long, x As *Object) 166 setLeastCapacity(data.Size + 1) 167 memmove(VarPtr(data.Elm[i + 1]), VarPtr(data.Elm[i]), SizeOf (*Object) * (data.Size - i)) 168 data.Elm[i] = x 169 data.Size++ 202 Return -1 203 End Function 204 205 Override Sub Insert(i As Long, object As Object) 206 SetLeastCapacity(size + 1) 207 memmove(VarPtr(pObject[i + 1]), VarPtr(pObject[i]), SizeOf (*Object) * (size - i)) 208 pObject[i] = object 209 size++ 170 210 End Sub 171 211 … … 174 214 End Sub 175 215 176 /*Const*/ Virtual Function LastIndexOf( x As *Object) As Long177 LastIndexOf( x, 0, data.Size)178 End Function 179 180 /*Const*/ Virtual Function LastIndexOf( x As *Object, startIndex As Long) As Long181 Return LastIndexOf( x, startIndex, data.Size - startIndex)182 End Function 183 184 /*Const*/ Virtual Function LastIndexOf( x As *Object, startIndex As Long, count As Long) As Long185 ' TODO: 実装 186 End Function 187 188 Override Sub Remove( x As *Object)189 Dim i = IndexOf( x)216 /*Const*/ Virtual Function LastIndexOf(object As Object) As Long 217 LastIndexOf(object, 0, size) 218 End Function 219 220 /*Const*/ Virtual Function LastIndexOf(object As Object, startIndex As Long) As Long 221 Return LastIndexOf(object, startIndex, size - startIndex) 222 End Function 223 224 /*Const*/ Virtual Function LastIndexOf(object As Object, startIndex As Long, count As Long) As Long 225 ' TODO: 実装 226 End Function 227 228 Override Sub Remove(object As Object) 229 Dim i = IndexOf(object) 190 230 If i > 0 Then 191 231 RemoveAt(i) 232 size-- 192 233 End If 193 234 End Sub … … 195 236 Override Sub RemoveAt(i As Long) 196 237 RemoveRange(i, 1) 238 size-- 197 239 End Sub 198 240 199 241 Virtual Sub RemoveRange(i As Long, count As Long) 200 242 Dim removeLastPos = i + count 201 memmove(VarPtr(data.Elm[i]), VarPtr(data.Elm[removeLastPos]), SizeOf (*Object) * (data.Size - removeLastPos)) 243 memmove(VarPtr(pObject[i]), VarPtr(pObject[removeLastPos]), SizeOf(*Object) * (size - removeLastPos)) 244 size -= count 202 245 End Sub 203 246 204 247 Virtual Sub Reverse() 205 Reverse(0, data.Size)248 Reverse(0, size) 206 249 End Sub 207 250 … … 219 262 220 263 Virtual Sub Sort(ByRef c As IComparer) 221 Sort(0, data.Size, c)264 Sort(0, size, c) 222 265 End Sub 223 266 … … 228 271 ' ToArray 229 272 Virtual Sub TrimToSize() 230 reallocBuffer(data.Size)273 Realloc(size) 231 274 End Sub 232 275 … … 273 316 End Function 274 317 275 Private276 Sub setLeastCapacity(c As Long)277 If data.Capacity < c Then278 reallocBuffer(c)279 End If280 End Sub281 282 Sub reallocBuffer(c As Long)283 Dim newBuf As ArrayList_Element(c)284 newBuf.Size = data.Size285 memcpy(newBuf.Elm, data.Elm, SizeOf (*Object) * newBuf.Size)286 newBuf.Swap(data)287 End Sub288 289 data As ArrayList_Element290 318 End Class 291 319 320 /* 292 321 Class ArrayList_Element 293 322 Public … … 335 364 Capacity As Long 336 365 End Class 366 */ -
Include/Classes/System/Collections/misc.ab
r118 r195 69 69 'Sub Clear() 70 70 '/*Const*/ Function Contains(value As *Object) As Boolean 71 /*Const*/ Function IndexOf(value As *Object) As Long72 Sub Insert(index As Long, value As *Object)73 Sub Remove(value As *Object)71 /*Const*/ Function IndexOf(value As Object) As Long 72 Sub Insert(index As Long, value As Object) 73 Sub Remove(value As Object) 74 74 Sub RemoveAt(index As Long) 75 75 ' Properties -
Include/Classes/System/Object.ab
r70 r195 1 1 Class Object 2 3 ' 実行時型情報 4 typeInfo As TypeInfo 5 2 6 Public 3 7 … … 8 12 9 13 ' 2つのオブジェクトが等しいかどうかを判断する 10 Virtual Function Equals( ByRef objAs Object ) As Boolean11 If VarPtr( This ) = VarPtr( obj) Then14 Virtual Function Equals( object As Object ) As Boolean 15 If This.GetHashCode() = object.GetHashCode() Then 12 16 Return True 13 17 Else … … 15 19 End If 16 20 End Function 17 Static Function Equals( ByRef objA As Object, ByRef objB As Object ) As Boolean18 Return obj A.Equals( objB )21 Static Function Equals( objectA As Object, objectB As Object ) As Boolean 22 Return objectA.Equals( objectB ) 19 23 End Function 20 24 … … 28 32 Return "Object" 29 33 End Function 34 35 /* 36 Function Operator Downcast() As VoidPtr 37 End Function 38 */ 30 39 End Class -
Include/Classes/System/TypeInfo.ab
r186 r195 1 1 ' 実装中... 2 2 '(※ まだ組み込んでいません) 3 4 5 'Namespace System 6 3 7 4 8 Class TypeInfo … … 35 39 36 40 ' 中間的な実装(継承専用) 37 Class Type Impl41 Class TypeBaseImpl 38 42 Inherits TypeInfo 39 43 … … 46 50 Protected 47 51 48 Sub Type Impl()52 Sub TypeBaseImpl() 49 53 name = "" 50 54 strNamespace = "" … … 52 56 End Sub 53 57 54 Sub Type Impl( name As String, strNamespace As String )58 Sub TypeBaseImpl( name As String, strNamespace As String ) 55 59 This.name = name 56 60 This.strNamespace = strNamespace 57 baseType = Nothing 58 End Sub 59 60 Sub TypeImpl( name As String, strNamespace As String, baseType As Type ) 61 TypeImpl( name, strNamespace ) 61 This.baseType = Nothing 62 End Sub 63 64 Sub TypeBaseImpl( name As String, strNamespace As String, baseType As TypeInfo ) 65 This.name = name 66 This.strNamespace = strNamespace 62 67 This.baseType = baseType 63 68 End Sub 64 69 65 70 /* 66 Sub Type Impl( name As String, strNamespace As String, baseType As Type, interfaces As ... )67 Type Impl( name, strNamespace, baseType )71 Sub TypeBaseImpl( name As String, strNamespace As String, baseType As Type, interfaces As ... ) 72 TypeBaseImpl( name, strNamespace, baseType ) 68 73 End Sub 69 74 */ … … 131 136 ' 値型を管理するためのクラス 132 137 Class _System_TypeForValueType 133 Inherits Type Impl134 Public 135 Sub _System_TypeForValueType( name )138 Inherits TypeBaseImpl 139 Public 140 Sub _System_TypeForValueType( name As String ) 136 141 TypeInfo( name, "" ) 137 142 End Sub … … 144 149 ' クラスを管理するためのクラス 145 150 Class _System_TypeForClass 146 Inherits TypeImpl 147 Public 151 Inherits TypeBaseImpl 152 Public 153 Sub _System_TypeForClass( name As String, strNamespace As String, baseType As TypeInfo ) 154 TypeBaseImpl( name, strNamespace, baseType ) 155 End Sub 156 Sub ~_System_TypeForClass() 157 End Sub 158 Override Function IsClass() As Boolean 159 Return True 160 End Function 148 161 End Class 149 162 150 163 ' インターフェイスを管理するためのクラス 151 164 Class _System_TypeForInterface 152 Inherits Type Impl165 Inherits TypeBaseImpl 153 166 Public 154 167 End Class … … 156 169 ' 列挙体を管理するためのクラス 157 170 Class _System_TypeForEnum 158 Inherits Type Impl171 Inherits TypeBaseImpl 159 172 Public 160 173 End Class … … 162 175 ' デリゲートを管理するためのクラス 163 176 Class _System_TypeForDelegate 164 Inherits Type Impl177 Inherits TypeBaseImpl 165 178 Public 166 179 End Class … … 171 184 '-------------------------------------------------------------------- 172 185 Class _System_TypeBase 173 p pTypes As *Type186 pTypes As *TypeInfo 174 187 count As Long 175 188 176 189 Sub _System_TypeBase() 177 p pTypes = GC_malloc( 1 )190 pTypes = GC_malloc( 1 ) 178 191 count = 0 179 192 End Sub 180 193 Sub ~_System_TypeBase() 181 Dim i As Long 182 For i=0 To ELM( count ) 183 Delete ppTypes[i] 184 Next 194 End Sub 195 196 Sub _add( typeInfo As TypeInfo ) 197 pTypes = realloc( pTypes, ( count + 1 ) * SizeOf(*TypeInfo) ) 198 pTypes[count] = typeInfo 199 count++ 185 200 End Sub 186 201 … … 190 205 Public 191 206 192 Sub Add( pType As *Type ) 193 ppTypes = realloc( ppTypes, ( count + 1 ) * SizeOf(*Type) ) 194 ppTypes[count] = pType 195 count++ 207 Static Sub Add( typeInfo As TypeInfo ) 208 obj._add( typeInfo ) 196 209 End Sub 197 210 … … 214 227 obj.Add( New _System_TypeForValueType( "Double" ) ) 215 228 End Sub 216 End Class 229 230 Static Sub InitializeUserTypes() 231 ' このメソッドの実装はコンパイラが自動生成する 232 End Sub 233 234 Static Sub Initialize() 235 ' 値型を初期化 236 InitializeValueType() 237 238 ' Class / Interface / Enum / Delegate を初期化 239 InitializeUserTypes() 240 End Sub 241 End Class 242 243 ' End Namespace ' System -
Include/Classes/System/index.ab
r175 r195 4 4 #require <Classes/System/String.ab. 5 5 #require <Classes/System/TimeSpan.ab> 6 #require <Classes/System/TypeInfo.ab> 6 7 #require <Classes/System/OperatingSystem.ab> 7 8 #require <Classes/System/Version.ab>
Note:
See TracChangeset
for help on using the changeset viewer.