Skip to content

Commit 2f1c235

Browse files
committed
Use C++11 range based loops
1 parent 2119a51 commit 2f1c235

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

amx-deps/src/CFunctions.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ int CFunctions::amxLoad(lua_State *luaVM) {
172172
amx_TimeInit(amx);
173173
amx_FileInit(amx);
174174
err = amx_SAMPInit(amx);
175-
for(map< string, SampPlugin* >::iterator it = loadedPlugins.begin(); it != loadedPlugins.end(); it++) {
176-
AmxLoad_t* pfnAmxLoad = it->second->AmxLoad;
175+
for (const auto& plugin : loadedPlugins) {
176+
AmxLoad_t* pfnAmxLoad = plugin.second->AmxLoad;
177177
if (pfnAmxLoad) {
178178
err = pfnAmxLoad(amx);
179179
}
@@ -206,7 +206,7 @@ int CFunctions::amxLoad(lua_State *luaVM) {
206206
lua_getfield(luaVM, LUA_REGISTRYINDEX, "amx");
207207
lua_getfield(luaVM, -1, resName);
208208
if(lua_isnil(luaVM, -1)) {
209-
lua_newtable(luaVM);
209+
lua_newtable(luaVM);
210210
lua_setfield(luaVM, -3, resName);
211211
}
212212

@@ -278,8 +278,8 @@ int CFunctions::amxCall(lua_State *luaVM) {
278278
cell ret;
279279
int err = amx_Exec(amx, &ret, fnIndex);
280280
// Release string arguments
281-
for(vector<cell>::iterator it = stringsToRelease.begin(); it != stringsToRelease.end(); it++) {
282-
amx_Release(amx, *it);
281+
for (const auto& amxStringAddr : stringsToRelease) {
282+
amx_Release(amx, amxStringAddr);
283283
}
284284
if(err != AMX_ERR_NONE) {
285285
if(err == AMX_ERR_SLEEP)
@@ -365,16 +365,16 @@ int CFunctions::amxUnload(lua_State *luaVM) {
365365
return 1;
366366
}
367367
// Call all plugins' AmxUnload function
368-
for(map< string, SampPlugin* >::iterator piIt = loadedPlugins.begin(); piIt != loadedPlugins.end(); piIt++) {
369-
AmxUnload_t *pfnAmxUnload = piIt->second->AmxUnload;
368+
for (const auto& plugin : loadedPlugins) {
369+
AmxUnload_t *pfnAmxUnload = plugin.second->AmxUnload;
370370
if (pfnAmxUnload) {
371371
pfnAmxUnload(amx);
372372
}
373373
}
374374
// Close any open databases
375375
if(loadedDBs.find(amx) != loadedDBs.end()) {
376-
for(map< int, sqlite3 * >::iterator dbIt = loadedDBs[amx].begin(); dbIt != loadedDBs[amx].end(); dbIt++)
377-
sqlite3_close(dbIt->second);
376+
for (const auto& db : loadedDBs[amx])
377+
sqlite3_close(db.second);
378378
loadedDBs.erase(amx);
379379
}
380380
// Unload
@@ -390,10 +390,10 @@ int CFunctions::amxUnload(lua_State *luaVM) {
390390

391391
// amxUnloadAllPlugins()
392392
int CFunctions::amxUnloadAllPlugins(lua_State *luaVM) {
393-
for (map< string, SampPlugin* >::iterator it = loadedPlugins.begin(); it != loadedPlugins.end(); it++) {
394-
it->second->Unload();
395-
freeLib(it->second->pPluginPointer);
396-
delete it->second;
393+
for (const auto& plugin : loadedPlugins) {
394+
plugin.second->Unload();
395+
freeLib(plugin.second->pPluginPointer);
396+
delete plugin.second;
397397
}
398398
loadedPlugins.clear();
399399
vecPfnProcessTick.clear();
@@ -477,9 +477,9 @@ int CFunctions::pawn(lua_State *luaVM) {
477477

478478
int fnIndex;
479479
AMX *amx = NULL;
480-
for(vector<AMX *>::iterator it = amxs.begin(); it != amxs.end(); it++) {
481-
if(amx_FindPublic(*it, fnName, &fnIndex) == AMX_ERR_NONE) {
482-
amx = *it;
480+
for (const auto& it : amxs) {
481+
if(amx_FindPublic(it, fnName, &fnIndex) == AMX_ERR_NONE) {
482+
amx = it;
483483
break;
484484
}
485485
}

amx-deps/src/ml_base.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ void logprintf(char *fmt, ...) {
116116
int AMXCallPublicFilterScript(char *fnName) {
117117
int fnIndex = -1;
118118
cell ret = 0;
119-
for(map< AMX *, AMXPROPS >::iterator it = loadedAMXs.begin(); it != loadedAMXs.end(); it++) {
120-
if(amx_FindPublic(it->first, "OnFilterScriptInit", &fnIndex) != AMX_ERR_NONE)
119+
for (const auto& it : loadedAMXs) {
120+
if(amx_FindPublic(it.first, "OnFilterScriptInit", &fnIndex) != AMX_ERR_NONE)
121121
continue;
122-
if(amx_FindPublic(it->first, fnName, &fnIndex) != AMX_ERR_NONE)
122+
if(amx_FindPublic(it.first, fnName, &fnIndex) != AMX_ERR_NONE)
123123
continue;
124-
amx_Exec(it->first, &ret, fnIndex);
124+
amx_Exec(it.first, &ret, fnIndex);
125125
return ret;
126126
}
127127
return 0;
@@ -130,12 +130,12 @@ int AMXCallPublicFilterScript(char *fnName) {
130130
int AMXCallPublicGameMode(char *fnName) {
131131
int fnIndex = -1;
132132
cell ret = 0;
133-
for(map< AMX *, AMXPROPS >::iterator it = loadedAMXs.begin(); it != loadedAMXs.end(); it++) {
134-
if(amx_FindPublic(it->first, "OnGameModeInit", &fnIndex) != AMX_ERR_NONE)
133+
for(const auto& it : loadedAMXs) {
134+
if(amx_FindPublic(it.first, "OnGameModeInit", &fnIndex) != AMX_ERR_NONE)
135135
continue;
136-
if(amx_FindPublic(it->first, fnName, &fnIndex) != AMX_ERR_NONE)
136+
if(amx_FindPublic(it.first, fnName, &fnIndex) != AMX_ERR_NONE)
137137
continue;
138-
amx_Exec(it->first, &ret, fnIndex);
138+
amx_Exec(it.first, &ret, fnIndex);
139139
return ret;
140140
}
141141
return 0;

amx-deps/src/util.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ void lua_pushremotevalues(lua_State *localVM, lua_State *remoteVM, int num) {
187187

188188
vector<AMX *> getResourceAMXs(lua_State *luaVM) {
189189
vector<AMX *> amxs;
190-
for(map< AMX *, AMXPROPS >::iterator it = loadedAMXs.begin(); it != loadedAMXs.end(); it++) {
191-
if(it->second.resourceVM == luaVM)
192-
amxs.push_back(it->first);
190+
for (const auto& it : loadedAMXs) {
191+
if (it.second.resourceVM == luaVM)
192+
amxs.push_back(it.first);
193193
}
194194
return amxs;
195195
}

0 commit comments

Comments
 (0)