source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/include/logger.h@ 685

Last change on this file since 685 was 523, checked in by dai_9181, 17 years ago

ヘッダファイルを整理中

File size: 2.6 KB
Line 
1#pragma once
2
3#define STDX_DSTREAM_BUFFERING
4
5namespace Jenga{
6namespace Common{
7
8
9class LoggerSetting : public BoostSerializationSupport<LoggerSetting>
10{
11public:
12 int stopStep;
13
14 LoggerSetting()
15 : stopStep( -1 )
16 {
17 }
18
19 // XMLシリアライズ用
20private:
21 virtual const char *RootTagName() const
22 {
23 return "loggerSetting";
24 }
25 friend class boost::serialization::access;
26 template<class Archive> void serialize(Archive& ar, const unsigned int version)
27 {
28 ar & BOOST_SERIALIZATION_NVP( stopStep );
29 }
30};
31
32
33// VC++ で STLport だと using std::char_traits; みたいなのが必要かも
34template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> >
35class basic_dbg_streambuf: public std::basic_stringbuf<Ch_T, Tr_T>
36{
37protected:
38 std::string saveFilePath;
39 int count;
40 LoggerSetting setting;
41
42public:
43 basic_dbg_streambuf( const std::string &saveFilePath, bool isOptionEnabled )
44 : saveFilePath( saveFilePath )
45 , count( 0 )
46 {
47#ifndef STDX_DSTREAM_BUFFERING
48 setbuf(0,0);
49#endif
50
51 if( isOptionEnabled )
52 {
53 // 設定ファイルを読み込む
54 char temporary[MAX_PATH];
55 char temp2[MAX_PATH];
56 char temp3[MAX_PATH];
57 _splitpath(saveFilePath.c_str(),temporary,temp2,temp3,NULL);
58
59 std::string settingXmlPath = (std::string)temporary + temp2 + temp3 + ".setting.xml";
60 if( Jenga::Common::Path( settingXmlPath ).IsExistFile() )
61 {
62 setting.ReadXml( settingXmlPath, false );
63 }
64 }
65 }
66
67 virtual ~basic_dbg_streambuf()
68 {
69 sync();
70 }
71
72protected:
73 int sync(void)
74 {
75 dbg_out(str().c_str());
76 pbump(static_cast<int>(pbase() - pptr()));
77 return 0;
78 }
79
80 void dbg_out(const Ch_T*);
81};
82
83template <>
84inline void basic_dbg_streambuf<char>::dbg_out(const char *str)
85{
86 std::ofstream ofs( ( saveFilePath ).c_str(), std::ios_base::app );
87 ofs << "[" << (count++) << "] " << str ;
88 ofs.close();
89
90 OutputDebugString( str );
91
92 if( (count-1) == setting.stopStep )
93 {
94 DebugBreak();
95 }
96}
97
98template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> >
99class basic_dbg_ostream: public std::basic_ostream<Ch_T, Tr_T>
100{
101public:
102 basic_dbg_ostream( const std::string &saveFilePath, bool isOptionEnabled )
103 : std::basic_ostream<Ch_T, Tr_T>(new basic_dbg_streambuf<Ch_T, Tr_T>(saveFilePath,isOptionEnabled))
104 {
105 std::ofstream ofs( ( saveFilePath ).c_str(), std::ios_base::trunc );
106 ofs.close();
107 }
108
109
110 virtual ~basic_dbg_ostream()
111 {
112 // flush(); // 不要らしい.http://www.tietew.jp/cppll/archive/607
113 delete rdbuf();
114 }
115};
116
117
118typedef basic_dbg_ostream<_TCHAR> Logger;
119
120
121}}
122
123BOOST_CLASS_IMPLEMENTATION(Jenga::Common::LoggerSetting, boost::serialization::object_serializable);
Note: See TracBrowser for help on using the repository browser.