Namespace System
	Namespace Diagnostics

		Class _System_TraceBase
			indentLevel As Long
			indentSize As Long


			' リスナ管理
			listeners As TraceListenerCollection

		Public

			' コンストラクタ
			Sub _System_TraceBase()
				listeners = New TraceListenerCollection
				listeners.Add( New DefaultTraceListener() )

				indentLevel = 0
				indentSize = 4
			End Sub

			'----------------------------------------------------------------
			' パブリック メソッド
			'----------------------------------------------------------------

			' アサート（コールスタックを表示）
			Sub Assert( condition As Boolean )
				If condition = False then
					'TODO: コールスタックを表示
				End If
			End Sub

			' アサート（メッセージ文字列を表示）
			Sub Assert( condition As Boolean, message As String )
				If condition = False then
					' TODO: メッセージボックス形式での表示に対応
					WriteLine( message )
				End If
			End Sub

			' アサート（メッセージ文字列と詳細文字列を表示）
			Sub Assert( condition As Boolean, message As String, detailMessage As String )
				If condition = False then
					' TODO: メッセージボックス形式での表示に対応
					WriteLine( message )
				End If
			End Sub


			' インデントレベルを上げる
			Sub Indent()
				IndentLevel = indentLevel + 1
			End Sub

			' インデントレベルを下げる
			Sub Unindent()
				If indentLevel <= 0 Then
					indentLevel = 0
					Return
				End If
				IndentLevel = indentLevel - 1
			End Sub

			' 文字列を出力
			Sub Write( value As Object )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.Write( value )
				Next
			End Sub
			Sub Write( message As String )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.Write( message )
				Next
			End Sub
			Sub Write( value As Object, category As String )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.Write( value, category )
				Next
			End Sub
			Sub Write( message As String, category As String )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.Write( message, category )
				Next
			End Sub

			' 一行の文字列を出力
			Sub WriteLine( value As Object )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.WriteLine( value )
				Next
			End Sub
			Sub WriteLine( message As String )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.WriteLine( message )
				Next
			End Sub
			Sub WriteLine( value As Object, category As String )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.WriteLine( value, category )
				Next
			End Sub
			Sub WriteLine( message As String, category As String )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.WriteLine( message, category )
				Next
			End Sub

			' 条件をもとに文字列を出力
			Sub WriteIf( condition As Boolean, value As Object )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.WriteIf( condition, value )
				Next
			End Sub
			Sub WriteIf( condition As Boolean, message As String )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.WriteIf( condition, message )
				Next
			End Sub
			Sub WriteIf( condition As Boolean, value As Object, category As String )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.WriteIf( condition, value, category )
				Next
			End Sub
			Sub WriteIf( condition As Boolean, message As String, category As String )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.WriteIf( condition, message, category )
				Next
			End Sub

			' 条件をもとに一行の文字列を出力
			Sub WriteLineIf( condition As Boolean, value As Object )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.WriteLineIf( condition, value )
				Next
			End Sub
			Sub WriteLineIf( condition As Boolean, message As String )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.WriteLineIf( condition, message )
				Next
			End Sub
			Sub WriteLineIf( condition As Boolean, value As Object, category As String )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.WriteLineIf( condition, value, category )
				Next
			End Sub
			Sub WriteLineIf( condition As Boolean, message As String, category As String )
				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.WriteLineIf( condition, message, category )
				Next
			End Sub


			'----------------------------------------------------------------
			' パブリック プロパティ
			'----------------------------------------------------------------

			' IndentLevelプロパティ
			Function IndentLevel() As Long
				Return indentLevel
			End Function
			Sub IndentLevel( indentLevel As Long )
				This.indentLevel = indentLevel

				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.IndentLevel = indentLevel
				Next
			End Sub

			' IndentSizeプロパティ
			Function IndentSize() As Long
				Return indentSize
			End Function
			Sub IndentSize( size As Long )
				indentSize = size

				Dim i As Long
				For i = 0 To ELM( listeners.Count )
					Dim listener = listeners[i]
					listener.IndentSize = indentSize
				Next
			End Sub

			' Listenersプロパティ
			Function Listeners() As TraceListenerCollection
				Return listeners
			End Function

		End Class

	End Namespace
End Namespace
