Changeset 432
- Timestamp:
- Feb 27, 2008, 1:04:59 AM (17 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Include/Classes/System/IO/File.ab
r406 r432 4 4 5 5 Enum FileAccess 6 Read 7 ReadWrite 8 Write 6 Read = -2147483648 'GENERIC_READ 7 ReadWrite = -1073741824 'GENERIC_READ Or GENERIC_WRITE 8 Write = 1073741824' GENERIC_WRITE 9 9 End Enum 10 10 … … 27 27 28 28 Enum FileMode 29 Append 30 Create 31 CreateNew 32 Open 33 OpenOrCreate 34 Truncate 29 Append = OPEN_ALWAYS 30 Create = CREATE_ALWAYS 31 CreateNew = CREATE_NEW 32 Open = OPEN_EXISTING 33 OpenOrCreate = OPEN_ALWAYS 34 Truncate = TRUNCATE_EXISTING 35 35 End Enum 36 36 37 37 Enum FileShare 38 DeleteFile39 None40 Read41 ReadWrite 42 Write38 None = 0 39 Read = FILE_SHARE_READ 40 Write = FILE_SHARE_WRITE 41 ReadWrite = FILE_SHARE_READ Or FILE_SHARE_WRITE 42 DeleteFile = FILE_SHARE_DELETE 43 43 End Enum 44 44 … … 158 158 End Function 159 159 160 Static Function OpenText( path As String ) As StreamReader161 ' TODO: 実装 162 End Function160 ' Static Function OpenText( path As String ) As StreamReader 161 ' TODO: 実装 162 ' End Function 163 163 164 164 Static Function OpenWrite( path As String ) As FileStream -
trunk/Include/Classes/System/IO/FileStream.ab
r430 r432 27 27 fileShare As DWord 28 28 fileOptions As DWord 29 ownsHandle As Boolean 29 30 30 31 offset As QWord 'オーバーラップドIO用 … … 33 34 /* コンストラクタ.NETと同じように実装は難しい、一先ず動くものを実装したが変更が必要だと思う */ 34 35 Sub FileStream(path As String, mode As FileMode, access As FileAccess, share As FileShare, options As FileOptions) 35 Dim ac As DWord 36 Dim mo As DWord 37 Dim sh As DWord 38 Dim op As DWord 39 40 Select Case access 41 Case FileAccess.Read 42 ac=GENERIC_READ 43 Case FileAccess.ReadWrite 44 ac=GENERIC_READ or GENERIC_WRITE 45 Case FileAccess.Write 46 ac=GENERIC_WRITE 47 End Select 48 49 Select Case share 50 Case FileShare.DeleteFile 51 sh=FILE_SHARE_DELETE 52 Case FileShare.None 53 sh=0 54 Case FileShare.Read 55 sh=FILE_SHARE_READ 56 Case FileShare.ReadWrite 57 sh=FILE_SHARE_READ or FILE_SHARE_WRITE 58 Case FileShare.Write 59 sh=FILE_SHARE_WRITE 60 End Select 61 62 Select Case mode 63 Case FileMode.Append 64 mo=OPEN_ALWAYS 65 Case FileMode.Create 66 mo=CREATE_ALWAYS 67 Case FileMode.CreateNew 68 mo=CREATE_NEW 69 Case FileMode.Open 70 mo=OPEN_EXISTING 71 Case FileMode.OpenOrCreate 72 mo=OPEN_ALWAYS 73 Case FileMode.Truncate 74 mo=TRUNCATE_EXISTING 75 End Select 76 77 op = options As DWord 36 Dim ac = access As DWord 37 Dim sh = share As DWord 38 Dim mo = mode As DWord 39 Dim op = options As DWord 78 40 ' If (Environment.OSVersion.Platform As DWord) <> (PlatformID.Win32NT As DWord) Then 'ToDo: なぜかアクセス違反になる 79 41 op And= Not FILE_FLAG_OVERLAPPED … … 97 59 This.fileOptions = op 98 60 This.offset = 0 61 This.ownsHandle = True 99 62 End Sub 100 63 Sub FileStream(path As String, mode As FileMode, access As FileAccess, share As FileShare) … … 122 85 This.FileStream(path,mode,access,FileShare.None,FileOptions.None) 123 86 End Sub 87 /* 88 @date 2008/02/26 89 @auther Egtra 90 '不要になったら削除すること 91 */ 92 Sub FileStream(h As HANDLE, access As FileAccess, owns As Boolean) 93 handle = h 94 fileAccess = access As DWord 95 ownsHandle = owns 96 End Sub 97 124 98 Public 125 99 /*! … … 259 233 /* CreateObjRef*/ 260 234 261 Override Sub Dispose(disposing As Boolean)262 Flush()263 CloseHandle(InterlockedExchangePointer(VarPtr(This.handle),NULL))264 End Sub265 266 235 Override Function EndRead(asyncResult As System.IAsyncResult) As Long 267 236 'TODO … … 450 419 451 420 Protected 421 Override Sub Dispose(disposing As Boolean) 422 If handle <> 0 Then 423 Flush() 424 CloseHandle(InterlockedExchangePointer(VarPtr(handle), NULL)) 425 End If 426 End Sub 427 452 428 Override Function CreateWaitHandle() As System.Threading.WaitHandle 453 Return New System.Threading.AutoResetEvent(False) 429 '調査した限りでは、System.Threading.EventWaitHandleクラスをNewする模様。 430 '現状ではSystem.Threading.WaitHandleクラスをNewしてからHandleにて設定 431 Dim wh As System.Threading.WaitHandle 432 wh.Handle=CreateEvent(NULL,TRUE,FALSE,NULL) 433 Return wh 454 434 End Function 455 435 -
trunk/Include/Classes/System/IO/Stream.ab
r391 r432 48 48 Write(buffer,offset,count) 49 49 End Function 50 VirtualSub Close()50 Sub Close() 51 51 Dispose(True) 52 52 End Sub 53 VirtualSub Dispose()53 Sub Dispose() 54 54 Dispose(True) 55 55 End Sub 56 Virtual Sub Dispose(disposing As Boolean): End Sub57 56 Virtual Function EndRead(ByRef asyncResult As System.IAsyncResult) As Long: End Function 58 57 Virtual Sub EndWrite(ByRef asyncResult As System.IAsyncResult): End Sub … … 78 77 End Sub 79 78 Protected 80 Virtual Function CreateWaitHandle() As System.Threading.WaitHandle: End Function 79 Virtual Sub Dispose(disposing As Boolean) 80 End Sub 81 Virtual Function CreateWaitHandle() As System.Threading.WaitHandle 82 End Function 81 83 End Class 82 84 -
trunk/Include/Classes/System/IO/StreamReader.ab
r426 r432 1 'Classes/System/IO/StreamReader.ab 2 1 3 Namespace System 2 4 Namespace IO 3 5 6 /* 7 @brief ストリームから読み取りを行うTextReaderの実装。 8 @date 2008/02/25 9 @auther Egtra 10 */ 4 11 Class StreamReader 5 12 Inherits TextReader 6 13 Public 14 /* 15 @date 2008/02/25 16 @auther Egtra 17 */ 7 18 Sub StreamReader(path As String) 8 19 init(New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) 9 20 End Sub 10 21 22 /* 23 @date 2008/02/25 24 @auther Egtra 25 */ 11 26 Sub StreamReader(stream As Stream) 12 27 init(stream) 13 28 End Sub 14 29 15 Override Sub Dispose(disposing As Boolean) 16 s.Dispose(disposing) 17 size = 0 18 cur = 0 19 last = 0 20 End Sub 21 30 /* 31 @date 2008/02/25 32 @auther Egtra 33 */ 22 34 Override Function Peek() As Long 23 35 If cur = last Then … … 32 44 End Function 33 45 46 /* 47 @date 2008/02/25 48 @auther Egtra 49 */ 34 50 Override Function Read() As Long 35 51 Read = Peek() … … 37 53 End Function 38 54 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 55 /* 56 @date 2008/02/26 57 @auther Egtra 58 */ 59 Override Function ReadToEnd() As String 60 Dim sb = New Text.StringBuilder(65536) 61 sb.Append(buf, cur, last - cur) 62 Do 63 Dim read = Read(buf, 0, size) 64 sb.Append(buf, 0, read) 65 If read < size Then 66 ReadToEnd = sb.ToString 67 Exit Function 68 End If 69 Loop 70 End Function 71 72 Protected 73 /* 74 @date 2008/02/25 75 @auther Egtra 76 */ 77 Override Sub Dispose(disposing As Boolean) 78 If disposing Then 79 If Not ActiveBasic.IsNothing(s) Then 80 s.Dispose(True) 81 End If 43 82 End If 83 s = Nothing 84 size = 0 85 cur = 0 86 last = 0 87 End Sub 44 88 89 /* 90 @date 2008/02/25 91 @auther Egtra 92 */ 93 Override Function ReadImpl(buffer As *StrChar, index As Long, count As Long) As Long 45 94 Dim n = last - cur 46 95 If count <= n Then 47 Read = ReadFromBuffer(buffer, index, count)96 ReadImpl = ReadFromBuffer(buffer, index, count) 48 97 Exit Function 49 98 End If 50 99 Dim p = VarPtr(buffer[index]) 51 Read = ReadFromBuffer(p, 0, n)52 If Read = count Then 'バッファの中身で足りた場合100 ReadImpl = ReadFromBuffer(p, 0, n) 101 If ReadImpl = count Then 'バッファの中身で足りた場合 53 102 Exit Function 54 103 End If … … 62 111 End If 63 112 p = VarPtr(p[n]) 64 Read += n113 ReadImpl += n 65 114 count -= n 66 115 End If … … 70 119 Exit Function 71 120 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 121 ReadImpl += ReadFromBuffer(p, 0, Math.Min(last, count)) 109 122 End Function 110 123 111 124 Private 125 /* 126 @date 2008/02/25 127 @auther Egtra 128 */ 112 129 Sub init(str As Stream) 113 130 s = str … … 120 137 /** 121 138 @brief バッファの中身から読み取る。 139 @date 2008/02/25 140 @auther Egtra 122 141 文字数が足りなくても、元のストリームまで読みには行かない。 123 142 */ … … 132 151 cur As Long 133 152 last As Long '中身の終わり 134 buf As * Byte '暫定153 buf As *SByte '暫定 135 154 End Class 136 155 -
trunk/Include/Classes/System/IO/TextReader.ab
r426 r432 25 25 End Sub 26 26 27 Abstract Function Peek() As Long 28 Abstract Function Read() As Long 29 /* 30 @date 2008/02/26 31 @auther Egtra 32 */ 33 Function Read(buffer As *StrChar, index As Long, count As Long) As Long 34 If buffer = 0 Then 35 ElseIf index < 0 Then 36 ElseIf count < 0 Then 37 End If 38 End Function 39 40 /* 41 @date 2008/02/26 42 @auther Egtra 43 @retval Nothing EOFに達しているとき 44 @retval 有効なStringインスタンス 読み取った1行 45 */ 46 Virtual Function ReadLine() As String 47 If Peek() = -1 Then 48 Exit Function 49 End If 50 Dim sb = New Text.StringBuilder(256) 51 Do 52 Dim ch = Read() 53 If ch = &h0D Then 54 If Peek() = &h0A Then 55 Read() 'CR LFの場合 56 End If 57 Exit Do 58 End If 59 Select Case ch 60 Case -1 'EOF 61 Exit Do 62 Case &h0A 'LF 63 Exit Do 64 Case &h0B 'VT 65 Exit Do 66 Case &h0C 'FF 67 Exit Do 68 Case &h0D 'CR 69 Exit Do 70 ' Case &h85 'NEL 71 ' Exit Do 72 ' Case &h2028 'LS 73 ' Exit Do 74 ' Case &h2029 'PS 75 ' Exit Do 76 End Select 77 sb.Append(ch As StrChar) 'ToDo キャスト不要にすべきというチケットを書くこと 78 Loop 79 ReadLine = sb.ToString 80 End Function 81 /* 82 @date 2008/02/26 83 @auther Egtra 84 */ 85 Virtual Function ReadToEnd() As String 86 Dim sb = New Text.StringBuilder(8192) 87 Do 88 Dim ch = Read() 89 If ch = -1 Then 90 ReadToEnd = sb.ToString 91 Exit Function 92 End If 93 sb.Append(ch As StrChar) 94 Loop 95 End Function 96 97 Protected 27 98 Abstract Sub Dispose(disposing As Boolean) 28 99 29 Abstract Function Peek() As Long 30 Abstract Function Read() 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) 100 /* 101 @date 2008/02/26 102 @auther Egtra 103 */ 104 Virtual Function ReadImpl(buffer As *StrChar, index As Long, count As Long) As Long 105 Dim i As Long 106 Dim p = VarPtr(buffer[index]) 107 For i = 0 To ELM(count) 108 Dim c = Read() 109 If c = -1 Then 110 ReadImpl = i - 1 111 Exit Function 112 Else 113 p[i] = c As StrChar 114 End If 115 Next 116 ReadImpl = i - 1 34 117 End Function 35 Abstract Function ReadLine() As String36 Abstract Function ReadToEnd() As String37 118 End Class 38 119 -
trunk/Include/Classes/index.ab
r424 r432 10 10 #require "./ActiveBasic/Windows/Windows.ab" 11 11 #require "./System/Blittable.ab" 12 #require "./System/Console.ab" 12 13 #require "./System/DateTime.ab" 13 14 #require "./System/Delegate.ab" … … 67 68 #require "./System/IO/Path.ab" 68 69 #require "./System/IO/Stream.ab" 70 #require "./System/IO/TextReader.ab" 69 71 #require "./System/IO/StreamReader.ab" 72 #require "./System/IO/StringReader.ab" 70 73 #require "./System/IO/StreamWriter.ab" 71 74 #require "./System/IO/TextReader.ab" -
trunk/Include/basic/dos_console.sbp
r391 r432 9 9 Dim _System_hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE) 10 10 Dim _System_hConsoleIn = GetStdHandle(STD_INPUT_HANDLE) 11 System.Console.SetIn( 12 New System.IO.StreamReader( 13 New System.IO.FileStream(_System_hConsoleIn, System.IO.FileAccess.Read, False))) 11 14 12 15 '---------- command.sbp内で定義済み ---------- … … 15 18 '--------------------------------------------- 16 19 Sub INPUT_FromPrompt(ShowStr As String) 17 Dim InputBuf[1023] As TCHAR 18 Dim dwAccessBytes As DWord 19 20 *InputReStart 21 20 *InputReStart '多重Continueがあるので、これはループ構文に直せない。 22 21 PRINT_ToPrompt(ShowStr) 23 22 24 23 '入力 25 ReadConsole(_System_hConsoleIn, InputBuf, Len(InputBuf), dwAccessBytes, 0) 26 If InputBuf[dwAccessBytes-2] = &h0d And InputBuf[dwAccessBytes-1] = &h0a Then 27 InputBuf[dwAccessBytes-2] = 0 28 dwAccessBytes -= 2 24 Dim input = System.Console.ReadLine() 25 If ActiveBasic.IsNothing(input) Then 26 Exit Sub 29 27 End If 30 28 31 If dwAccessBytes= 0 Then Goto *InputReStart29 If input.Length = 0 Then Goto *InputReStart 32 30 33 31 'データを変数に格納 34 32 Const comma = &h2c As StrChar 'Asc(",") 35 Dim broken = ActiveBasic.Strings.Detail.Split( New String(InputBuf, dwAccessBytes As Long), comma)33 Dim broken = ActiveBasic.Strings.Detail.Split(input, comma) 36 34 Dim i As Long 37 35 For i = 0 To ELM(broken.Count) 38 36 If _System_InputDataPtr[i] = 0 Then 39 37 PRINT_ToPrompt(Ex"入力データの個数が多すぎます\r\n") 40 Goto *InputReStart38 Goto *InputReStart 41 39 End If 42 40 _System_Input_SetArgument(_System_InputDataPtr[i], _System_InputDataType[i], broken[i]) … … 45 43 If _System_InputDataPtr[i]<>0 Then 46 44 PRINT_ToPrompt(Ex"入力データの個数が足りません\r\n") 47 Goto *InputReStart45 Goto *InputReStart 48 46 End If 49 47 End Sub … … 54 52 55 53 Sub PRINT_ToPrompt(buf As String) 54 If String.IsNullOrEmpty(buf) Then 55 Exit Sub 56 End If 57 56 58 Dim dwAccessBytes As DWord 57 59 #ifdef __STRING_UNICODE_WINDOWS_ANSI -
trunk/TestCase/SimpleTestCase/ExceptionTest.ab
r388 r432 33 33 34 34 End Namespace 35 36 35 ExceptionTest.TestMain() -
trunk/TestCase/SimpleTestCase/SimpleTestCase.idx
r424 r432 34 34 #include "EncodingTest.ab" 35 35 _ClearNamespaceImported 36 #include "StreamTest.ab" 37 _ClearNamespaceImported 36 38 #include "XmlTest.ab" 37 39 _ClearNamespaceImported -
trunk/TestCase/SimpleTestCase/SimpleTestCase.pj
r424 r432 42 42 TypeInfoTest.ab 43 43 EncodingTest.ab 44 StreamTest.ab 44 45 XmlTest.ab
Note:
See TracChangeset
for help on using the changeset viewer.