forked from dolphinsmalltalk/DolphinVM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTraceStream.h
More file actions
108 lines (90 loc) · 2.18 KB
/
TraceStream.h
File metadata and controls
108 lines (90 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#pragma once
#include <windows.h>
#pragma warning(push,3)
#pragma warning(disable:4530)
#include <ostream>
#include <streambuf>
#pragma warning(default:4530)
#pragma warning(pop)
#include "CritSect.h"
template<class charT, class traits = std::char_traits<charT> >
class basic_tracestreambuf : public std::basic_streambuf<charT, traits>
{
public:
// Public interface
basic_tracestreambuf () : std::basic_streambuf<charT, traits>()
{
setp(buffer, buffer+bufSize);
}
virtual ~basic_tracestreambuf ()
{
// Ensure buffer is flushed on destruct
sync();
}
protected:
// Implementation
int_type overflow(int_type ch = traits::eof())
{
if (output_buffer() < 0)
return traits::eof();
else
{
if (!traits::eq_int_type(traits::eof(), ch))
return sputc(traits::to_char_type(ch));
else
return traits::not_eof(ch);
}
}
int sync()
{
return output_buffer();
}
private:
int output_buffer()
{
char* pb = pbase();
long count = pptr() - pb;
if (count != 0)
{
pb[count] = 0;
::OutputDebugString(pb);
}
// Empty the put area
pbump(-count);
return 0;
}
private:
// State
enum {bufSize = 255};
// Allow an extra char for null terminator
char_type buffer[bufSize+1];
};
typedef basic_tracestreambuf<char> tracestreambuf;
template<class charT, class traits = std::char_traits<charT> >
class basic_tracestream : public std::basic_ostream<charT, traits>
{
private:
// Suppress autogenerated copy constructor and assignment operator
basic_tracestream(const basic_tracestream&);
basic_tracestream& operator=(const basic_tracestream&);
public:
typedef basic_tracestreambuf<charT, traits> buf_type;
basic_tracestream() : std::basic_ostream<charT, traits>(&m_buf), m_buf() {}
virtual ~basic_tracestream()
{}
buf_type *rdbuf() const
{
return ((buf_type*)&m_buf);
}
void Lock() {m_mutex.Lock(); }
void Unlock() {m_mutex.Unlock();}
private:
CMonitor m_mutex;
buf_type m_buf;
};
typedef basic_tracestream<char> tracestream;
typedef CAutoLock<tracestream> tracelock;
struct _SYSTEMTIME;
std::ostream& operator<<(std::ostream& stream, const _SYSTEMTIME& st);
struct _CONTEXT;
std::ostream& operator<<(std::ostream& stream, const _CONTEXT* pCtx);