OSDN Git Service

Avoid infinite loops in the RegularExpression::subst() function when the length of...
[winmerge-jp/winmerge-jp.git] / Src / StdAfx.h
1 // stdafx.h : include file for standard system include files,
2 //  or project specific include files that are used frequently, but
3 //      are changed infrequently
4 //
5 /**
6  * @file  Src/StdAfx.h
7  *
8  * @brief Project-wide includes and declarations
9  */
10 #pragma once
11
12 // On Win XP, with VS2008, do not use default WINVER 0x0600 because of 
13 // some windows structure used in API (on VISTA they are longer)
14 #if !defined(WINVER)
15 #  define WINVER 0x0501
16 #endif /* !defined(WINVER) */
17
18 #define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
19
20 // Common MFC headers
21
22 #include <afxwin.h>         // MFC core and standard components
23 #include <afxext.h>         // MFC extensions
24 #include <afxcmn.h>         // MFC support for Windows Common Controls
25
26 #include <afxtempl.h>       // MFC C++ template collection classes
27 #include <afxpriv.h>        // MFC private declarations (crystal text needs but doesn't include this)
28 #include <afxole.h>         // MFC OLE (COM) support
29
30 #include <atlimage.h>
31
32 // For CSizingControlBar
33 #include "sizecbar.h"
34 #include "scbarg.h"
35
36 #include <string>
37 #include <vector>
38 #include <map>
39 #include <unordered_set>
40 #include <stack>
41 #include <list>
42 #include <array>
43 #include <algorithm>
44 #include <iostream>
45 #include <sstream>
46 #include <memory>
47 #include <functional>
48 #include <cassert>
49 #include <ctime>
50 #include <boost/flyweight.hpp>
51
52 /**
53  * @name User-defined Windows-messages
54  */
55 /* @{ */
56 /// Directory compare thread asks UI (view) update
57 const UINT MSG_UI_UPDATE = WM_USER + 1;
58 /// Request to save panesizes
59 const UINT MSG_STORE_PANESIZES = WM_USER + 2;
60 /// Request to generate file compare report
61 const UINT MSG_GENERATE_FLIE_COMPARE_REPORT = WM_USER + 3;
62 /* @} */
63
64 /// Seconds ignored in filetime differences if option enabled
65 static const UINT SmallTimeDiff = 2;
66
67 #include "UnicodeString.h"
68 #include "MergeApp.h"
69
70         /** @brief Wrapper around CMergeApp::TranslateDialog() */
71 void NTAPI LangTranslateDialog(HWND);
72
73         /** @brief Lang aware version of AfxMessageBox() */
74 int NTAPI LangMessageBox(UINT, UINT nType = MB_OK, UINT nIDHelp = (UINT)-1);
75
76         /** @brief include for the custom dialog boxes, with do not ask/display again */
77 #include "MessageBoxDialog.h"
78
79 #ifdef _MAX_PATH
80 #  undef _MAX_PATH
81 #endif
82 #define _MAX_PATH (260 * sizeof(wchar_t) / sizeof(tchar_t))
83
84 #ifdef MAX_PATH
85 #  undef MAX_PATH
86 #endif
87 #define MAX_PATH (260 * sizeof(wchar_t) / sizeof(tchar_t))
88
89 #ifdef MAX_PATH_FULL
90 #  undef MAX_PATH_FULL
91 #endif
92 #define MAX_PATH_FULL (32767 * sizeof(wchar_t) / sizeof(tchar_t))
93
94 #define WMPROFILE(x) CWinMergeProfile __wmtl__(x)
95
96 class CWinMergeProfile
97 {
98 private:
99         static int level;
100         static CMapStringToPtr map;
101         static LARGE_INTEGER origin;
102         LARGE_INTEGER li[2];
103         LARGE_INTEGER freq;
104         tchar_t funcname[256];
105 public:
106         explicit CWinMergeProfile(const tchar_t* pFuncName) {
107                 tchar_t buf[256];
108                 _stprintf_s(buf, _T("%-*s funcname=%s Start\n"), level, L"", pFuncName);
109                 OutputDebugString(buf);
110                 lstrcpy(funcname, pFuncName);
111                 QueryPerformanceFrequency(&freq);
112                 QueryPerformanceCounter(&li[0]);
113                 if (origin.QuadPart == 0)
114                         origin = li[0];
115                 ++level;
116         }
117         ~CWinMergeProfile() {
118                 QueryPerformanceCounter(&li[1]);
119                 tchar_t buf[256];
120                 level--;
121                 int elapsed = (int)((double)(li[1].QuadPart - li[0].QuadPart) / freq.QuadPart*1000.0*1000.0);
122                 int tim = (int)((double)(li[1].QuadPart - origin.QuadPart) / freq.QuadPart*1000.0*1000.0);
123                 struct stat {
124                         int sum = 0;
125                         int count = 0;
126                 } *pstat;
127                 void *pstatv = nullptr;
128                 if (!map.Lookup(funcname, pstatv))
129                 {
130                         pstat = new stat();
131                         map[funcname] = (void *)pstat;
132                 }
133                 else
134                 {
135                         pstat = reinterpret_cast<stat *>(pstatv);
136                 }
137                 pstat->sum += elapsed;
138                 pstat->count++;
139                 _stprintf_s(buf, _T("%-*s funcname=%s t=%d[us] count=%d sum=%d[us] time=%g[ms]\n"), level, L"", funcname, elapsed, pstat->count, pstat->sum, tim/1000.0);
140                 OutputDebugString(buf);
141         }
142         static void ResetTimer()
143         {
144                 QueryPerformanceCounter(&origin);
145         }
146         static void Terminiate()
147         {
148                 map.RemoveAll();
149         }
150 };