source: dev/branches/egtra/ab5.0/abdev/BasicCompiler_Common/include/logger.h

Last change on this file was 817, checked in by イグトランス (egtra), 14 years ago

compilerにおいて、各クラスのコピー禁止を明確化、ならびにコピー可能なものにムーブコンストラクタ・ムーブ代入演算子を追加。

File size: 2.7 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 LoggerSetting(LoggerSetting const&);
32 LoggerSetting operator =(LoggerSetting const&);
33};
34
35
36// VC++ で STLport だと using std::char_traits; みたいなのが必要かも
37template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> >
38class basic_dbg_streambuf: public std::basic_stringbuf<Ch_T, Tr_T>
39{
40protected:
41 std::string saveFilePath;
42 int count;
43 LoggerSetting setting;
44
45public:
46 basic_dbg_streambuf( const std::string &saveFilePath, bool isOptionEnabled )
47 : saveFilePath( saveFilePath )
48 , count( 0 )
49 {
50#ifndef STDX_DSTREAM_BUFFERING
51 setbuf(0,0);
52#endif
53
54 if( isOptionEnabled )
55 {
56 // 設定ファイルを読み込む
57 char temporary[MAX_PATH];
58 char temp2[MAX_PATH];
59 char temp3[MAX_PATH];
60 _splitpath(saveFilePath.c_str(),temporary,temp2,temp3,NULL);
61
62 std::string settingXmlPath = (std::string)temporary + temp2 + temp3 + ".setting.xml";
63 if( Jenga::Common::Path( settingXmlPath ).IsExistFile() )
64 {
65 setting.ReadXml( settingXmlPath, false );
66 }
67 }
68 }
69
70 virtual ~basic_dbg_streambuf()
71 {
72 sync();
73 }
74
75protected:
76 int sync(void)
77 {
78 dbg_out(str().c_str());
79 pbump(static_cast<int>(pbase() - pptr()));
80 return 0;
81 }
82
83 void dbg_out(const Ch_T*);
84};
85
86template <>
87inline void basic_dbg_streambuf<char>::dbg_out(const char *str)
88{
89 std::ofstream ofs( ( saveFilePath ).c_str(), std::ios_base::app );
90 ofs << "[" << (count++) << "] " << str ;
91 ofs.close();
92
93 OutputDebugString( str );
94
95 if( (count-1) == setting.stopStep )
96 {
97 DebugBreak();
98 }
99}
100
101template <typename Ch_T, typename Tr_T = std::char_traits<Ch_T> >
102class basic_dbg_ostream: public std::basic_ostream<Ch_T, Tr_T>
103{
104public:
105 basic_dbg_ostream( const std::string &saveFilePath, bool isOptionEnabled )
106 : std::basic_ostream<Ch_T, Tr_T>(new basic_dbg_streambuf<Ch_T, Tr_T>(saveFilePath,isOptionEnabled))
107 {
108 std::ofstream ofs( ( saveFilePath ).c_str(), std::ios_base::trunc );
109 ofs.close();
110 }
111
112
113 virtual ~basic_dbg_ostream()
114 {
115 // flush(); // 不要らしい.http://www.tietew.jp/cppll/archive/607
116 delete rdbuf();
117 }
118};
119
120
121typedef basic_dbg_ostream<_TCHAR> Logger;
122
123
124}}
125
126BOOST_CLASS_IMPLEMENTATION(Jenga::Common::LoggerSetting, boost::serialization::object_serializable);
Note: See TracBrowser for help on using the repository browser.