OSDN Git Service

とりあえず実行できるようになった。
[winaudioj/stedx.git] / 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 #ifdef _DEBUG
16   
17 // VC++ \82Å STLport \82¾\82Æ using std::char_traits; \82Ý\82½\82¢\82È\82Ì\82ª\95K\97v\82©\82à
18 template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> >
19 class basic_dbg_streambuf: public std::basic_stringbuf<Ch_T, Tr_T>
20 {
21 public:
22   basic_dbg_streambuf()
23     {
24 #ifndef STDX_DSTREAM_BUFFERING
25       setbuf(0,0);
26 #endif
27     }
28
29   virtual ~basic_dbg_streambuf()
30     {
31       sync();
32     }
33
34 protected:
35   int sync(void)
36     {
37       dbg_out(str().c_str());
38       pbump(static_cast<int>(pbase() - pptr()));
39       return 0;
40     }
41
42   void dbg_out(const Ch_T*);
43 };
44
45 template <>
46 inline void basic_dbg_streambuf<char>::dbg_out(const char *str)
47 {
48   ::OutputDebugStringA(str);
49 }
50
51 template <>
52 inline void basic_dbg_streambuf<wchar_t>::dbg_out(const wchar_t *str)
53 {
54   ::OutputDebugStringW(str);
55 }
56
57 template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> >
58 class basic_dbg_ostream: public std::basic_ostream<Ch_T, Tr_T>
59 {
60 public:
61   basic_dbg_ostream() : std::basic_ostream<Ch_T, Tr_T>(new basic_dbg_streambuf<Ch_T, Tr_T>())
62     {
63     }
64
65   virtual ~basic_dbg_ostream()
66     {
67       // flush(); // \95s\97v\82ç\82µ\82¢\81Dhttp://www.tietew.jp/cppll/archive/607
68       delete rdbuf();
69     }
70 };
71
72 typedef basic_dbg_streambuf<wchar_t>  wdbg_streambuf;
73 typedef basic_dbg_ostream<wchar_t> wdstream;
74
75 // \82±\82ê\82ð\92è\8b`\82µ\82Ä\82¨\82­\82Æ\81C dout \82Ì\90é\8c¾\82ª\82¢\82ç\82È\82­\82È\82é\81D
76
77 static wdstream wdout;
78 #define DOUT(x) wdout << x 
79 }
80 #else
81 #define DOUT(x) 
82 #define wdout //
83 //  struct dummy_wdout {
84 //    //template <typename R>
85 //    //inline dummy_wdout& operator<<(const R v) {return *this;};
86 //
87 //    //template <typename R>
88 //    //inline dummy_wdout& operator<<(const R* v) {return *this;};
89 //
90 //    //template <typename R>
91 //    //inline dummy_wdout& operator<<(const R& v) {return *this;};
92 //
93 //    //template <typename R>
94 //    //inline dummy_wdout& operator<<(const R&& v) {return *this;};
95 //
96 //    ////template <typename R,int N>
97 //    ////inline dummy_wdout& operator<<(const R(&a)[N]) {return *this;};
98 //
99 //  };
100 //
101 //  static dummy_wdout wdout;
102 //}
103 //
104 //template <typename L>
105 //inline sf::dummy_wdout& operator<<(sf::dummy_wdout& p,const L v) {return p;};
106 //
107 //template <typename L>
108 //inline sf::dummy_wdout& operator<<(sf::dummy_wdout& p,const L& v) {return p;};
109 //
110 //template <typename L>
111 //inline sf::dummy_wdout& operator<<(sf::dummy_wdout& p,const L&& v) {return p;};
112 //
113 ////template <typename L>
114 ////inline sf::dummy_wdout& operator<<(sf::dummy_wdout& p,const L* v) {return p;};
115 //
116 //template <typename L,int N>
117 //inline sf::dummy_wdout& operator<<(sf::dummy_wdout& p,const L(&a)[N]) {return p;};
118 //
119 //template <typename L>
120 //inline L& operator<<(const L v,sf::dummy_wdout& p) {return v;};
121 //
122 //template <typename L>
123 //inline L& operator<<(sf::dummy_wdout& p,L v) {return v;};
124 //
125 //
126 //template <typename L>
127 //inline sf::dummy_wdout& operator<<(const L v,sf::dummy_wdout& p) {return p;};
128 //
129 //template <typename L>
130 //inline sf::dummy_wdout& operator<<(const L& v,sf::dummy_wdout& p) {return p;};
131 //
132 ////template <typename L>
133 ////inline sf::dummy_wdout& operator<<(const L* v,sf::dummy_wdout& p) {return p;};
134 //
135 //template <typename L>
136 //inline sf::dummy_wdout& operator<<(const L&& v,sf::dummy_wdout& p) {return p;};
137 //
138 //
139 //template <typename L,int N>
140 //inline sf::dummy_wdout& operator<<(const L(&a)[N],sf::dummy_wdout& p) {return p;};
141 ////
142 //template <typename L>
143 //inline sf::dummy_wdout& operator<<(sf::dummy_wdout& p , const L *v) {return p;};
144
145 //
146 }
147 #endif
148 #endif // STDX_DSTREAM_