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

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

Trace/Debugクラスを実装(リスナ系にちょっとTODOが残っている…)。

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