#pragma once #include #include //streamsize #include //basic_streambuf #include //char_traits, basic_string #include //char_traits, basic_string #include #include #include #include #include #define STDX_DSTREAM_BUFFERING using namespace std; namespace Jenga{ namespace Common{ // VC++ で STLport だと using std::char_traits; みたいなのが必要かも template > class basic_dbg_streambuf: public std::basic_stringbuf { protected: std::string saveFilePath; public: basic_dbg_streambuf( const std::string &saveFilePath ) : saveFilePath( saveFilePath ) { #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( ( saveFilePath ).c_str(), ios_base::app ); ofs << str ; ofs.close(); } template > class basic_dbg_ostream: public std::basic_ostream { public: basic_dbg_ostream( const string &saveFilePath ) : std::basic_ostream(new basic_dbg_streambuf(saveFilePath)) { ofstream ofs( ( saveFilePath ).c_str(), ios_base::trunc ); ofs.close(); } virtual ~basic_dbg_ostream() { // flush(); // 不要らしい.http://www.tietew.jp/cppll/archive/607 delete rdbuf(); } }; typedef basic_dbg_ostream<_TCHAR> Logger; }}