Changeset 457 for trunk/Include/Classes/System
- Timestamp:
- Mar 6, 2008, 9:49:43 PM (17 years ago)
- Location:
- trunk/Include/Classes/System
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Include/Classes/System/IO/TextReader.ab
r432 r457 36 36 ElseIf count < 0 Then 37 37 End If 38 Read = ReadImpl(buffer, index, count) 38 39 End Function 39 40 … … 80 81 End Function 81 82 /* 83 @brief 現在位置からストリームの終わりまで読み込む。 82 84 @date 2008/02/26 83 85 @auther Egtra … … 93 95 sb.Append(ch As StrChar) 94 96 Loop 97 End Function 98 99 Static Function Synchronized(reader As TextReader) As TextReader 95 100 End Function 96 101 … … 118 123 End Class 119 124 125 Namespace Detail 126 127 Class SynchronizedTextReader 128 Inherits TextReader 129 Public 130 Sub SynchronizedTextReader(reader As TextReader) 131 cs = New ActiveBasic.Windows.CriticalSection 132 base = reader 133 End Sub 134 135 Override Function Peek() As Long 136 ' Using lock = cs.Lock 137 Peek = base.Peek 138 ' End Using 139 End Function 140 141 Override Function Read() As Long 142 ' Using lock = cs.Lock 143 Read = base.Read 144 ' End Using 145 End Function 146 147 Override Function ReadLine() As String 148 ' Using lock = cs.Lock 149 ReadLine = base.ReadLine 150 ' End Using 151 End Function 152 153 Override Function ReadToEnd() As String 154 ' Using lock = cs.Lock 155 ReadToEnd = base.ReadToEnd 156 ' End Using 157 End Function 158 159 Protected 160 Override Sub Dispose(disposing As Boolean) 161 Dim s = Nothing As Stream 162 SetPointer(VarPtr(s) As *VoidPtr, InterlockedExchangePointer(ByVal VarPtr(base) As *VoidPtr, 0)) 163 If disposing Then 164 If Not ActiveBasic.IsNothing(s) Then 165 s.Dispose() 166 End If 167 cs.Dispose() 168 End If 169 End Sub 170 171 Override Function ReadImpl(buffer As *StrChar, index As Long, count As Long) As Long 172 ' Using lock = cs.Lock 173 ReadImpl = base.ReadImpl(buffer, index, count) 174 ' End Using 175 End Function 176 Private 177 cs As ActiveBasic.Windows.CriticalSection 178 base As TextReader 179 End Class 180 181 End Namespace 182 120 183 End NameSpace 121 184 End NameSpace -
trunk/Include/Classes/System/Math.ab
r299 r457 127 127 128 128 Static Function Ceiling(x As Double) As Long 129 If Floor(x) = x then 130 Return x As Long 131 Else 132 Return Floor(x) + 1 129 Ceiling = Floor(x) 130 If Ceiling <> x Then 131 Ceiling++ 133 132 End If 134 133 End Function … … 145 144 146 145 Static Function Cosh(value As Double) As Double 147 Dim t As Double 148 t = Math.Exp(value) 146 Dim t = Math.Exp(value) 149 147 return (t + 1 / t) * 0.5 150 148 End Function … … 156 154 157 155 Static Function DivRem(x As Int64, y As Int64, ByRef ret As Int64) As Int64 158 ret = x - (x \ y) *y159 ret urn x \y156 DivRem = x \ y 157 ret = x - (DivRem) * y 160 158 End Function 161 159 … … 196 194 Return Int(value) 197 195 End Function 198 199 'GetHashCode200 201 'GetType202 196 203 197 Static Function IEEERemainder(x As Double, y As Double) As Double … … 513 507 514 508 Static Function Sqrt(x As Double) As Double 515 Dim s As Double, last As Double516 Dim i As *Word, j As Long, jj As Long, k As Long517 509 If x > 0 Then 518 510 If ActiveBasic.Math.IsInf(x) Then … … 520 512 Else 521 513 Sqrt = x 522 i = (VarPtr(Sqrt) + 6) As *Word523 jj = GetWord(i)524 j = jj >> 5525 k = jj And &h0000001f526 j = (j +511) << 4 + k514 Dim i = (VarPtr(Sqrt) + 6) As *Word 515 Dim jj = GetWord(i) As Long 516 Dim j = jj >> 5 As Long 517 Dim k = (jj And &h0000001f) As Long 518 j = (j + 511) << 4 + k 527 519 SetWord(i, j) 520 Dim last As Double 528 521 Do 529 522 last = Sqrt 530 Sqrt = (x / Sqrt + Sqrt) * 0.5523 Sqrt = (x / Sqrt + Sqrt) * 0.5 531 524 Loop While Sqrt <> last 532 525 End If -
trunk/Include/Classes/System/String.ab
r428 r457 27 27 28 28 Class String 29 ' Inherits IComparable, ICloneable, IConvertible, IEnumerable29 Implements /*IComparable, ICloneable, IConvertible, IComparable<String>, IEnumerable, IEnumerable<StrChar>, IEquatable<String>*/ 30 30 31 31 m_Length As Long … … 34 34 Sub validPointerCheck(p As VoidPtr, size = 1 As Long) 35 35 If p As ULONG_PTR < &h10000 Then 36 'Throw ArgumentException 37 Debug 36 Throw New ArgumentException 38 37 ElseIf IsBadReadPtr(p, size As ULONG_PTR) Then 39 'Throw ArgumentException 40 Debug 38 Throw New ArgumentException 41 39 End If 42 40 End Sub … … 153 151 154 152 Const Function Operator == (y As String) As Boolean 155 Return String.Compare(This, y) = 0153 Return Compare(This, y) = 0 156 154 End Function 157 155 158 156 Const Function Operator == (y As *StrChar) As Boolean 159 Return String.Compare(This, y) = 0157 Return Compare(This, y) = 0 160 158 End Function 161 159 162 160 Const Function Operator <> (y As String) As Boolean 163 Return String.Compare(This, y) <> 0161 Return Compare(This, y) <> 0 164 162 End Function 165 163 166 164 Const Function Operator <> (y As *StrChar) As Boolean 167 Return String.Compare(This, y) <> 0165 Return Compare(This, y) <> 0 168 166 End Function 169 167 170 168 Const Function Operator < (y As String) As Boolean 171 Return String.Compare(This, y) < 0169 Return Compare(This, y) < 0 172 170 End Function 173 171 174 172 Const Function Operator < (y As *StrChar) As Boolean 175 Return String.Compare(This, y) < 0173 Return Compare(This, y) < 0 176 174 End Function 177 175 178 176 Const Function Operator > (y As String) As Boolean 179 Return String.Compare(This, y) > 0177 Return Compare(This, y) > 0 180 178 End Function 181 179 182 180 Const Function Operator > (y As *StrChar) As Boolean 183 Return String.Compare(This, y) > 0181 Return Compare(This, y) > 0 184 182 End Function 185 183 186 184 Const Function Operator <= (y As String) As Boolean 187 Return String.Compare(This, y) <= 0185 Return Compare(This, y) <= 0 188 186 End Function 189 187 190 188 Const Function Operator <= (y As *StrChar) As Boolean 191 Return String.Compare(This, y) <= 0189 Return Compare(This, y) <= 0 192 190 End Function 193 191 194 192 Const Function Operator >= (y As String) As Boolean 195 Return String.Compare(This, y) >= 0193 Return Compare(This, y) >= 0 196 194 End Function 197 195 198 196 Const Function Operator >= (y As *StrChar) As Boolean 199 Return String.Compare(This, y) >= 0197 Return Compare(This, y) >= 0 200 198 End Function 201 199 … … 205 203 206 204 Public 205 'Compareなどで、x.Charsではなく、StrPtr(x)と書く理由は、xがNothingの場合のため。 206 207 207 Static Function Compare(x As String, indexX As Long, y As String, indexY As Long, length As Long) As Long 208 Return String.CompareOrdinal(x, indexX, y, indexY, length)208 Return CompareOrdinal(x, indexX, y, indexY, length) 209 209 End Function 210 210 211 211 Static Function CompareOrdinal(x As String, y As String) As Long 212 Return String.CompareOrdinal(x.Chars, y.Chars)212 Return CompareOrdinal(StrPtr(x), StrPtr(y)) 213 213 End Function 214 214 215 215 Static Function CompareOrdinal(x As String, indexX As Long, y As String, indexY As Long, length As Long) As Long 216 Return String.CompareOrdinal(x.Chars, indexX, y.Chars, indexY, length)216 Return CompareOrdinal(StrPtr(x), indexX, StrPtr(y), indexY, length) 217 217 End Function 218 218 Private 219 219 Static Function Compare(x As String, y As *StrChar) As Long 220 Return String.CompareOrdinal(x, y)220 Return CompareOrdinal(x, y) 221 221 End Function 222 222 223 223 Static Function CompareOrdinal(x As String, y As *StrChar) As Long 224 Return String.CompareOrdinal(x.Chars, y)224 Return CompareOrdinal(StrPtr(x), y) 225 225 End Function 226 226 … … 257 257 Function CompareTo(y As Object) As Long 258 258 If Not Object.Equals(This.GetType(), y.GetType()) Then 259 Throw New ArgumentException("String.CompareTo: An argument is out of range value.", "y")259 Throw New ArgumentException("String.CompareTo: The type of the argument y is not String.", "y") 260 260 End If 261 261 Return CompareTo(y As String) … … 351 351 End Function 352 352 353 Static Function Concat(x As String, y As String, z As String) As String 354 Dim sb = New Text.StringBuilder(removeNull(x).Length + removeNull(y).Length + removeNull(z).Length) 355 sb.Append(x).Append(y).Append(z) 356 Concat = sb.ToString 357 End Function 358 359 Static Function Concat(x As String, y As String, z As String, w As String) As String 360 Dim sb = New Text.StringBuilder(removeNull(x).Length + removeNull(y).Length + removeNull(z).Length + removeNull(w).Length) 361 sb.Append(x).Append(y).Append(z).Append(w) 362 Concat = sb.ToString 363 End Function 364 353 365 Static Function Concat(x As Object, y As Object) As String 354 Return String.Concat(x.ToString, y.ToString) 366 Return Concat(x.ToString, y.ToString) 367 End Function 368 369 Static Function Concat(x As Object, y As Object, z As Object) As String 370 Return Concat(x.ToString, y.ToString, z.ToString) 371 End Function 372 373 Static Function Concat(x As Object, y As Object, z As Object, w As Object) As String 374 Return Concat(x.ToString, y.ToString, z.ToString, w.ToString) 355 375 End Function 356 376 … … 575 595 Clone = This 576 596 End Function 577 597 /* 598 Function Clone() As Object 599 Clone = This 600 End Function 601 */ 578 602 Static Function Copy(s As String) As String 579 603 Copy = New String(s.Chars, s.m_Length) … … 656 680 End If 657 681 End Sub 682 683 Static Function removeNull(s As String) As String 684 If ActiveBasic.IsNothing(s) Then 685 removeNull = Empty 686 Else 687 removeNull = s 688 End If 689 End Function 658 690 End Class 659 691 -
trunk/Include/Classes/System/Text/StringBuilder.ab
r435 r457 182 182 ElseIf c > Capacity Then 183 183 Dim p = GC_malloc_atomic((c + 1) * SizeOf (StrChar)) As *StrChar 184 If p = 0 Then185 'Throw OutOfMemoryException186 Debug187 End If188 184 ActiveBasic.Strings.ChrCopy(p, chars, size As SIZE_T) 189 185 chars = p … … 488 484 This.size = 0 489 485 This.chars = GC_malloc_atomic((This.capacity + 1) * SizeOf (StrChar)) 490 If chars = 0 Then491 'Throw OutOfMemoryException492 Debug493 End If494 495 486 End Sub 496 487
Note:
See TracChangeset
for help on using the changeset viewer.