Changeset 426
- Timestamp:
- Feb 26, 2008, 3:33:49 AM (17 years ago)
- Location:
- trunk/Include/Classes
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Include/Classes/ActiveBasic/Math/Math.ab
r289 r426 46 46 47 47 Function IsNaN(ByVal x As Double) As Boolean 48 Dim p As *DWord 49 p = VarPtr(x) As *DWord 48 Dim p = VarPtr(x) As *DWord 50 49 IsNaN = False 51 50 If (p[1] And &H7FF00000) = &H7FF00000 Then … … 103 102 Dim s = 0 As DWord 104 103 If sign Then s = (1 As DWord) << 31 105 Dim p As *DWord 106 p = VarPtr(GetInf) As *DWord 104 Dim p = VarPtr(GetInf) As *DWord 107 105 p[0] = 0 108 106 p[1] = &h7FF00000 Or s -
trunk/Include/Classes/System/IO/FileStream.ab
r391 r426 76 76 77 77 op = options As DWord 78 If Not Environment.OSVersion.Platform = PlatformID.Win32NT Then 78 ' If (Environment.OSVersion.Platform As DWord) <> (PlatformID.Win32NT As DWord) Then 'ToDo: なぜかアクセス違反になる 79 79 op And= Not FILE_FLAG_OVERLAPPED 80 End If80 ' End If 81 81 82 82 This.handle=CreateFile(ToTCStr(path),ac,sh,ByVal NULL,mo,op,0) … … 305 305 End Sub 306 306 307 Override Function Read( 307 Override Function Read(buffer As *Byte, offset As Long, count As Long) As Long 308 308 disposedCheck() 309 309 If buffer = 0 Then 310 ' Throw ArgumentNullException("FileStream.Read: An argument is null value.", "buffer")310 Throw New ArgumentNullException("FileStream.Read: An argument is null value.", "buffer") 311 311 ElseIf Not This.CanRead() Then 312 ' Throw NotSupportedException("FileStream.Read: This stream is not readable.")312 Throw New NotSupportedException("FileStream.Read: This stream is not readable.") 313 313 End If 314 314 … … 320 320 overlapped.hEvent = CreateEvent(0, TRUE, FALSE, 0) 321 321 If overlapped.hEvent = 0 Then 322 ' Throw OutOfMemoryException("FileStream.Read: Failed to create an event object.")322 Throw New OutOfMemoryException("FileStream.Read: Failed to create an event object.") 323 323 End If 324 324 Try … … 327 327 Dim error = GetLastError() 328 328 If error <> ERROR_IO_PENDING Then 329 'Detail.ThrowWinIOException("FileStream.Read: Failed to read.", error)329 Detail.ThrowWinIOException("FileStream.Read: Failed to read.", error) 330 330 End If 331 331 End If 332 332 ret = GetOverlappedResult(This.handle, overlapped, readBytes, TRUE) 333 333 If ret = FALSE Then 334 'Detail.ThrowWinLastErrorIOException("FileStream.Read: Failed to read.")334 Detail.ThrowWinLastErrorIOException("FileStream.Read: Failed to read.") 335 335 End If 336 336 offset += Read … … 341 341 ret = ReadFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(readBytes),ByVal NULL) 342 342 If ret = FALSE Then 343 'Detail.ThrowWinLastErrorIOException("FileStream.Read: Failed to read.")343 Detail.ThrowWinLastErrorIOException("FileStream.Read: Failed to read.") 344 344 End If 345 345 End If -
trunk/Include/Classes/System/IO/StreamReader.ab
r420 r426 2 2 Namespace IO 3 3 4 Class StreamReader 5 Inherits TextReader 6 Public 7 Sub StreamReader(path As String) 8 init(New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) 9 End Sub 4 10 5 Class StreamReader 6 Inherits System.IO.TextReader 7 ' TODO: 実装 11 Sub StreamReader(stream As Stream) 12 init(stream) 13 End Sub 14 15 Override Sub Dispose(disposing As Boolean) 16 s.Dispose(disposing) 17 size = 0 18 cur = 0 19 last = 0 20 End Sub 21 22 Override Function Peek() As Long 23 If cur = last Then 24 last = s.Read(buf, 0, size) 25 cur = 0 26 If last = 0 Then 27 Peek = -1 28 Exit Function 29 End If 30 End If 31 Peek = buf[cur] 32 End Function 33 34 Override Function Read() As Long 35 Read = Peek() 36 cur++ 37 End Function 38 39 Override Function Read(buffer As *StrChar, index As Long, count As Long) As Long 40 If buffer = 0 Then 41 ElseIf index < 0 Then 42 ElseIf count < 0 Then 43 End If 44 45 Dim n = last - cur 46 If count <= n Then 47 Read = ReadFromBuffer(buffer, index, count) 48 Exit Function 49 End If 50 Dim p = VarPtr(buffer[index]) 51 Read = ReadFromBuffer(p, 0, n) 52 If Read = count Then 'バッファの中身で足りた場合 53 Exit Function 54 End If 55 p = VarPtr(p[n]) 56 count -= n 57 If count > size Then 58 n = (count \ size) * size 'sizeの倍数分だけは直接bufferへ読み込ませる 59 Dim read = s.Read(p, 0, n) 60 If read = 0 Then 'EOF 61 Exit Function 62 End If 63 p = VarPtr(p[n]) 64 Read += n 65 count -= n 66 End If 67 last = s.Read(buffer, 0, size) 68 cur = 0 69 If last = 0 Then 'EOF 70 Exit Function 71 End If 72 Read += ReadFromBuffer(p, 0, Math.Min(last, count)) 73 End Function 74 75 Override Function ReadLine() As String 76 Dim sb = New Text.StringBuilder(256) 77 Do 78 Dim ch = Read() 79 If ch = &h0D Then 80 If Peek() = &h0A Then 81 Read() 'CR LFの場合 82 End If 83 Exit Do 84 End If 85 Select Case ch 86 Case -1 'EOF 87 Exit Do 88 Case &h0A 'LF 89 Exit Do 90 Case &h0B 'VT 91 Exit Do 92 Case &h0C 'FF 93 Exit Do 94 Case &h0D 'CR 95 Exit Do 96 ' Case &h85 'NEL 97 ' Exit Do 98 ' Case &h2028 'LS 99 ' Exit Do 100 ' Case &h2029 'PS 101 ' Exit Do 102 End Select 103 sb.Append(ch As StrChar) 'ToDo キャスト不要にすべきというチケットを書くこと 104 Loop 105 ReadLine = sb.ToString 106 End Function 107 108 Override Function ReadToEnd() As String 109 End Function 110 111 Private 112 Sub init(str As Stream) 113 s = str 114 size = 4096 115 last = 0 116 cur = 0 117 buf = GC_malloc(size) 118 End Sub 119 120 /** 121 @brief バッファの中身から読み取る。 122 文字数が足りなくても、元のストリームまで読みには行かない。 123 */ 124 Function ReadFromBuffer(p As *StrChar, index As Long, count As Long) As Long 125 memcpy(VarPtr(p[index]), VarPtr(buf[cur]), count * SizeOf (StrChar)) 126 cur += count 127 ReadFromBuffer = count 128 End Function 129 130 s As Stream 131 size As Long 132 cur As Long 133 last As Long '中身の終わり 134 buf As *Byte '暫定 8 135 End Class 9 10 136 11 137 End Namespace -
trunk/Include/Classes/System/IO/TextReader.ab
r420 r426 6 6 7 7 Public 8 Virtual Sub TextReader() :End Sub 9 Virtual Sub ~TextReader() :End Sub 8 'Protected 9 Sub TextReader() 10 End Sub 11 Public 12 Virtual Sub ~TextReader() 13 Dispose(False) 14 End Sub 10 15 11 /* Null*/ 16 ' Static Null = StreamReader.Null As TextReader 12 17 13 18 Public 14 VirtualSub Close()15 This.Dispose()19 Sub Close() 20 Dispose(True) 16 21 End Sub 17 /* CreateObjRef*/ 18 /* Dispose*/ 19 /* Equals*/ 20 /* GetHashCode*/ 21 /* GetLifetimeService*/ 22 /* GetType*/ 23 /* InitializeLifetimeService*/ 22 23 Sub Dispose() 24 Dispose(True) 25 End Sub 26 27 Abstract Sub Dispose(disposing As Boolean) 28 24 29 Abstract Function Peek() As Long 25 30 Abstract Function Read() As Long 26 Abstract Function Read(buffer As LPTSTR, index As Long, count As Long) As Long 27 Abstract Function ReadBlock(buffer As LPTSTR, index As Long, count As Long) As Long 31 Abstract Function Read(buffer As *StrChar, index As Long, count As Long) As Long 32 Virtual Function ReadBlock(buffer As *StrChar, index As Long, count As Long) As Long 33 ReadBlock = Read(buffer, index, count) 34 End Function 28 35 Abstract Function ReadLine() As String 29 36 Abstract Function ReadToEnd() As String 30 /* ReferenceEquals*/31 /* Synchronized*/32 /* ToString*/33 /* Dispose*/34 /* Finalize*/35 /* MemberwiseClone*/36 37 End Class 37 38 -
trunk/Include/Classes/System/String.ab
r400 r426 117 117 118 118 Const Function Operator + (y As PCSTR) As String 119 Return Concat(y, lstrlenA(y)) 119 If y = 0 Then 120 Return This 121 Else 122 Return Concat(y, lstrlenA(y)) 123 End If 120 124 End Function 121 125 122 126 Const Function Operator + (y As PCWSTR) As String 123 Return Concat(y, lstrlenW(y)) 127 If y = 0 Then 128 Return This 129 Else 130 Return Concat(y, lstrlenW(y)) 131 End If 124 132 End Function 125 133 126 134 Const Function Operator + (y As String) As String 127 Return Concat(y.Chars, y.m_Length) 135 If ActiveBasic.IsNothing(y) Then 136 Return This 137 Else 138 Return Concat(y.Chars, y.m_Length) 139 End If 128 140 End Function 129 141 … … 133 145 134 146 Const Function Operator & (y As PCWSTR) As String 135 Dim tempString = This + y 136 Return tempString 147 Return This + y 137 148 End Function 138 149 139 150 Const Function Operator & (y As String) As String 140 Dim tempString = This + y 141 Return tempString 151 Return This + y 142 152 End Function 143 153
Note:
See TracChangeset
for help on using the changeset viewer.