'Classes/System/Console.ab

Namespace System

/*
@brief コンソール入出力・ウィンドウなどのクラス
@date 2008/02/26
@auther Egtra
*/
Class Console
Public
	/*
	@brief 標準入力を設定する
	@date 2008/02/26
	@auther Egtra
	*/
	Static Sub SetIn(newIn As IO.TextReader)
		If ActiveBasic.IsNothing(newIn) Then
			Throw New ArgumentNullException("newIn")
		End If
		in = newIn
	End Sub
	/*
	@brief 標準入力を取得する
	@date 2008/02/26
	@auther Egtra
	*/
	Static Function In() As IO.TextReader
		In = in
	End Function

	/*
	@brief 標準入力から1行読み込む
	@date 2008/02/26
	@auther Egtra
	*/
	Static Function ReadLine() As String
		ReadLine = in.ReadLine()
	End Function

	/*
	@brief 標準入力から1行読み込む
	@date 2008/02/26
	@auther Egtra
	*/
	Static Function Read() As Long
		Read = in.Read()
	End Function
Private
	Function enter() As ActiveBasic.Windows.CriticalSectionLock
		Imports ActiveBasic.Windows
		If ActiveBasic.IsNothing(cs) Then
			Dim lock = New CriticalSectionLock(_System_CriticalSection)
			Try
				If ActiveBasic.IsNothing(cs) Then
					cs = New CriticalSection
				End If
			Finally
				lock.Dispose()
			End Try
		End If
		enter = cs.Enter
	End Function

	Static in = Nothing As IO.TextReader
	Static cs = Nothing As ActiveBasic.Windows.CriticalSection
End Class

End Namespace 'System
