Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

fogcreek shellext: use ATL strings and collections, part 2

Changeset 9d4d5bcf994e

Parent 44148c334a69

by David Golub

Changes to 6 files · Browse files at 9d4d5bcf994e Showing diff from parent 44148c334a69 Diff from another changeset...

 
187
188
189
190
 
191
192
193
 
553
554
555
556
557
 
 
558
559
 
560
561
562
 
601
602
603
604
605
 
 
606
607
608
609
610
611
 
612
613
614
615
 
616
617
618
 
619
620
621
 
187
188
189
 
190
191
192
193
 
553
554
555
 
 
556
557
558
 
559
560
561
562
 
601
602
603
 
 
604
605
606
607
608
609
610
 
611
612
613
614
 
615
616
617
 
618
619
620
621
@@ -187,7 +187,7 @@
    }   - myMenuIdMap.clear(); + myMenuIdMap.RemoveAll();  }     @@ -553,10 +553,10 @@
  {   UINT idCmd = LOWORD(lpcmi->lpVerb);   ATLTRACE("CShellExtCMenu::InvokeCommand: idCmd = %d\n", idCmd); - MenuIdCmdMap::iterator iter = myMenuIdMap.find(idCmd); - if (iter != myMenuIdMap.end()) + const MenuIdCmdMap::CPair* p = myMenuIdMap.Lookup(idCmd); + if (p != NULL)   { - RunDialog(iter->second.name); + RunDialog(p->m_value.name);   hr = S_OK;   }   else @@ -601,21 +601,21 @@
  ATLTRACE("CShellExtCMenu::GetCommandString: idCmd = %d, uFlags = %d (%s), "   "cchMax = %d\n", idCmd, uFlags, sflags, cchMax);   - MenuIdCmdMap::iterator iter = myMenuIdMap.find(static_cast<UINT>(idCmd)); - if (iter == myMenuIdMap.end()) + const MenuIdCmdMap::CPair* p = myMenuIdMap.Lookup((UINT)idCmd); + if (p == NULL)   {   ATLTRACE("***** CShellExtCMenu::GetCommandString: idCmd not found\n");   }   else   { - ATLTRACE("CShellExtCMenu::GetCommandString: name = '%s'\n", iter->second.name); + ATLTRACE("CShellExtCMenu::GetCommandString: name = '%s'\n", p->m_value.name);     if (uFlags == GCS_HELPTEXTW)   { - pszw = iter->second.helpText; + pszw = p->m_value.helpText;   res = S_OK;   - size_t size = iter->second.helpText.GetLength(); + size_t size = p->m_value.helpText.GetLength();   if (size >= 40)   {   ATLTRACE("***** CShellExtCMenu::GetCommandString: warning: "
 
1
2
3
4
5
6
7
8
9
10
 
15
16
17
18
19
20
 
21
22
23
 
1
2
3
 
 
 
 
4
5
6
 
11
12
13
 
 
 
14
15
16
17
@@ -1,10 +1,6 @@
 #ifndef _CShellExtCMenu_h_  #define _CShellExtCMenu_h_   -#include <vector> -#include <string> -#include <map> -  struct MenuDescription  {   CString name; @@ -15,9 +11,7 @@
 };    typedef CAtlMap<CString, MenuDescription> MenuDescriptionMap; - -typedef std::map<UINT, MenuDescription> MenuIdCmdMap; - +typedef CAtlMap<UINT, MenuDescription> MenuIdCmdMap;    class CShellExtCMenuBase :   public CComObjectRootEx<CComMultiThreadModel>,
 
39
40
41
42
 
 
43
44
 
45
46
47
 
88
89
90
91
 
92
93
94
95
96
97
 
 
98
99
100
 
 
 
101
102
103
 
105
106
107
108
 
109
110
111
 
134
135
136
137
138
 
 
139
140
141
 
 
 
142
143
144
145
146
147
 
 
148
149
 
 
150
151
 
152
153
154
 
180
181
182
183
184
 
 
185
186
 
 
187
188
189
190
 
 
191
192
193
 
200
201
202
203
 
 
204
205
 
206
207
208
 
217
218
219
220
 
 
221
222
223
 
 
 
224
225
226
 
229
230
231
232
 
233
234
235
 
39
40
41
 
42
43
44
 
45
46
47
48
 
89
90
91
 
92
93
94
95
96
 
 
97
98
99
 
 
100
101
102
103
104
105
 
107
108
109
 
110
111
112
113
 
136
137
138
 
 
139
140
141
 
 
142
143
144
145
146
147
148
 
 
149
150
151
 
152
153
154
 
155
156
157
158
 
184
185
186
 
 
187
188
189
 
190
191
192
193
 
 
194
195
196
197
198
 
205
206
207
 
208
209
210
 
211
212
213
214
 
223
224
225
 
226
227
228
 
 
229
230
231
232
233
234
 
237
238
239
 
240
241
242
243
@@ -39,9 +39,10 @@
   Directory::~Directory()  { - for (DirsT::iterator i = subdirs_.begin(); i != subdirs_.end(); ++i) + POSITION position = subdirs_.GetHeadPosition(); + while (position != NULL)   { - delete *i; + delete subdirs_.GetNext(position);   }  }   @@ -88,16 +89,17 @@
  if (base.IsEmpty())   {   e.name = n; - cur->files_.push_back(e); + cur->files_.AddTail(e);   return 1;   }     Directory* d = 0; - for (DirsT::iterator i = cur->subdirs_.begin(); - i != cur->subdirs_.end(); ++i) + POSITION position = cur->subdirs_.GetHeadPosition(); + while (position != NULL)   { - if ((*i)->name_ == base) { - d = *i; + Directory* pItem = cur->subdirs_.GetNext(position); + if (pItem->name_ == base) { + d = pItem;   break;   }   } @@ -105,7 +107,7 @@
  if (!d)   {   d = new Directory(cur, base, cur->path()); - cur->subdirs_.push_back(d); + cur->subdirs_.AddTail(d);   }     n = rest; @@ -134,21 +136,23 @@
    if (base.IsEmpty())   { - for (FilesT::const_iterator i = cur->files_.begin(); - i != cur->files_.end(); ++i) + POSITION position = cur->files_.GetHeadPosition(); + while (position != NULL)   { - if (i->name == n) - return &(*i); + const Direntry& rItem = cur->files_.GetNext(position); + if (rItem.name == n) + return &rItem;   }   return 0;   }   - for (DirsT::const_iterator i = cur->subdirs_.begin(); - i != cur->subdirs_.end(); ++i) + POSITION position = cur->subdirs_.GetHeadPosition(); + while (position != NULL)   { - if ((*i)->name_ == base) + Directory* pItem = cur->subdirs_.GetNext(position); + if (pItem->name_ == base)   { - cur = *i; + cur = pItem;   n = rest;   goto loopstart;   } @@ -180,14 +184,15 @@
  const bool leaf = base.IsEmpty();   const CString& searchstr = (leaf ? n : base);   - for (DirsT::const_iterator i = cur->subdirs_.begin(); - i != cur->subdirs_.end(); ++i) + POSITION position = cur->subdirs_.GetHeadPosition(); + while (position != NULL)   { - if ((*i)->name_ == searchstr) + Directory* pItem = cur->subdirs_.GetNext(position); + if (pItem->name_ == searchstr)   {   if (leaf) - return *i; - cur = *i; + return pItem; + cur = pItem;   n = rest;   goto loopstart;   } @@ -200,9 +205,10 @@
   void Directory::print() const  { - for (DirsT::const_iterator i = subdirs_.begin(); i != subdirs_.end(); ++i) + POSITION position = subdirs_.GetHeadPosition(); + while (position != NULL)   { - const Directory* d = *i; + const Directory* d = subdirs_.GetNext(position);   if (!d)   {   ATLTRACE("Directory('%s')::print: error: d is 0\n", (LPCTSTR)path()); @@ -217,10 +223,12 @@
  CString s;   char ctime_res[26];   - for (FilesT::const_iterator i = files_.begin(); i != files_.end(); ++i) + position = files_.GetHeadPosition(); + while (position != NULL)   { - CString p = (!base.IsEmpty() ? base + "/" + i->name : i->name); - t = i->mtime; + const Direntry& rItem = files_.GetNext(position); + CString p = (!base.IsEmpty() ? base + "/" + rItem.name : rItem.name); + t = rItem.mtime;   errno_t err = ctime_s(ctime_res, 26, &t);   if (err == 0) {   s = ctime_res; @@ -229,7 +237,7 @@
  else {   s = "unset";   } - printf("%c %6o %10u %-24s %s\n", i->state, i->mode, i->size, + printf("%c %6o %10u %-24s %s\n", rItem.state, rItem.mode, rItem.size,   (LPCTSTR)s, (LPCTSTR)p);   }  }
 
26
27
28
29
30
31
32
33
34
35
36
37
 
 
38
39
40
 
26
27
28
 
 
 
29
30
31
32
 
 
33
34
35
36
37
@@ -26,15 +26,12 @@
   class Directory  { - typedef std::vector<Directory*> DirsT; - typedef std::vector<Direntry> FilesT; -   Directory* const parent_;   const CString name_;   CString path_;   - DirsT subdirs_; - FilesT files_; + CAtlList<Directory*> subdirs_; + CAtlList<Direntry> files_;    public:   Directory(Directory* p, const CString& n, const CString& basepath);
 
29
30
31
32
 
 
33
34
35
36
 
 
37
38
 
39
40
41
42
43
 
44
45
46
 
58
59
60
61
 
62
63
64
 
75
76
77
78
 
79
80
 
81
82
83
84
 
85
86
87
 
90
91
92
93
94
 
 
95
96
97
98
99
100
101
102
103
104
 
105
106
107
108
109
110
 
111
112
113
114
115
116
 
 
117
118
119
 
120
121
 
122
123
124
125
 
126
127
128
129
130
131
132
 
133
134
135
 
29
30
31
 
32
33
34
 
 
 
35
36
37
 
38
39
40
41
42
 
43
44
45
46
 
58
59
60
 
61
62
63
64
 
75
76
77
 
78
79
 
80
81
82
83
 
84
85
86
87
 
90
91
92
 
 
93
94
95
96
97
98
99
 
100
 
 
 
101
102
103
104
105
106
 
107
108
109
110
111
 
 
112
113
114
 
 
115
116
 
117
118
119
120
 
121
122
123
124
125
126
127
 
128
129
130
131
@@ -29,18 +29,18 @@
    relpath += '/';   - for (V::const_iterator i = v_.begin(); i != v_.end(); ++i) + POSITION position = v_.GetHeadPosition(); + while (position != NULL)   { - const E& e = *i; - if (relpath.IsEmpty() || - e.path_.compare(0, relpath.GetLength(), relpath) == 0) + const E& rEntry = v_.GetNext(position); + if (relpath.IsEmpty() || rEntry.path_.Left(relpath.GetLength()) == relpath)   { - if (e.status_ == 'm' || e.status_ == 'r') + if (rEntry.status_ == 'm' || rEntry.status_ == 'r')   {   modified = true;   break;   } - if (e.status_ == 'a') + if (rEntry.status_ == 'a')   added = true;   }   } @@ -58,7 +58,7 @@
   int DirectoryStatus::read(const CString& hgroot, const CString& cwd)  { - v_.clear(); + v_.RemoveAll();   noicons_ = false;     CString p = hgroot + "\\.hg\\thgstatus"; @@ -75,13 +75,13 @@
  DirectoryStatus::E e;     int res = 1; - const std::string noicons = "@@noicons"; + const CString noicons = "@@noicons";   - std::vector<char> vline(200); + CString line;     for (;;)   { - vline.clear(); + line.Empty();   char t;     for (;;) @@ -90,46 +90,42 @@
  goto close;   if (t == '\n')   break; - vline.push_back(t); - if (vline.size() > 1000) + line.AppendChar(t); + if (line.GetLength() > 1000)   {   res = 0;   goto close;   }   } - vline.push_back(0);   - std::string line = &vline[0]; - - if (line.substr(0, noicons.size()) == noicons) + if (StartsWith(line, noicons))   {   noicons_ = true;   goto close;   }   - if (line.empty()) + if (line.IsEmpty())   goto close;     e.status_ = line[0];   - std::string path; - if (line.size() > 1) + CString path; + if (line.GetLength() > 1)   { - path = line.c_str() + 1; - ::CharLower(const_cast<char*>(path.c_str())); + path = line.Mid(1).MakeLower();   } - path.push_back('/'); + path.AppendChar('/');     e.path_ = path;   - v_.push_back(e); + v_.AddTail(e);   }    close:   fclose(f);     ATLTRACE("DirectoryStatus::read(%d): done. %d entries read. noicons_ = %d\n", - v_.size(), noicons_); + v_.GetCount(), noicons_);     return res;  }
 
14
15
16
17
18
19
20
21
22
23
24
25
 
26
27
28
29
30
31
32
 
33
34
35
 
14
15
16
 
 
 
 
17
18
19
20
 
21
22
23
24
25
26
 
 
27
28
29
30
@@ -14,22 +14,17 @@
 // You should have received a copy of the GNU General Public License  // along with this program. If not, see <http://www.gnu.org/licenses/>.   -#include <string> -#include <vector> - -  class DirectoryStatus  {   struct E   { - std::string path_; + CString path_;   char status_;     E(): status_(0) {}   };   - typedef std::vector<E> V; - V v_; + CAtlList<E> v_;   bool noicons_;    public: