source: Include/Classes/System/Diagnostics/TraceListener.ab@ 290

Last change on this file since 290 was 290, checked in by dai, 17 years ago

TraceListener.WriteIfメソッドを実装

File size: 3.3 KB
Line 
1Namespace System
2 Namespace Diagnostics
3
4 ' リスナ
5 Class TraceListener
6 indentLevel As Long
7 indentSize As Long
8
9 Protected
10 Function GetIndentString() As String
11 Dim i As Long
12
13 Dim IndentStr = ""
14 For i = 0 To ELM( indentSize )
15 IndentStr = IndentStr + " "
16 Next
17
18 Dim ResultStr = ""
19 For i = 0 To ELM( indentLevel )
20 ResultStr = ResultStr + IndentStr
21 Next
22
23 Return ResultStr
24 End Function
25
26 Public
27 Sub TraceListener()
28 indentLevel = 0
29 indentSize = 4
30 End Sub
31
32 ' コピーコンストラクタ
33 Sub TraceListener( ByRef listener As TraceListener )
34 indentLevel = listener.indentLevel
35 indentSize = listener.indentSize
36 End Sub
37
38
39 '----------------------------------------------------------------
40 ' パブリック コンストラクタ
41 '----------------------------------------------------------------
42
43 Virtual Sub Write( message As String )
44 '派生クラスで実装 (基底では何もしない)
45 End Sub
46 Virtual Sub Write( value As Object )
47 Write( value.ToString() )
48 End Sub
49 Virtual Sub Write( value As Object, category As String )
50 Write( category + ": " + value.ToString() )
51 End Sub
52 Virtual Sub Write( message As String, category As String )
53 Write( category + ": " + message )
54 End Sub
55
56 Virtual Sub WriteLine( message As String )
57 '派生クラスで実装 (基底では何もしない)
58 End Sub
59 Virtual Sub WriteLine( value As Object )
60 WriteLine( value.ToString() )
61 End Sub
62 Virtual Sub WriteLine( value As Object, category As String )
63 WriteLine( category + ": " + value.ToString() )
64 End Sub
65 Virtual Sub WriteLine( message As String, category As String )
66 WriteLine( category + ": " + message )
67 End Sub
68
69 ' 条件をもとに文字列を出力
70 Sub WriteIf( condition As Boolean, value As Object )
71 If condition Then
72 Write( value )
73 End If
74 End Sub
75 Sub WriteIf( condition As Boolean, message As String )
76 If condition Then
77 Write( message )
78 End If
79 End Sub
80 Sub WriteIf( condition As Boolean, value As Object, category As String )
81 If condition Then
82 Write( value, category )
83 End If
84 End Sub
85 Sub WriteIf( condition As Boolean, message As String, category As String )
86 If condition Then
87 Write( message, category )
88 End If
89 End Sub
90
91
92 '----------------------------------------------------------------
93 ' パブリック プロパティ
94 '----------------------------------------------------------------
95
96 ' IndentLevelプロパティ
97 Function IndentLevel() As Long
98 Return indentLevel
99 End Function
100 Sub IndentLevel( indentLevel As Long )
101 This.indentLevel = indentLevel
102 End Sub
103
104 ' IndentSizeプロパティ
105 Function IndentSize() As Long
106 Return indentSize
107 End Function
108 Sub IndentSize( size As Long )
109 indentSize = size
110 End Sub
111 End Class
112
113 ' デフォルトリスナ(デバッガビューへの出力)
114 Class DefaultTraceListener
115 Inherits TraceListener
116 Public
117
118 Override Sub Write( message As String )
119 ' デバッグビューへ出力
120 Dim tempStr = GetIndentString() + message
121 OutputDebugString( tempStr )
122
123 ' デバッグログへ書き込む
124 ' TODO: 実装
125 End Sub
126
127 Override Sub WriteLine( message As String )
128 Write( GetIndentString() + message + Ex"\r\n" )
129 End Sub
130 End Class
131
132 End Namespace
133End Namespace
Note: See TracBrowser for help on using the repository browser.