Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/shared/Utils.h

Issue 11012013: Hanging resolved (critical sections unlocking) (Closed)
Patch Set: Using CriticalSection class instead Created June 17, 2013, 10:03 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« src/plugin/PluginFilter.h ('K') | « src/plugin/PluginFilter.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #ifndef UTILS_H 1 #ifndef UTILS_H
2 #define UTILS_H 2 #define UTILS_H
3 3
4 #include <algorithm> 4 #include <algorithm>
5 #include <locale> 5 #include <locale>
6 #include <functional> 6 #include <functional>
7 #include <string> 7 #include <string>
8 8
9 9
10 bool IsWindowsVistaOrLater(); 10 bool IsWindowsVistaOrLater();
11 11
12 std::string ToUtf8String(const std::wstring& str); 12 std::string ToUtf8String(const std::wstring& str);
13 std::wstring ToUtf16String(const std::string& str); 13 std::wstring ToUtf16String(const std::string& str);
14 std::wstring GetDllDir(); 14 std::wstring GetDllDir();
15 std::wstring GetAppDataPath(); 15 std::wstring GetAppDataPath();
16 16
17 template<class T> 17 template<class T>
18 T TrimString(T text) 18 T TrimString(T text)
19 { 19 {
20 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-st dstring 20 // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-st dstring
21 T trimmed(text); 21 T trimmed(text);
22 std::function<bool(T::value_type)> isspace = std::bind(&std::isspace<T::value_ type>, std::placeholders::_1, std::locale::classic()); 22 std::function<bool(T::value_type)> isspace = std::bind(&std::isspace<T::value_ type>, std::placeholders::_1, std::locale::classic());
23 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end(), st d::not1(isspace))); 23 trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end(), st d::not1(isspace)));
24 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(isspace )).base(), trimmed.end()); 24 trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(isspace )).base(), trimmed.end());
25 return trimmed; 25 return trimmed;
26 } 26 }
27 27
28 namespace
Wladimir Palant 2013/06/17 12:57:24 If it's a public class then it shouldn't be declar
29 {
30 class CriticalSection
31 {
32 public:
33 CriticalSection()
34 {
35 InitializeCriticalSection(&section);
36 }
37
38 ~CriticalSection()
39 {
40 DeleteCriticalSection(&section);
41 }
42
43 class Lock
44 {
45 public:
46 Lock(CriticalSection& cs)
47 : section(&cs.section)
48 {
49 EnterCriticalSection(section);
50 }
51
52 ~Lock()
53 {
54 LeaveCriticalSection(section);
55 }
56 private:
57 LPCRITICAL_SECTION section;
58 Lock(const Lock&);
59 Lock& operator=(const Lock&);
60 };
61 private:
62 CRITICAL_SECTION section;
63 CriticalSection(const CriticalSection&);
64 CriticalSection& operator=(const CriticalSection&);
65 };
66 }
28 #endif // UTILS_H 67 #endif // UTILS_H
OLDNEW
« src/plugin/PluginFilter.h ('K') | « src/plugin/PluginFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld