OSDN Git Service

基本ファイルを追加
[winaudioj/sfwasapi.git] / sfwasapi / dout.h
1 #pragma once
2
3 /* http://vision.kuee.kyoto-u.ac.jp/~nob/doc/win32/win32.html#doc1_42 
4         \82æ\82è\94q\8eØ
5 */
6
7
8 #ifndef STDX_DSTREAM_H
9
10 #define STDX_DSTREAM_H
11
12 namespace sf
13 {
14   
15 // VC++ \82Å STLport \82¾\82Æ using std::char_traits; \82Ý\82½\82¢\82È\82Ì\82ª\95K\97v\82©\82à
16 template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> >
17 class basic_dbg_streambuf: public std::basic_stringbuf<Ch_T, Tr_T>
18 {
19 public:
20   basic_dbg_streambuf()
21     {
22 #ifndef STDX_DSTREAM_BUFFERING
23       setbuf(0,0);
24 #endif
25     }
26
27   virtual ~basic_dbg_streambuf()
28     {
29       sync();
30     }
31
32 protected:
33   int sync(void)
34     {
35       dbg_out(str().c_str());
36       pbump(static_cast<int>(pbase() - pptr()));
37       return 0;
38     }
39
40   void dbg_out(const Ch_T*);
41 };
42
43 template <>
44 inline void basic_dbg_streambuf<char>::dbg_out(const char *str)
45 {
46   ::OutputDebugStringA(str);
47 }
48
49 template <>
50 inline void basic_dbg_streambuf<wchar_t>::dbg_out(const wchar_t *str)
51 {
52   ::OutputDebugStringW(str);
53 }
54
55 template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> >
56 class basic_dbg_ostream: public std::basic_ostream<Ch_T, Tr_T>
57 {
58 public:
59   basic_dbg_ostream() : std::basic_ostream<Ch_T, Tr_T>(new basic_dbg_streambuf<Ch_T, Tr_T>())
60     {
61     }
62
63   virtual ~basic_dbg_ostream()
64     {
65       // flush(); // \95s\97v\82ç\82µ\82¢\81Dhttp://www.tietew.jp/cppll/archive/607
66       delete rdbuf();
67     }
68 };
69
70 typedef basic_dbg_streambuf<wchar_t>  wdbg_streambuf;
71 typedef basic_dbg_ostream<wchar_t> wdstream;
72
73 // \82±\82ê\82ð\92è\8b`\82µ\82Ä\82¨\82­\82Æ\81C dout \82Ì\90é\8c¾\82ª\82¢\82ç\82È\82­\82È\82é\81D
74 static wdstream wdout;
75
76 }
77
78 #endif // STDX_DSTREAM_