Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #include "stdafx.h" | 1 #include "stdafx.h" |
2 | 2 |
3 #include <fstream> | 3 #include <fstream> |
4 #include <stdio.h> | 4 #include <stdio.h> |
5 | 5 |
6 #include "Debug.h" | 6 #include "Debug.h" |
7 #include "Utils.h" | 7 #include "Utils.h" |
8 | 8 |
9 #ifdef _DEBUG | 9 #ifdef _DEBUG |
Felix Dahlke
2013/06/04 06:57:58
I assume this is something defined in the plugin?
Wladimir Palant
2013/06/04 09:33:59
No, this is defined by the compiler.
Felix Dahlke
2013/06/04 09:39:09
Hm, didn't know that one, seems to be MSVS only. B
| |
10 | 10 |
11 namespace | 11 namespace |
12 { | 12 { |
13 class CriticalSection | 13 class CriticalSection |
14 { | 14 { |
15 public: | 15 public: |
16 CriticalSection() | 16 CriticalSection() |
17 { | 17 { |
18 InitializeCriticalSection(§ion); | 18 InitializeCriticalSection(§ion); |
19 } | 19 } |
20 | 20 |
21 ~CriticalSection() | 21 ~CriticalSection() |
Felix Dahlke
2013/06/04 06:57:58
Rule of Three again :P I suggest making copy const
| |
22 { | 22 { |
23 DeleteCriticalSection(§ion); | 23 DeleteCriticalSection(§ion); |
24 } | 24 } |
25 | 25 |
26 class Lock | 26 class Lock |
27 { | 27 { |
28 public: | 28 public: |
29 Lock(CriticalSection& cs) | 29 Lock(CriticalSection& cs) |
30 : section(&cs.section) | 30 : section(&cs.section) |
31 { | 31 { |
32 EnterCriticalSection(section); | 32 EnterCriticalSection(section); |
33 } | 33 } |
34 | 34 |
35 ~Lock() | 35 ~Lock() |
Felix Dahlke
2013/06/04 06:57:58
Same as above, should have a private copy construc
| |
36 { | 36 { |
37 LeaveCriticalSection(section); | 37 LeaveCriticalSection(section); |
38 } | 38 } |
39 private: | 39 private: |
40 LPCRITICAL_SECTION section; | 40 LPCRITICAL_SECTION section; |
41 Lock(const Lock&); | |
42 Lock& operator=(const Lock&); | |
41 }; | 43 }; |
42 private: | 44 private: |
43 CRITICAL_SECTION section; | 45 CRITICAL_SECTION section; |
46 CriticalSection(const CriticalSection&); | |
47 CriticalSection& operator=(const CriticalSection&); | |
44 }; | 48 }; |
45 | 49 |
46 static CriticalSection debugLock; | 50 CriticalSection debugLock; |
Felix Dahlke
2013/06/04 06:57:58
static in namespaces is deprecated in C++. Don't t
| |
47 } | 51 } |
48 | 52 |
49 void Debug(const std::string& text) | 53 void Debug(const std::string& text) |
50 { | 54 { |
51 SYSTEMTIME st; | 55 SYSTEMTIME st; |
52 ::GetSystemTime(&st); | 56 ::GetSystemTime(&st); |
53 | 57 |
54 char timeBuf[14]; | 58 char timeBuf[14]; |
55 _snprintf_s(timeBuf, _TRUNCATE, "%02i:%02i:%02i.%03i", st.wHour, st.wMinute, s t.wSecond, st.wMilliseconds); | 59 _snprintf_s(timeBuf, _TRUNCATE, "%02i:%02i:%02i.%03i", st.wHour, st.wMinute, s t.wSecond, st.wMilliseconds); |
56 | 60 |
57 std::wstring filePath = GetAppDataPath() + L"\\debug_engine.txt"; | 61 std::wstring filePath = GetAppDataPath() + L"\\debug_engine.txt"; |
58 | 62 |
59 CriticalSection::Lock lock(debugLock); | 63 CriticalSection::Lock lock(debugLock); |
60 std::ofstream out(filePath, std::ios::app); | 64 std::ofstream out(filePath, std::ios::app); |
61 out << timeBuf << " - " << text << std::endl; | 65 out << timeBuf << " - " << text << std::endl; |
62 out.flush(); | 66 out.flush(); |
63 } | 67 } |
64 | 68 |
65 void DebugLastError(const std::string& message) | 69 void DebugLastError(const std::string& message) |
66 { | 70 { |
67 std::stringstream stream; | 71 std::stringstream stream; |
68 stream << message << " (Error code: " << GetLastError() << ")"; | 72 stream << message << " (Error code: " << GetLastError() << ")"; |
69 Debug(stream.str()); | 73 Debug(stream.str()); |
70 } | 74 } |
71 | 75 |
72 void DebugException(const std::exception& exception) | 76 void DebugException(const std::exception& exception) |
73 { | 77 { |
74 Debug(std::string("An exception occurred: ") + exception.what()); | 78 Debug(std::string("An exception occurred: ") + exception.what()); |
75 } | 79 } |
76 | 80 #else |
81 void Debug(const std::string& text) {} | |
Felix Dahlke
2013/06/04 09:39:09
These are already defined in Debug.h, no?
Wladimir Palant
2013/06/04 10:17:01
No, not any more - Oleksandr moved them in a diffe
| |
82 void DebugLastError(const std::string& message) {} | |
83 void DebugException(const std::exception& exception) {} | |
77 #endif // _DEBUG | 84 #endif // _DEBUG |
LEFT | RIGHT |