Ticket #8749: map_iterator.patch
File map_iterator.patch, 13.8 KB (added by , 17 years ago) |
---|
-
gui/eval.cpp
310 310 if (includeAliases) { 311 311 AliasesMap::const_iterator itera = _aliases.find(s); 312 312 if (itera != _aliases.end()) 313 var = &(itera-> _value);313 var = &(itera->second); 314 314 } 315 315 316 316 VariablesMap::const_iterator iterv = _vars.find(*var); 317 317 if (iterv != _vars.end()) 318 return iterv-> _value;318 return iterv->second; 319 319 320 320 return EVAL_UNDEF_VAR; 321 321 } -
gui/launcher.cpp
576 576 const ConfigManager::DomainMap &domains = ConfMan.getGameDomains(); 577 577 ConfigManager::DomainMap::const_iterator iter = domains.begin(); 578 578 for (iter = domains.begin(); iter != domains.end(); ++iter) { 579 String gameid(iter-> _value.get("gameid"));580 String description(iter-> _value.get("description"));579 String gameid(iter->second.get("gameid")); 580 String description(iter->second.get("description")); 581 581 582 582 if (gameid.empty()) 583 gameid = iter-> _key;583 gameid = iter->first; 584 584 if (description.empty()) { 585 585 GameDescriptor g = Base::findGame(gameid); 586 586 if (g.contains("description")) … … 596 596 #endif 597 597 598 598 if (description.empty()) 599 description = "Unknown (target " + iter-> _key+ ", gameid " + gameid + ")";599 description = "Unknown (target " + iter->first + ", gameid " + gameid + ")"; 600 600 601 601 if (!gameid.empty() && !description.empty()) { 602 602 // Insert the game into the launcher list … … 605 605 while (pos < size && (scumm_stricmp(description.c_str(), l[pos].c_str()) > 0)) 606 606 pos++; 607 607 l.insert_at(pos, description); 608 _domains.insert_at(pos, iter-> _key);608 _domains.insert_at(pos, iter->first); 609 609 } 610 610 } 611 611 … … 738 738 739 739 // Copy all non-empty key/value pairs into the new domain 740 740 for (GameDescriptor::const_iterator iter = result.begin(); iter != result.end(); ++iter) { 741 if (!iter-> _value.empty() && iter->_key!= "preferredtarget")742 ConfMan.set(iter-> _key, iter->_value, domain);741 if (!iter->second.empty() && iter->first != "preferredtarget") 742 ConfMan.set(iter->first, iter->second, domain); 743 743 } 744 744 745 745 // TODO: Setting the description field here has the drawback -
engines/agi/detection.cpp
2133 2133 char name[8]; 2134 2134 2135 2135 for (IntMap::const_iterator f = allFiles.begin(); f != allFiles.end(); ++f) { 2136 if (f-> _key.hasSuffix("vol.0")) {2136 if (f->first.hasSuffix("vol.0")) { 2137 2137 memset(name, 0, 8); 2138 strncpy(name, f-> _key.c_str(), MIN((uint)8, f->_key.size() > 5 ? f->_key.size() - 5 : f->_key.size()));2138 strncpy(name, f->first.c_str(), MIN((uint)8, f->first.size() > 5 ? f->first.size() - 5 : f->first.size())); 2139 2139 2140 2140 if (allFiles.contains("object") && allFiles.contains("words.tok") && 2141 2141 allFiles.contains(Common::String(name) + "dir")) { -
common/file.cpp
320 320 // Try all default directories 321 321 StringIntMap::const_iterator x(_defaultDirectories->begin()); 322 322 for (; _handle == NULL && x != _defaultDirectories->end(); ++x) { 323 _handle = fopenNoCase(filename, x-> _key, modeStr);323 _handle = fopenNoCase(filename, x->first, modeStr); 324 324 } 325 325 } 326 326 … … 430 430 if (_defaultDirectories) { 431 431 StringIntMap::const_iterator i(_defaultDirectories->begin()); 432 432 for (; i != _defaultDirectories->end(); ++i) { 433 FilesystemNode file2(i-> _key+ filename);433 FilesystemNode file2(i->first + filename); 434 434 435 435 if(file2.exists()) 436 436 return !file2.isDirectory(); -
common/advancedDetector.cpp
275 275 printf("and its version/language/etc.:\n"); 276 276 277 277 for (StringMap::const_iterator file = filesMD5.begin(); file != filesMD5.end(); ++file) 278 printf(" \"%s\", \"%s\", %d\n", file-> _key.c_str(), file->_value.c_str(), filesSize[file->_key]);278 printf(" \"%s\", \"%s\", %d\n", file->first.c_str(), file->second.c_str(), filesSize[file->first]); 279 279 280 280 printf("\n"); 281 281 } … … 372 372 } else { 373 373 // Get the information of the requested files 374 374 for (StringSet::const_iterator file = filesList.begin(); file != filesList.end(); ++file) { 375 tstr = file-> _key;375 tstr = file->first; 376 376 377 377 debug(3, "+ %s", tstr.c_str()); 378 378 if (!filesMD5.contains(tstr)) { … … 380 380 filesSize[tstr] = (int32)testFile.size(); 381 381 testFile.close(); 382 382 383 if (md5_file_string(file-> _key.c_str(), md5str, params.md5Bytes)) {383 if (md5_file_string(file->first.c_str(), md5str, params.md5Bytes)) { 384 384 filesMD5[tstr] = md5str; 385 385 debug(3, "> %s: %s", tstr.c_str(), md5str); 386 386 } -
common/config-manager.cpp
285 285 if (!_domainSaveOrder.contains(kApplicationDomain)) 286 286 writeDomain(cfg_file, kApplicationDomain, _appDomain); 287 287 for (d = _gameDomains.begin(); d != _gameDomains.end(); ++d) { 288 if (!_domainSaveOrder.contains(d-> _key))289 writeDomain(cfg_file, d-> _key, d->_value);288 if (!_domainSaveOrder.contains(d->first)) 289 writeDomain(cfg_file, d->first, d->second); 290 290 } 291 291 } 292 292 #endif // !__DC__ … … 312 312 // Write all key/value pairs in this domain, including comments 313 313 Domain::const_iterator x; 314 314 for (x = domain.begin(); x != domain.end(); ++x) { 315 if (!x-> _value.empty()) {315 if (!x->second.empty()) { 316 316 // Write comment (if any) 317 if (domain.hasKVComment(x-> _key)) {318 comment = domain.getKVComment(x-> _key);317 if (domain.hasKVComment(x->first)) { 318 comment = domain.getKVComment(x->first); 319 319 stream.writeString(comment); 320 320 } 321 321 // Write the key/value pair 322 stream.writeString(x-> _key);322 stream.writeString(x->first); 323 323 stream.writeByte('='); 324 stream.writeString(x-> _value);324 stream.writeString(x->second); 325 325 stream.writeByte('\n'); 326 326 } 327 327 } … … 632 632 Domain &newDom = _gameDomains[newName]; 633 633 Domain::const_iterator iter; 634 634 for (iter = oldDom.begin(); iter != oldDom.end(); ++iter) 635 newDom[iter-> _key] = iter->_value;635 newDom[iter->first] = iter->second; 636 636 637 637 _gameDomains.erase(oldName); 638 638 } … … 649 649 const String &ConfigManager::Domain::get(const String &key) const { 650 650 const_iterator iter(find(key)); 651 651 if (iter != end()) 652 return iter-> _value;652 return iter->second; 653 653 654 654 #if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__)) 655 655 return String::emptyString; -
common/hashmap.h
85 85 */ 86 86 template <class Key, class Val, class HashFunc = Hash<Key>, class EqualFunc = EqualTo<Key> > 87 87 class HashMap { 88 friend class const_iterator;89 88 private: 90 89 #if defined (PALMOS_MODE) 91 90 public: … … 94 93 typedef HashMap<Key, Val, HashFunc, EqualFunc> HM_t; 95 94 96 95 struct Node { 97 const Key _key;98 Val _value;99 Node(const Key &key) : _key(key) {}96 const Key first; 97 Val second; 98 Node(const Key &key) : first(key), second() {} 100 99 }; 101 100 102 101 Node **_arr; // hashtable of size arrsize. … … 117 116 int lookupAndCreateIfMissing(const Key &key); 118 117 void expand_array(uint newsize); 119 118 120 public: 121 class const_iterator {122 typedef const HashMap<Key, Val, HashFunc, EqualFunc> * 119 template <class NodeType> 120 class Iterator { 121 typedef const HashMap<Key, Val, HashFunc, EqualFunc> *hashmap_t; 123 122 friend class HashMap<Key, Val, HashFunc, EqualFunc>; 124 123 protected: 125 124 uint _idx; 126 125 hashmap_t _hashmap; 127 const_iterator(uint idx, hashmap_t hashmap) : _idx(idx), _hashmap(hashmap) {}126 Iterator(uint idx, hashmap_t hashmap) : _idx(idx), _hashmap(hashmap) {} 128 127 129 const Node *deref() const {128 NodeType *deref() const { 130 129 assert(_hashmap != 0); 131 Node *node = _hashmap->_arr[_idx];130 NodeType *node = _hashmap->_arr[_idx]; 132 131 assert(node != 0); 133 132 return node; 134 133 } 135 134 136 135 public: 137 const_iterator() : _idx(0), _hashmap(0) {} 136 Iterator() : _idx(0), _hashmap(0) {} 137 // HACK: to allow non const/const begin, end and find to work 138 Iterator(const Iterator<Node> &iter) : _idx(iter._idx), _hashmap(iter._hashmap) {} 138 139 139 const Node &operator *() const { return *deref(); } 140 const Node *operator->() const { return deref(); } 141 bool operator ==(const const_iterator &iter) const { return _idx == iter._idx && _hashmap == iter._hashmap; } 142 bool operator !=(const const_iterator &iter) const { return !(*this == iter); } 143 const_iterator operator ++() { 140 NodeType &operator *() const { return *deref(); } 141 NodeType *operator->() const { return deref(); } 142 143 bool operator ==(const Iterator &iter) const { return _idx == iter._idx && _hashmap == iter._hashmap; } 144 bool operator !=(const Iterator &iter) const { return !(*this == iter); } 145 146 Iterator &operator ++() { 144 147 assert(_hashmap); 145 148 do { 146 149 _idx++; … … 150 153 151 154 return *this; 152 155 } 156 157 Iterator operator ++(int) { 158 Iterator old = *this; 159 operator ++(); 160 return old; 161 } 153 162 }; 154 163 164 public: 165 typedef Iterator<Node> iterator; 166 typedef Iterator<const Node> const_iterator; 167 155 168 HashMap(); 156 169 HashMap(const HM_t& map); 157 170 ~HashMap(); … … 183 196 184 197 uint size() const { return _nele; } 185 198 199 iterator begin() { 200 // Find and return the first non-empty entry 201 for (uint ctr = 0; ctr < _arrsize; ++ctr) { 202 if (_arr[ctr]) 203 return iterator(ctr, this); 204 } 205 return end(); 206 } 207 iterator end() { 208 return iterator((uint)-1, this); 209 } 210 186 211 const_iterator begin() const { 187 212 // Find and return the first non-empty entry 188 213 for (uint ctr = 0; ctr < _arrsize; ++ctr) { … … 195 220 return const_iterator((uint)-1, this); 196 221 } 197 222 223 iterator find(const Key &key) { 224 uint ctr = lookup(key); 225 if (_arr[ctr]) 226 return iterator(ctr, this); 227 return end(); 228 } 229 198 230 const_iterator find(const Key &key) const { 199 231 uint ctr = lookup(key); 200 232 if (_arr[ctr]) … … 327 359 // Since we know that no key exists twice in the old table, we 328 360 // can do this slightly better than by calling lookup, since we 329 361 // don't have to call _equal(). 330 dex = _hash(old_arr[ctr]-> _key) % _arrsize;362 dex = _hash(old_arr[ctr]->first) % _arrsize; 331 363 while (_arr[dex] != NULL) { 332 364 dex = (dex + 1) % _arrsize; 333 365 } … … 349 381 int HashMap<Key, Val, HashFunc, EqualFunc>::lookup(const Key &key) const { 350 382 uint ctr = _hash(key) % _arrsize; 351 383 352 while (_arr[ctr] != NULL && !_equal(_arr[ctr]-> _key, key)) {384 while (_arr[ctr] != NULL && !_equal(_arr[ctr]->first, key)) { 353 385 ctr = (ctr + 1) % _arrsize; 354 386 355 387 #ifdef DEBUG_HASH_COLLISIONS … … 406 438 Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) { 407 439 uint ctr = lookupAndCreateIfMissing(key); 408 440 assert(_arr[ctr] != NULL); 409 return _arr[ctr]-> _value;441 return _arr[ctr]->second; 410 442 } 411 443 412 444 template <class Key, class Val, class HashFunc, class EqualFunc> 413 445 const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) const { 414 446 uint ctr = lookup(key); 415 447 if (_arr[ctr] != NULL) 416 return _arr[ctr]-> _value;448 return _arr[ctr]->second; 417 449 else 418 450 return _defaultVal; 419 451 } … … 422 454 void HashMap<Key, Val, HashFunc, EqualFunc>::setVal(const Key &key, const Val &val) { 423 455 uint ctr = lookupAndCreateIfMissing(key); 424 456 assert(_arr[ctr] != NULL); 425 _arr[ctr]-> _value= val;457 _arr[ctr]->second = val; 426 458 } 427 459 428 460 template <class Key, class Val, class HashFunc, class EqualFunc> … … 444 476 break; 445 477 // Compute the slot where the content of the next slot should normally be, 446 478 // assuming an empty table, and check whether we have to move it. 447 uint k = _hash(_arr[j]-> _key) % _arrsize;479 uint k = _hash(_arr[j]->first) % _arrsize; 448 480 if ((j > i && (k <= i || k > j)) || 449 481 (j < i && (k <= i && k > j)) ) { 450 482 _arr[i] = _arr[j]; -
base/commandLine.cpp
571 571 const ConfigManager::DomainMap &domains = ConfMan.getGameDomains(); 572 572 ConfigManager::DomainMap::const_iterator iter = domains.begin(); 573 573 for (iter = domains.begin(); iter != domains.end(); ++iter) { 574 Common::String name(iter-> _key);575 Common::String description(iter-> _value.get("description"));574 Common::String name(iter->first); 575 Common::String description(iter->second.get("description")); 576 576 577 577 if (description.empty()) { 578 578 // FIXME: At this point, we should check for a "gameid" override … … 599 599 Common::ConfigManager::DomainMap::const_iterator iter = domains.begin(); 600 600 int success = 0, failure = 0; 601 601 for (iter = domains.begin(); iter != domains.end(); ++iter) { 602 Common::String name(iter-> _key);603 Common::String gameid(iter-> _value.get("gameid"));604 Common::String path(iter-> _value.get("path"));602 Common::String name(iter->first); 603 Common::String gameid(iter->second.get("gameid")); 604 Common::String path(iter->second.get("path")); 605 605 printf("Looking at target '%s', gameid '%s', path '%s' ...\n", 606 606 name.c_str(), gameid.c_str(), path.c_str()); 607 607 if (path.empty()) { … … 739 739 740 740 // Finally, store the command line settings into the config manager. 741 741 for (Common::StringMap::const_iterator x = settings.begin(); x != settings.end(); ++x) { 742 Common::String key(x-> _key);743 Common::String value(x-> _value);742 Common::String key(x->first); 743 Common::String value(x->second); 744 744 745 745 // Replace any "-" in the key by "_" (e.g. change "save-slot" to "save_slot"). 746 746 for (Common::String::iterator c = key.begin(); c != key.end(); ++c)