Changeset 205 in dev for trunk/jenga/include/common
- Timestamp:
- Jul 12, 2007, 2:57:04 AM (17 years ago)
- Location:
- trunk/jenga/include/common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/jenga/include/common/BoostXmlSupport.h
r190 r205 19 19 #include <boost/serialization/is_abstract.hpp> 20 20 21 #include <windows.h> 22 21 23 namespace Jenga{ 22 24 namespace Common{ … … 27 29 virtual const char *RootTagName() const = 0; 28 30 31 void echo( const char *msg ) const 32 { 33 MessageBox( NULL, msg, "XMLシリアライズの例外", MB_OK ); 34 } 35 29 36 public: 30 bool Read( istream& ifs )37 bool Read( istream& ifs, bool isShowExceptionMessage = true ) 31 38 { 32 39 bool isSuccessful = false; … … 40 47 isSuccessful = true; 41 48 } 49 catch( boost::archive::archive_exception e ) 50 { 51 if( isShowExceptionMessage ) 52 { 53 echo( e.what() ); 54 } 55 } 42 56 catch(...){ 43 // 失敗 57 if( isShowExceptionMessage ) 58 { 59 echo( "archive_exception以外の不明な例外" ); 60 } 44 61 } 45 62 … … 52 69 } 53 70 54 bool Write( ostream& ofs ) const71 bool Write( ostream& ofs, bool isShowExceptionMessage = true ) const 55 72 { 56 73 bool isSuccessful = false; … … 64 81 isSuccessful = true; 65 82 } 66 catch( ... ){ 67 // 失敗 83 catch( boost::archive::archive_exception e ) 84 { 85 if( isShowExceptionMessage ) 86 { 87 echo( e.what() ); 88 } 89 } 90 catch(...){ 91 if( isShowExceptionMessage ) 92 { 93 echo( "archive_exception以外の不明な例外" ); 94 } 68 95 } 69 96 … … 76 103 } 77 104 78 bool Read( const string &xmlFilePath )105 bool Read( const string &xmlFilePath, bool isShowExceptionMessage = true ) 79 106 { 80 107 bool isSuccessful = false; … … 83 110 std::ifstream ifs( xmlFilePath.c_str() ); 84 111 85 bool result = Read(ifs );112 bool result = Read(ifs,isShowExceptionMessage); 86 113 87 114 // 入力を閉じる … … 91 118 } 92 119 93 bool Write( const string &xmlFilePath ) const120 bool Write( const string &xmlFilePath, bool isShowExceptionMessage = true ) const 94 121 { 95 122 // 出力アーカイブの作成 96 123 std::ofstream ofs( xmlFilePath.c_str() ); 97 124 98 bool result = Write(ofs );125 bool result = Write(ofs,isShowExceptionMessage); 99 126 100 127 // 出力を閉じる … … 104 131 } 105 132 106 bool ReadFromString( const wstring &xmlBuffer )133 bool ReadFromString( const string &xmlBuffer ) 107 134 { 108 135 bool isSuccessful = false; -
trunk/jenga/include/common/logger.h
r166 r205 13 13 14 14 #include <jenga/include/common/Environment.h> 15 #include <jenga/include/common/BoostXmlSupport.h> 15 16 16 17 #define STDX_DSTREAM_BUFFERING … … 23 24 24 25 26 class LoggerSetting : public BoostXmlSupport<LoggerSetting> 27 { 28 public: 29 int stopStep; 30 31 LoggerSetting() 32 : stopStep( -1 ) 33 { 34 } 35 36 // XMLシリアライズ用 37 private: 38 virtual const char *RootTagName() const 39 { 40 return "loggerSetting"; 41 } 42 friend class boost::serialization::access; 43 template<class Archive> void serialize(Archive& ar, const unsigned int version) 44 { 45 ar & BOOST_SERIALIZATION_NVP( stopStep ); 46 } 47 }; 48 49 25 50 // VC++ で STLport だと using std::char_traits; みたいなのが必要かも 26 51 template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> > … … 29 54 protected: 30 55 std::string saveFilePath; 56 int count; 57 LoggerSetting setting; 31 58 32 59 public: 33 basic_dbg_streambuf( const std::string &saveFilePath )60 basic_dbg_streambuf( const std::string &saveFilePath, bool isOptionEnabled ) 34 61 : saveFilePath( saveFilePath ) 62 , count( 0 ) 35 63 { 36 64 #ifndef STDX_DSTREAM_BUFFERING 37 65 setbuf(0,0); 38 66 #endif 67 68 if( isOptionEnabled ) 69 { 70 // 設定ファイルを読み込む 71 char temporary[MAX_PATH]; 72 char temp2[MAX_PATH]; 73 char temp3[MAX_PATH]; 74 _splitpath(saveFilePath.c_str(),temporary,temp2,temp3,NULL); 75 setting.Read( (string)temporary + temp2 + temp3 + ".setting.xml", false ); 76 } 39 77 } 40 78 … … 59 97 { 60 98 ofstream ofs( ( saveFilePath ).c_str(), ios_base::app ); 61 ofs << str ;99 ofs << "[" << (count++) << "] " << str ; 62 100 ofs.close(); 101 102 if( (count-1) == setting.stopStep ) 103 { 104 DebugBreak(); 105 } 63 106 } 64 107 … … 67 110 { 68 111 public: 69 basic_dbg_ostream( const string &saveFilePath )70 : std::basic_ostream<Ch_T, Tr_T>(new basic_dbg_streambuf<Ch_T, Tr_T>(saveFilePath ))112 basic_dbg_ostream( const string &saveFilePath, bool isOptionEnabled ) 113 : std::basic_ostream<Ch_T, Tr_T>(new basic_dbg_streambuf<Ch_T, Tr_T>(saveFilePath,isOptionEnabled)) 71 114 { 72 115 ofstream ofs( ( saveFilePath ).c_str(), ios_base::trunc ); … … 87 130 88 131 }} 132 133 BOOST_CLASS_IMPLEMENTATION(Jenga::Common::LoggerSetting, boost::serialization::object_serializable);
Note:
See TracChangeset
for help on using the changeset viewer.