#pragma once #include #include //streamsize #include //basic_streambuf #include //char_traits, basic_string #include //char_traits, basic_string #include #include #include #include #define STDX_DSTREAM_BUFFERING using namespace std; // VC++ で STLport だと using std::char_traits; みたいなのが必要かも template > class basic_dbg_streambuf: public std::basic_stringbuf { public: basic_dbg_streambuf() { #ifndef STDX_DSTREAM_BUFFERING setbuf(0,0); #endif } virtual ~basic_dbg_streambuf() { sync(); } protected: int sync(void) { dbg_out(str().c_str()); pbump(static_cast(pbase() - pptr())); return 0; } void dbg_out(const Ch_T*); }; template <> inline void basic_dbg_streambuf::dbg_out(const char *str) { ofstream ofs( ( (string)/*BasicSystemDir +*/ "logger.log" ).c_str(), ios_base::app ); ofs << str ; ofs.close(); } template > class basic_dbg_ostream: public std::basic_ostream { public: basic_dbg_ostream() : std::basic_ostream(new \ basic_dbg_streambuf()) { ofstream ofs( ( (string)/*BasicSystemDir +*/ + "logger.log" ).c_str(), ios_base::trunc ); ofs.close(); } virtual ~basic_dbg_ostream() { // flush(); // 不要らしい.http://www.tietew.jp/cppll/archive/607 delete rdbuf(); } }; // ログ生成しない場合はこの下の行をコメントアウトする #define USE_TRACE #ifdef USE_TRACE static basic_dbg_ostream<_TCHAR> logger; #define trace(s) logger << s << endl #else #define trace(s) #endif